Commit 8e8fb1a3 authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Separated Get/Set for Metadata and data

Added additional routines that allow to get/set the
data and metadata separately.
parent 50f8e2a8
......@@ -186,68 +186,178 @@ void vtkHierarchicalBoxDataSet::SetDataSet(
}
//----------------------------------------------------------------------------
vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(
unsigned int level,unsigned int id,vtkAMRBox& box)
void vtkHierarchicalBoxDataSet::SetDataSet(
unsigned int level, unsigned int idx, vtkUniformGrid *grid )
{
if (this->GetNumberOfLevels() <= level ||
this->GetNumberOfDataSets(level) <= id)
assert( "Input grid is NULL!" && (grid!=NULL) );
// STEP 0: Resize the number of levels accordingly
if( level >= this->GetNumberOfLevels() )
{
return 0;
this->SetNumberOfLevels( level+1 );
}
vtkMultiPieceDataSet* levelDS = vtkMultiPieceDataSet::SafeDownCast(
this->Superclass::GetChild(level));
if (levelDS)
// STEP 1: Insert data at the given location
vtkMultiPieceDataSet* levelDS =
vtkMultiPieceDataSet::SafeDownCast( this->Superclass::GetChild(level));
if( levelDS != NULL )
{
vtkUniformGrid* ds = vtkUniformGrid::SafeDownCast(levelDS->GetPiece(id));
vtkInformation* info = levelDS->GetMetaData(id);
if (info)
{
levelDS->SetPiece(idx, grid);
}
else
{
vtkErrorMacro( "Multi-piece data-structure is NULL!!!!" );
}
}
// Sanity Checks
vtkAssertUtils::assertTrue(
info->Has(BOX_DIMENSIONALITY()),__FILE__, __LINE__);
vtkAssertUtils::assertTrue(info->Has(BOX()),__FILE__,__LINE__);
vtkAssertUtils::assertTrue(info->Has(BOX_ORIGIN()),__FILE__,__LINE__);
vtkAssertUtils::assertTrue(info->Has(RANK()),__FILE__,__LINE__);
vtkAssertUtils::assertTrue(info->Has(BLOCK_ID()),__FILE__,__LINE__);
vtkAssertUtils::assertTrue(info->Has(REAL_EXTENT()),__FILE__,__LINE__);
box.SetDimensionality( info->Get( BOX_DIMENSIONALITY() ) );
int *dims = info->Get( BOX() );
box.SetDimensions(dims,dims+3);
box.SetDataSetOrigin( info->Get( BOX_ORIGIN() ) );
box.SetProcessId( info->Get( RANK() ) );
box.SetBlockId( info->Get( BLOCK_ID() ) );
box.SetRealExtent( info->Get( REAL_EXTENT() ) );
box.SetLevel( level );
double *spacing = info->Get( SPACING() );
vtkAssertUtils::assertNotNull( spacing, __FILE__, __LINE__ );
box.SetGridSpacing( spacing );
// int dimensionality = info->Has(BOX_DIMENSIONALITY())?
// info->Get()
// int dimensionality = info->Has(BOX_DIMENSIONALITY())?
// info->Get(BOX_DIMENSIONALITY()) : 3;
// box.SetDimensionality(dimensionality);
//
// int* boxVec = info->Get(BOX());
// if (boxVec)
// {
// box.SetDimensions(boxVec,boxVec+3);
// }
//------------------------------------------------------------------------------
void vtkHierarchicalBoxDataSet::SetMetaData(
unsigned int level, unsigned int id, const vtkAMRBox &box )
{
}
else
{
vtkErrorMacro( "Metadata is NULL!" );
}
return ds;
// STEP 0: Resize the number of levels accordingly
if( level >= this->GetNumberOfLevels() )
{
this->SetNumberOfLevels( level+1 );
}
return 0;
// STEP 1: Insert the meta data at the given location
vtkMultiPieceDataSet* levelDS =
vtkMultiPieceDataSet::SafeDownCast( this->Superclass::GetChild(level));
if( levelDS != NULL )
{
if( id >= levelDS->GetNumberOfPieces() )
levelDS->SetPiece( id+1, NULL);
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!!!!" );
}
}
//------------------------------------------------------------------------------
vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(
unsigned int level, unsigned int id )
{
if( this->GetNumberOfLevels() <= level ||
this->GetNumberOfDataSets(level) <= id )
{
return NULL;
}
vtkMultiPieceDataSet* levelDS =
vtkMultiPieceDataSet::SafeDownCast(this->Superclass::GetChild(level));
if( levelDS )
{
return( vtkUniformGrid::SafeDownCast( levelDS->GetPiece( id ) ) );
}
vtkErrorMacro( "Unexcepected NULL pointer encountered!\n" );
return NULL;
}
//----------------------------------------------------------------------------
vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(
unsigned int level, unsigned int id, vtkAMRBox& box )
{
if( this->GetMetaData( level, id, box ) != 1 )
{
vtkErrorMacro( "Could not retrieve meta-data for the given data set!" );
}
return( this->GetDataSet( level, id ) );
}
//vtkUniformGrid* vtkHierarchicalBoxDataSet::GetDataSet(
// unsigned int level,unsigned int id,vtkAMRBox& box)
//{
// if (this->GetNumberOfLevels() <= level ||
// this->GetNumberOfDataSets(level) <= id)
// {
// return 0;
// }
//
// vtkMultiPieceDataSet* levelDS = vtkMultiPieceDataSet::SafeDownCast(
// this->Superclass::GetChild(level));
// if (levelDS)
// {
// vtkUniformGrid* ds = vtkUniformGrid::SafeDownCast(levelDS->GetPiece(id));
// vtkInformation* info = levelDS->GetMetaData(id);
// if (info)
// {
//
// // Sanity Checks
// vtkAssertUtils::assertTrue(
// info->Has(BOX_DIMENSIONALITY()),__FILE__, __LINE__);
// vtkAssertUtils::assertTrue(info->Has(BOX()),__FILE__,__LINE__);
// vtkAssertUtils::assertTrue(info->Has(BOX_ORIGIN()),__FILE__,__LINE__);
// vtkAssertUtils::assertTrue(info->Has(RANK()),__FILE__,__LINE__);
// vtkAssertUtils::assertTrue(info->Has(BLOCK_ID()),__FILE__,__LINE__);
// vtkAssertUtils::assertTrue(info->Has(REAL_EXTENT()),__FILE__,__LINE__);
//
// box.SetDimensionality( info->Get( BOX_DIMENSIONALITY() ) );
// int *dims = info->Get( BOX() );
// box.SetDimensions(dims,dims+3);
// box.SetDataSetOrigin( info->Get( BOX_ORIGIN() ) );
// box.SetProcessId( info->Get( RANK() ) );
// box.SetBlockId( info->Get( BLOCK_ID() ) );
// box.SetRealExtent( info->Get( REAL_EXTENT() ) );
// box.SetLevel( level );
//
// double *spacing = info->Get( SPACING() );
// vtkAssertUtils::assertNotNull( spacing, __FILE__, __LINE__ );
// box.SetGridSpacing( spacing );
//
//// int dimensionality = info->Has(BOX_DIMENSIONALITY())?
//// info->Get()
//// int dimensionality = info->Has(BOX_DIMENSIONALITY())?
//// info->Get(BOX_DIMENSIONALITY()) : 3;
//// box.SetDimensionality(dimensionality);
////
//// int* boxVec = info->Get(BOX());
//// if (boxVec)
//// {
//// box.SetDimensions(boxVec,boxVec+3);
//// }
//
// }
// else
// {
// vtkErrorMacro( "Metadata is NULL!" );
// }
// return ds;
// }
// return 0;
//}
//----------------------------------------------------------------------------
......@@ -295,6 +405,51 @@ int vtkHierarchicalBoxDataSet::GetRefinementRatio(vtkCompositeDataIterator* iter
return info->Has(REFINEMENT_RATIO())? info->Get(REFINEMENT_RATIO()): 0;
}
//----------------------------------------------------------------------------
int vtkHierarchicalBoxDataSet::GetMetaData(
unsigned int level, unsigned int index, vtkAMRBox &box)
{
vtkMultiPieceDataSet* levelMDS =
vtkMultiPieceDataSet::SafeDownCast( this->GetChild(level) );
if( levelMDS != NULL )
{
vtkInformation* info = levelMDS->GetMetaData( index );
if( info != NULL )
{
// Sanity Checks
assert( "Expected Meta-data" && info->Has( BOX_DIMENSIONALITY() ) );
assert( "Expected Meta-data" && info->Has( BOX() ) );
assert( "Expected Meta-data" && info->Has( RANK() ) );
assert( "Expected Meta-data" && info->Has( BOX_ORIGIN() ) );
assert( "Expected Meta-data" && info->Has( BLOCK_ID() ) );
assert( "Expected Meta-data" && info->Has( REAL_EXTENT() ) );
box.SetDimensionality( info->Get( BOX_DIMENSIONALITY() ) );
int *dims = info->Get( BOX() );
box.SetDimensions(dims,dims+3);
box.SetDataSetOrigin( info->Get( BOX_ORIGIN() ) );
box.SetProcessId( info->Get( RANK() ) );
box.SetBlockId( info->Get( BLOCK_ID() ) );
box.SetRealExtent( info->Get( REAL_EXTENT() ) );
box.SetLevel( level );
double *spacing = info->Get( SPACING() );
box.SetGridSpacing( spacing );
return 1;
}
else
{
vtkErrorMacro( "No meta-data found for requested object!\n" );
return 0;
}
}
else
{
vtkErrorMacro( "No data found at requested level!\n" );
}
return 0;
}
//----------------------------------------------------------------------------
vtkInformation* vtkHierarchicalBoxDataSet::GetMetaData(unsigned int level,
unsigned int index)
......
......@@ -95,6 +95,17 @@ public:
// levels and the number of datasets in the level to fit level, id requested.
void SetDataSet(unsigned int level, unsigned int id,
int LoCorner[3], int HiCorner[3], vtkUniformGrid* dataSet);
// Description:
// Set the dataset pointer for a given node without any metadata. This will
// resize the number of levels and the number of datasets accordingly.
void SetDataSet(unsigned int level, unsigned int id, vtkUniformGrid* dataSet);
// Description:
// Sets the meta-data object at a given node. This will resize the number
// of levels and number of datasets acoordingly.
void SetMetaData(unsigned int level, unsigned int id, const vtkAMRBox &box );
//BTX
// Description:
// Set the dataset pointer for a given node. This will resize the number of
......@@ -112,6 +123,7 @@ public:
vtkUniformGrid* GetDataSet(unsigned int level,
unsigned int id,
vtkAMRBox& box);
vtkUniformGrid* GetDataSet(unsigned int level,unsigned int id );
// Description:
// Returns the AMR box for the location pointer by the iterator.
......@@ -137,6 +149,11 @@ public:
// avoid unnecessary allocations.
vtkInformation* GetMetaData(unsigned int level, unsigned int index);
// Description:
// Get the AMR box meta-data associated with a given dataset.
// Returns 1 iff GetMetaData() was successful, else 0.
int GetMetaData(unsigned int level, unsigned int index, vtkAMRBox &box);
// Description:
// Returns if meta-data exists for a given dataset under a given level.
int HasMetaData(unsigned int level, unsigned int index);
......
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