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

ENH: Initial commit of AMR dataset cache

Adding AMR dataset cache to the repository and
build. The AMR dataset cache provides functionality
for caching AMR blocks & data and is intended to be
used as the means to minimize the out-of-core
operations.
parent 47ecd7b7
......@@ -13,6 +13,7 @@ SET(Kit_SRCS
vtkAMRBaseReader.cxx
vtkAMRConnectivityFilter.cxx
vtkAMRContourFilter.cxx
vtkAMRDataSetCache.cxx
vtkAMRDualMeshExtractor.cxx
vtkAMREnzoParticlesReader.cxx
vtkAMREnzoReader.cxx
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAMRDataSetCache.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkAMRDataSetCache.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkUniformGrid.h"
#include <cassert>
vtkStandardNewMacro( vtkAMRDataSetCache );
vtkAMRDataSetCache::vtkAMRDataSetCache()
{
this->Size = 100; // Cache 100 blocks by default
}
//------------------------------------------------------------------------------
vtkAMRDataSetCache::~vtkAMRDataSetCache()
{
vtkstd::map< int, vtkUniformGrid* >::iterator iter;
for( iter = this->Cache.begin(); iter != this->Cache.end(); ++iter )
{
if( iter->second != NULL )
iter->second->Delete();
}
this->Cache.clear();
}
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::PrintSelf( std::ostream &os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
}
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlock(
const int compositeIdx, vtkUniformGrid *amrGrid)
{
assert( "pre: AMR block is NULL" && (amrGrid != NULL) );
if( !this->HasAMRBlock( compositeIdx ) )
{
this->Cache[ compositeIdx ] = amrGrid;
}
}
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockPointData(
const int compositeIdx, vtkDataArray *dataArray )
{
assert( "pre: AMR array is NULL" && (dataArray != NULL) );
assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );
vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
assert( "pre: AMR block should not be NULL" && ( amrBlock != NULL ) );
vtkPointData *PD = amrBlock ->GetPointData();
assert( "pre: PointData should not be NULL" && ( PD != NULL ) );
if( !PD->HasArray( dataArray->GetName() ) )
PD->AddArray( dataArray );
}
//------------------------------------------------------------------------------
void vtkAMRDataSetCache::InsertAMRBlockCellData(
const int compositeIdx, vtkDataArray *dataArray )
{
assert( "pre: AMR array is NULL" && (dataArray != NULL) );
assert( "pre: AMR block is cached" && ( this->HasAMRBlock( compositeIdx ) ) );
vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
assert( "pre: AMR block should not be NULL" &&
(this->HasAMRBlock( compositeIdx ) ) );
vtkCellData *CD = amrBlock ->GetCellData();
assert( "pre: CellData should not be NULL" && (CD != NULL) );
if( !CD->HasArray( dataArray->GetName() ) )
CD->AddArray( dataArray );
}
//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockCellData(
const int compositeIdx, const char *dataName )
{
if( this->HasAMRBlockCellData( compositeIdx, dataName ) )
{
vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
assert( "pre: AMR block should not be NULL" &&
(this->HasAMRBlock( compositeIdx ) ) );
vtkCellData *CD = amrBlock ->GetCellData();
assert( "pre: CellData should not be NULL" && (CD != NULL) );
if( CD->HasArray( dataName ) )
return CD->GetArray( dataName );
else
return NULL;
}
return NULL;
}
//------------------------------------------------------------------------------
vtkDataArray* vtkAMRDataSetCache::GetAMRBlockPointData(
const int compositeIdx, const char *dataName )
{
if( this->HasAMRBlockPointData( compositeIdx, dataName ) )
{
vtkUniformGrid *amrBlock = this->GetAMRBlock( compositeIdx );
assert( "pre: AMR block should not be NULL" && ( amrBlock != NULL ) );
vtkPointData *PD = amrBlock ->GetPointData();
assert( "pre: PointData should not be NULL" && ( PD != NULL ) );
if( PD->HasArray( dataName ) )
return PD->GetArray( dataName );
else
return NULL;
}
return NULL;
}
//------------------------------------------------------------------------------
vtkUniformGrid* vtkAMRDataSetCache::GetAMRBlock( const int compositeIdx )
{
if( this->HasAMRBlock( compositeIdx ) )
return this->Cache[ compositeIdx ];
return NULL;
}
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockCellData(
const int compositeIdx, const char *name)
{
assert( "pre: array name is NULL" && (name != NULL) );
if( this->HasAMRBlock( compositeIdx ) )
{
vtkCellData *CD = this->Cache[ compositeIdx ]->GetCellData();
assert( "pre: cell data is NULL" && (CD != NULL) );
if( CD->HasArray( name ) )
return true;
else
return false;
}
return false;
}
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlockPointData(
const int compositeIdx, const char *name)
{
assert( "pre: array name is NULL" && (name != NULL) );
if( this->HasAMRBlock( compositeIdx ) )
{
vtkPointData *PD = this->Cache[ compositeIdx ]->GetPointData();
assert( "pre: point data is NULL" && (PD != NULL) );
if( PD->HasArray( name ) )
return true;
else
return false;
}
return false;
}
//------------------------------------------------------------------------------
bool vtkAMRDataSetCache::HasAMRBlock(const int compositeIdx )
{
if( this->Cache.find( compositeIdx) != this->Cache.end() )
return true;
return false;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkAMRDataSetCache.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkAMRDataSetCache.h -- A cache for AMR blocks and block data
//
// .SECTION Description
// A concrete implementation of vtkObject that provides functionality for
// caching AMR blocks. The primary intent of this class is to be used by the
// AMR reader infrastructure for caching blocks/data in memory to minimize
// out-of-core operations.
#ifndef VTKAMRDATASETCACHE_H_
#define VTKAMRDATASETCACHE_H_
#include "vtkObject.h"
#include <vtkstd/map> // For STL map
class vtkUniformGrid;
class vtkAMRBox;
class vtkDataArray;
class VTK_AMR_EXPORT vtkAMRDataSetCache : public vtkObject
{
public:
static vtkAMRDataSetCache* New();
vtkTypeMacro( vtkAMRDataSetCache, vtkObject );
void PrintSelf( std::ostream &os, vtkIndent indent );
// Description:
// Set/Get Size of the cache.
vtkSetMacro( Size, int );
vtkGetMacro( Size, int );
// Description:
// Inserts an AMR block to the cache
void InsertAMRBlock(const 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 );
// Description:
// Inserts a cell data array to an already cached block
// NOTE: this->HasAMRBlock( compositeIdx ) == true
void InsertAMRBlockCellData(
const 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 );
// 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 );
// 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 );
// 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);
// 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);
// Description:
// Checks if the AMR block associated with the given composite is cached.
bool HasAMRBlock( const int compositeIdx );
protected:
vtkAMRDataSetCache();
virtual ~vtkAMRDataSetCache();
int Size;
vtkstd::map< int, vtkUniformGrid* > Cache;
private:
vtkAMRDataSetCache( const vtkAMRDataSetCache& ); // Not implemented
void operator=( const vtkAMRDataSetCache& ); // Not implemented
};
#endif /* VTKAMRDATASETCACHE_H_ */
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