[Insight-users] ERROR: VTKPolyDataWriter

Luis Ibanez luis.ibanez at kitware.com
Tue Jun 30 17:02:33 EDT 2009



Hi Noe,


You don't need any the following lines:



 > vtkPolyData *vtkPolyDataOut = NULL;
 > itkMeshTovtkPolyData * itkMesh2PolyData = new itkMeshTovtkPolyData();
 > itkMesh2PolyData->SetInput (meshSource->GetOutput());
 > vtkPolyDataOut = itkMesh2PolyData->GetOutput();



Simply create the polydata writer and connect the
output of the mesh filter to it.


Like:


    typedef itk::VTKPolyDataWriter<MeshType>WriterType;
    WriterType::Pointer writer1 = WriterType::New();

    write1->SetInput( meshSource->GetOutput() );


then call

    write1->Update();


That will save the ITK mesh into a vtkPolyData (legacy) file.



     Regards,


        Luis



Noé Jimenez Costa wrote:
> 
> Hi guys,
> I need your help. I want convert my itkmesh to vtkPolydata and after I 
> want to write it in "ojo.vtk". But, when I try it the mistake appears. 
> Can you help me??
> 
> 
> int main(int argc, char * argv[] )
> {
> 
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: IsoSurfaceExtraction  inputImageFile   
> objectValue" << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   const unsigned int Dimension = 3;
>   typedef signed short PixelType;
> 
>   typedef itk::Image< PixelType, Dimension >   ImageType;
> 
>   typedef itk::ImageFileReader< ImageType >    ReaderType;
>   ReaderType::Pointer reader = ReaderType::New();
>   reader->SetFileName( argv[1] );
> 
>   try
>     {
>     reader->Update();
>     }
>   catch( itk::ExceptionObject & exp )
>     {
>     std::cerr << "Exception thrown while reading the input file " << 
> std::endl;
>     std::cerr << exp << std::endl;
>     return EXIT_FAILURE;
>     }
>  
>   typedef itk::DefaultDynamicMeshTraits<double, 3, 3,double,double> 
> TriangleMeshTraits; ///////////////
>   typedef itk::Mesh<double,3, TriangleMeshTraits> MeshType;
>   typedef itk::BinaryMask3DMeshSource< ImageType, MeshType > MeshSourceType;
> 
>   MeshSourceType::Pointer meshSource = MeshSourceType::New();
>  
>   const PixelType objectValue = static_cast<PixelType>( atof( argv[2] ) );
>   meshSource->SetObjectValue( objectValue );
>   meshSource->SetInput( reader->GetOutput() );
> 
>   try
>     {
>     meshSource->Update();
>     }
>   catch( itk::ExceptionObject & exp )
>     {
>     std::cerr << "Exception thrown during Update() " << std::endl;
>     std::cerr << exp << std::endl;
>     return EXIT_FAILURE;
>     }
> 
>   std::cout << "Nodes = " << meshSource->GetNumberOfNodes() << std::endl;
>   std::cout << "Cells = " << meshSource->GetNumberOfCells() << std::endl;
> 
> vtkPolyData *vtkPolyDataOut = NULL;
> itkMeshTovtkPolyData * itkMesh2PolyData = new itkMeshTovtkPolyData();
> itkMesh2PolyData->SetInput (meshSource->GetOutput());
> vtkPolyDataOut = itkMesh2PolyData->GetOutput();
> 
> typedef itk::VTKPolyDataWriter<MeshType>WriterType;
> WriterType::Pointer writer1 = WriterType::New();
> 
> write1->SetInput(vtkPolyDataOut);  ///////////////////////////////////  
> ERROR
> writer1->SetFileName( "ojo.vtk" );
> 
>   try
>     {
>     writer1->Update();
>     }
>   catch( itk::ExceptionObject & exp )
>     {
>     std::cerr << "Exception thrown during Update() " << std::endl;
>     std::cerr << exp << std::endl;
>     return EXIT_FAILURE;
>     }
> 
> writer1->Delete();
> return 0;
> 
>   return EXIT_SUCCESS;
> }
> 
> 
> thanks for your help.
> 
> ------------------------------------------------------------------------
> Diferentes formas de estar en contacto con amigos y familiares. 
> Descúbrelas. Descúbrelas. 
> <http://www.microsoft.com/windows/windowslive/default.aspx>
> 
> 
> ------------------------------------------------------------------------
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list