Commit 22c36ddb authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Cleanup & Modularization

Modularized the GenerateVisibility() function and
cleaned up the code to use newer API to access the
AMR box metadata. Added also some code to facilitate
debugging which will be removed later.
parent 3494632c
......@@ -160,55 +160,6 @@ void vtkHierarchicalBoxDataSet::SetDataSet(
this->SetMetaData( level, id, box );
}
//void vtkHierarchicalBoxDataSet::SetDataSet(
// unsigned int level, unsigned int id, vtkAMRBox& box, vtkUniformGrid* dataSet)
//{
// if (level >= this->GetNumberOfLevels())
// {
// this->SetNumberOfLevels(level+1);
// }
// vtkMultiPieceDataSet* levelDS = vtkMultiPieceDataSet::SafeDownCast(
// this->Superclass::GetChild(level));
// if (levelDS)
// {
//
// levelDS->SetPiece(id, dataSet);
// vtkInformation* info = levelDS->GetMetaData(id);
// if (info)
// {
// const int *loCorner=box.GetLoCorner();
// const int *hiCorner=box.GetHiCorner();
// info->Set(BOX_DIMENSIONALITY(), box.GetDimensionality());
// info->Set(BOX(),loCorner[0], loCorner[1], loCorner[2],
// hiCorner[0], hiCorner[1], hiCorner[2]);
// double x0[3];
// box.GetBoxOrigin( x0 );
// info->Set(BOX_ORIGIN(), x0[0], x0[1], x0[2] );
// info->Set(RANK(), box.GetProcessId() );
// info->Set(BLOCK_ID(), box.GetBlockId() );
//
// double spacing[3];
// box.GetGridSpacing( spacing );
// info->Set(SPACING(),spacing[0],spacing[1],spacing[2]);
//
// int realExtent[6];
// box.GetRealExtent( realExtent );
// info->Set(REAL_EXTENT(),
// realExtent[0], realExtent[1], realExtent[2],
// realExtent[3], realExtent[4], realExtent[5] );
// }
// else
// {
// vtkErrorMacro( "Metadata object is NULL!!!!" );
// }
//
// }
// else
// {
// vtkErrorMacro( "Multi-piece data-structure is NULL!!!" );
// }
//}
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::SetDataSet(
unsigned int level, unsigned int idx, vtkUniformGrid *grid )
......@@ -473,7 +424,7 @@ void vtkHierarchicalBoxDataSet::GetGlobalAMRBoxWithSpacing(
int ndim[3];
ndim[0]=ndim[1]=ndim[2]=0;
for(int i=0; i < root.GetDimensionality(); ++i )
for(int i=0; i < 3; ++i )
{
// Note -1 is subtracted here because the data
// is cell-centered and we downshift to number
......@@ -484,7 +435,7 @@ void vtkHierarchicalBoxDataSet::GetGlobalAMRBoxWithSpacing(
int lo[3];
lo[0]=lo[1]=lo[2]=0;
box.SetDimensionality( root.GetDimensionality() );
// box.SetDimensionality( root.GetDimensionality() );
box.SetDataSetOrigin( min );
box.SetGridSpacing( h );
box.SetDimensions( lo, ndim );
......@@ -582,123 +533,140 @@ int vtkHierarchicalBoxDataSetIsInBoxes(vtkAMRBoxList& boxes,
}
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
void vtkHierarchicalBoxDataSet::GetHigherResolutionCoarsenedBoxes(
vtkAMRBoxList &boxes, const unsigned int levelIdx )
{
unsigned int numLevels = this->GetNumberOfLevels();
// if we are at the highest level, return immediately.
if( levelIdx == this->GetNumberOfLevels()-1 )
return;
for (unsigned int levelIdx=0; levelIdx<numLevels; levelIdx++)
unsigned int numDataSets = this->GetNumberOfDataSets( levelIdx+1 );
unsigned int dataSetIdx = 0;
for( ; dataSetIdx<numDataSets; dataSetIdx++)
{
// Copy boxes of higher level and coarsen to this level
vtkAMRBoxList boxes;
unsigned int numDataSets = this->GetNumberOfDataSets(levelIdx+1);
unsigned int dataSetIdx;
if (levelIdx < numLevels - 1)
{
for (dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
if( !this->HasMetaData(levelIdx+1, dataSetIdx) ||
!this->HasLevelMetaData(levelIdx))
{
if( !this->HasMetaData(levelIdx+1, dataSetIdx) ||
!this->HasLevelMetaData(levelIdx))
{
if( !this->HasMetaData(levelIdx+1, dataSetIdx) )
std::cout << "No MetaData associated with this instance!\n";
{
vtkGenericWarningMacro(
"No MetaData associated with this instance!\n" );
}
if( !this->HasLevelMetaData(levelIdx) )
std::cout << "No Level MetaData associated with this instance!\n";
std::cout.flush( );
{
vtkGenericWarningMacro(
"No Level MetaData associated with this instance!\n" );
}
continue;
}
}
// vtkAMRBox coarsebox;
// this->GetMetaData( levelIdx+1,dataSetIdx, coarsebox );
vtkAMRBox coarsebox;
this->GetMetaData( levelIdx+1, dataSetIdx, coarsebox );
int refinementRatio = this->GetRefinementRatio(levelIdx);
assert( "Invalid refinement ratio!" && (refinementRatio >= 2) );
// int dimensionality = info->Has(BOX_DIMENSIONALITY())?
// info->Get(BOX_DIMENSIONALITY()) : 3;
// vtkAMRBox coarsebox( boxVec );
// vtkAMRBox coarsebox(dimensionality,boxVec,boxVec+3);
coarsebox.Coarsen(refinementRatio);
boxes.push_back(coarsebox);
vtkInformation* info = this->GetMetaData(levelIdx+1,dataSetIdx);
int* boxVec = info->Get(BOX());
vtkAMRBox coarsebox(boxVec,boxVec+3);
int refinementRatio = this->GetRefinementRatio(levelIdx);
if (refinementRatio == 0)
{
continue;
}
coarsebox.Coarsen(refinementRatio);
boxes.push_back(coarsebox);
}
}
} // END for all datasets
numDataSets = this->GetNumberOfDataSets(levelIdx);
}
for (dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
{
vtkAMRBox box;
vtkUniformGrid* grid = this->GetDataSet(levelIdx, dataSetIdx, box);
if (grid && !box.Empty())
//----------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::GenerateVisibilityArrays()
{
// this->PadCellVisibility = true;
unsigned int numLevels = this->GetNumberOfLevels();
for (unsigned int levelIdx=0; levelIdx<numLevels; levelIdx++)
{
// Copy boxes of higher level and coarsen to this level
vtkAMRBoxList boxes;
this->GetHigherResolutionCoarsenedBoxes( boxes, levelIdx );
unsigned int numDataSets = this->GetNumberOfDataSets(levelIdx);
for( unsigned int dataSetIdx=0; dataSetIdx<numDataSets; dataSetIdx++)
{
// int cellDims[3];
// box.GetNumberOfNodes(cellDims);
// int N = box.GetNumberOfNodes();
std::cout << "==============================================\n";
std::cout << "Blanking grid: " << levelIdx << ", " << dataSetIdx;
std::cout << std::endl;
std::cout.flush();
int cellDims[3];
box.GetNumberOfCells(cellDims);
int N = box.GetNumberOfCells();
vtkAMRBox box;
vtkUniformGrid* grid = this->GetDataSet(levelIdx, dataSetIdx, box);
if (grid && !box.Empty())
{
int cellDims[3];
box.GetNumberOfCells(cellDims);
int N = box.GetNumberOfCells();
vtkUnsignedCharArray* vis = vtkUnsignedCharArray::New();
vis->SetNumberOfTuples( N );
vis->FillComponent(0,static_cast<char>(1));
vtkIdType numBlankedPts = 0;
vtkUnsignedCharArray* vis = vtkUnsignedCharArray::New();
vis->SetNumberOfTuples( N );
vis->FillComponent(0,static_cast<char>(1));
vtkIdType numBlankedPts = 0;
if (!boxes.empty())
{
if (!boxes.empty())
{
const int *loCorner=box.GetLoCorner();
const int *hiCorner=box.GetHiCorner();
for (int iz=loCorner[2]; iz<=hiCorner[2]; iz++)
{
for (int iy=loCorner[1]; iy<=hiCorner[1]; iy++)
{
for (int ix=loCorner[0]; ix<=hiCorner[0]; ix++)
std::cout << "Here is the list of coarsened boxes:\n";
for( unsigned int bb=0; bb < boxes.size(); ++bb )
{
boxes[ bb ].Print( std::cout );
std::cout << std::endl;
std::cout.flush();
}
const int *loCorner=box.GetLoCorner();
const int *hiCorner=box.GetHiCorner();
for (int iz=loCorner[2]; iz<=hiCorner[2]; iz++)
{
for (int iy=loCorner[1]; iy<=hiCorner[1]; iy++)
{
for (int ix=loCorner[0]; ix<=hiCorner[0]; ix++)
{
// Blank if cell is covered by a box of higher level
if (vtkHierarchicalBoxDataSetIsInBoxes(
boxes, ix, iy, iz))
{
vtkIdType id = box.GetCellLinearIndex( ix, iy, iz );
assert( "cell index out-of-bounds!" &&
( (id >=0) && (id < vis->GetNumberOfTuples() ) ) );
vis->SetValue(id, 0);
numBlankedPts++;
}
} // END for x
} // END for y
} // END for z
} // END if the list of boxes is not empty
grid->SetCellVisibilityArray(vis);
vis->Delete();
if( this->PadCellVisibility == true )
{
grid->AttachCellVisibilityToCellData();
// Turn off visibility since it is attached as cell data
grid->GetCellVisibilityArray()->FillComponent(
0,static_cast<char>(1));
}
// Blank if cell is covered by a box of higher level
if (vtkHierarchicalBoxDataSetIsInBoxes(boxes, ix, iy, iz))
{
vtkIdType id =
(iz-loCorner[2])*cellDims[0]*cellDims[1] +
(iy-loCorner[1])*cellDims[0] +
(ix-loCorner[0]);
assert( "cell index out-of-bounds!" &&
( (id >=0) && (id < vis->GetNumberOfTuples() ) ) );
vis->SetValue(id, 0);
numBlankedPts++;
}
} // END for x
} // END for y
} // END for z
}
if (this->HasMetaData(levelIdx, dataSetIdx))
{
vtkInformation* infotmp =
this->GetMetaData(levelIdx,dataSetIdx);
infotmp->Set(NUMBER_OF_BLANKED_POINTS(), numBlankedPts);
}
grid->SetCellVisibilityArray(vis);
vis->Delete();
if( this->PadCellVisibility == true )
{
grid->AttachCellVisibilityToCellData();
}
} // END if
} // END for all datasets
if (this->HasMetaData(levelIdx, dataSetIdx))
{
vtkInformation* infotmp =
this->GetMetaData(levelIdx,dataSetIdx);
infotmp->Set(NUMBER_OF_BLANKED_POINTS(), numBlankedPts);
}
} // END for all low-res levels
}
}
}
}
//----------------------------------------------------------------------------
......
......@@ -41,6 +41,7 @@
#define __vtkHierarchicalBoxDataSet_h
#include "vtkCompositeDataSet.h"
#include <vtkstd/vector> // For STL vector
class vtkAMRBox;
class vtkInformationIdTypeKey;
......@@ -48,6 +49,8 @@ class vtkInformationIntegerKey;
class vtkInformationIntegerVectorKey;
class vtkUniformGrid;
typedef vtkstd::vector<vtkAMRBox> vtkAMRBoxList;
class VTK_FILTERING_EXPORT vtkHierarchicalBoxDataSet: public vtkCompositeDataSet
{
public:
......@@ -256,6 +259,11 @@ protected:
vtkHierarchicalBoxDataSet();
~vtkHierarchicalBoxDataSet();
// Description:
// Gets the list of higher res boxes from this level at the level, l+1
void GetHigherResolutionCoarsenedBoxes(
vtkAMRBoxList &blist, const unsigned int l );
// Description:
// Compute the range of the scalars and cache it into ScalarRange
// only if the cache became invalid (ScalarRangeComputeTime).
......
Supports Markdown
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