8#ifndef OPENSUBDIV_PATCH_MAP_H_
9#define OPENSUBDIV_PATCH_MAP_H_
11#include <opensubdiv/far/patchTable.h>
31 std::memset(
this, 0,
sizeof(
QuadNode));
44 void SetChild(
int quadrant,
int index,
bool isLeaf);
49 using Handle = OpenSubdiv::Far::PatchTable::PatchHandle;
55 PatchMap(OpenSubdiv::Far::PatchTable
const &patchTable);
90 return _patchesAreTriangular;
98 const std::vector<QuadNode> &
nodes()
104 void initializeHandles(OpenSubdiv::Far::PatchTable
const &patchTable);
105 void initializeQuadtree(OpenSubdiv::Far::PatchTable
const &patchTable);
107 using QuadTree = std::vector<QuadNode>;
110 void assignRootNode(
QuadNode *node,
int index);
111 QuadNode *assignLeafOrChildNode(
QuadNode *node,
bool isLeaf,
int quadrant,
int index);
113 template<
class T>
static int transformUVToQuadQuadrant(
T const &median,
T &u,
T &
v);
115 static int transformUVToTriQuadrant(
T const &median,
T &u,
T &
v,
bool &rotated);
117 bool _patchesAreTriangular;
123 std::vector<Handle> _handles;
124 std::vector<QuadNode> _quadtree;
147template<
class T>
inline int PatchMap::transformUVToQuadQuadrant(
T const &median,
T &u,
T &
v)
150 int uHalf = (u >= median);
155 int vHalf = (
v >= median);
160 return (vHalf << 1) | uHalf;
164int inline PatchMap::transformUVToTriQuadrant(
T const &median,
T &u,
T &
v,
bool &rotated)
176 if ((u +
v) >= median) {
193 if ((u +
v) < median) {
209 if ((faceid < _minPatchFace) || (faceid > _maxPatchFace)) {
213 QuadNode const *node = &_quadtree[faceid - _minPatchFace];
222 assert((u >= 0.0) && (u <= 1.0) && (
v >= 0.0) && (
v <= 1.0));
225 bool triRotated =
false;
227 for (
int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
229 int quadrant = _patchesAreTriangular ? transformUVToTriQuadrant(median, u,
v, triRotated) :
230 transformUVToQuadQuadrant(median, u,
v);
ATTR_WARN_UNUSED_RESULT const BMVert * v
int getMinPatchFace() const
const std::vector< QuadNode > & nodes()
bool getPatchesAreTriangular() const
const std::vector< Handle > & getHandles()
OpenSubdiv::Far::PatchTable::PatchHandle Handle
PatchMap(OpenSubdiv::Far::PatchTable const &patchTable)
Constructor.
Handle const * FindPatch(int patchFaceId, double u, double v) const
Returns a handle to the sub-patch of the face at the given (u,v). Note that the patch face ID corresp...
int getMaxPatchFace() const
#define assert(assertion)
void SetChildren(int index)
void SetChild(int quadrant, int index, bool isLeaf)