Blender  V2.93
curves.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "render/curves.h"
18 #include "device/device.h"
19 #include "render/mesh.h"
20 #include "render/object.h"
21 #include "render/scene.h"
22 
23 #include "util/util_foreach.h"
24 #include "util/util_map.h"
25 #include "util/util_progress.h"
26 #include "util/util_vector.h"
27 
29 
30 /* Curve functions */
31 
32 void curvebounds(float *lower, float *upper, float3 *p, int dim)
33 {
34  float *p0 = &p[0].x;
35  float *p1 = &p[1].x;
36  float *p2 = &p[2].x;
37  float *p3 = &p[3].x;
38 
39  /* Catmull-Rom weights. */
40  float curve_coef[4];
41  curve_coef[0] = p1[dim];
42  curve_coef[1] = 0.5f * (-p0[dim] + p2[dim]);
43  curve_coef[2] = 0.5f * (2 * p0[dim] - 5 * p1[dim] + 4 * p2[dim] - p3[dim]);
44  curve_coef[3] = 0.5f * (-p0[dim] + 3 * p1[dim] - 3 * p2[dim] + p3[dim]);
45 
46  float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
47  float ta = -1.0f;
48  float tb = -1.0f;
49 
50  if (discroot >= 0) {
51  discroot = sqrtf(discroot);
52  ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
53  tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
54  ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
55  tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
56  }
57 
58  *upper = max(p1[dim], p2[dim]);
59  *lower = min(p1[dim], p2[dim]);
60 
61  float exa = p1[dim];
62  float exb = p2[dim];
63 
64  if (ta >= 0.0f) {
65  float t2 = ta * ta;
66  float t3 = t2 * ta;
67  exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
68  }
69  if (tb >= 0.0f) {
70  float t2 = tb * tb;
71  float t3 = t2 * tb;
72  exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
73  }
74 
75  *upper = max(*upper, max(exa, exb));
76  *lower = min(*lower, min(exa, exb));
77 }
78 
CCL_NAMESPACE_BEGIN void curvebounds(float *lower, float *upper, float3 *p, int dim)
Definition: curves.cpp:32
#define CCL_NAMESPACE_END
#define sqrtf(x)
#define min(a, b)
Definition: sort.c:51
float x
Definition: sky_float3.h:35
float max