25 #ifndef OPENSUBDIV_PATCH_MAP_H_
26 #define OPENSUBDIV_PATCH_MAP_H_
28 #include <opensubdiv/far/patchTable.h>
31 namespace opensubdiv {
49 std::memset(
this, 0,
sizeof(
QuadNode));
62 void SetChild(
int quadrant,
int index,
bool isLeaf);
73 PatchMap(OpenSubdiv::Far::PatchTable
const &patchTable);
108 return _patchesAreTriangular;
116 const std::vector<QuadNode> &
nodes()
122 void initializeHandles(OpenSubdiv::Far::PatchTable
const &patchTable);
123 void initializeQuadtree(OpenSubdiv::Far::PatchTable
const &patchTable);
125 typedef std::vector<QuadNode> QuadTree;
128 void assignRootNode(QuadNode *
node,
int index);
129 QuadNode *assignLeafOrChildNode(QuadNode *
node,
bool isLeaf,
int quad,
int index);
131 template<
class T>
static int transformUVToQuadQuadrant(
T const &median,
T &u,
T &
v);
133 static int transformUVToTriQuadrant(
T const &median,
T &u,
T &
v,
bool &rotated);
136 bool _patchesAreTriangular;
142 std::vector<Handle> _handles;
143 std::vector<QuadNode> _quadtree;
166 template<
class T>
inline int PatchMap::transformUVToQuadQuadrant(
T const &median,
T &u,
T &
v)
169 int uHalf = (u >= median);
173 int vHalf = (
v >= median);
177 return (vHalf << 1) | uHalf;
181 int inline PatchMap::transformUVToTriQuadrant(
T const &median,
T &u,
T &
v,
bool &rotated)
193 if ((u +
v) >= median) {
210 if ((u +
v) < median) {
227 if ((faceid < _minPatchFace) || (faceid > _maxPatchFace))
230 QuadNode const *
node = &_quadtree[faceid - _minPatchFace];
232 if (!
node->children[0].isSet)
238 assert((u >= 0.0) && (u <= 1.0) && (
v >= 0.0) && (
v <= 1.0));
241 bool triRotated =
false;
243 for (
int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
245 int quadrant = _patchesAreTriangular ? transformUVToTriQuadrant(median, u,
v, triRotated) :
246 transformUVToQuadQuadrant(median, u,
v);
249 assert(
node->children[quadrant].isSet);
251 if (
node->children[quadrant].isLeaf) {
252 return &_handles[
node->children[quadrant].index];
255 node = &_quadtree[
node->children[quadrant].index];
ATTR_WARN_UNUSED_RESULT const BMVert * v
An quadtree-based map connecting coarse faces to their sub-patches.
const std::vector< QuadNode > & nodes()
int getMinPatchFace() const
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
CCL_NAMESPACE_BEGIN struct PatchHandle PatchHandle
void SetChildren(int index)
void SetChild(int quadrant, int index, bool isLeaf)