Loading...
Searching...
No Matches
surface.h
Go to the documentation of this file.
//
// Copyright 2021 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef OPENSUBDIV3_BFR_SURFACE_H
#define OPENSUBDIV3_BFR_SURFACE_H
#include "../version.h"
#include "../bfr/surfaceData.h"
#include "../bfr/parameterization.h"
#include "../vtr/array.h"
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Bfr {
template <typename REAL>
class Surface {
public:
struct PointDescriptor {
PointDescriptor() : size(0), stride(0) { }
PointDescriptor(int n) : size(n), stride(n) { }
PointDescriptor(int n, int m) : size(n), stride(m) { }
int size, stride;
};
typedef int Index;
public:
bool IsValid() const { return _data.isValid(); }
void Clear() { _data.reinitialize(); }
Surface();
Surface(Surface const & src) = default;
Surface& operator=(Surface const & src) = default;
~Surface() = default;
Parameterization GetParameterization() const { return _data.getParam(); }
int GetFaceSize() const { return GetParameterization().GetFaceSize(); }
bool IsRegular() const { return _data.isRegular(); }
bool IsLinear() const { return _data.isLinear(); }
int GetNumControlPoints() const { return _data.getNumCVs(); }
int GetControlPointIndices(Index meshPointIndices[]) const;
template <typename REAL_MESH>
void GatherControlPoints(REAL_MESH const meshPoints[],
PointDescriptor const & meshPointDesc,
REAL controlPoints[],
PointDescriptor const & controlPointDesc) const;
void BoundControlPoints(REAL const controlPoints[],
PointDescriptor const & controlPointDesc,
REAL minExtent[],
REAL maxExtent[]) const;
void BoundControlPointsFromMesh(REAL const meshPoints[],
PointDescriptor const & meshPointDesc,
REAL minExtent[],
REAL maxExtent[]) const;
int GetNumPatchPoints() const;
void PreparePatchPoints(REAL const meshPoints[],
PointDescriptor const & meshPointDesc,
REAL patchPoints[],
PointDescriptor const & patchPointDesc) const;
void ComputePatchPoints(REAL patchPoints[],
PointDescriptor const & patchPointDesc) const;
void Evaluate(REAL const uv[2],
REAL const patchPoints[], PointDescriptor const & pointDesc,
REAL P[]) const;
void Evaluate(REAL const uv[2],
REAL const patchPoints[], PointDescriptor const & pointDesc,
REAL P[], REAL Du[], REAL Dv[]) const;
void Evaluate(REAL const uv[2],
REAL const patchPoints[], PointDescriptor const & pointDesc,
REAL P[], REAL Du[], REAL Dv[],
REAL Duu[], REAL Duv[], REAL Dvv[]) const;
int EvaluateStencil(REAL const uv[2], REAL sP[]) const;
int EvaluateStencil(REAL const uv[2], REAL sP[],
REAL sDu[], REAL sDv[]) const;
int EvaluateStencil(REAL const uv[2], REAL sP[],
REAL sDu[], REAL sDv[],
REAL sDuu[], REAL sDuv[], REAL sDvv[]) const;
void ApplyStencil(REAL const stencil[],
REAL const controlPoints[], PointDescriptor const &,
REAL result[]) const;
void ApplyStencilFromMesh(REAL const stencil[],
REAL const meshPoints[], PointDescriptor const &,
REAL result[]) const;
private:
// Internal methods for evaluating derivatives, basis weights and
// stencils for regular, irregular and irregular linear patches:
typedef Vtr::ConstArray<int> IndexArray;
void evaluateDerivs(REAL const uv[2], REAL const patchPoints[],
PointDescriptor const &, REAL * derivs[]) const;
void evalRegularDerivs(REAL const uv[2], REAL const patchPoints[],
PointDescriptor const &, REAL * derivs[]) const;
void evalIrregularDerivs(REAL const uv[2], REAL const patchPoints[],
PointDescriptor const &, REAL * derivs[]) const;
void evalMultiLinearDerivs(REAL const uv[2], REAL const patchPoints[],
PointDescriptor const &, REAL * derivs[]) const;
void evalRegularBasis(REAL const uv[2], REAL * wDeriv[]) const;
IndexArray evalIrregularBasis(REAL const uv[2], REAL * wDeriv[]) const;
int evalMultiLinearBasis(REAL const uv[2], REAL * wDeriv[]) const;
int evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const;
int evalRegularStencils(REAL const uv[2], REAL * sDeriv[]) const;
int evalIrregularStencils(REAL const uv[2], REAL * sDeriv[]) const;
int evalMultiLinearStencils(REAL const uv[2], REAL * sDeriv[]) const;
// Internal methods to compute patch points:
void computeLinearPatchPoints(REAL p[], PointDescriptor const &) const;
void computeIrregularPatchPoints(REAL p[], PointDescriptor const &) const;
// Internal methods specific to regular or irregular patches:
unsigned char getRegPatchType() const { return _data.getRegPatchType(); }
unsigned char getRegPatchMask() const { return _data.getRegPatchMask(); }
internal::IrregularPatchType const & getIrregPatch() const;
private:
// Access to the set of member variables - provided to the Factory:
friend class SurfaceFactory;
internal::SurfaceData & getSurfaceData() { return _data; }
internal::SurfaceData const & getSurfaceData() const { return _data; }
private:
// All member variables encapsulated in a single class:
internal::SurfaceData _data;
};
//
// Simple inline methods composed of other methods:
//
template <typename REAL>
inline void
Surface<REAL>::ComputePatchPoints(REAL points[],
PointDescriptor const & pointDesc) const {
if (!IsRegular()) {
if (IsLinear()) {
computeLinearPatchPoints(points, pointDesc);
} else {
computeIrregularPatchPoints(points, pointDesc);
}
}
}
template <typename REAL>
inline void
Surface<REAL>::PreparePatchPoints(
REAL const meshPoints[], PointDescriptor const & meshPointDesc,
REAL patchPoints[], PointDescriptor const & patchPointDesc) const {
GatherControlPoints(meshPoints, meshPointDesc, patchPoints, patchPointDesc);
ComputePatchPoints(patchPoints, patchPointDesc);
}
//
// Inline invocations of more general methods for derivative overloads:
//
template <typename REAL>
inline void
Surface<REAL>::evaluateDerivs(REAL const uv[2],
REAL const patchPoints[],
PointDescriptor const & pointDesc,
REAL * derivatives[]) const {
if (IsRegular()) {
evalRegularDerivs(uv, patchPoints, pointDesc, derivatives);
} else if (IsLinear()) {
evalMultiLinearDerivs(uv, patchPoints, pointDesc, derivatives);
} else {
evalIrregularDerivs(uv, patchPoints, pointDesc, derivatives);
}
}
template <typename REAL>
inline void
Surface<REAL>::Evaluate(REAL const uv[2],
REAL const patchPoints[],
PointDescriptor const & pointDesc,
REAL P[]) const {
REAL * derivatives[6] = { P, 0, 0, 0, 0, 0 };
evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
}
template <typename REAL>
inline void
Surface<REAL>::Evaluate(REAL const uv[2],
REAL const patchPoints[],
PointDescriptor const & pointDesc,
REAL P[], REAL Du[], REAL Dv[]) const {
REAL * derivatives[6] = { P, Du, Dv, 0, 0, 0 };
evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
}
template <typename REAL>
inline void
Surface<REAL>::Evaluate(REAL const uv[2],
REAL const patchPoints[],
PointDescriptor const & pointDesc,
REAL P[], REAL Du[], REAL Dv[],
REAL Duu[], REAL Duv[], REAL Dvv[]) const {
REAL * derivatives[6] = { P, Du, Dv, Duu, Duv, Dvv };
evaluateDerivs(uv, patchPoints, pointDesc, derivatives);
}
template <typename REAL>
inline int
Surface<REAL>::evaluateStencils(REAL const uv[2], REAL * sDeriv[]) const {
if (IsRegular()) {
return evalRegularStencils(uv, sDeriv);
} else if (IsLinear()) {
return evalMultiLinearStencils(uv, sDeriv);
} else {
return evalIrregularStencils(uv, sDeriv);
}
}
template <typename REAL>
inline int
Surface<REAL>::EvaluateStencil(REAL const uv[2], REAL sP[]) const {
REAL * derivativeStencils[6] = { sP, 0, 0, 0, 0, 0 };
return evaluateStencils(uv, derivativeStencils);
}
template <typename REAL>
inline int
Surface<REAL>::EvaluateStencil(REAL const uv[2],
REAL sP[], REAL sDu[], REAL sDv[]) const {
REAL * derivativeStencils[6] = { sP, sDu, sDv, 0, 0, 0 };
return evaluateStencils(uv, derivativeStencils);
}
template <typename REAL>
inline int
Surface<REAL>::EvaluateStencil(REAL const uv[2],
REAL sP[], REAL sDu[], REAL sDv[],
REAL sDuu[], REAL sDuv[], REAL sDvv[]) const {
REAL * derivativeStencils[6] = { sP, sDu, sDv, sDuu, sDuv, sDvv };
return evaluateStencils(uv, derivativeStencils);
}
} // end namespace Bfr
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_BFR_SURFACE */
array.h
parameterization.h
OpenSubdiv
Definition limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:33
OpenSubdiv::OPENSUBDIV_VERSION::Bfr
Definition limits.h:35
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::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::SurfaceFactory
friend class SurfaceFactory
Definition surface.h:315
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::Vtr::ConstArray
Definition array.h:53