[Insight-users] How to get the index for the TriangleMeshToBinaryImageFilter?
lynx.abraxas at freenet.de
lynx.abraxas at freenet.de
Sun Jun 20 10:19:17 EDT 2010
Hello!
My aim is to create a binary image from a vtk-polydata mesh. I found loads of
info to this in the mailinglist archives but still I'm stuck:
I want to do it without an input image but let the
TriangleMeshToBinaryImageFilter create one which seems to be the problem
because my program terminates with:
itk::ExceptionObject (0x811f060)
Location: "void itk::TriangleMeshToBinaryImageFilter<TInputMesh,
TOutputImage>::GenerateData() [with TInputMesh = itk::Mesh<double, 3u,
itk::DefaultStaticMeshTraits<double, 3u, 3u, float, float, double> >,
TOutputImage = itk::Image<unsigned char, 3u>]"
File:
/usr/local/include/InsightToolkit/BasicFilters/itkTriangleMeshToBinaryImageFilter.txx
Line: 224
Description: itk::ERROR: TriangleMeshToBinaryImageFilter(0x8119ff0): No Image
Indices Found.
So I wonder how can I supply an index for TriangleMeshToBinaryImageFilter?
Thanks for any help or hints
Lynx
________________________________
#include <itkVTKPolyDataReader.h>
#include <itkTriangleMeshToBinaryImageFilter.h>
#include <itkImageFileWriter.h>
int main( int argc, char *argv[] ){
if( argc != 9 )
{
std::cerr << "Usage: " << argv[0];
std::cerr << " input_VTKpolydata-mesh";
std::cerr << " outputImage";
std::cerr << " dx dy dz ox oy oz";
std::cerr << std::endl;
return EXIT_FAILURE;
}
typedef unsigned char PixelType;
const unsigned int Dimension = 3;
//typedef itk::DefaultDynamicMeshTraits<double, 3, 3,double,double> TriangleMeshTraits;
//typedef itk::Mesh<double,3, TriangleMeshTraits> TriangleMeshType;
//typedef itk::QuadEdgeMesh< float, Dimension > MeshType;
typedef itk::Mesh< double, 3 > MeshType;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::VTKPolyDataReader<MeshType> VTKmeshreaderType;
VTKmeshreaderType::Pointer meshReader = VTKmeshreaderType::New();
meshReader->SetFileName(argv[1]);
// Set Size, Spacing and origin
ImageType::SizeType size;
size[ 0 ] = atoi(argv[3]);
size[ 1 ] = atoi(argv[4]);
size[ 2 ] = atoi(argv[5]);
ImageType::SpacingType spacing;
spacing[0] = 1; //100.0 / size[0];
spacing[1] = 1; //100.0 / size[1];
spacing[2] = 1; //100.0 / size[2];
ImageType::PointType origin;
origin[0]= atoi(argv[6]);
origin[1]= atoi(argv[7]);
origin[2]= atoi(argv[8]);
//Set Inside/Outside voxel value
const PixelType empty = 0;
const PixelType fill = 255;
typedef itk::TriangleMeshToBinaryImageFilter<MeshType, ImageType> MeshFilterType;
MeshFilterType::Pointer meshFilter = MeshFilterType::New();
meshFilter->SetInput(meshReader->GetOutput());
//meshFilter->SetInfoImage(); //
meshFilter->SetTolerance (1.0);
meshFilter->SetSize (size);
meshFilter->SetSpacing (spacing);
meshFilter->SetOrigin(origin);
//meshFilter->SetIndex (index);
//meshFilter->SetUseObjectValue( true );
meshFilter->SetInsideValue(fill);
meshFilter->SetOutsideValue(empty);
//meshFilter->Update();
// Write the image
typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(argv[2]);
writer->SetInput(meshFilter->GetOutput());
try
{
meshFilter->Update();
writer->Update();
}
catch( itk::ExceptionObject & excp )
{
std::cerr << excp << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
More information about the Insight-users
mailing list