25 float mins[3] = {FLT_MAX, FLT_MAX, FLT_MAX};
26 float maxs[3] = {FLT_MIN, FLT_MIN, FLT_MIN};
28 for(
int i = 0; i < vertexNum; i++) {
29 float coord[3] = {0, 0, 0};
31 for(
int j = 0; j < 3; j++) {
32 if(coord[j] < mins[j])
34 if(coord[j] > maxs[j])
39 for(
int j = 0; j < 3; j++) {
40 center_[j] = (mins[j] + maxs[j]) / 2.0;
41 size_[j] = (maxs[j] - mins[j]) / 2.0;
63 for(uint32_t lc = node->
locCode_; lc != 1; lc >>= 3)
73 const uint32_t locCodeParent = node->
locCode_ >> 3;
74 return lookupNode(locCodeParent);
84 for(
int i = 0; i < 8; i++) {
86 const uint32_t locCodeChild = (node->
locCode_ << 3) | i;
87 const OctreeNode *child = lookupNode(locCodeChild);
98 unordered_map<uint32_t, OctreeNode>::iterator it;
99 for(it = allNodes_.begin(); it != allNodes_.end(); it++) {
100 if(it->second.childExists_ && it->second.vertexIds_.size() > 0) {
101 this->
printErr(
"[Octree] WRONG! The internal node "
102 + to_string(it->second.locCode_)
103 +
" should not contain any vertices!");
106 if(it->second.vertexIds_.size() > 0) {
107 vertexCount += it->second.vertexIds_.size();
110 if(vertexCount != vertexNum) {
111 this->
printErr(
"The number of vertices in the tree is "
112 + to_string(vertexCount) +
", which is not equal to "
113 + to_string(vertexNum));
129 if(current ==
nullptr) {
132 uint32_t location = current->
locCode_;
133 std::array<float, 3> ncenter{}, nsize{};
135 while(current !=
nullptr && current->
childExists_ != 0) {
136 computeCenterSize(location, ncenter, nsize);
137 location = getChildLocation(location, vertexId, ncenter);
138 current = lookupNode(location);
141 if(current ==
nullptr) {
143 newnode.
vertexIds_ = vector<SimplexId>{vertexId};
144 OctreeNode *parent = lookupNode(location >> 3);
146 allNodes_[location] = newnode;
164 std::array<float, 3> ncenter{}, nsize{};
165 for(
int i = 0; i < dim; i++) {
171 while(current !=
nullptr && current->
childExists_ != 0) {
173 computeCenterSize(location, ncenter, nsize);
174 location = getChildLocation(location, vertexId, ncenter);
175 current = lookupNode(location);
178 if(current ==
nullptr) {
179 this->
printErr(
"[Octree] insertCell(): Cannot find the vertex id ("
180 + to_string(vertexId) +
") in the tree!");
184 current->
cellIds_ = vector<SimplexId>{cellId};
185 }
else if(current->
cellIds_.back() != cellId) {
186 current->
cellIds_.push_back(cellId);
198 vector<SimplexId> &nodes,
199 vector<SimplexId> &cells) {
201 vector<int> cellMap(totalCells, -1);
208 stack<const OctreeNode *> nodeStack;
209 nodeStack.push(root);
211 while(!nodeStack.empty()) {
215 if(topNode ==
nullptr) {
216 this->
printErr(
"[Octree] reindex(): shouldn't get here!");
220 for(
int i = 0; i < 8; i++) {
222 const uint32_t locCodeChild = (topNode->
locCode_ << 3) | i;
223 const OctreeNode *child = lookupNode(locCodeChild);
224 nodeStack.push(child);
230 vector<SimplexId> tmp(topNode->
vertexIds_.size(), leafCount);
231 nodes.insert(nodes.end(), tmp.begin(), tmp.end());
237 if(cellMap[*it] == -1) {
238 cellMap[*it] = cellCount++;
246 cells.resize(totalCells);
247 for(
int i = 0; i < totalCells; i++) {
248 if(cellMap[i] == -1) {
251 cells.at(cellMap[i]) = i;
253 this->
printMsg(
"reindex(): There are " + to_string(count)
254 +
" wrong entries!");
257void Octree::computeCenterSize(uint32_t location,
258 std::array<float, 3> ¢erArr,
259 std::array<float, 3> &sizeArr) {
261 uint32_t tmp = location;
265 if(leftmost % 3 != 0) {
266 this->
printMsg(
"Location: " + std::to_string(location)
267 +
", leftmost: " + std::to_string(leftmost));
268 this->
printErr(
"computeCenterSize(): the location seems not correct!");
269 this->
printErr(
"Please try a larger bucket capacity!");
278 for(
int i = leftmost - 1; i >= 0; i -= 3) {
282 for(
int j = 0; j < 3; j++) {
284 if(location & mask) {
285 centerArr[j] += sizeArr[j];
287 centerArr[j] -= sizeArr[j];
293uint32_t Octree::getChildLocation(uint32_t parLoc,
295 const std::array<float, 3> ¢erArr) {
296 float xval{}, yval{}, zval{};
298 this->
printErr(
"getChildLocation(): FAILED to get the coordinate values "
300 + std::to_string(vertexId));
304 if(xval < centerArr[0]) {
305 if(yval < centerArr[1]) {
306 if(zval < centerArr[2]) {
307 return (parLoc << 3);
309 return (parLoc << 3) + 1;
312 if(zval < centerArr[2]) {
313 return (parLoc << 3) + 2;
315 return (parLoc << 3) + 3;
319 if(yval < centerArr[1]) {
320 if(zval < centerArr[2]) {
321 return (parLoc << 3) + 4;
323 return (parLoc << 3) + 5;
326 if(zval < centerArr[2]) {
327 return (parLoc << 3) + 6;
329 return (parLoc << 3) + 7;
334 this->
printErr(
"getChildLocation(): Shouldn't get here!");
342 if((
int)node->
vertexIds_.size() > capacity_) {
343 uint32_t childCode = 0;
344 std::array<float, 3> ncenter{}, nsize{};
346 computeCenterSize(node->
locCode_, ncenter, nsize);
348 for(
int const v : node->vertexIds_) {
349 childCode = getChildLocation(node->
locCode_, v, ncenter);
350 OctreeNode *childNode = lookupNode(childCode);
352 if(childNode ==
nullptr) {
354 newnode.vertexIds_.push_back(v);
355 allNodes_[childCode] = newnode;
364 for(uint32_t i = 0; i < 8; i++) {
366 subdivide(lookupNode((node->
locCode_ << 3) | i));
std::vector< ttk::SimplexId > cellIds_
std::vector< ttk::SimplexId > vertexIds_
Octree(const ttk::AbstractTriangulation *t)
size_t getNodeTreeDepth(const OctreeNode *node)
void visitAll(const OctreeNode *node)
int insertVertex(ttk::SimplexId &vertexId)
void initialize(const ttk::AbstractTriangulation *t, const int k)
int insertCell(ttk::SimplexId &cellId)
void reindex(std::vector< ttk::SimplexId > &vertices, std::vector< ttk::SimplexId > &nodes, std::vector< ttk::SimplexId > &cells)
OctreeNode * getParentNode(OctreeNode *node)
int verifyTree(ttk::SimplexId &vertexNum)
AbstractTriangulation is an interface class that defines an interface for efficient traversal methods...
virtual int getVertexPoint(const SimplexId &vertexId, float &x, float &y, float &z) const
virtual SimplexId getNumberOfCells() const
virtual SimplexId getNumberOfVertices() const
virtual int getCellVertex(const SimplexId &cellId, const int &localVertexId, SimplexId &vertexId) const
virtual SimplexId getCellVertexNumber(const SimplexId &cellId) const
void setDebugMsgPrefix(const std::string &prefix)
int printErr(const std::string &msg, const debug::LineMode &lineMode=debug::LineMode::NEW, std::ostream &stream=std::cerr) const
int SimplexId
Identifier type for simplices of any dimension.
printMsg(debug::output::BOLD+" | | | | | . \\ | | (__| | / __/| |_| / __/|__ _|"+debug::output::ENDCOLOR, debug::Priority::PERFORMANCE, debug::LineMode::NEW, stream)