Commit af87dde7 authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Implement AMR cache using STL map

Implement the AMR cache as an STL map.
parent b385026e
......@@ -18,7 +18,6 @@
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkUniformGrid.h"
#include "vtkMultiBlockDataSet.h"
#include <cassert>
......@@ -27,13 +26,19 @@ vtkStandardNewMacro( vtkAMRDataSetCache );
vtkAMRDataSetCache::vtkAMRDataSetCache()
{
this->Cache = vtkMultiBlockDataSet::New();
}
//------------------------------------------------------------------------------
vtkAMRDataSetCache::~vtkAMRDataSetCache()
{
this->Cache->Delete();
AMRCacheType::iterator iter = this->Cache.begin();
for( ; iter != this->Cache.end(); ++iter )
{
if( iter->second != NULL )
iter->second->Delete();
this->Cache.erase( iter );
}
}
//------------------------------------------------------------------------------
......@@ -44,20 +49,19 @@ void vtkAMRDataSetCache::PrintSelf( std::ostream &os, vtkIndent indent )
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlock(
const int compositeIdx, vtkUniformGrid *amrGrid)
int compositeIdx, vtkUniformGrid *amrGrid)
{
assert( "pre: AMR block is NULL" && (amrGrid != NULL) );
if( !this->HasAMRBlock( compositeIdx ) )
{
this->Cache->SetBlock( compositeIdx, amrGrid );
this->history.insert( compositeIdx );
this->Cache[ compositeIdx ] = amrGrid;
}
}
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockPointData(
const int compositeIdx, vtkDataArray *dataArray )
int compositeIdx, vtkDataArray *dataArray )
{
assert( "pre: AMR array is NULL" && (dataArray != NULL) );
assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );
......@@ -74,7 +78,7 @@ void vtkAMRDataSetCache::InsertAMRBlockPointData(
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockCellData(
const int compositeIdx, vtkDataArray *dataArray )
int compositeIdx, vtkDataArray *dataArray )
{
assert( "pre: AMR array is NULL" && (dataArray != NULL) );
assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );
......@@ -92,7 +96,7 @@ void vtkAMRDataSetCache::InsertAMRBlockCellData(
//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockCellData(
const int compositeIdx, const char *dataName )
int compositeIdx, const char *dataName )
{
if( this->HasAMRBlockCellData( compositeIdx, dataName ) )
{
......@@ -113,7 +117,7 @@ vtkDataArray* vtkAMRDataSetCache::GetAMRBlockCellData(
//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockPointData(
const int compositeIdx, const char *dataName )
int compositeIdx, const char *dataName )
{
if( this->HasAMRBlockPointData( compositeIdx, dataName ) )
......@@ -137,15 +141,14 @@ vtkUniformGrid* vtkAMRDataSetCache::GetAMRBlock( const int compositeIdx )
{
if( this->HasAMRBlock( compositeIdx ) )
{
return( vtkUniformGrid::SafeDownCast(
this->Cache->GetBlock( compositeIdx ) ) );
return this->Cache[ compositeIdx ];
}
return NULL;
}
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockCellData(
const int compositeIdx, const char *name)
int compositeIdx, const char *name)
{
assert( "pre: array name is NULL" && (name != NULL) );
......@@ -167,7 +170,7 @@ bool vtkAMRDataSetCache::HasAMRBlockCellData(
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockPointData(
const int compositeIdx, const char *name)
int compositeIdx, const char *name)
{
assert( "pre: array name is NULL" && (name != NULL) );
......@@ -188,12 +191,13 @@ bool vtkAMRDataSetCache::HasAMRBlockPointData(
}
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlock(const int compositeIdx )
bool vtkAMRDataSetCache::HasAMRBlock(int compositeIdx )
{
if( this->history.empty( ) )
if( this->Cache.empty( ) )
return false;
if( this->history.find( compositeIdx) != this->history.end() )
return true;
if( this->Cache.find( compositeIdx ) != this->Cache.end() )
return true;
return false;
}
......@@ -24,12 +24,10 @@
#define VTKAMRDATASETCACHE_H_
#include "vtkObject.h"
#include <set> // For STL set
#include <vtkstd/map> // For STL map used as the data-structure for the cache.
class vtkUniformGrid;
class vtkAMRBox;
class vtkDataArray;
class vtkMultiBlockDataSet;
class VTK_AMR_EXPORT vtkAMRDataSetCache : public vtkObject
{
......@@ -40,48 +38,48 @@ class VTK_AMR_EXPORT vtkAMRDataSetCache : public vtkObject
// Description:
// Inserts an AMR block to the cache
void InsertAMRBlock(const int compositeIdx,vtkUniformGrid *amrGrid);
void InsertAMRBlock(int compositeIdx,vtkUniformGrid *amrGrid);
// Description:
// Inserts a point data array to an already cached block
// NOTE: this->HasAMRBlock( compositeIdx ) == true
void InsertAMRBlockPointData(
const int compositeIdx, vtkDataArray *dataArray );
int compositeIdx, vtkDataArray *dataArray );
// Description:
// Inserts a cell data array to an already cached block
// NOTE: this->HasAMRBlock( compositeIdx ) == true
void InsertAMRBlockCellData(
const int compositeIdx, vtkDataArray *dataArray );
int compositeIdx, vtkDataArray *dataArray );
// Description:
// Given the name of the cell array and AMR block composite index, this
// method returns a pointer to the cell data array.
// NOTE: Null is returned if the cell array and/or block is not cached.
vtkDataArray* GetAMRBlockCellData(
const int compositeIdx, const char *dataName );
int compositeIdx, const char *dataName );
// Description:
// Given the name of the point array and AMR block composite index, this
// method returns a pointer to the point data array.
// NOTE: Null is returend if the point array and /or block is not cached.
vtkDataArray* GetAMRBlockPointData(
const int compositeIdx, const char *dataName );
int compositeIdx, const char *dataName );
// Description:
// Given the composite index, this method returns the AMR block.
// NOTE: Null is returned if the AMR block does not exist in the cache.
vtkUniformGrid* GetAMRBlock( const int compositeIdx );
vtkUniformGrid* GetAMRBlock(int compositeIdx );
// Description:
// Checks if the cell data array, associated with the provided name, has
// been cached for the AMR block with the given composite index.
bool HasAMRBlockCellData(const int compositeIdx, const char *name);
bool HasAMRBlockCellData(int compositeIdx, const char *name);
// Description:
// Checks if the point data array, associated with the provided name, has
// been cached for the AMR block with the given composite index.
bool HasAMRBlockPointData(const int compositeIdx, const char *name);
bool HasAMRBlockPointData(int compositeIdx, const char *name);
// Description:
// Checks if the AMR block associated with the given composite is cached.
......@@ -91,8 +89,10 @@ class VTK_AMR_EXPORT vtkAMRDataSetCache : public vtkObject
vtkAMRDataSetCache();
virtual ~vtkAMRDataSetCache();
vtkMultiBlockDataSet *Cache;
std::set< int > history;
//BTX
typedef vtkstd::map< int, vtkUniformGrid* > AMRCacheType;
AMRCacheType Cache;
//ETX
private:
vtkAMRDataSetCache( const vtkAMRDataSetCache& ); // Not implemented
......
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