<br>Hi Amardeep,<br><br>I think that this typically happens when the image parameters<br>are such that the image is not overlapping with your input mesh<br>in Physical space.<br><br><br>You should choose the <br><br>    * Origin<br>
    * Spacing<br>    * Number of pixels<br><br>of you image to create a grid on top of the Physical space that<br>is occupied by the Mesh.<br><br>Have you looked at your Mesh, and found the bounds of the<br>mesh nodes in space ?<br>
<br>Can you please post to the mailing list what the BoundingBox<br>of your mesh is ?<br><br>These values can be used to select proper parameters for the<br>output image that contains the rasterization of the Mesh.<br><br>
<br>The image parameters should match the extent of the input Mesh,<br>not the extent of an image that you read from disk. Unless your<br>Mesh was extracted from that image that you are reading from<br>disk...<br><br><br>
<br>You could get a feeling for these parameters by loading your<br>Mesh into ParaView (or any other visualization tool).<br><br><br>    Please let us know,<br><br><br>       Thanks<br><br><br>            Luis<br><br><br>
--------------------------------------------------------------------------------<br><div class="gmail_quote">On Thu, Jul 2, 2009 at 3:34 PM, Amardeep Singh <span dir="ltr">&lt;<a href="mailto:amar.singh@gmx.de">amar.singh@gmx.de</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Dear ITK Users<br>
<br>
I would like to use the &quot;itkTriangleMeshToImageFilter&quot;. In a first experiment, I just want to create<br>
a sphere using the &quot;itkRegularSphereMeshSource&quot;, binarize it and save the output. I take the size, origin and spacing<br>
of the resulting image from an image that I read from the harddisk (just for convenience).<br>
Unfortunately, I get the following error:<br>
<br>
Start Processing!<br>
[-90, 126, -72]          &lt;--- origin<br>
[182, 218, 182]        &lt;--- size of image<br>
[1, 1, 1]                    &lt;--- spacing of image<br>
[0, 0, 0]                    &lt;--- index<br>
Exception caught !<br>
<br>
itk::ExceptionObject (0x81a3b00)<br>
Location: &quot;void itk::TriangleMeshToBinaryImageFilter&lt;TInputMesh, TOutputImage&gt;::GenerateData() [with TInputMesh = itk::Mesh&lt;float, 3u, itk::DefaultStaticMeshTraits&lt;float, 3u, 3u, float, float, float&gt; &gt;, TOutputImage = itk::Image&lt;unsigned char, 3u&gt;]&quot;<br>

File: /workspace/InsightToolkit-3.14.0/Code/BasicFilters/itkTriangleMeshToBinaryImageFilter.txx<br>
Line: 224<br>
Description: itk::ERROR: TriangleMeshToBinaryImageFilter(0x8141ec8): No Image Indices Found.<br>
<br>
Above, I have included output, indicating the origin, size, spacing and index of the largest region of the image that I read from the harddisk. These are the values that I pass to the &quot;itkTriangleMeshToImageFilter&quot;, so they should be fine, I think.<br>

