8#ifndef OPENSUBDIV3_FAR_PATCH_MAP_H
9#define OPENSUBDIV3_FAR_PATCH_MAP_H
11#include "../version.h"
13#include "../far/patchTable.h"
18namespace OPENSUBDIV_VERSION {
60 void initializeHandles(
PatchTable const & patchTable);
61 void initializeQuadtree(
PatchTable const & patchTable);
66 QuadNode() { std::memset(
this, 0,
sizeof(QuadNode)); }
75 void SetChildren(
int index);
78 void SetChild(
int quadrant,
int index,
bool isLeaf);
82 typedef std::vector<QuadNode> QuadTree;
85 void assignRootNode(QuadNode * node,
int index);
86 QuadNode * assignLeafOrChildNode(QuadNode * node,
bool isLeaf,
int quad,
int index);
89 static int transformUVToQuadQuadrant(T
const & median, T & u, T & v);
91 static int transformUVToTriQuadrant(T
const & median, T & u, T & v,
bool & rotated);
94 bool _patchesAreTriangular;
100 std::vector<Handle> _handles;
101 std::vector<QuadNode> _quadtree;
126PatchMap::transformUVToQuadQuadrant(T
const & median, T & u, T & v) {
128 int uHalf = (u >= median);
129 if (uHalf) u -= median;
131 int vHalf = (v >= median);
132 if (vHalf) v -= median;
134 return (vHalf << 1) | uHalf;
139PatchMap::transformUVToTriQuadrant(T
const & median, T & u, T & v,
bool & rotated) {
150 if ((u + v) >= median) {
166 if ((u + v) < median) {
183 if ((faceid < _minPatchFace) || (faceid > _maxPatchFace))
return 0;
185 QuadNode
const * node = &_quadtree[faceid - _minPatchFace];
187 if (!node->children[0].isSet)
return 0;
192 assert( (u>=0.0) && (u<=1.0) && (v>=0.0) && (v<=1.0) );
195 bool triRotated =
false;
197 for (
int depth = 0; depth <= _maxDepth; ++depth, median *= 0.5) {
199 int quadrant = _patchesAreTriangular
200 ? transformUVToTriQuadrant(median, u, v, triRotated)
201 : transformUVToQuadQuadrant(median, u, v);
204 assert(node->children[quadrant].isSet);
206 if (node->children[quadrant].isLeaf) {
207 return &_handles[node->children[quadrant].index];
209 node = &_quadtree[node->children[quadrant].index];
219using namespace OPENSUBDIV_VERSION;
An quadtree-based map connecting coarse faces to their sub-patches.
PatchMap(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...
PatchTable::PatchHandle Handle
Container for arrays of parametric patches.
Handle that can be used as unique patch identifier within PatchTable.