<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"><<a href="mailto:amar.singh@gmx.de">amar.singh@gmx.de</a>></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 "itkTriangleMeshToImageFilter". In a first experiment, I just want to create<br>
a sphere using the "itkRegularSphereMeshSource", 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] <--- origin<br>
[182, 218, 182] <--- size of image<br>
[1, 1, 1] <--- spacing of image<br>
[0, 0, 0] <--- index<br>
Exception caught !<br>
<br>
itk::ExceptionObject (0x81a3b00)<br>
Location: "void itk::TriangleMeshToBinaryImageFilter<TInputMesh, TOutputImage>::GenerateData() [with TInputMesh = itk::Mesh<float, 3u, itk::DefaultStaticMeshTraits<float, 3u, 3u, float, float, float> >, TOutputImage = itk::Image<unsigned char, 3u>]"<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 "itkTriangleMeshToImageFilter", so they should be fine, I think.<br>
There has been a similar posting on the mailing list ("<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>"), 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 "itkImageRegionIterator.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
#include "itkTriangleMeshToBinaryImageFilter.h"<br>
#include "itkDefaultStaticMeshTraits.h"<br>
#include "itkMesh.h"<br>
#include "itkRegularSphereMeshSource.h"<br>
<br>
#include "iostream"<br>
<br>
<br>
int main(int argc, char *argv[] )<br>
{<br>
std::cout << "Start Processing!" << std::endl;<br>
<br>
typedef unsigned char BinaryPixelType;<br>
typedef float PixelType;<br>
typedef itk::DefaultStaticMeshTraits<float, 3, 3,float,float> TriangleMeshTraits;<br>
typedef itk::Mesh<float,3, TriangleMeshTraits> TriangleMeshType;<br>
typedef itk::RegularSphereMeshSource<TriangleMeshType> SphereMeshSourceType;<br>
typedef SphereMeshSourceType::PointType PointType;<br>
<br>
typedef itk::Image<BinaryPixelType, 3> BinaryImageType;<br>
typedef itk::Image<PixelType, 3> ImageType;<br>
<br>
typedef itk::TriangleMeshToBinaryImageFilter<TriangleMeshType, BinaryImageType> TriangleMeshToBinaryImageFilterType;<br>
<br>
<br>
TriangleMeshToBinaryImageFilterType::Pointer triangleMeshToImage = TriangleMeshToBinaryImageFilterType::New();<br>
SphereMeshSourceType::Pointer sphere = SphereMeshSourceType::New();<br>
sphere->SetScale(5);<br>
sphere->SetResolution(5);<br>
<br>
typedef itk::ImageFileReader<ImageType> ReaderType;<br>
typedef itk::ImageFileWriter<BinaryImageType> WriterType;<br>
<br>
ReaderType::Pointer reader = ReaderType::New();<br>
reader->SetFileName("/test_image.nii.gz");<br>
try<br>
{<br>
reader->Update();<br>
}<br>
catch( itk::ExceptionObject & excep )<br>
{<br>
std::cerr << "Exception caught !" << std::endl;<br>
std::cerr << excep << std::endl;<br>
}<br>
<br>
PointType center;<br>
center[0] = 10;<br>
center[1] = 10;<br>
center[2] = 10;<br>
sphere->SetCenter(center);<br>
triangleMeshToImage->SetInput(sphere->GetOutput());<br>
<br>
ImageType::Pointer orgImage = reader->GetOutput();<br>
const ImageType::PointType orgOrigin = orgImage->GetOrigin();<br>
const ImageType::SizeType orgSize = orgImage->GetLargestPossibleRegion().GetSize();<br>
const ImageType::SpacingType orgSpacing = orgImage->GetSpacing();<br>
const ImageType::IndexType orgIndex = orgImage->GetLargestPossibleRegion().GetIndex();<br>
<br>
std::cout << orgOrigin << std::endl;<br>
std::cout << orgSize << std::endl;<br>
std::cout << orgSpacing << std::endl;<br>
std::cout << orgIndex << std::endl;<br>
<br>
triangleMeshToImage->SetTolerance (1.0);<br>
triangleMeshToImage->SetSpacing (orgSpacing);<br>
triangleMeshToImage->SetOrigin(orgOrigin);<br>
triangleMeshToImage->SetSize (orgSize);<br>
triangleMeshToImage->SetIndex (orgIndex);<br>
<br>
WriterType::Pointer writer = WriterType::New();<br>
<br>
writer->SetFileName("/test_output.nii.gz");<br>
writer->SetInput(triangleMeshToImage->GetOutput());<br>
<br>
try<br>
{<br>
sphere->Update();<br>
triangleMeshToImage->Update();<br>
writer->Update();<br>
}<br>
catch( itk::ExceptionObject & excep )<br>
{<br>
std::cerr << "Exception caught !" << std::endl;<br>
std::cerr << excep << 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>