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 Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24
25#ifndef OPENSUBDIV3_BFR_SURFACE_H
26#define OPENSUBDIV3_BFR_SURFACE_H
27
28#include "../version.h"
29
30#include "../bfr/surfaceData.h"
31#include "../bfr/parameterization.h"
32#include "../vtr/array.h"
33
34namespace OpenSubdiv {
35namespace OPENSUBDIV_VERSION {
36
37namespace Bfr {
38
58template <typename REAL>
59 class Surface {
60public:
63 struct PointDescriptor {
64 PointDescriptor() : size(0), stride(0) { }
65 PointDescriptor(int n) : size(n), stride(n) { }
66 PointDescriptor(int n, int m) : size(n), stride(m) { }
67
68 int size, stride;
69 };
70
72 typedef int Index;
73
74public:
76
84
86 bool IsValid() const { return _data.isValid(); }
87
89 void Clear() { _data.reinitialize(); }
90
92 Surface();
93
94 Surface(Surface const & src) = default;
95 Surface& operator=(Surface const & src) = default;
96 ~Surface() = default;
98
100
104
106 Parameterization GetParameterization() const { return _data.getParam(); }
107
109 int GetFaceSize() const { return GetParameterization().GetFaceSize(); }
110
112 bool IsRegular() const { return _data.isRegular(); }
113
115 bool IsLinear() const { return _data.isLinear(); }
117
119
135
137 int GetNumControlPoints() const { return _data.getNumCVs(); }
138
140 int GetControlPointIndices(Index meshPointIndices[]) const;
141
151 template <typename REAL_MESH>
152 void GatherControlPoints(REAL_MESH const meshPoints[],
153 PointDescriptor const & meshPointDesc,
154 REAL controlPoints[],
155 PointDescriptor const & controlPointDesc) const;
156
158 void BoundControlPoints(REAL const controlPoints[],
159 PointDescriptor const & controlPointDesc,
160 REAL minExtent[],
161 REAL maxExtent[]) const;
162
164 void BoundControlPointsFromMesh(REAL const meshPoints[],
165 PointDescriptor const & meshPointDesc,
166 REAL minExtent[],
167 REAL maxExtent[]) const;
169
171
177
179 int GetNumPatchPoints() const;
180
199 void PreparePatchPoints(REAL const meshPoints[],
200 PointDescriptor const & meshPointDesc,
201 REAL patchPoints[],
202 PointDescriptor const & patchPointDesc) const;
203
213 void ComputePatchPoints(REAL patchPoints[],
214 PointDescriptor const & patchPointDesc) const;
216
218
225
227 void Evaluate(REAL const uv[2],
228 REAL const patchPoints[], PointDescriptor const & pointDesc,
229 REAL P[]) const;
230
232 void Evaluate(REAL const uv[2],
233 REAL const patchPoints[], PointDescriptor const & pointDesc,
234 REAL P[], REAL Du[], REAL Dv[]) const;
235
237 void Evaluate(REAL const uv[2],
238 REAL const patchPoints[], PointDescriptor const & pointDesc,
239 REAL P[], REAL Du[], REAL Dv[],
240 REAL Duu[], REAL Duv[], REAL Dvv[]) const;
242
244
256
258 int EvaluateStencil(REAL const uv[2], REAL sP[]) const;
259
261 int EvaluateStencil(REAL const uv[2], REAL sP[],
262 REAL sDu[], REAL sDv[]) const;
263
265 int EvaluateStencil(REAL const uv[2], REAL sP[],
266 REAL sDu[], REAL sDv[],
267 REAL sDuu[], REAL sDuv[], REAL sDvv[]) const;
268
270 void ApplyStencil(REAL const stencil[],
271 REAL const controlPoints[], PointDescriptor const &,
272 REAL result[]) const;
273
275 void ApplyStencilFromMesh(REAL const stencil[],
276 REAL const meshPoints[], PointDescriptor const &,
277 REAL result[]) const;
279
280private:
281 // Internal methods for evaluating derivatives, basis weights and
282 // stencils for regular, irregular and irregular linear patches:
283 typedef Vtr::ConstArray<int> IndexArray;
284
285 void evaluateDerivs(REAL const uv[2], REAL const patchPoints[],
286 PointDescriptor const &, REAL * derivs[]) const;
287 void evalRegularDerivs(REAL const uv[2], REAL const patchPoints[],
288 PointDescriptor const &, REAL * derivs[]) const;
289 void evalIrregularDerivs(REAL const uv[2], REAL const patchPoints[],
290 PointDescriptor const &, REAL * derivs[]) const;
291 void evalMultiLinearDerivs(REAL const uv[2], REAL const patchPoints[],
292 PointDescriptor const &, REAL * derivs[]) const;
293
294 void evalRegularBasis(REAL const uv[2], REAL * wDeriv[]) const;
295 IndexArray evalIrregularBasis(REAL const uv[2], REAL * wDeriv[]) const;
296 int evalMultiLinearBasis(REAL const uv[2], REAL * wDeriv[]) const;
297
298 int evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const;
299 int evalRegularStencils(REAL const uv[2], REAL * sDeriv[]) const;
300 int evalIrregularStencils(REAL const uv[2], REAL * sDeriv[]) const;
301 int evalMultiLinearStencils(REAL const uv[2], REAL * sDeriv[]) const;
302
303 // Internal methods to compute patch points:
304 void computeLinearPatchPoints(REAL p[], PointDescriptor const &) const;
305 void computeIrregularPatchPoints(REAL p[], PointDescriptor const &) const;
306
307 // Internal methods specific to regular or irregular patches:
308 unsigned char getRegPatchType() const { return _data.getRegPatchType(); }
309 unsigned char getRegPatchMask() const { return _data.getRegPatchMask(); }
310
311 internal::IrregularPatchType const & getIrregPatch() const;
312
313private:
314 // Access to the set of member variables - provided to the Factory:
315 friend class SurfaceFactory;
316
317 internal::SurfaceData & getSurfaceData() { return _data; }
318 internal::SurfaceData const & getSurfaceData() const { return _data; }
319
320private:
321 // All member variables encapsulated in a single class:
322 internal::SurfaceData _data;
323};
324
325
326//
327// Simple inline methods composed of other methods:
328//
329template <typename REAL>
330inline void
331Surface<REAL>::ComputePatchPoints(REAL points[],
332 PointDescriptor const & pointDesc) const {
333
334 if (!IsRegular()) {
335 if (IsLinear()) {
336 computeLinearPatchPoints(points, pointDesc);
337 } else {
338 computeIrregularPatchPoints(points, pointDesc);
339 }
340 }
341}
342
343template <typename REAL>
344inline void
345Surface<REAL>::PreparePatchPoints(
346 REAL const meshPoints[], PointDescriptor const & meshPointDesc,
347 REAL patchPoints[], PointDescriptor const & patchPointDesc) const {
348
349 GatherControlPoints(meshPoints, meshPointDesc, patchPoints, patchPointDesc);
350 ComputePatchPoints(patchPoints, patchPointDesc);
351}
352
353//
354// Inline invocations of more general methods for derivative overloads:
355//
356template <typename REAL>
357inline void
358 Surface<REAL>::evaluateDerivs(REAL const uv[2],
359 REAL const patchPoints[],
360 PointDescriptor const & pointDesc,
361 REAL * derivatives[]) const {
362 if (IsRegular()) {
363 evalRegularDerivs(uv, patchPoints, pointDesc, derivatives);
364 } else if (IsLinear()) {
365 evalMultiLinearDerivs(uv, patchPoints, pointDesc, derivatives);
366 } else {
367 evalIrregularDerivs(uv, patchPoints, pointDesc, derivatives);
368 }
369}
370template <typename REAL>
371inline void
372Surface<REAL>::Evaluate(REAL const uv[2],
373 REAL const patchPoints[],
374 PointDescriptor const & pointDesc,
375 REAL P[]) const {
376
377 REAL * derivatives[6] = { P, 0, 0, 0, 0, 0 };
378 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
379}
380template <typename REAL>
381inline void
382 Surface<REAL>::Evaluate(REAL const uv[2],
383 REAL const patchPoints[],
384 PointDescriptor const & pointDesc,
385 REAL P[], REAL Du[], REAL Dv[]) const {
386
387 REAL * derivatives[6] = { P, Du, Dv, 0, 0, 0 };
388 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
389}
390template <typename REAL>
391inline void
392 Surface<REAL>::Evaluate(REAL const uv[2],
393 REAL const patchPoints[],
394 PointDescriptor const & pointDesc,
395 REAL P[], REAL Du[], REAL Dv[],
396 REAL Duu[], REAL Duv[], REAL Dvv[]) const {
397
398 REAL * derivatives[6] = { P, Du, Dv, Duu, Duv, Dvv };
399 evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
400}
401
402template <typename REAL>
403inline int
404 Surface<REAL>::evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const {
405
406 if (IsRegular()) {
407 return evalRegularStencils(uv, sDeriv);
408 } else if (IsLinear()) {
409 return evalMultiLinearStencils(uv, sDeriv);
410 } else {
411 return evalIrregularStencils(uv, sDeriv);
412 }
413}
414template <typename REAL>
415inline int
416Surface<REAL>::EvaluateStencil(REAL const uv[2], REAL sP[]) const {
417
418 REAL * derivativeStencils[6] = { sP, 0, 0, 0, 0, 0 };
419 return evaluateStencils(uv, derivativeStencils);
420}
421template <typename REAL>
422inline int
423 Surface<REAL>::EvaluateStencil(REAL const uv[2],
424 REAL sP[], REAL sDu[], REAL sDv[]) const {
425
426 REAL * derivativeStencils[6] = { sP, sDu, sDv, 0, 0, 0 };
427 return evaluateStencils(uv, derivativeStencils);
428}
429template <typename REAL>
430inline int
431 Surface<REAL>::EvaluateStencil(REAL const uv[2],
432 REAL sP[], REAL sDu[], REAL sDv[],
433 REAL sDuu[], REAL sDuv[], REAL sDvv[]) const {
434
435 REAL * derivativeStencils[6] = { sP, sDu, sDv, sDuu, sDuv, sDvv };
436 return evaluateStencils(uv, derivativeStencils);
437}
438
439} // end namespace Bfr
440
441} // end namespace OPENSUBDIV_VERSION
442using namespace OPENSUBDIV_VERSION;
443
444} // end namespace OpenSubdiv
445
446#endif /* OPENSUBDIV3_BFR_SURFACE */
OpenSubdiv
Definition: limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition: parameterization.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization::GetFaceSize
int GetFaceSize() const
Returns the size (number of vertices) of the corresponding face.
Definition: parameterization.h:101
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface
Encapsulates the limit surface for a face of a mesh.
Definition: surface.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetNumControlPoints
int GetNumControlPoints() const
Return the number of control points affecting the Surface.
Definition: surface.h:137
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:372
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::GetFaceSize
int GetFaceSize() const
Return the size of the face.
Definition: surface.h:109
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsRegular
bool IsRegular() const
Return if the Surface is a single regular patch.
Definition: surface.h:112
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::Index
int Index
Integer type representing a mesh index.
Definition: surface.h:72
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:106
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:89
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:345
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsValid
bool IsValid() const
Return true if successfully initialized.
Definition: surface.h:86
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:331
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::IsLinear
bool IsLinear() const
Return if the Surface is linear.
Definition: surface.h:115
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:416
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor
Simple struct defining the size and stride of points in arrays.
Definition: surface.h:63
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::stride
int stride
Definition: surface.h:68
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::size
int size
Definition: surface.h:68
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor(int n)
Definition: surface.h:65
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor(int n, int m)
Definition: surface.h:66
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface::PointDescriptor::PointDescriptor
PointDescriptor()
Definition: surface.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory
Base class providing initialization of a Surface for each face of a mesh.
Definition: surfaceFactory.h:103
OpenSubdiv::OPENSUBDIV_VERSION::Vtr::ConstArray
Definition: array.h:53