OpenSubdiv: opensubdiv/bfr/surface.h Source File

| 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"
14#include "../bfr/parameterization.h"
15#include "../vtr/array.h"
16
17namespace OpenSubdiv {
18namespace OPENSUBDIV_VERSION {
19
20namespace Bfr {
21
41template <typename REAL>
42 class Surface {
43public:
46 struct PointDescriptor {
47 PointDescriptor() : size(0), stride(0) { }
48 PointDescriptor(int n) : size(n), stride(n) { }
49 PointDescriptor(int n, int m) : size(n), stride(m) { }
50
51 int size, stride;
52 };
53
55 typedef int Index;
56
57public:
59
67
69 bool IsValid() const { return _data.isValid(); }
70
72 void Clear() { _data.reinitialize(); }
73
75 Surface();
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:
266 typedef Vtr::ConstArray<int> IndexArray;
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
314Surface<REAL>::ComputePatchPoints(REAL points[],
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
328Surface<REAL>::PreparePatchPoints(
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
365 Surface<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
375 Surface<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
406 Surface<REAL>::EvaluateStencil(REAL const uv[2],
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
414 Surface<REAL>::EvaluateStencil(REAL const uv[2],
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 */
array.h
parameterization.h
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:18
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition parameterization.h:35
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition parameterization.h:84
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetNumControlPoints
int GetNumControlPoints() const
Return the number of control points affecting the Surface.
Definition surface.h:120
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::Evaluate
void Evaluate(REAL const uv[2], REAL const patchPoints[], PointDescriptor const &pointDesc, REAL P[]) const
Evaluation of position.
Definition surface.h:355
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetFaceSize
int GetFaceSize() const
Return the size of the face.
Definition surface.h:92
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsRegular
bool IsRegular() const
Return if the Surface is a single regular patch.
Definition surface.h:95
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::BoundControlPoints
void BoundControlPoints(REAL const controlPoints[], PointDescriptor const &controlPointDesc, REAL minExtent[], REAL maxExtent[]) const
Compute bounds of control points from a local array.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetControlPointIndices
int GetControlPointIndices(Index meshPointIndices[]) const
Identify indices of control points in the mesh.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::SurfaceFactory
friend class SurfaceFactory
Definition surface.h:298
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::Index
int Index
Integer type representing a mesh index.
Definition surface.h:55
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::ApplyStencil
void ApplyStencil(REAL const stencil[], REAL const controlPoints[], PointDescriptor const &, REAL result[]) const
Apply a single stencil to control points from a local array.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetParameterization
Parameterization GetParameterization() const
Return the Parameterization.
Definition surface.h:89
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::Surface
Surface()
Default construction produces an invalid instance.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::ApplyStencilFromMesh
void ApplyStencilFromMesh(REAL const stencil[], REAL const meshPoints[], PointDescriptor const &, REAL result[]) const
Apply a single stencil to control points from the mesh data.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::operator=
Surface & operator=(Surface const &src)=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::BoundControlPointsFromMesh
void BoundControlPointsFromMesh(REAL const meshPoints[], PointDescriptor const &meshPointDesc, REAL minExtent[], REAL maxExtent[]) const
Compute bounds of control points from the mesh data.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::~Surface
~Surface()=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::Clear
void Clear()
Clear a previously initialized Surface.
Definition surface.h:72
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::Surface
Surface(Surface const &src)=default
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PreparePatchPoints
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
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsValid
bool IsValid() const
Return true if successfully initialized.
Definition surface.h:69
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GatherControlPoints
void GatherControlPoints(REAL_MESH const meshPoints[], PointDescriptor const &meshPointDesc, REAL controlPoints[], PointDescriptor const &controlPointDesc) const
Gather control points in a local array.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::ComputePatchPoints
void ComputePatchPoints(REAL patchPoints[], PointDescriptor const &patchPointDesc) const
Compute all patch points following the control points.
Definition surface.h:314
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsLinear
bool IsLinear() const
Return if the Surface is linear.
Definition surface.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetNumPatchPoints
int GetNumPatchPoints() const
Return the number of patch points representing the Surface.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::EvaluateStencil
int EvaluateStencil(REAL const uv[2], REAL sP[]) const
Evaluation of the limit stencil for position.
Definition surface.h:399
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor
Simple struct defining the size and stride of points in arrays.
Definition surface.h:46
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::stride
int stride
Definition surface.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::size
int size
Definition surface.h:51
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor(int n)
Definition surface.h:48
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor(int n, int m)
Definition surface.h:49
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor()
Definition surface.h:47
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray
Definition array.h:36