From e59dd7a391e1068a2994785acf39e71a22880d4e Mon Sep 17 00:00:00 2001 From: Erik Broberg Date: Thu, 23 Jun 2016 20:16:47 -0400 Subject: [PATCH] Enable finding a ChunkNode in ChunkNode tree based on a Geodetic2 point --- modules/globebrowsing/chunk/chunknode.cpp | 37 +++++++++++++++++++++-- modules/globebrowsing/chunk/chunknode.h | 5 +++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/modules/globebrowsing/chunk/chunknode.cpp b/modules/globebrowsing/chunk/chunknode.cpp index 2efda5a548..2198fc4276 100644 --- a/modules/globebrowsing/chunk/chunknode.cpp +++ b/modules/globebrowsing/chunk/chunknode.cpp @@ -154,6 +154,40 @@ void ChunkNode::reverseBreadthFirst(const std::function& } } +#define CHUNK_NODE_FIND(node, p) \ + while (!node->isLeaf()) { \ + const Geodetic2 center = node->_chunk.surfacePatch().center();\ + int index = 0;\ + if (center.lon < p.lon) {\ + ++index;\ + }\ + if (p.lat < center.lat) {\ + ++index;\ + ++index;\ + }\ + node = &(node->getChild((Quad)index));\ + } + +const ChunkNode& ChunkNode::find(const Geodetic2& location) const { + const ChunkNode* node = this; + CHUNK_NODE_FIND(node, location); + return *node; +} + +ChunkNode& ChunkNode::find(const Geodetic2& location) { + ChunkNode* node = this; + CHUNK_NODE_FIND(node, location); + return *node; +} + +const ChunkNode& ChunkNode::getChild(Quad quad) const { + return *_children[quad]; +} + +ChunkNode& ChunkNode::getChild(Quad quad) { + return *_children[quad]; +} + void ChunkNode::split(int depth) { if (depth > 0 && isLeaf()) { for (size_t i = 0; i < 4; i++) { @@ -180,9 +214,6 @@ void ChunkNode::merge() { ghoul_assert(isLeaf(), "ChunkNode must be leaf after merge"); } -const ChunkNode& ChunkNode::getChild(Quad quad) const { - return *_children[quad]; -} const Chunk& ChunkNode::getChunk() const { return _chunk; diff --git a/modules/globebrowsing/chunk/chunknode.h b/modules/globebrowsing/chunk/chunknode.h index 8ee054ba2b..3968559cee 100644 --- a/modules/globebrowsing/chunk/chunknode.h +++ b/modules/globebrowsing/chunk/chunknode.h @@ -65,8 +65,13 @@ public: void depthFirst(const std::function& f) const; void breadthFirst(const std::function& f) const; void reverseBreadthFirst(const std::function& f) const; + + const ChunkNode& find(const Geodetic2& location) const; + ChunkNode& find(const Geodetic2& location); const ChunkNode& getChild(Quad quad) const; + ChunkNode& getChild(Quad quad); + const Chunk& getChunk() const; bool updateChunkTree(const RenderData& data);