surfaceFactory.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_FACTORY_H
#define OPENSUBDIV3_BFR_SURFACE_FACTORY_H
#include "../version.h"
#include "../bfr/surface.h"
#include "../bfr/surfaceFactoryMeshAdapter.h"
#include "../sdc/options.h"
#include "../sdc/types.h"
#include <cstdint>
namespace OpenSubdiv {
namespace OPENSUBDIV_VERSION {
namespace Bfr {
//
// Forward declarations of public and internal classes used by factories:
//
class SurfaceFactoryCache;
class FaceTopology;
class FaceSurface;
class SurfaceFactory : public SurfaceFactoryMeshAdapter {
public:
class Options {
public:
Options() : _dfltFVarID(-1), _externCache(0), _enableCache(true),
_approxLevelSmooth(2), _approxLevelSharp(6) { }
Options & SetDefaultFVarID(FVarID id);
FVarID GetDefaultFVarID() const { return _dfltFVarID; }
Options & EnableCaching(bool on);
bool IsCachingEnabled() const { return _enableCache; }
Options & SetExternalCache(SurfaceFactoryCache * c);
SurfaceFactoryCache * GetExternalCache() const { return _externCache; }
// Set refinement levels used to approximate the limit surface
// for smooth and sharp features (reasonable defaults assigned):
Options & SetApproxLevelSmooth(int level);
int GetApproxLevelSmooth() const { return _approxLevelSmooth; }
Options & SetApproxLevelSharp(int level);
int GetApproxLevelSharp() const { return _approxLevelSharp; }
private:
// Member variables:
FVarID _dfltFVarID;
SurfaceFactoryCache * _externCache;
unsigned char _enableCache : 1;
unsigned char _approxLevelSmooth;
unsigned char _approxLevelSharp;
};
public:
~SurfaceFactory() override;
Sdc::SchemeType GetSchemeType() const { return _subdivScheme; }
Sdc::Options GetSchemeOptions() const { return _subdivOptions; }
public:
bool FaceHasLimitSurface(Index faceIndex) const;
Parameterization GetFaceParameterization(Index faceIndex) const;
public:
template <typename REAL>
bool InitVertexSurface(Index faceIndex, Surface<REAL> * surface) const;
template <typename REAL>
bool InitVaryingSurface(Index faceIndex, Surface<REAL> * surface) const;
template <typename REAL>
bool InitFaceVaryingSurface(Index faceIndex, Surface<REAL> * surface) const;
template <typename REAL>
bool InitFaceVaryingSurface(Index faceIndex, Surface<REAL> * surface,
FVarID fvarID) const;
template <typename REAL>
bool InitSurfaces(Index faceIndex, Surface<REAL> * vtxSurface,
Surface<REAL> * fvarSurfaces,
FVarID const fvarIDs[] = 0,
int fvarCount = 0,
Surface<REAL> * varSurface = 0) const;
//
// WIP - considering removing these since non-essential
//
template <typename REAL=float>
Surface<REAL> * CreateVertexSurface(Index faceIndex) const;
template <typename REAL=float>
Surface<REAL> * CreateVaryingSurface(Index faceIndex) const;
template <typename REAL=float>
Surface<REAL> * CreateFaceVaryingSurface(Index faceIndex) const;
template <typename REAL=float>
Surface<REAL> * CreateFaceVaryingSurface(Index faceIndex, FVarID id) const;
protected:
SurfaceFactory(Sdc::SchemeType schemeType,
Sdc::Options const & schemeOptions,
Options const & limitOptions);
void setInternalCache(SurfaceFactoryCache * cache);
SurfaceFactory(SurfaceFactory const &) = delete;
SurfaceFactory & operator=(SurfaceFactory const &) = delete;
private:
// Supporting internal methods:
void setSubdivisionOptions(Sdc::SchemeType, Sdc::Options const & options);
void setFactoryOptions(Options const & factoryOptions);
bool faceHasLimitSimple(Index faceIndex, int faceSize) const;
bool faceHasLimitNeighborhood(Index faceIndex) const;
bool faceHasLimitNeighborhood(FaceTopology const & faceTopology) const;
class SurfaceSet;
bool populateAllSurfaces( Index faceIndex, SurfaceSet * sSetPtr) const;
bool populateLinearSurfaces( Index faceIndex, SurfaceSet * sSetPtr) const;
bool populateNonLinearSurfaces(Index faceIndex, SurfaceSet * sSetPtr) const;
bool initSurfaces(Index faceIndex, internal::SurfaceData * vtxSurface,
internal::SurfaceData * varSurface,
internal::SurfaceData * fvarSurfaces,
int fvarCount,
FVarID const fvarIDs[]) const;
// Methods to assemble topology and corresponding indices for entire face:
bool isFaceNeighborhoodRegular(Index faceIndex,
FVarID const * fvarPtrOrVtx,
Index indices[]) const;
bool initFaceNeighborhoodTopology(Index faceIndex,
FaceTopology * topology) const;
bool gatherFaceNeighborhoodTopology(Index faceIndex,
FaceTopology * topology) const;
int gatherFaceNeighborhoodIndices(Index faceIndex,
FaceTopology const & topology,
FVarID const * fvarPtrOrVtx,
Index indices[]) const;
// Methods to assemble Surfaces for the different categories of patch:
typedef internal::SurfaceData SurfaceType;
void assignLinearSurface(SurfaceType * surfacePtr,
Index faceIndex,
FVarID const * fvarPtrOrVtx) const;
void assignRegularSurface(SurfaceType * surfacePtr,
Index const surfacePatchPoints[]) const;
void assignRegularSurface(SurfaceType * surfacePtr,
FaceSurface const & surfaceDescription) const;
void assignIrregularSurface(SurfaceType * surfacePtr,
FaceSurface const & surfaceDescription) const;
void copyNonLinearSurface(SurfaceType * surfacePtr,
SurfaceType const & surfaceSource,
FaceSurface const & surfaceDescription) const;
private:
// Members describing options and subdivision properties (very little
// memory and low initialization cost)
Sdc::SchemeType _subdivScheme;
Sdc::Options _subdivOptions;
Options _factoryOptions;
// Members related to subdivision topology, options and limit tests:
unsigned int _linearScheme : 1;
unsigned int _linearFVarInterp : 1;
unsigned int _testNeighborhoodForLimit : 1;
unsigned int _rejectSmoothBoundariesForLimit : 1;
unsigned int _rejectIrregularFacesForLimit : 1;
int _regFaceSize;
// Members related to caching:
SurfaceFactoryCache mutable * _topologyCache;
};
//
// Inline methods for Options:
//
inline SurfaceFactory::Options &
SurfaceFactory::Options::SetDefaultFVarID(FVarID id) {
_dfltFVarID = id;
return *this;
}
inline SurfaceFactory::Options &
SurfaceFactory::Options::EnableCaching(bool on) {
_enableCache = on;
return *this;
}
inline SurfaceFactory::Options &
SurfaceFactory::Options::SetExternalCache(SurfaceFactoryCache * c) {
_externCache = c;
return *this;
}
inline SurfaceFactory::Options &
SurfaceFactory::Options::SetApproxLevelSmooth(int level) {
_approxLevelSmooth = (unsigned char) level;
return *this;
}
inline SurfaceFactory::Options &
SurfaceFactory::Options::SetApproxLevelSharp(int level) {
_approxLevelSharp = (unsigned char) level;
return *this;
}
//
// Inline methods to initializes Surfaces:
//
template <typename REAL>
inline bool
SurfaceFactory::InitVertexSurface(Index face, Surface<REAL> * s) const {
return initSurfaces(face, &s->getSurfaceData(), 0, 0, 0, 0);
}
template <typename REAL>
inline bool
SurfaceFactory::InitVaryingSurface(Index face, Surface<REAL> * s) const {
return initSurfaces(face, 0, &s->getSurfaceData(), 0, 0, 0);
}
template <typename REAL>
inline bool
SurfaceFactory::InitFaceVaryingSurface(Index face, Surface<REAL> * s,
FVarID fvarID) const {
return initSurfaces(face, 0, 0, &s->getSurfaceData(), 1, &fvarID);
}
template <typename REAL>
inline bool
SurfaceFactory::InitFaceVaryingSurface(Index face, Surface<REAL> * s) const {
FVarID dfltID = _factoryOptions.GetDefaultFVarID();
return initSurfaces(face, 0, 0, &s->getSurfaceData(), 1, &dfltID);
}
template <typename REAL>
inline bool
SurfaceFactory::InitSurfaces(Index faceIndex, Surface<REAL> * vtxSurface,
Surface<REAL> * fvarSurfaces, FVarID const fvarIDs[], int fvarCount,
Surface<REAL> * varSurface) const {
bool useDfltFVarID = fvarSurfaces && (fvarIDs == 0) && (fvarCount == 0);
FVarID dfltFVarID = useDfltFVarID ? _factoryOptions.GetDefaultFVarID() : 0;
return initSurfaces(faceIndex,
vtxSurface ? &vtxSurface->getSurfaceData() : 0,
varSurface ? &varSurface->getSurfaceData() : 0,
fvarSurfaces ? &fvarSurfaces->getSurfaceData() : 0,
fvarCount ? fvarCount : (fvarSurfaces != 0),
useDfltFVarID ? &dfltFVarID : fvarIDs);
}
//
// Inline methods to allocate and initialize Surfaces:
//
template <typename REAL>
inline Surface<REAL> *
SurfaceFactory::CreateVertexSurface(Index faceIndex) const {
Surface<REAL> * s = new Surface<REAL>();
if (InitVertexSurface<REAL>(faceIndex, s)) return s;
delete s;
return 0;
}
template <typename REAL>
inline Surface<REAL> *
SurfaceFactory::CreateVaryingSurface(Index faceIndex) const {
Surface<REAL> * s = new Surface<REAL>();
if (InitVaryingSurface<REAL>(faceIndex, s)) return s;
delete s;
return 0;
}
template <typename REAL>
inline Surface<REAL> *
SurfaceFactory::CreateFaceVaryingSurface(Index faceIndex, FVarID fvarID) const {
Surface<REAL> * s = new Surface<REAL>();
if (InitFaceVaryingSurface<REAL>(faceIndex, s, fvarID)) return s;
delete s;
return 0;
}
template <typename REAL>
inline Surface<REAL> *
SurfaceFactory::CreateFaceVaryingSurface(Index face) const {
FVarID dfltID = _factoryOptions.GetDefaultFVarID();
return CreateFaceVaryingSurface<REAL>(face, dfltID);
}
} // end namespace Bfr
} // end namespace OPENSUBDIV_VERSION
using namespace OPENSUBDIV_VERSION;
} // end namespace OpenSubdiv
#endif /* OPENSUBDIV3_BFR_SURFACE_FACTORY_H */
OpenSubdiv
Definition: limits.h:32
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::SchemeType
SchemeType
Enumerated type for all subdivision schemes supported by OpenSubdiv.
Definition: types.h:37
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Parameterization
Simple class defining the 2D parameterization of a face.
Definition: parameterization.h:52
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::Surface
Encapsulates the limit surface for a face of a mesh.
Definition: surface.h:59
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::Bfr::SurfaceFactory::setInternalCache
void setInternalCache(SurfaceFactoryCache *cache)
Subclass to identify an internal cache for use by base class.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::~SurfaceFactory
~SurfaceFactory() override
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::InitFaceVaryingSurface
bool InitFaceVaryingSurface(Index faceIndex, Surface< REAL > *surface) const
Initialize a Surface for the default face-varying data.
Definition: surfaceFactory.h:500
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::GetSchemeOptions
Sdc::Options GetSchemeOptions() const
Return the set of subdivision options.
Definition: surfaceFactory.h:173
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::GetFaceParameterization
Parameterization GetFaceParameterization(Index faceIndex) const
Return the Parameterization of a face with a limit surface.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::SurfaceFactory
SurfaceFactory(SurfaceFactory const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::FaceHasLimitSurface
bool FaceHasLimitSurface(Index faceIndex) const
Return if a specified face has a limit surface.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::operator=
SurfaceFactory & operator=(SurfaceFactory const &)=delete
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::CreateVertexSurface
Surface< REAL > * CreateVertexSurface(Index faceIndex) const
Construct a Surface for vertex data.
Definition: surfaceFactory.h:527
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::CreateFaceVaryingSurface
Surface< REAL > * CreateFaceVaryingSurface(Index faceIndex) const
Construct a Surface for the default face-varying data.
Definition: surfaceFactory.h:551
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::InitSurfaces
bool InitSurfaces(Index faceIndex, Surface< REAL > *vtxSurface, Surface< REAL > *fvarSurfaces, FVarID const fvarIDs[]=0, int fvarCount=0, Surface< REAL > *varSurface=0) const
Initialize multiple Surfaces at once.
Definition: surfaceFactory.h:507
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::GetSchemeType
Sdc::SchemeType GetSchemeType() const
Return the subdivision scheme.
Definition: surfaceFactory.h:170
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::CreateVaryingSurface
Surface< REAL > * CreateVaryingSurface(Index faceIndex) const
Construct a Surface for varying data.
Definition: surfaceFactory.h:535
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::InitVertexSurface
bool InitVertexSurface(Index faceIndex, Surface< REAL > *surface) const
Initialize a Surface for vertex data.
Definition: surfaceFactory.h:482
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::InitVaryingSurface
bool InitVaryingSurface(Index faceIndex, Surface< REAL > *surface) const
Initialize a Surface for varying data.
Definition: surfaceFactory.h:488
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::SurfaceFactory
SurfaceFactory(Sdc::SchemeType schemeType, Sdc::Options const &schemeOptions, Options const &limitOptions)
Constructor to be used by subclasses.
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options
Simple set of options assigned to instances of SurfaceFactory.
Definition: surfaceFactory.h:116
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::SetExternalCache
Options & SetExternalCache(SurfaceFactoryCache *c)
Assign an external cache to override the internal.
Definition: surfaceFactory.h:462
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::EnableCaching
Options & EnableCaching(bool on)
Enable or disable caching (default is true):
Definition: surfaceFactory.h:457
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::SetApproxLevelSmooth
Options & SetApproxLevelSmooth(int level)
Assign maximum refinement level for smooth features.
Definition: surfaceFactory.h:467
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::GetApproxLevelSmooth
int GetApproxLevelSmooth() const
Return maximum refinement level for smooth features.
Definition: surfaceFactory.h:142
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::Options
Options()
Definition: surfaceFactory.h:118
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::IsCachingEnabled
bool IsCachingEnabled() const
Return if caching is enable.
Definition: surfaceFactory.h:130
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::SetDefaultFVarID
Options & SetDefaultFVarID(FVarID id)
Assign the default face-varying ID (none assigned by default)
Definition: surfaceFactory.h:452
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::SetApproxLevelSharp
Options & SetApproxLevelSharp(int level)
Assign maximum refinement level for sharp features.
Definition: surfaceFactory.h:472
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::GetDefaultFVarID
FVarID GetDefaultFVarID() const
Return the default face-varying ID.
Definition: surfaceFactory.h:125
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::GetApproxLevelSharp
int GetApproxLevelSharp() const
Return maximum refinement level for sharp features.
Definition: surfaceFactory.h:147
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactory::Options::GetExternalCache
SurfaceFactoryCache * GetExternalCache() const
Return any assigned external cache.
Definition: surfaceFactory.h:135
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryCache
Container used internally by SurfaceFactory to store reusable information.
Definition: surfaceFactoryCache.h:59
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryMeshAdapter
Abstract interface adapting SurfaceFactory to a connected mesh representation.
Definition: surfaceFactoryMeshAdapter.h:65
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryMeshAdapter::Index
int Index
Integer type representing a mesh index.
Definition: surfaceFactoryMeshAdapter.h:68
OpenSubdiv::OPENSUBDIV_VERSION::Bfr::SurfaceFactoryMeshAdapter::FVarID
std::intptr_t FVarID
Type used to identify and specify face-varying primvars.
Definition: surfaceFactoryMeshAdapter.h:80
OpenSubdiv::OPENSUBDIV_VERSION::Sdc::Options
All supported options applying to subdivision scheme.
Definition: options.h:51