Blender  V3.3
scene/curves.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Copyright 2011-2022 Blender Foundation */
3 
4 #include "scene/curves.h"
5 #include "device/device.h"
6 #include "scene/mesh.h"
7 #include "scene/object.h"
8 #include "scene/scene.h"
9 
10 #include "util/foreach.h"
11 #include "util/map.h"
12 #include "util/progress.h"
13 #include "util/vector.h"
14 
16 
17 /* Curve functions */
18 
19 void curvebounds(float *lower, float *upper, float3 *p, int dim)
20 {
21  float *p0 = &p[0].x;
22  float *p1 = &p[1].x;
23  float *p2 = &p[2].x;
24  float *p3 = &p[3].x;
25 
26  /* Catmull-Rom weights. */
27  float curve_coef[4];
28  curve_coef[0] = p1[dim];
29  curve_coef[1] = 0.5f * (-p0[dim] + p2[dim]);
30  curve_coef[2] = 0.5f * (2 * p0[dim] - 5 * p1[dim] + 4 * p2[dim] - p3[dim]);
31  curve_coef[3] = 0.5f * (-p0[dim] + 3 * p1[dim] - 3 * p2[dim] + p3[dim]);
32 
33  float discroot = curve_coef[2] * curve_coef[2] - 3 * curve_coef[3] * curve_coef[1];
34  float ta = -1.0f;
35  float tb = -1.0f;
36 
37  if (discroot >= 0) {
38  discroot = sqrtf(discroot);
39  ta = (-curve_coef[2] - discroot) / (3 * curve_coef[3]);
40  tb = (-curve_coef[2] + discroot) / (3 * curve_coef[3]);
41  ta = (ta > 1.0f || ta < 0.0f) ? -1.0f : ta;
42  tb = (tb > 1.0f || tb < 0.0f) ? -1.0f : tb;
43  }
44 
45  *upper = max(p1[dim], p2[dim]);
46  *lower = min(p1[dim], p2[dim]);
47 
48  float exa = p1[dim];
49  float exb = p2[dim];
50 
51  if (ta >= 0.0f) {
52  float t2 = ta * ta;
53  float t3 = t2 * ta;
54  exa = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * ta + curve_coef[0];
55  }
56  if (tb >= 0.0f) {
57  float t2 = tb * tb;
58  float t3 = t2 * tb;
59  exb = curve_coef[3] * t3 + curve_coef[2] * t2 + curve_coef[1] * tb + curve_coef[0];
60  }
61 
62  *upper = max(*upper, max(exa, exb));
63  *lower = min(*lower, min(exa, exb));
64 }
65 
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
#define sqrtf(x)
Definition: metal/compat.h:243
CCL_NAMESPACE_BEGIN void curvebounds(float *lower, float *upper, float3 *p, int dim)
#define min(a, b)
Definition: sort.c:35
float x
float max