25 #ifndef OPENSUBDIV3_FAR_PATCH_MAP_H
26 #define OPENSUBDIV3_FAR_PATCH_MAP_H
28 #include "../version.h"
30 #include "../far/patchTable.h"
34 namespace OpenSubdiv {
35 namespace OPENSUBDIV_VERSION {
77 void initializeHandles(
PatchTable const & patchTable);
78 void initializeQuadtree(
PatchTable const & patchTable);
83 QuadNode() { std::memset(
this, 0,
sizeof(QuadNode)); }
92 void SetChildren(
int index);
95 void SetChild(
int quadrant,
int index,
bool isLeaf);
99 typedef std::vector<QuadNode> QuadTree;
102 void assignRootNode(QuadNode * node,
int index);
103 QuadNode * assignLeafOrChildNode(QuadNode * node,
bool isLeaf,
int quad,
int index);
106 static int transformUVToQuadQuadrant(T
const & median, T & u, T & v);
108 static int transformUVToTriQuadrant(T
const & median, T & u, T & v,
bool & rotated);
111 bool _patchesAreTriangular;
117 std::vector<Handle> _handles;
118 std::vector<QuadNode> _quadtree;
143 PatchMap::transformUVToQuadQuadrant(T
const & median, T & u, T & v) {
145 int uHalf = (u >= median);
146 if (uHalf) u -= median;
148 int vHalf = (v >= median);
149 if (vHalf) v -= median;
151 return (vHalf << 1) | uHalf;
156 PatchMap::transformUVToTriQuadrant(T
const & median, T & u, T & v,
bool & rotated) {
167 if ((u + v) >= median) {
183 if ((u + v) < median) {
200 if ((faceid < _minPatchFace) || (faceid > _maxPatchFace))
return 0;
202 QuadNode
const * node = &_quadtree[faceid - _minPatchFace];
204 if (!node->children[0].isSet)
return 0;
209 assert( (u>=0.0) && (u<=1.0) && (v>=0.0) && (v<=1.0) );
212 bool triRotated =
false;
214 for (
int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
216 int quadrant = _patchesAreTriangular
217 ? transformUVToTriQuadrant(median, u, v, triRotated)
218 : transformUVToQuadQuadrant(median, u, v);
221 assert(node->children[quadrant].isSet);
223 if (node->children[quadrant].isLeaf) {
224 return &_handles[node->children[quadrant].index];
226 node = &_quadtree[node->children[quadrant].index];
236 using namespace OPENSUBDIV_VERSION;
PatchTable::PatchHandle Handle
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...
An quadtree-based map connecting coarse faces to their sub-patches.
PatchMap(PatchTable const &patchTable)
Constructor.
Container for arrays of parametric patches.
Handle that can be used as unique patch identifier within PatchTable.