Skip to content

Commit

Permalink
Thread traverseTree.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Aug 3, 2020
1 parent b650045 commit eca5429
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
20 changes: 7 additions & 13 deletions plugins/i3s/io/EsriReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,9 +543,7 @@ bool EsriReader::processPoint(PointRef& dst, const TileContents& tile)
// it to the list of nodes to be pulled later.
void EsriReader::traverseTree(PagePtr page, int node)
{
std::cerr << "Traverse tree for node = " << node << "!\n";
int index = node % m_nodeCap;
int pageIndex = node / m_nodeCap;

// find node information
NL::json& j = *page;
Expand All @@ -566,12 +564,6 @@ void EsriReader::traverseTree(PagePtr page, int node)

double density = pCount / area;

// update maximum node to stop reading files at the right time
if ((firstChild + cCount - 1) > m_maxNode)
{
m_maxNode = firstChild + cCount - 1;
}

try
{
Obb obb(j["nodes"][index]["obb"]);
Expand All @@ -592,15 +584,18 @@ void EsriReader::traverseTree(PagePtr page, int node)
// if it's a child node and we're fetching full density, add leaf nodes
if (m_args->max_density == -1 && m_args->min_density == -1 && cCount == 0)
{
std::unique_lock<std::mutex> lock(m_mutex);
m_nodes.push_back(name);
return;
}
if (density < m_args->max_density && density > m_args->min_density)
{
std::unique_lock<std::mutex> lock(m_mutex);
m_nodes.push_back(name);
}

// if we've already reached the last node, stop the process, otherwise
// increment depth and begin looking at child nodes
if (name == m_maxNode || cCount == 0)
// if have no children, we're done this branch,.
if (cCount == 0)
return;

for (int i = 0; i < cCount; ++i)
Expand All @@ -615,8 +610,7 @@ void EsriReader::traverseTree(PagePtr page, int node)
node = firstChild + i;
if (i == 0 || node % m_nodeCap == 0)
page = m_pageManager->getPage(node / m_nodeCap);
// m_pool->add([this, page, node](){traverseTree(page, node);});
traverseTree(page, node);
m_pool->add([this, page, node](){traverseTree(page, node);});
}
}

Expand Down
1 change: 0 additions & 1 deletion plugins/i3s/io/EsriReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class PDAL_DLL EsriReader : public Reader, public Streamable
std::unique_ptr<Args> m_args;
NL::json m_info;
int m_nodeCap;
int m_maxNode = 0;
i3s::Version m_version;
SpatialReference m_nativeSrs;
std::unique_ptr<i3s::PageManager> m_pageManager;
Expand Down
4 changes: 4 additions & 0 deletions plugins/i3s/io/PageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ void PageManager::fetchPage(int index)

PagePtr PageManager::getPage(int index)
{
// In case someone forgot to call fetchPage() before calling this function or in the
// case a cached page were to get evicted since the time fetchPage() was called,
// we loop and try to fetch again if we couldn't get the page that we expected to
// be around.
while (true)
{
PagePtr p = getPageLocked(index);
Expand Down

0 comments on commit eca5429

Please sign in to comment.