Blender  V3.3
CCGSubSurf_inline.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #pragma once
8 
9 BLI_INLINE int ccg_gridsize(int level)
10 {
11  BLI_assert(level > 0);
12  BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
13  return (1 << (level - 1)) + 1;
14 }
15 
16 BLI_INLINE int ccg_edgesize(int level)
17 {
18  BLI_assert(level > 0);
19  BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
20  return 1 + (1 << level);
21 }
22 
23 BLI_INLINE int ccg_spacing(int high_level, int low_level)
24 {
25  BLI_assert(high_level > 0 && low_level > 0);
26  BLI_assert(high_level >= low_level);
27  BLI_assert((high_level - low_level) <= CCGSUBSURF_LEVEL_MAX);
28  return 1 << (high_level - low_level);
29 }
30 
31 BLI_INLINE int ccg_edgebase(int level)
32 {
33  BLI_assert(level > 0);
34  BLI_assert(level <= CCGSUBSURF_LEVEL_MAX + 1);
35  return level + (1 << level) - 1;
36 }
37 
38 /* **** */
39 
41 {
42  return (byte *)(&(v)[1]);
43 }
44 
46 {
47  return (byte *)(&(e)[1]);
48 }
49 
51 {
52  return (CCGVert **)(&f[1]);
53 }
54 
56 {
57  return (CCGEdge **)(&(FACE_getVerts(f)[f->numVerts]));
58 }
59 
61 {
62  return (byte *)(&(FACE_getEdges(f)[(f)->numVerts]));
63 }
64 
65 /* **** */
66 
67 BLI_INLINE void *ccg_vert_getCo(CCGVert *v, int lvl, int dataSize)
68 {
69  return &VERT_getLevelData(v)[lvl * dataSize];
70 }
71 
72 BLI_INLINE float *ccg_vert_getNo(CCGVert *v, int lvl, int dataSize, int normalDataOffset)
73 {
74  return (float *)&VERT_getLevelData(v)[lvl * dataSize + normalDataOffset];
75 }
76 
77 BLI_INLINE void *ccg_edge_getCo(CCGEdge *e, int lvl, int x, int dataSize)
78 {
79  int levelBase = ccg_edgebase(lvl);
80  return &EDGE_getLevelData(e)[dataSize * (levelBase + x)];
81 }
82 
83 BLI_INLINE float *ccg_edge_getNo(CCGEdge *e, int lvl, int x, int dataSize, int normalDataOffset)
84 {
85  int levelBase = ccg_edgebase(lvl);
86  return (float *)&EDGE_getLevelData(e)[dataSize * (levelBase + x) + normalDataOffset];
87 }
88 
89 BLI_INLINE void *ccg_face_getIECo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize)
90 {
91  int maxGridSize = ccg_gridsize(levels);
92  int spacing = ccg_spacing(levels, lvl);
93  byte *gridBase = FACE_getCenterData(f) +
94  dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
95  return &gridBase[dataSize * x * spacing];
96 }
97 
99  CCGFace *f, int lvl, int S, int x, int levels, int dataSize, int normalDataOffset)
100 {
101  int maxGridSize = ccg_gridsize(levels);
102  int spacing = ccg_spacing(levels, lvl);
103  byte *gridBase = FACE_getCenterData(f) +
104  dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
105  return &gridBase[dataSize * x * spacing + normalDataOffset];
106 }
107 
109  CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize)
110 {
111  int maxGridSize = ccg_gridsize(levels);
112  int spacing = ccg_spacing(levels, lvl);
113  byte *gridBase = FACE_getCenterData(f) +
114  dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
115  return &gridBase[dataSize * (maxGridSize + (y * maxGridSize + x) * spacing)];
116 }
117 
119  CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize, int normalDataOffset)
120 {
121  int maxGridSize = ccg_gridsize(levels);
122  int spacing = ccg_spacing(levels, lvl);
123  byte *gridBase = FACE_getCenterData(f) +
124  dataSize * (1 + S * (maxGridSize + maxGridSize * maxGridSize));
125  return (float *)&gridBase[dataSize * (maxGridSize + (y * maxGridSize + x) * spacing) +
126  normalDataOffset];
127 }
128 
130 {
131  for (int i = 0; i < f->numVerts; i++) {
132  if (FACE_getVerts(f)[i] == v) {
133  return i;
134  }
135  }
136  return -1;
137 }
138 
140 {
141  for (int i = 0; i < f->numVerts; i++) {
142  if (FACE_getEdges(f)[i] == e) {
143  return i;
144  }
145  }
146  return -1;
147 }
148 
150  CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, int eX, int eY, int levels, int dataSize)
151 {
152  int maxGridSize = ccg_gridsize(levels);
153  int spacing = ccg_spacing(levels, lvl);
154  int x, y, cx, cy;
155 
156  BLI_assert(f_ed_idx == ccg_face_getEdgeIndex(f, e));
157 
158  eX = eX * spacing;
159  eY = eY * spacing;
160  if (e->v0 != FACE_getVerts(f)[f_ed_idx]) {
161  eX = (maxGridSize * 2 - 1) - 1 - eX;
162  }
163  y = maxGridSize - 1 - eX;
164  x = maxGridSize - 1 - eY;
165  if (x < 0) {
166  f_ed_idx = (f_ed_idx + f->numVerts - 1) % f->numVerts;
167  cx = y;
168  cy = -x;
169  }
170  else if (y < 0) {
171  f_ed_idx = (f_ed_idx + 1) % f->numVerts;
172  cx = -y;
173  cy = x;
174  }
175  else {
176  cx = x;
177  cy = y;
178  }
179  return ccg_face_getIFCo(f, levels, f_ed_idx, cx, cy, levels, dataSize);
180 }
181 
182 BLI_INLINE void Normalize(float no[3])
183 {
184  const float length = sqrtf(no[0] * no[0] + no[1] * no[1] + no[2] * no[2]);
185 
186  if (length > EPSILON) {
187  const float length_inv = 1.0f / length;
188 
189  no[0] *= length_inv;
190  no[1] *= length_inv;
191  no[2] *= length_inv;
192  }
193  else {
194  NormZero(no);
195  }
196 }
197 
198 /* Data layers mathematics. */
199 
200 BLI_INLINE bool VertDataEqual(const float a[], const float b[], const CCGSubSurf *ss)
201 {
202  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
203  if (a[i] != b[i]) {
204  return false;
205  }
206  }
207  return true;
208 }
209 
210 BLI_INLINE void VertDataZero(float v[], const CCGSubSurf *ss)
211 {
212  memset(v, 0, sizeof(float) * ss->meshIFC.numLayers);
213 }
214 
215 BLI_INLINE void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss)
216 {
217  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
218  dst[i] = src[i];
219  }
220 }
221 
222 BLI_INLINE void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss)
223 {
224  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
225  a[i] += b[i];
226  }
227 }
228 
229 BLI_INLINE void VertDataSub(float a[], const float b[], const CCGSubSurf *ss)
230 {
231  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
232  a[i] -= b[i];
233  }
234 }
235 
236 BLI_INLINE void VertDataMulN(float v[], float f, const CCGSubSurf *ss)
237 {
238  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
239  v[i] *= f;
240  }
241 }
242 
243 BLI_INLINE void VertDataAvg4(float v[],
244  const float a[],
245  const float b[],
246  const float c[],
247  const float d[],
248  const CCGSubSurf *ss)
249 {
250  for (int i = 0; i < ss->meshIFC.numLayers; i++) {
251  v[i] = (a[i] + b[i] + c[i] + d[i]) * 0.25f;
252  }
253 }
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define BLI_INLINE
BLI_INLINE void * ccg_face_getIENo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize, int normalDataOffset)
BLI_INLINE int ccg_edgesize(int level)
BLI_INLINE void Normalize(float no[3])
BLI_INLINE void * ccg_face_getIECo(CCGFace *f, int lvl, int S, int x, int levels, int dataSize)
BLI_INLINE float * ccg_vert_getNo(CCGVert *v, int lvl, int dataSize, int normalDataOffset)
BLI_INLINE int ccg_gridsize(int level)
BLI_INLINE float * ccg_face_getIFNo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize, int normalDataOffset)
BLI_INLINE void VertDataZero(float v[], const CCGSubSurf *ss)
BLI_INLINE void * ccg_face_getIFCo(CCGFace *f, int lvl, int S, int x, int y, int levels, int dataSize)
BLI_INLINE bool VertDataEqual(const float a[], const float b[], const CCGSubSurf *ss)
BLI_INLINE void * ccg_vert_getCo(CCGVert *v, int lvl, int dataSize)
BLI_INLINE int ccg_edgebase(int level)
BLI_INLINE int ccg_face_getEdgeIndex(CCGFace *f, CCGEdge *e)
BLI_INLINE int ccg_spacing(int high_level, int low_level)
BLI_INLINE void * ccg_edge_getCo(CCGEdge *e, int lvl, int x, int dataSize)
BLI_INLINE void VertDataSub(float a[], const float b[], const CCGSubSurf *ss)
BLI_INLINE void VertDataCopy(float dst[], const float src[], const CCGSubSurf *ss)
BLI_INLINE int ccg_face_getVertIndex(CCGFace *f, CCGVert *v)
BLI_INLINE byte * VERT_getLevelData(CCGVert *v)
BLI_INLINE byte * FACE_getCenterData(CCGFace *f)
BLI_INLINE CCGEdge ** FACE_getEdges(CCGFace *f)
BLI_INLINE void * ccg_face_getIFCoEdge(CCGFace *f, CCGEdge *e, int f_ed_idx, int lvl, int eX, int eY, int levels, int dataSize)
BLI_INLINE void VertDataMulN(float v[], float f, const CCGSubSurf *ss)
BLI_INLINE CCGVert ** FACE_getVerts(CCGFace *f)
BLI_INLINE float * ccg_edge_getNo(CCGEdge *e, int lvl, int x, int dataSize, int normalDataOffset)
BLI_INLINE void VertDataAvg4(float v[], const float a[], const float b[], const float c[], const float d[], const CCGSubSurf *ss)
BLI_INLINE void VertDataAdd(float a[], const float b[], const CCGSubSurf *ss)
BLI_INLINE byte * EDGE_getLevelData(CCGEdge *e)
#define EPSILON
#define NormZero(av)
#define CCGSUBSURF_LEVEL_MAX
_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 y
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
SyclQueue void void * src
#define sqrtf(x)
Definition: metal/compat.h:243
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
T length(const vec_base< T, Size > &a)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
int numLayers
Definition: CCGSubSurf.h:21
CCGMeshIFC meshIFC