There has been a similar posting on the mailing list (&quot;<a href="http://www.nabble.com/converting-mesh-to-binary-image-td21170657.html" target="_blank">http://www.nabble.com/converting-mesh-to-binary-image-td21170657.html</a>&quot;), but the solution to the problem was not made explicit, unfortunately. Please, find my source code attached.<br>

Does anyone know how to resolve this problem?<br>
Thank you very much!<br>
<br>
Best regards<br>
Amardeep<br>
<br>
<br>
#include &quot;itkImageRegionIterator.h&quot;<br>
#include &quot;itkImageFileReader.h&quot;<br>
#include &quot;itkImageFileWriter.h&quot;<br>
#include &quot;itkTriangleMeshToBinaryImageFilter.h&quot;<br>
#include &quot;itkDefaultStaticMeshTraits.h&quot;<br>
#include &quot;itkMesh.h&quot;<br>
#include &quot;itkRegularSphereMeshSource.h&quot;<br>
<br>
#include &quot;iostream&quot;<br>
<br>
<br>
int main(int argc, char *argv[] )<br>
{<br>
   std::cout &lt;&lt; &quot;Start Processing!&quot; &lt;&lt; std::endl;<br>
<br>
   typedef unsigned char BinaryPixelType;<br>
   typedef float PixelType;<br>
   typedef itk::DefaultStaticMeshTraits&lt;float, 3, 3,float,float&gt; TriangleMeshTraits;<br>
   typedef itk::Mesh&lt;float,3, TriangleMeshTraits&gt; TriangleMeshType;<br>
   typedef itk::RegularSphereMeshSource&lt;TriangleMeshType&gt;  SphereMeshSourceType;<br>
   typedef SphereMeshSourceType::PointType PointType;<br>
<br>
   typedef itk::Image&lt;BinaryPixelType, 3&gt;      BinaryImageType;<br>
   typedef itk::Image&lt;PixelType, 3&gt; ImageType;<br>
<br>
   typedef itk::TriangleMeshToBinaryImageFilter&lt;TriangleMeshType, BinaryImageType&gt; TriangleMeshToBinaryImageFilterType;<br>
<br>
  <br>
   TriangleMeshToBinaryImageFilterType::Pointer triangleMeshToImage = TriangleMeshToBinaryImageFilterType::New();<br>
   SphereMeshSourceType::Pointer sphere = SphereMeshSourceType::New();<br>
   sphere-&gt;SetScale(5);<br>
   sphere-&gt;SetResolution(5);<br>
<br>
   typedef itk::ImageFileReader&lt;ImageType&gt; ReaderType;<br>
   typedef itk::ImageFileWriter&lt;BinaryImageType&gt; WriterType;<br>
<br>
   ReaderType::Pointer reader = ReaderType::New();<br>
   reader-&gt;SetFileName(&quot;/test_image.nii.gz&quot;);<br>
   try<br>
   {<br>
     reader-&gt;Update();<br>
   }<br>
   catch( itk::ExceptionObject &amp; excep )<br>
   {<br>
     std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>
     std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>
   }<br>
<br>
   PointType center;<br>
   center[0] = 10;<br>
   center[1] = 10;<br>
   center[2] = 10;<br>
   sphere-&gt;SetCenter(center);<br>
   triangleMeshToImage-&gt;SetInput(sphere-&gt;GetOutput());<br>
<br>
   ImageType::Pointer orgImage = reader-&gt;GetOutput();<br>
   const ImageType::PointType orgOrigin = orgImage-&gt;GetOrigin();<br>
   const ImageType::SizeType orgSize = orgImage-&gt;GetLargestPossibleRegion().GetSize();<br>
   const ImageType::SpacingType orgSpacing = orgImage-&gt;GetSpacing();<br>
   const ImageType::IndexType orgIndex = orgImage-&gt;GetLargestPossibleRegion().GetIndex();<br>
<br>
   std::cout &lt;&lt; orgOrigin &lt;&lt; std::endl;<br>
   std::cout &lt;&lt; orgSize &lt;&lt; std::endl;<br>
   std::cout &lt;&lt; orgSpacing &lt;&lt; std::endl;<br>
   std::cout &lt;&lt; orgIndex &lt;&lt; std::endl;<br>
<br>
   triangleMeshToImage-&gt;SetTolerance (1.0);<br>
   triangleMeshToImage-&gt;SetSpacing (orgSpacing);<br>
   triangleMeshToImage-&gt;SetOrigin(orgOrigin);<br>
   triangleMeshToImage-&gt;SetSize (orgSize);<br>
   triangleMeshToImage-&gt;SetIndex (orgIndex);<br>
<br>
   WriterType::Pointer writer = WriterType::New();<br>
<br>
   writer-&gt;SetFileName(&quot;/test_output.nii.gz&quot;);<br>
   writer-&gt;SetInput(triangleMeshToImage-&gt;GetOutput());<br>
<br>
   try<br>
   {<br>
       sphere-&gt;Update();<br>
       triangleMeshToImage-&gt;Update();<br>
       writer-&gt;Update();<br>
   }<br>
   catch( itk::ExceptionObject &amp; excep )<br>
   {<br>
     std::cerr &lt;&lt; &quot;Exception caught !&quot; &lt;&lt; std::endl;<br>
     std::cerr &lt;&lt; excep &lt;&lt; std::endl;<br>
   }<br>
<br>
   return 0;<br>
<br>
}<br>
<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>
Please keep messages on-topic and check the ITK FAQ at: <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>