<div dir="ltr">Hi,<br>Thanks for reply, You were right,<br>We have some bug in the origin details, and when we fixed it, it worked great.<br>Many thanks,<br>Moti <br><br><div class="gmail_quote">On Wed, Dec 31, 2008 at 8:17 PM, Luis Ibanez <span dir="ltr"><<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</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;"><br>
Hi Moti,<br>
<br>
Please print out the values of:<br>
<br>
orgSpacing<br>
orgOrigin<br>
orgSize<br>
orgIndex<br>
<br>
just before you pass them to the meshFilter.<br>
<br>
It is likely that the values in "orgSize" are zeros.<br>
<br>
<br>
Please let us know what you find.<br>
<br>
<br>
Thanks<br>
<br>
<br>
Luis<br>
<br>
<br>
---------------------<br>
Moti Freiman wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div class="Wj3C7c">
Hi,<br>
I'm trying to convert a 3d surface (got as some segmentation result) to a binary image, for comparison between different segmentations.<br>
I build a mesh from points and triangles which I got and save it as a vtk polygonal data. It performs well and I can visualize it properly using paraview.<br>
However, when I'm trying to convert it to a 3D binary volume using itkTriangleMeshToBinaryImageFilter I got the following exception:<br>
------------------------------------------------------ start of output -------------------------------------------------------------------------<br>
ExceptionObject caught !<br>
<br>
itk::ExceptionObject (012CFB38)<br>
Location: "void __thiscall itk::TriangleMeshToBinaryImageFilter<class itk::Mesh<unsigned char,3,class itk::DefaultStaticMeshTraits<unsigned char,3,3,float,float,unsigned char> >,class itk::Image<unsigned char,3> >::GenerateData(void)"<br>
File: e:\libs\insighttoolkit-3.10.0\code\basicfilters\itkTriangleMeshToBinaryImageFilter.txx<br>
Line: 224<br>
Description: itk::ERROR: TriangleMeshToBinaryImageFilter(038FD670): No Image Indices Found.<br>
<br>
<br>
Press any key to continue<br>
<br>
<br>
<br>
------------------------------------------------------- end of output -------------------------------------------------------------------------<br>
<br>
My code is below,<br>
<br>
------------------------------------------------------ start of code-------------------------------------------------------------------------<br>
#include "itkVTKPolyDataWriter.h"<br>
#include "itkVTKPolyDataReader.h"<br>
#include "itkImageFileReader.h"<br>
#include "itkImageFileWriter.h"<br>
#include "itkCastImageFilter.h"<br>
<br>
<br>
#include "itkMesh.h"<br>
#include "itkTriangleCell.h"<br>
#include <fstream><br>
<br>
<br>
#include "itkTriangleMeshToBinaryImageFilter.h"<br>
<br>
<br>
<br>
int main( int argc, char **argv )<br>
{ char *points_name = NULL, *faces_name = NULL, *output_mesh = NULL, *input_image = NULL, *output_name = NULL;<br>
<br>
<br>
points_name = argv[1];<br>
faces_name = argv[2];<br>
output_mesh = argv[3];<br>
input_image = argv[4];<br>
output_name = argv[5];<br>
<br>
typedef short PixelType;<br>
typedef unsigned char OutputPixelType;<br>
const unsigned int Dimension = 3;<br>
<br>
typedef itk::Mesh <OutputPixelType, Dimension> itkMeshType;<br>
<br>
itkMeshType::Pointer mesh = itkMeshType::New();<br>
std::fstream pointsReader;<br>
pointsReader.open (points_name, std::ios::in);<br>
int i=0;<br>
while (pointsReader.peek () != EOF)<br>
{<br>
itkMeshType::PointType p;<br>
pointsReader >> p[0] >> p[1] >> p[2];<br>
mesh->SetPoint (i,p);<br>
++i;<br>
}<br>
pointsReader.close();<br>
typedef itkMeshType::CellType CellType;<br>
typedef itk::TriangleCell < CellType > FaceType;<br>
<br>
typedef CellType::CellAutoPointer CellAutoPointer;<br>
<br>
<br>
<br>
std::fstream facesReader;<br>
facesReader.open (faces_name, std::ios::in);<br>
i=0;<br>
while (facesReader.peek () != EOF)<br>
{<br>
int p[3];<br>
facesReader >> p[0] >> p[1] >> p[2];<br>
CellAutoPointer face;<br>
face.TakeOwnership( new FaceType );<br>
<br>
face->SetPointId (0, p[0]);<br>
face->SetPointId (1, p[1]);<br>
face->SetPointId (2, p[2]);<br>
<br>
mesh->SetCell (i,face);<br>
++i;<br>
}<br>
facesReader.close();<br>
mesh->Update();<br>
<br>
<br>
<br>
typedef itk::VTKPolyDataWriter<itkMeshType> itkVTKPolyDataWriterType;<br>
<br>
itkVTKPolyDataWriterType::Pointer meshWriter = itkVTKPolyDataWriterType::New();<br>
meshWriter->SetFileName( output_mesh );<br>
meshWriter->SetInput (mesh);<br>
try<br>
{<br>
meshWriter->Update();<br>
}<br>
catch ( itk::ExceptionObject &err)<br>
{<br>
std::cout << "ExceptionObject caught !" << std::endl;<br>
std::cout << err << std::endl;<br>
return -1;<br>
}<br>
<br>
<br>
<br>
typedef itk::Image< PixelType, Dimension > ImageType;<br>
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;<br>
typedef itk::ImageFileReader< ImageType > ImageReaderType;<br>
<br>
<br>
<br>
<br>
<br>
// Read the input files<br>
ImageReaderType::Pointer reader = ImageReaderType::New();<br>
reader->SetFileName( input_image );<br>
try<br>
{<br>
reader->Update();<br>
}<br>
catch ( itk::ExceptionObject &err)<br>
{<br>
std::cout << "ExceptionObject caught !" << std::endl;<br>
std::cout << err << std::endl;<br>
return -1;<br>
}<br>
<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>
<br>
typedef itk::TriangleMeshToBinaryImageFilter <itkMeshType, OutputImageType> itkTriangleMeshToBinaryImageFilterType;<br>
itkTriangleMeshToBinaryImageFilterType::Pointer meshFilter = itkTriangleMeshToBinaryImageFilterType::New();<br>
meshFilter->SetTolerance (1.0);<br>
meshFilter->SetSpacing (orgSpacing);<br>
meshFilter->SetOrigin(orgOrigin);<br>
meshFilter->SetSize (orgSize);<br>
meshFilter->SetIndex (orgIndex);<br>
meshFilter->SetInput(mesh);<br>
try<br>
{<br>
meshFilter->Update();<br>
}<br>
catch ( itk::ExceptionObject &err )<br>
{<br>
std::cout << "ExceptionObject caught !" << std::endl;<br>
std::cout << err << std::endl;<br>
return -1;<br>
}<br>
// Write the output image containing the binary volume.<br>
typedef itk::ImageFileWriter< OutputImageType > WriterType;<br>
WriterType::Pointer writer = WriterType::New();<br>
writer->SetInput( meshFilter->GetOutput() );<br>
writer->SetFileName( output_name );<br>
try<br>
{<br>
writer->Update();<br>
}<br>
catch ( itk::ExceptionObject &err )<br>
{<br>
std::cout << "ExceptionObject caught !" << std::endl;<br>
std::cout << err << std::endl;<br>
return -1;<br>
}<br>
<br>
return 0; }<br>
<br>
------------------------------------------------------ end of code-------------------------------------------------------------------------<br>
<br>
Thanks for any help,<br>
Moti<br>
-- <br>
__<br>
Moti Freiman, Ph.D Student.<br>
Medical Image Processing and Computer-Assisted Surgery Laboratory.<br>
School of Computer Science and Engineering.<br>
The Hebrew University of Jerusalem Givat Ram, Jerusalem 91904, Israel<br>
Phone: +(972)-2-658-5371 (laboratory)<br>
WWW site: <a href="http://www.cs.huji.ac.il/%7Efreiman" target="_blank">http://www.cs.huji.ac.il/~freiman</a><br>
<br>
<br></div></div>
------------------------------------------------------------------------<br>
<br>
_______________________________________________<br>
Insight-users mailing list<br>
<a href="mailto:Insight-users@itk.org" target="_blank">Insight-users@itk.org</a><br>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank">http://www.itk.org/mailman/listinfo/insight-users</a><br>
</blockquote>
</blockquote></div><br><br clear="all"><br>-- <br>__<br>Moti Freiman, Ph.D Student.<br>Medical Image Processing and Computer-Assisted Surgery Laboratory.<br>School of Computer Science and Engineering.<br>The Hebrew University of Jerusalem Givat Ram, Jerusalem 91904, Israel<br>
Phone: +(972)-2-658-5371 (laboratory)<br>WWW site: <a href="http://www.cs.huji.ac.il/~freiman">http://www.cs.huji.ac.il/~freiman</a><br>
</div>