Hi Lynx,<div><br></div><div>that index mentioned in the error message is filter&#39;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&#39;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.<br>
<div><br></div><div>Regards,</div><div>Dženan<br><br><div class="gmail_quote">On Sun, Jun 20, 2010 at 16:19,  <span dir="ltr">&lt;<a href="mailto:lynx.abraxas@freenet.de">lynx.abraxas@freenet.de</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello!<br>
<br>
<br>
My  aim is to create a binary image from a vtk-polydata mesh. I found loads of<br>
info to this in the mailinglist archives but still I&#39;m stuck:<br>
I   want   to   do   it   without    an    input    image    but    let    the<br>
TriangleMeshToBinaryImageFilter  create  one  which  seems  to  be the problem<br>
because my program terminates with:<br>
<br>
itk::ExceptionObject (0x811f060)<br>
Location:        &quot;void        itk::TriangleMeshToBinaryImageFilter&lt;TInputMesh,<br>
TOutputImage&gt;::GenerateData()   [with   TInputMesh   =  itk::Mesh&lt;double,  3u,<br>
itk::DefaultStaticMeshTraits&lt;double,  3u,  3u,  float,   float,   double&gt;   &gt;,<br>
TOutputImage = itk::Image&lt;unsigned char, 3u&gt;]&quot;<br>
File:<br>
/usr/local/include/InsightToolkit/BasicFilters/itkTriangleMeshToBinaryImageFilter.txx<br>
Line: 224<br>
Description:  itk::ERROR: TriangleMeshToBinaryImageFilter(0x8119ff0): No Image<br>
Indices Found.<br>
<br>
So I wonder how can I supply an index for TriangleMeshToBinaryImageFilter?<br>
<br>
Thanks for any help or hints<br>
Lynx<br>
<br>
<br>
<br>
________________________________<br>
<br>
<br>
#include &lt;itkVTKPolyDataReader.h&gt;<br>
#include &lt;itkTriangleMeshToBinaryImageFilter.h&gt;<br>
#include &lt;itkImageFileWriter.h&gt;<br>
<br>
<br>
<br>
int main( int argc, char *argv[] ){<br>
<br>
<br>
    if( argc != 9 )<br>
        {<br>
        std::cerr &lt;&lt; &quot;Usage: &quot; &lt;&lt; argv[0];<br>
        std::cerr &lt;&lt; &quot; input_VTKpolydata-mesh&quot;;<br>
        std::cerr &lt;&lt; &quot; outputImage&quot;;<br>
        std::cerr &lt;&lt; &quot; dx dy dz ox oy oz&quot;;<br>
        std::cerr &lt;&lt; std::endl;<br>
        return EXIT_FAILURE;<br>
        }<br>
<br>
<br>
<br>
    typedef unsigned char  PixelType;<br>
    const unsigned int    Dimension = 3;<br>
<br>
    //typedef itk::DefaultDynamicMeshTraits&lt;double, 3, 3,double,double&gt; TriangleMeshTraits;<br>
    //typedef itk::Mesh&lt;double,3, TriangleMeshTraits&gt; TriangleMeshType;<br>
<br>
    //typedef itk::QuadEdgeMesh&lt; float, Dimension &gt;   MeshType;<br>
<br>
    typedef itk::Mesh&lt; double, 3 &gt; MeshType;<br>
<br>
    typedef itk::Image&lt; PixelType, Dimension &gt;       ImageType;<br>
<br>
<br>
    typedef itk::VTKPolyDataReader&lt;MeshType&gt; VTKmeshreaderType;<br>
<br>
    VTKmeshreaderType::Pointer meshReader = VTKmeshreaderType::New();<br>
    meshReader-&gt;SetFileName(argv[1]);<br>
<br>
<br>
   // Set Size, Spacing and origin<br>
    ImageType::SizeType size;<br>
    size[ 0 ] = atoi(argv[3]);<br>
    size[ 1 ] = atoi(argv[4]);<br>
    size[ 2 ] = atoi(argv[5]);<br>
<br>
    ImageType::SpacingType spacing;<br>
    spacing[0] =  1; //100.0 / size[0];<br>
    spacing[1] =  1; //100.0 / size[1];<br>
    spacing[2] =  1; //100.0 / size[2];<br>
<br>
    ImageType::PointType origin;<br>
    origin[0]= atoi(argv[6]);<br>
    origin[1]= atoi(argv[7]);<br>
    origin[2]= atoi(argv[8]);<br>
<br>
<br>
    //Set Inside/Outside voxel value<br>
    const PixelType empty  = 0;<br>
    const PixelType fill =  255;<br>
<br>
<br>
<br>
    typedef itk::TriangleMeshToBinaryImageFilter&lt;MeshType, ImageType&gt; MeshFilterType;<br>
    MeshFilterType::Pointer meshFilter = MeshFilterType::New();<br>
<br>
    meshFilter-&gt;SetInput(meshReader-&gt;GetOutput());<br>
    //meshFilter-&gt;SetInfoImage(); //<br>
    meshFilter-&gt;SetTolerance (1.0);<br>
    meshFilter-&gt;SetSize (size);<br>
    meshFilter-&gt;SetSpacing (spacing);<br>
    meshFilter-&gt;SetOrigin(origin);<br>
    //meshFilter-&gt;SetIndex (index);<br>
    //meshFilter-&gt;SetUseObjectValue( true );<br>
    meshFilter-&gt;SetInsideValue(fill);<br>
    meshFilter-&gt;SetOutsideValue(empty);<br>
<br>
    //meshFilter-&gt;Update();<br>
<br>
    // Write the image<br>
    typedef itk::ImageFileWriter&lt; ImageType &gt;     WriterType;<br>
    WriterType::Pointer writer = WriterType::New();<br>
<br>
    writer-&gt;SetFileName(argv[2]);<br>
    writer-&gt;SetInput(meshFilter-&gt;GetOutput());<br>
    try<br>
        {<br>
        meshFilter-&gt;Update();<br>
        writer-&gt;Update();<br>
        }<br>
    catch( itk::ExceptionObject &amp; excp )<br>
        {<br>
        std::cerr &lt;&lt; excp &lt;&lt; std::endl;<br>
        return EXIT_FAILURE;<br>
        }<br>
<br>
<br>
    return EXIT_SUCCESS;<br>
    }<br>
<br>
<br>
<br>
_____________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.html" target="_blank">http://www.kitware.com/products/protraining.html</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" target="_blank">http://www.itk.org/Wiki/ITK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote></div><br></div></div>