[Insight-users] How to use TriangleMeshToBinaryImageFilter without an input image?

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Thu Jul 1 15:20:45 EDT 2010


On 30/06/10 14:18:20, Dženan Zukić wrote:
> Hi Lynx,
>
> that index mentioned in the error message is filter's internal variable. You
> cannot set it directly. The most likely cause for that is miscalculation of
> your image parameters (origin, size) with regards to mesh's volume. Try
> playing with parameters you give to your program to see if it makes a
> difference - try smaller mesh, try smaller image, larger image etc.

Thanks Dženan for Your reply. I tried with different parameters  like  smaller
mesh, smaller image, larger image but nothing helped.

With  a  new  version  of my code (attached) where I allocate the output image
frist the problem remains.
I figured out though that it has to be a vtk-file not a vtp-file. If I  use  a
vtp-file I get the error (more below):
terminate called after throwing an instance of 'std::out_of_range'


How  would  I have to ajust my code if I just want to specify the dimension in
x,y,z and let the program set origin and extend  and  spacing  such  that  the
whole mesh is just fitting into the output?

Many thanks for any help or hints.
Lynx


__________________________________________________________

~/itk/simple/voxelizer_itk_02 cone_01.vtp cone_01.tif 20 20 20 -10 -10 -10
Reading: cone_01.vtp
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::basic_string
Abgebrochen


gdb ~/itk/simple/voxelizer_itk_02
GNU gdb 6.6.50.20070726-cvs
Copyright (C) 2007 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-suse-linux"...
Using host libthread_db library "/lib64/libthread_db.so.1".
(gdb) run cone_01.vtp cone_01.tif 20 20 20 10 10 10
Starting program: /net/home/aaa/itk/simple/voxelizer_itk_02 cone_01.vtp cone_01.tif 20 20 20 10 10 10
[Thread debugging using libthread_db enabled]
[New Thread 0x2b7ccd2e6df0 (LWP 1330)]
terminate called after throwing an instance of 'std::out_of_range'
  what():  basic_string::basic_string

Program received signal SIGABRT, Aborted.
[Switching to Thread 0x2b7ccd2e6df0 (LWP 1330)]
0x00002b7cccb98b45 in raise () from /lib64/libc.so.6
(gdb) bt
#0  0x00002b7cccb98b45 in raise () from /lib64/libc.so.6
#1  0x00002b7cccb9a0e0 in abort () from /lib64/libc.so.6
#2  0x00002b7ccc716d34 in __gnu_cxx::__verbose_terminate_handler () from /usr/lib64/libstdc++.so.6
#3  0x00002b7ccc714ce6 in ?? () from /usr/lib64/libstdc++.so.6
#4  0x00002b7ccc714d13 in std::terminate () from /usr/lib64/libstdc++.so.6
#5  0x00002b7ccc714dfa in __cxa_throw () from /usr/lib64/libstdc++.so.6
#6  0x00002b7ccc6b111a in std::__throw_out_of_range () from /usr/lib64/libstdc++.so.6
#7  0x00002b7ccc6f2ebd in std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string () from /usr/lib64/libstdc++.so.6
#8  0x00000000004e1e60 in itk::VTKPolyDataReader<itk::Mesh<double, 3u, itk::DefaultStaticMeshTraits<double, 3u, 3u, float, float, double> > >::GenerateData ()
#9  0x000000000069234b in itk::ProcessObject::UpdateOutputData ()
#10 0x000000000069241d in itk::ProcessObject::UpdateOutputData ()
#11 0x00000000004c02b5 in main ()

-------------- next part --------------
////////program to voxelize a vtk-polydata-mesh into a itk-voxel-image
////////supposingly quicker than pure vtk: http://www.cmake.org/Wiki/VTK/Examples/PolyDataToImageData
//allocating image before voxelization

//#include <itkImage.h>
//#include <itkQuadEdgeMesh.h>
#include <itkVTKPolyDataReader.h>
#include <itkTriangleMeshToBinaryImageFilter.h>
#include <itkImageFileWriter.h>
#include "itkFilterWatcher2.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]);
    
    std::cout << "Reading: " << argv[1] << std::endl;
    try
        {
        meshReader->Update();
        }
    catch( itk::ExceptionObject & excp )
        {
        std::cerr << "Exception: " << excp << std::endl;
        return EXIT_FAILURE;
        }

    std::cout << "Read: " << argv[1] << std::endl;


   // 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]);
 
    //allocate the output image 
    ImageType::Pointer output = ImageType::New();

    output->SetRegions(size);
    output->SetSpacing(spacing);
    output->SetOrigin(origin);
    //output->SetRegions(reader1->GetOutput()->GetRequestedRegion());
    output->Allocate();


    //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(output); //
    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);
    FilterWatcher watcher(meshFilter, "filter");
    //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