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 typedef OpenSubdiv::Far::PatchTable::PatchHandle
Handle;
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 typedef std::vector<QuadNode> QuadTree;
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);
118 bool _patchesAreTriangular;
124 std::vector<Handle> _handles;
125 std::vector<QuadNode> _quadtree;
148template<
class T>
inline int PatchMap::transformUVToQuadQuadrant(
T const &median,
T &u,
T &
v)
151 int uHalf = (u >= median);
156 int vHalf = (
v >= median);
161 return (vHalf << 1) | uHalf;
165int inline PatchMap::transformUVToTriQuadrant(
T const &median,
T &u,
T &
v,
bool &rotated)
177 if ((u +
v) >= median) {
194 if ((u +
v) < median) {
211 if ((faceid < _minPatchFace) || (faceid > _maxPatchFace)) {
215 QuadNode const *node = &_quadtree[faceid - _minPatchFace];
224 assert((u >= 0.0) && (u <= 1.0) && (
v >= 0.0) && (
v <= 1.0));
227 bool triRotated =
false;
229 for (
int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
231 int quadrant = _patchesAreTriangular ? transformUVToTriQuadrant(median, u,
v, triRotated) :
232 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()
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...
OpenSubdiv::Far::PatchTable::PatchHandle Handle
int getMaxPatchFace() const
void SetChildren(int index)
void SetChild(int quadrant, int index, bool isLeaf)