Blender  V3.3
quadric.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
19 #include "BLI_math.h"
20 #include "BLI_strict_flags.h"
21 
22 #include "BLI_quadric.h" /* own include */
23 
24 #define QUADRIC_FLT_TOT (sizeof(Quadric) / sizeof(double))
25 
26 void BLI_quadric_from_plane(Quadric *q, const double v[4])
27 {
28  q->a2 = v[0] * v[0];
29  q->b2 = v[1] * v[1];
30  q->c2 = v[2] * v[2];
31 
32  q->ab = v[0] * v[1];
33  q->ac = v[0] * v[2];
34  q->bc = v[1] * v[2];
35 
36  q->ad = v[0] * v[3];
37  q->bd = v[1] * v[3];
38  q->cd = v[2] * v[3];
39 
40  q->d2 = v[3] * v[3];
41 }
42 
43 #if 0 /* UNUSED */
44 
45 static void quadric_to_tensor_m3(const Quadric *q, double m[3][3])
46 {
47  m[0][0] = q->a2;
48  m[0][1] = q->ab;
49  m[0][2] = q->ac;
50 
51  m[1][0] = q->ab;
52  m[1][1] = q->b2;
53  m[1][2] = q->bc;
54 
55  m[2][0] = q->ac;
56  m[2][1] = q->bc;
57  m[2][2] = q->c2;
58 }
59 
60 #endif
61 
71 static bool quadric_to_tensor_m3_inverse(const Quadric *q, double m[3][3], double epsilon)
72 {
73  const double det = (q->a2 * (q->b2 * q->c2 - q->bc * q->bc) -
74  q->ab * (q->ab * q->c2 - q->ac * q->bc) +
75  q->ac * (q->ab * q->bc - q->ac * q->b2));
76 
77  if (fabs(det) > epsilon) {
78  const double invdet = 1.0 / det;
79 
80  m[0][0] = (q->b2 * q->c2 - q->bc * q->bc) * invdet;
81  m[1][0] = (q->bc * q->ac - q->ab * q->c2) * invdet;
82  m[2][0] = (q->ab * q->bc - q->b2 * q->ac) * invdet;
83 
84  m[0][1] = (q->ac * q->bc - q->ab * q->c2) * invdet;
85  m[1][1] = (q->a2 * q->c2 - q->ac * q->ac) * invdet;
86  m[2][1] = (q->ab * q->ac - q->a2 * q->bc) * invdet;
87 
88  m[0][2] = (q->ab * q->bc - q->ac * q->b2) * invdet;
89  m[1][2] = (q->ac * q->ab - q->a2 * q->bc) * invdet;
90  m[2][2] = (q->a2 * q->b2 - q->ab * q->ab) * invdet;
91 
92  return true;
93  }
94 
95  return false;
96 }
97 
98 void BLI_quadric_to_vector_v3(const Quadric *q, double v[3])
99 {
100  v[0] = q->ad;
101  v[1] = q->bd;
102  v[2] = q->cd;
103 }
104 
106 {
107  memset(q, 0, sizeof(*q));
108 }
109 
111 {
112  add_vn_vn_d((double *)a, (double *)b, QUADRIC_FLT_TOT);
113 }
114 
116 {
117  add_vn_vnvn_d((double *)r, (const double *)a, (const double *)b, QUADRIC_FLT_TOT);
118 }
119 
120 void BLI_quadric_mul(Quadric *a, const double scalar)
121 {
122  mul_vn_db((double *)a, QUADRIC_FLT_TOT, scalar);
123 }
124 
125 double BLI_quadric_evaluate(const Quadric *q, const double v[3])
126 {
127  const double v00 = v[0] * v[0], v01 = v[0] * v[1], v02 = v[0] * v[2];
128  const double v11 = v[1] * v[1], v12 = v[1] * v[2];
129  const double v22 = v[2] * v[2];
130  return ((q->a2 * v00) + (q->ab * 2 * v01) + (q->ac * 2 * v02) + (q->ad * 2 * v[0]) + /* a */
131  (q->b2 * v11) + (q->bc * 2 * v12) + (q->bd * 2 * v[1]) + /* b */
132  (q->c2 * v22) + (q->cd * 2 * v[2]) + /* c */
133  (q->d2) /* d */
134  );
135 }
136 
137 bool BLI_quadric_optimize(const Quadric *q, double v[3], const double epsilon)
138 {
139  double m[3][3];
140 
143  mul_m3_v3_db(m, v);
144  negate_v3_db(v);
145  return true;
146  }
147 
148  return false;
149 }
void mul_m3_v3_db(const double M[3][3], double r[3])
Definition: math_matrix.c:931
void add_vn_vnvn_d(double *array_tar, const double *array_src_a, const double *array_src_b, int size)
Definition: math_vector.c:1282
MINLINE void negate_v3_db(double r[3])
void add_vn_vn_d(double *array_tar, const double *array_src, int size)
Definition: math_vector.c:1272
void mul_vn_db(double *array_tar, int size, double f)
Definition: math_vector.c:1296
Strict compiler flags for areas of code we want to ensure don't do conversions without us knowing abo...
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble GLdouble r _GL_VOID_RET _GL_VOID GLfloat GLfloat r _GL_VOID_RET _GL_VOID GLint GLint r _GL_VOID_RET _GL_VOID GLshort GLshort r _GL_VOID_RET _GL_VOID GLdouble GLdouble r
ATTR_WARN_UNUSED_RESULT const BMVert * v
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
static unsigned a[3]
Definition: RandGen.cpp:78
static double epsilon
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
void BLI_quadric_mul(Quadric *a, const double scalar)
Definition: quadric.c:120
bool BLI_quadric_optimize(const Quadric *q, double v[3], const double epsilon)
Definition: quadric.c:137
void BLI_quadric_from_plane(Quadric *q, const double v[4])
Definition: quadric.c:26
#define QUADRIC_FLT_TOT
Definition: quadric.c:24
void BLI_quadric_to_vector_v3(const Quadric *q, double v[3])
Definition: quadric.c:98
static bool quadric_to_tensor_m3_inverse(const Quadric *q, double m[3][3], double epsilon)
Definition: quadric.c:71
double BLI_quadric_evaluate(const Quadric *q, const double v[3])
Definition: quadric.c:125
void BLI_quadric_add_qu_qu(Quadric *a, const Quadric *b)
Definition: quadric.c:110
void BLI_quadric_clear(Quadric *q)
Definition: quadric.c:105
void BLI_quadric_add_qu_ququ(Quadric *r, const Quadric *a, const Quadric *b)
Definition: quadric.c:115
double cd
Definition: BLI_quadric.h:15
double d2
Definition: BLI_quadric.h:15
double bd
Definition: BLI_quadric.h:15
double c2
Definition: BLI_quadric.h:15
double bc
Definition: BLI_quadric.h:15
double ab
Definition: BLI_quadric.h:15
double ad
Definition: BLI_quadric.h:15
double ac
Definition: BLI_quadric.h:15
double a2
Definition: BLI_quadric.h:15
double b2
Definition: BLI_quadric.h:15