Skip to content

Commit

Permalink
fix nodata/zero histogram entry situation
Browse files Browse the repository at this point in the history
  • Loading branch information
gillins committed Dec 14, 2024
1 parent 4a71813 commit 685f366
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions python/extrat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,14 +865,21 @@ pybind11::object getImageBlock(pybind11::object &dataset, uint32_t nBand,
class NeighbourPage
{
public:
NeighbourPage(size_t nStartVal, size_t length)
NeighbourPage(size_t nStartVal, size_t length, uint64_t *pHistogram)
:m_neighbours(length)
{
m_nFinished = 0;
m_nTodo = 0;
m_nStartVal = nStartVal;
for( size_t n = 0; n < length; n++ )
{
// need to create this for every value as kealib requires it
m_neighbours[n] = new std::vector<size_t>();
// count the non-zero histgram values in this page
// (assume nodata has a histogram of zero which it should be via RIOS)
if( pHistogram[nStartVal + n] > 0 )
{
m_nTodo++;
}
}
}
~NeighbourPage()
Expand All @@ -886,6 +893,10 @@ class NeighbourPage
throw PyKeaLibException("Page already written out");
}
auto neighbours = m_neighbours[nVal - m_nStartVal];
if( neighbours == nullptr)
{
fprintf(stderr, "git null got nval %zu\n", nVal);
}
if( std::find(neighbours->begin(), neighbours->end(), nNewNeighbour) == neighbours->end() )
{
neighbours->push_back(nNewNeighbour);
Expand All @@ -895,8 +906,8 @@ class NeighbourPage
{
bool bDone = false;
// we've completed all the neighbours for this value
m_nFinished++;
if( m_nFinished == m_neighbours.size() )
m_nTodo--;
if( m_nTodo == 0 )
{
// this page is done
//fprintf(stderr, "writing page for %zu\n", m_nStartVal);
Expand All @@ -908,7 +919,7 @@ class NeighbourPage

private:
std::vector<std::vector<size_t>* > m_neighbours;
size_t m_nFinished;
size_t m_nTodo;
size_t m_nStartVal;
};

Expand Down Expand Up @@ -959,7 +970,8 @@ class NeighbourAccumulator
{
// not in our map - add it
size_t nLength = std::min(PAGE_SIZE, m_nHistSize - nPageId);
pPage = new NeighbourPage(nPageId, nLength);
pPage = new NeighbourPage(nPageId, nLength, m_pHistogram);

m_neighbourPageMap.insert({nPageId, pPage});
//fprintf(stderr, "Creating page for %zu %zu\n", nPageId, nLength);
}
Expand Down

0 comments on commit 685f366

Please sign in to comment.