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

COMP: Use vtkImageToStructuredGrid instead

Remove vtkImageDataToStructuredGridFilter and its
use in the example code TestImageDataToStructuredGridFilter
in favor to vtkImageToStructuredGrid which essentially
provides the same functionality but has a more conscise
name.
parent abc0a5e9
......@@ -17,7 +17,7 @@
// A simple utility that demonstrates & tests the functionality of the
// vtkImageDataToStructuredGridFilter.
#include "vtkImageDataToStructuredGridFilter.h"
#include "vtkImageToStructuredGrid.h"
#include "vtkStructuredGrid.h"
#include "vtkImageData.h"
#include "vtkUniformGrid.h"
......@@ -41,8 +41,7 @@ int main( int argc, char **argv )
vtkAssertUtils::assertNotNull( myGrid, __FILE__, __LINE__ );
vtkAssertUtils::assertEquals(
myGrid->GetCellData()->GetNumberOfArrays(),1,__FILE__,__LINE__);
vtkImageDataToStructuredGridFilter* myFilter =
vtkImageDataToStructuredGridFilter::New( );
vtkImageToStructuredGrid* myFilter = vtkImageToStructuredGrid::New( );
vtkAssertUtils::assertNotNull( myFilter, __FILE__, __LINE__ );
myFilter->SetInput( myGrid );
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageDataToStructuredGridFilter.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 "vtkImageDataToStructuredGridFilter.h"
#include "vtkObjectFactory.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkDataObject.h"
#include "vtkImageData.h"
#include "vtkPoints.h"
#include "vtkStructuredGrid.h"
#include "vtkPointData.h"
#include "vtkCellData.h"
#include <cassert>
//
// Standard methods
//
vtkStandardNewMacro(vtkImageDataToStructuredGridFilter)
vtkImageDataToStructuredGridFilter::vtkImageDataToStructuredGridFilter()
{
// TODO Auto-generated constructor stub
}
//------------------------------------------------------------------------------
vtkImageDataToStructuredGridFilter::~vtkImageDataToStructuredGridFilter()
{
// TODO Auto-generated destructor stub
}
//------------------------------------------------------------------------------
void vtkImageDataToStructuredGridFilter::PrintSelf( std::ostream &oss,
vtkIndent indent )
{
this->Superclass::PrintSelf( oss, indent );
}
//------------------------------------------------------------------------------
int vtkImageDataToStructuredGridFilter::FillInputPortInformation(
int port, vtkInformation* info)
{
info->Set(vtkAlgorithm::INPUT_REQUIRED_DATA_TYPE(),"vtkImageData");
return 1;
}
//------------------------------------------------------------------------------
int vtkImageDataToStructuredGridFilter::FillOutputPortInformation(
int port, vtkInformation* info )
{
info->Set(vtkDataObject::DATA_TYPE_NAME(),"vtkStructuredGrid");
return 1;
}
//------------------------------------------------------------------------------
int vtkImageDataToStructuredGridFilter::RequestData(
vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector )
{
vtkInformation* inInfo = inputVector[0]->GetInformationObject( 0 );
vtkInformation* outInfo = outputVector->GetInformationObject( 0 );
assert( inInfo != NULL );
assert( outInfo != NULL );
vtkImageData* img = vtkImageData::SafeDownCast(
inInfo->Get(vtkImageData::DATA_OBJECT() ) );
assert( img != NULL );
vtkStructuredGrid* grid = vtkStructuredGrid::SafeDownCast(
outInfo->Get( vtkStructuredGrid::DATA_OBJECT() ) );
assert( grid != NULL );
int dims[3];
img->GetDimensions( dims );
vtkPoints *gridPoints = vtkPoints::New();
assert( gridPoints != NULL );
gridPoints->SetDataTypeToDouble();
gridPoints->SetNumberOfPoints( img->GetNumberOfPoints() );
double pnt[3];
for( int i=0; i < img->GetNumberOfPoints(); ++i )
{
img->GetPoint( i, pnt );
gridPoints->SetPoint(i,pnt);
}
grid->SetDimensions(dims);
grid->SetPoints( gridPoints );
this->CopyPointData( img, grid );
this->CopyCellData( img, grid );
return 1;
}
//------------------------------------------------------------------------------
void vtkImageDataToStructuredGridFilter::CopyPointData(
vtkImageData* img, vtkStructuredGrid* sgrid)
{
assert( img != NULL );
assert( sgrid != NULL );
if( img->GetPointData()->GetNumberOfArrays() == 0 )
return;
for( int i=0; i < img->GetPointData()->GetNumberOfArrays(); ++i)
{
vtkDataArray* myArray = img->GetPointData()->GetArray( i );
sgrid->GetPointData()->AddArray( myArray );
} // END for all node arrays
}
//------------------------------------------------------------------------------
void vtkImageDataToStructuredGridFilter::CopyCellData(
vtkImageData* img, vtkStructuredGrid* sgrid )
{
assert( img != NULL );
assert( sgrid != NULL );
if( img->GetCellData()->GetNumberOfArrays() == 0)
return;
for( int i=0; i < img->GetCellData()->GetNumberOfArrays(); ++i)
{
vtkDataArray* myArray = img->GetCellData()->GetArray( i );
sgrid->GetCellData()->AddArray( myArray );
} // END for all cell arrays
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkImageDataToStructuredGridFilter.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 vtkImageDataToStructuredGridFilter.h -- A filter to convert image
// data to structured grid.
//
// .SECTION Description
// A concrete instance of vtkStructuredGridAlgorithm which provides
// functionality for converting instances of vtkImageData to vtkStructuredGrid.
#ifndef VTKIMAGEDATATOSTRUCTUREDGRIDFILTER_H_
#define VTKIMAGEDATATOSTRUCTUREDGRIDFILTER_H_
#include "vtkStructuredGridAlgorithm.h"
class vtkStructuredGrid;
class vtkImageData;
class vtkInformation;
class vtkInformationVector;
class VTK_FILTERING_EXPORT vtkImageDataToStructuredGridFilter :
public vtkStructuredGridAlgorithm
{
public:
static vtkImageDataToStructuredGridFilter* New();
vtkTypeMacro(vtkImageDataToStructuredGridFilter,vtkStructuredGridAlgorithm);
void PrintSelf( std::ostream &oss, vtkIndent indent );
protected:
vtkImageDataToStructuredGridFilter();
virtual ~vtkImageDataToStructuredGridFilter();
virtual int RequestData(
vtkInformation* request,
vtkInformationVector** inputVector,
vtkInformationVector* outputVector );
// Description:
// Helper function to copy point/cell data from image to grid
void CopyPointData( vtkImageData*, vtkStructuredGrid* );
void CopyCellData( vtkImageData*, vtkStructuredGrid* );
virtual int FillInputPortInformation(int, vtkInformation* info);
virtual int FillOutputPortInformation(int, vtkInformation* info );
private:
vtkImageDataToStructuredGridFilter(
const vtkImageDataToStructuredGridFilter& ); //Not implemented
void operator=(const vtkImageDataToStructuredGridFilter&);//Not implemented
};
#endif /* VTKIMAGEDATATOSTRUCTUREDGRIDFILTER_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