Commit 338fee9a authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Bi-directional (level,id) to flat ID mapping

Implemented bi-directional conversion of (level,id)
to a flat index. The flat indices are defined as
in level-order, i.e., starting from level 0.
parent ca94d84b
......@@ -29,6 +29,7 @@
#include "vtkUniformGrid.h"
#include "vtkUnsignedCharArray.h"
#include "vtkIdList.h"
#include "vtkAMRGridIndexEncoder.h"
#include <cmath>
#include <limits>
......@@ -738,15 +739,40 @@ unsigned int vtkHierarchicalBoxDataSet::GetFlatIndex(unsigned int level,
return 0;
}
unsigned int findex=0;
for (unsigned int l=0; l < level; l++)
unsigned int findex = 0;
for( unsigned int l=0; l < level; l++ )
findex += this->GetNumberOfDataSets( l );
for( int i=0; i < index; ++i )
findex++;
return( findex );
// unsigned int findex=0;
// for (unsigned int l=0; l < level; l++)
// {
// findex += 1;
// findex += this->GetNumberOfDataSets(l);
// }
// findex += 1;
// findex += (index + 1);
// return findex;
}
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::GetLevelAndIndex(
const unsigned int flatIdx, unsigned int &level, unsigned int &idx )
{
unsigned int counter = 0;
for( level=0; level < this->GetNumberOfLevels(); ++level )
{
findex += 1;
findex += this->GetNumberOfDataSets(l);
}
findex += 1;
findex += (index + 1);
return findex;
for( idx=0; idx < this->GetNumberOfDataSets( level ); ++idx)
{
++counter;
if( counter == flatIdx )
return;
} // END for all ids
} // END for all levels
}
//----------------------------------------------------------------------------
......
......@@ -251,6 +251,12 @@ public:
// and dataset index are valid.
unsigned int GetFlatIndex(unsigned int level, unsigned int index);
// Description:
// Given the flat index, returns the corresponding level and index, idx,
// of the dataset.
void GetLevelAndIndex(
const unsigned int flatIdx, unsigned int &level, unsigned int &idx );
// Description:
// In-line Set & Get
vtkSetMacro( PadCellVisibility, bool );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment