OpenSubdiv
Loading...
Searching...
No Matches
surface.h
Go to the documentation of this file.
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7
8#ifndef OPENSUBDIV3_BFR_SURFACE_H
9#define OPENSUBDIV3_BFR_SURFACE_H
10
11#include "../version.h"
12
13#include "../bfr/surfaceData.h"
15#include "../vtr/array.h"
16
17namespace OpenSubdiv {
18namespace OPENSUBDIV_VERSION {
19
20namespace Bfr {
21
41template <typename REAL>
42class Surface {
43public:
48 PointDescriptor(int n) : size(n), stride(n) { }
49 PointDescriptor(int n, int m) : size(n), stride(m) { }
50
52 };
53
55 typedef int Index;
56
57public:
59
67
69 bool IsValid() const { return _data.isValid(); }
70
72 void Clear() { _data.reinitialize(); }
73
76
77 Surface(Surface const & src) = default;
78 Surface& operator=(Surface const & src) = default;
79 ~Surface() = default;
81
83
87
89 Parameterization GetParameterization() const { return _data.getParam(); }
90
92 int GetFaceSize() const { return GetParameterization().GetFaceSize(); }
93
95 bool IsRegular() const { return _data.isRegular(); }
96
98 bool IsLinear() const { return _data.isLinear(); }
100
102
118
120 int GetNumControlPoints() const { return _data.getNumCVs(); }
121
123 int GetControlPointIndices(Index meshPointIndices[]) const;
124
134 template <typename REAL_MESH>
135 void GatherControlPoints(REAL_MESH const meshPoints[],
136 PointDescriptor const & meshPointDesc,
137 REAL controlPoints[],
138 PointDescriptor const & controlPointDesc) const;
139
141 void BoundControlPoints(REAL const controlPoints[],
142 PointDescriptor const & controlPointDesc,
143 REAL minExtent[],
144 REAL maxExtent[]) const;
145
147 void BoundControlPointsFromMesh(REAL const meshPoints[],
148 PointDescriptor const & meshPointDesc,
149 REAL minExtent[],
150 REAL maxExtent[]) const;
152
154
160
162 int GetNumPatchPoints() const;
163
182 void PreparePatchPoints(REAL const meshPoints[],
183 PointDescriptor const & meshPointDesc,
184 REAL patchPoints[],
185 PointDescriptor const & patchPointDesc) const;
186
196 void ComputePatchPoints(REAL patchPoints[],
197 PointDescriptor const & patchPointDesc) const;
199
201
208
210 void Evaluate(REAL const uv[2],
211 REAL const patchPoints[], PointDescriptor const & pointDesc,
212 REAL P[]) const;
213
215 void Evaluate(REAL const uv[2],
216 REAL const patchPoints[], PointDescriptor const & pointDesc,
217 REAL P[], REAL Du[], REAL Dv[]) const;
218
220 void Evaluate(REAL const uv[2],
221 REAL const patchPoints[], PointDescriptor const & pointDesc,
222 REAL P[], REAL Du[], REAL Dv[],
223 REAL Duu[], REAL Duv[], REAL Dvv[]) const;
225
227
239
241 int EvaluateStencil(REAL const uv[2], REAL sP[]) const;
242
244 int EvaluateStencil(REAL const uv[2], REAL sP[],
245 REAL sDu[], REAL sDv[]) const;
246
248 int EvaluateStencil(REAL const uv[2], REAL sP[],
249 REAL sDu[], REAL sDv[],
250 REAL sDuu[], REAL sDuv[], REAL sDvv[]) const;
251
253 void ApplyStencil(REAL const stencil[],
254 REAL const controlPoints[], PointDescriptor const &,
255 REAL result[]) const;
256
258 void ApplyStencilFromMesh(REAL const stencil[],
259 REAL const meshPoints[], PointDescriptor const &,
260 REAL result[]) const;
262
263private:
264 // Internal methods for evaluating derivatives, basis weights and
265 // stencils for regular, irregular and irregular linear patches:
267
268 void evaluateDerivs(REAL const uv[2], REAL const patchPoints[],
269 PointDescriptor const &, REAL * derivs[]) const;
270 void evalRegularDerivs(REAL const uv[2], REAL const patchPoints[],
271 PointDescriptor const &, REAL * derivs[]) const;
272 void evalIrregularDerivs(REAL const uv[2], REAL const patchPoints[],
273 PointDescriptor const &, REAL * derivs[]) const;
274 void evalMultiLinearDerivs(REAL const uv[2], REAL const patchPoints[],
275 PointDescriptor const &, REAL * derivs[]) const;
276
277 void evalRegularBasis(REAL const uv[2], REAL * wDeriv[]) const;
278 IndexArray evalIrregularBasis(REAL const uv[2], REAL * wDeriv[]) const;
279 int evalMultiLinearBasis(REAL const uv[2], REAL * wDeriv[]) const;
280
281 int evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const;
282 int evalRegularStencils(REAL const uv[2], REAL * sDeriv[]) const;
283 int evalIrregularStencils(REAL const uv[2], REAL * sDeriv[]) const;
284 int evalMultiLinearStencils(REAL const uv[2], REAL * sDeriv[]) const;
285
286 // Internal methods to compute patch points:
287 void computeLinearPatchPoints(REAL p[], PointDescriptor const &) const;
288 void computeIrregularPatchPoints(REAL p[], PointDescriptor const &) const;
289
290 // Internal methods specific to regular or irregular patches:
291 unsigned char getRegPatchType() const { return _data.getRegPatchType(); }
292 unsigned char getRegPatchMask() const { return _data.getRegPatchMask(); }
293
294 internal::IrregularPatchType const & getIrregPatch() const;
295
296private:
297 // Access to the set of member variables - provided to the Factory:
298 friend class SurfaceFactory;
299
300 internal::SurfaceData & getSurfaceData() { return _data; }
301 internal::SurfaceData const & getSurfaceData() const { return _data; }
302
303private:
304 // All member variables encapsulated in a single class:
305 internal::SurfaceData _data;
306};
307
308
309//
310// Simple inline methods composed of other methods:
311//
312template <typename REAL>
313inline void
315 PointDescriptor const & pointDesc) const {
316
317 if (!IsRegular()) {
318 if (IsLinear()) {
319 computeLinearPatchPoints(points, pointDesc);
320 } else {
321 computeIrregularPatchPoints(points, pointDesc);
322 }
323 }
324}
325
326template <typename REAL>
327inline void
329 REAL const meshPoints[], PointDescriptor const & meshPointDesc,
330 REAL patchPoints[], PointDescriptor const & patchPointDesc) const {
331
332 GatherControlPoints(meshPoints, meshPointDesc, patchPoints, patchPointDesc);
333 ComputePatchPoints(patchPoints, patchPointDesc);
334}
335
336//
337// Inline invocations of more general methods for derivative overloads:
338//
339template <typename REAL>
340inline void
341Surface<REAL>::evaluateDerivs(REAL const uv[2],
342 REAL const patchPoints[],
343 PointDescriptor const & pointDesc,
344 REAL * derivatives[]) const {
345 if (IsRegular()) {
346 evalRegularDerivs(uv, patchPoints, pointDesc, derivatives);
347 } else if (IsLinear()) {
348 evalMultiLinearDerivs(uv, patchPoints, pointDesc, derivatives);
349 } else {
350 evalIrregularDerivs(uv, patchPoints, pointDesc, derivatives);
351 }
352}
353template <typename REAL>
354inline void
355Surface<REAL>::Evaluate(REAL const uv[2],
356 REAL const patchPoints[],
357 PointDescriptor const & pointDesc,
358 REAL P[]) const {
359
360 REAL * derivatives[6] = { P, 0, 0, 0, 0, 0 };
361 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
362}
363template <typename REAL>
364inline void
365Surface<REAL>::Evaluate(REAL const uv[2],
366 REAL const patchPoints[],
367 PointDescriptor const & pointDesc,
368 REAL P[], REAL Du[], REAL Dv[]) const {
369
370 REAL * derivatives[6] = { P, Du, Dv, 0, 0, 0 };
371 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
372}
373template <typename REAL>
374inline void
375Surface<REAL>::Evaluate(REAL const uv[2],
376 REAL const patchPoints[],
377 PointDescriptor const & pointDesc,
378 REAL P[], REAL Du[], REAL Dv[],
379 REAL Duu[], REAL Duv[], REAL Dvv[]) const {
380
381 REAL * derivatives[6] = { P, Du, Dv, Duu, Duv, Dvv };
382 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
383}
384
385template <typename REAL>
386inline int
387Surface<REAL>::evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const {
388
389 if (IsRegular()) {
390 return evalRegularStencils(uv, sDeriv);
391 } else if (IsLinear()) {
392 return evalMultiLinearStencils(uv, sDeriv);
393 } else {
394 return evalIrregularStencils(uv, sDeriv);
395 }
396}
397template <typename REAL>
398inline int
399Surface<REAL>::EvaluateStencil(REAL const uv[2], REAL sP[]) const {
400
401 REAL * derivativeStencils[6] = { sP, 0, 0, 0, 0, 0 };
402 return evaluateStencils(uv, derivativeStencils);
403}
404template <typename REAL>
405inline int
407 REAL sP[], REAL sDu[], REAL sDv[]) const {
408
409 REAL * derivativeStencils[6] = { sP, sDu, sDv, 0, 0, 0 };
410 return evaluateStencils(uv, derivativeStencils);
411}
412template <typename REAL>
413inline int
415 REAL sP[], REAL sDu[], REAL sDv[],
416 REAL sDuu[], REAL sDuv[], REAL sDvv[]) const {
417
418 REAL * derivativeStencils[6] = { sP, sDu, sDv, sDuu, sDuv, sDvv };
419 return evaluateStencils(uv, derivativeStencils);
420}
421
422} // end namespace Bfr
423
424} // end namespace OPENSUBDIV_VERSION
425using namespace OPENSUBDIV_VERSION;
426
427} // end namespace OpenSubdiv
428
429#endif /* OPENSUBDIV3_BFR_SURFACE */
Simple class defining the 2D parameterization of a face.
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Encapsulates the limit surface for a face of a mesh.
Definition surface.h:42
int Index
Integer type representing a mesh index.
Definition surface.h:55
int GetNumControlPoints() const
Return the number of control points affecting the Surface.
Definition surface.h:120
void Evaluate(REAL const uv[2], REAL const patchPoints[], PointDescriptor const &pointDesc, REAL P[]) const
Evaluation of position.
Definition surface.h:355
int GetFaceSize() const
Return the size of the face.
Definition surface.h:92
bool IsRegular() const
Return if the Surface is a single regular patch.
Definition surface.h:95
void BoundControlPoints(REAL const controlPoints[], PointDescriptor const &controlPointDesc, REAL minExtent[], REAL maxExtent[]) const
Compute bounds of control points from a local array.
int GetControlPointIndices(Index meshPointIndices[]) const
Identify indices of control points in the mesh.
void ApplyStencil(REAL const stencil[], REAL const controlPoints[], PointDescriptor const &, REAL result[]) const
Apply a single stencil to control points from a local array.
Parameterization GetParameterization() const
Return the Parameterization.
Definition surface.h:89
Surface()
Default construction produces an invalid instance.
void ApplyStencilFromMesh(REAL const stencil[], REAL const meshPoints[], PointDescriptor const &, REAL result[]) const
Apply a single stencil to control points from the mesh data.
Surface & operator=(Surface const &src)=default
void BoundControlPointsFromMesh(REAL const meshPoints[], PointDescriptor const &meshPointDesc, REAL minExtent[], REAL maxExtent[]) const
Compute bounds of control points from the mesh data.
void Clear()
Clear a previously initialized Surface.
Definition surface.h:72
void PreparePatchPoints(REAL const meshPoints[], PointDescriptor const &meshPointDesc, REAL patchPoints[], PointDescriptor const &patchPointDesc) const
Prepare patch points in a local array for evaluation.
Definition surface.h:328
bool IsValid() const
Return true if successfully initialized.
Definition surface.h:69
void GatherControlPoints(REAL_MESH const meshPoints[], PointDescriptor const &meshPointDesc, REAL controlPoints[], PointDescriptor const &controlPointDesc) const
Gather control points in a local array.
void ComputePatchPoints(REAL patchPoints[], PointDescriptor const &patchPointDesc) const
Compute all patch points following the control points.
Definition surface.h:314
bool IsLinear() const
Return if the Surface is linear.
Definition surface.h:98
int GetNumPatchPoints() const
Return the number of patch points representing the Surface.
int EvaluateStencil(REAL const uv[2], REAL sP[]) const
Evaluation of the limit stencil for position.
Definition surface.h:399
Simple struct defining the size and stride of points in arrays.
Definition surface.h:46
Base class providing initialization of a Surface for each face of a mesh.