Commit 75cbea2f authored by George Zagaris's avatar George Zagaris
Browse files

ENH: Use of vtkImageToStructuredGrid instead

Removed all the internal I/O to generate legacy
VTK files. vtkImageToStructuredGrid is used instead.
parent 6fd84a9b
......@@ -23,6 +23,9 @@
#include "vtkDataArray.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include "vtkImageToStructuredGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkStructuredGridWriter.h"
#include <string>
#include <sstream>
......@@ -69,7 +72,7 @@ void vtkAMRDataTransferFilter::Transfer( )
vtkAssertUtils::assertNotNull(this->ExtrudedData,__FILE__,__LINE__);
// STEP 1: Donor-Receiver search
// TODO: implement this
this->DonorSearch();
}
//------------------------------------------------------------------------------
......@@ -113,6 +116,20 @@ void vtkAMRDataTransferFilter::ExtrudeGhostLayers( )
}
//------------------------------------------------------------------------------
void vtkAMRDataTransferFilter::DonorSearch()
{
vtkAssertUtils::assertNotNull(this->ExtrudedData,__FILE__,__LINE__);
// TODO: implement this
}
//------------------------------------------------------------------------------
void vtkAMRDataTransferFilter::DataTransfer()
{
// TODO: implement this
}
//------------------------------------------------------------------------------
vtkUniformGrid* vtkAMRDataTransferFilter::GetExtrudedGrid( vtkAMRBox &ebox,
vtkUniformGrid* srcGrid )
......@@ -129,8 +146,6 @@ vtkUniformGrid* vtkAMRDataTransferFilter::GetExtrudedGrid( vtkAMRBox &ebox,
ebox.GetGridSpacing( h );
ebox.GetBoxOrigin( origin );
std::cout << "ndim: " << ndim[0] << " " << ndim[1] << " " << ndim[2] << "\n";
extrudedGrid->Initialize();
extrudedGrid->SetDimensions( ndim );
extrudedGrid->SetSpacing( h );
......@@ -159,7 +174,7 @@ void vtkAMRDataTransferFilter::WriteData( vtkHierarchicalBoxDataSet* amrData,
vtkUniformGrid *myGrid = amrData->GetDataSet(level,data,myBox);
if( myGrid != NULL )
myBox.WriteToVtkFile( oss.str().c_str() );
this->WriteGrid( myGrid, oss.str() );
} // END for all data
} // END for all levels
......@@ -171,117 +186,29 @@ void vtkAMRDataTransferFilter::WriteGrid( vtkUniformGrid* grid,
{
vtkAssertUtils::assertNotNull( grid, __FILE__, __LINE__ );
std::ostringstream oss;
oss.str( "" );
oss << prefix << ".vtk";
std::ofstream ofs;
ofs.open( oss.str( ).c_str( ) );
vtkAssertUtils::assertTrue( ofs.is_open(), __FILE__, __LINE__ );
ofs << "# vtk DataFile Version 3.0\n";
ofs << prefix << "\n";
ofs << "ASCII\n";
ofs << "DATASET STRUCTURED_GRID\n";
double pnt[3];
int ijk[3];
int N[3];
grid->GetDimensions( N );
ofs << "DIMENSIONS " << N[0] << " " << N[1] << " " << N[2] << std::endl;
ofs << "POINTS " << grid->GetNumberOfPoints( ) << " double\n";
for( int k=0; k < N[2]; ++k )
{
for( int j=0; j < N[1]; ++j )
{
for( int i=0; i < N[0]; ++i )
{
ijk[0] = i; ijk[1] = j; ijk[2] = k;
int pntIdx = vtkStructuredData::ComputePointId( N, ijk );
grid->GetPoint( pntIdx, pnt );
ofs << pnt[ 0 ] << " " << pnt[ 1 ] << " " << pnt[ 2 ] << "\n";
} // END for all k
} // END for all j
} // END for all i
vtkPointData *pntData = grid->GetPointData();
if( (pntData != NULL) && (pntData->GetNumberOfArrays() > 0) )
{
ofs << "POINT_DATA " << grid->GetNumberOfPoints() << std::endl;
for(int dataArray=0;dataArray < pntData->GetNumberOfArrays();++dataArray)
{
vtkDataArray *array = pntData->GetArray( dataArray );
vtkAssertUtils::assertNotNull( array, __FILE__, __LINE__ );
ofs << this->GetDataArrayVTKString( array );
} // END for all data arrays
} // if there are point data
vtkCellData *cellData = grid->GetCellData( );
if( (cellData != NULL) && ( cellData->GetNumberOfArrays() > 0) )
{
ofs << "CELL_DATA " << grid->GetNumberOfCells() << std::endl;
for( int arrayidx=0; arrayidx<cellData->GetNumberOfArrays(); ++arrayidx)
{
vtkDataArray *array = cellData->GetArray( arrayidx );
vtkAssertUtils::assertNotNull( array, __FILE__, __LINE__ );
ofs << this->GetDataArrayVTKString( array );
} // END for all arrays
}
ofs.close( );
// STEP 0: Setup the file name to use
std::string fileName = prefix + ".vtk";
}
// STEP 1: Convert to a structured grid
vtkImageToStructuredGrid *img2sgrid = vtkImageToStructuredGrid::New( );
vtkAssertUtils::assertNotNull( img2sgrid,__FILE__,__LINE__);
//------------------------------------------------------------------------------
std::string vtkAMRDataTransferFilter::GetDataArrayVTKString(vtkDataArray *d )
{
vtkAssertUtils::assertNotNull( d, __FILE__, __LINE__ );
std::ostringstream oss;
oss.str( "" );
int i=0;
switch( d->GetNumberOfComponents() )
{
case 1:
// Write as scalars
oss << "SCALARS " << d->GetName() << " " << d->GetDataTypeAsString();
oss << " 1\n";
oss << "LOOKUP_TABLE default\n";
for( i=0; i < d->GetNumberOfTuples(); ++i )
oss << d->GetComponent(i,1) << std::endl;
break;
default:
// Write as Vector
// TODO: implement this
break;
}
return( oss.str( ) );
}
img2sgrid->SetInput( grid );
img2sgrid->Update();
vtkStructuredGrid *myGrid = img2sgrid->GetOutput();
vtkAssertUtils::assertNotNull(myGrid,__FILE__,__LINE__);
//------------------------------------------------------------------------------
void vtkAMRDataTransferFilter::WriteGrids( )
{
vtkAssertUtils::assertNotNull( this->AMRDataSet,__FILE__,__LINE__);
// STEP 2: Use structured grid writer to write the grid object
vtkStructuredGridWriter *myWriter = vtkStructuredGridWriter::New();
vtkAssertUtils::assertNotNull( myWriter,__FILE__,__LINE__);
std::ostringstream oss;
std::cout << "Writing grid @" << fileName << std::endl;
std::cout.flush();
for( int l=0; l < this->AMRDataSet->GetNumberOfLevels(); ++l )
{
for( int idx=0; idx < this->AMRDataSet->GetNumberOfDataSets(l); ++idx )
{
vtkAMRBox myBox;
vtkUniformGrid* myGrid=this->AMRDataSet->GetDataSet( l, idx, myBox );
if( myGrid != NULL )
{
oss.str( "" );
oss << "INITIAL_" << myBox.GetBlockId() << "_";
oss << myBox.GetLevel();
this->WriteGrid( myGrid, oss.str( ) );
}
} // END for all data
} // END for all levels
myWriter->SetInput(0,myGrid);
myWriter->SetFileName( fileName.c_str( ) );
myWriter->Update();
myWriter->Delete();
img2sgrid->Delete();
}
......@@ -81,12 +81,12 @@ class VTK_AMR_EXPORT vtkAMRDataTransferFilter:
void WriteGrid( vtkUniformGrid* grid, std::string prefix );
// Description:
// Returns a VTK string representation of the supplied data array
std::string GetDataArrayVTKString( vtkDataArray* dataArray );
//
void DonorSearch();
// Description:
// Loops throught the data-set and writes each grid.
void WriteGrids( );
//
void DataTransfer();
int NumberOfGhostLayers;
vtkHierarchicalBoxDataSet *ExtrudedData;
......
......@@ -40,7 +40,6 @@ vtkMultiProcessController *Controller;
// Function Prototypes
vtkHierarchicalBoxDataSet* GetAMRDataSet( );
vtkUniformGrid* GetGrid( double* origin,double* h,int* ndim );
void WriteAMRData( vtkHierarchicalBoxDataSet *amrdata, const char* filename );
int main( int argc, char **argv )
{
......@@ -61,7 +60,6 @@ int main( int argc, char **argv )
vtkAssertUtils::assertEquals(
amrData->GetNumberOfDataSets(1),2,__FILE__,__LINE__ );
WriteAMRData( amrData, "Input" );
std::cout << "Done reading!" << std::endl;
std::cout.flush( );
......@@ -114,17 +112,6 @@ int main( int argc, char **argv )
// Function Prototype Implementation
//=============================================================================
void WriteAMRData( vtkHierarchicalBoxDataSet* amrdata, const char* filename )
{
vtkAssertUtils::assertNotNull(amrdata,__FILE__,__LINE__);
// vtkXMLPHierarchicalBoxDataWriter *myWriter =
// vtkXMLPHierarchicalBoxDataWriter::New( );
// myWriter->SetInput( amrdata );
// myWriter->SetFileName( filename );
// myWriter->Write();
}
//------------------------------------------------------------------------------
vtkHierarchicalBoxDataSet* GetAMRDataSet( )
{
......
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