Hello, <br><br>I am using visual stoudio 2010 and cmake. I am trying to
run the "DeformableModel1.cxx". But when I run it from the command line
window my .exe program stop working, while it is trying to dodeformable
mesh fitting.In this message I include the code. Could someone help me with this problem?<br>
<br>Thanks in advance<br><br><br>///////// code////// <br><br><br>#include <iostream><br><br>#include "itkDeformableMesh3DFilter.h"<br><br>#include "<div id=":10y">itkGradientRecursiveGaussianImageFilter.h"<br>
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"<br><br>#include "itkImage.h"<br>#include "itkMesh.h"<br><br><br>#include "itkCovariantVector.h"<br><br>#include "itkPointSetToImageFilter.h"<br>
<br>#include "itkImageFileReader.h"<br>#include "itkImageFileWriter.h"<br><br>int main( int argc, char *argv[] )<br>{<br><br> if( argc < 4 )<br> {<br> std::cerr << "Missing Parameters " << std::endl;<br>
std::cerr << "Usage: " << argv[0];<br> std::cerr << " InputImage BinaryImage DeformedMaskImage" << std::endl;<br> return 1;<br> }<br> <br><br> <br> const unsigned int Dimension = 3;<br>
typedef double PixelType;<br> typedef itk::Image<PixelType, Dimension> ImageType;<br><br> typedef itk::Image< unsigned char, Dimension > BinaryImageType;<br> <br> typedef itk::Mesh<double> MeshType;<br>
<br> typedef itk::CovariantVector< double, Dimension > GradientPixelType;<br> typedef itk::Image< GradientPixelType, Dimension > GradientImageType;<br> <br> typedef itk::GradientRecursiveGaussianImageFilter<ImageType, GradientImageType><br>
GradientFilterType;<br> typedef itk::GradientMagnitudeRecursiveGaussianImageFilter<ImageType,ImageType><br> GradientMagnitudeFilterType;<br> <br><br> typedef itk::BinaryMask3DMeshSource< BinaryImageType, MeshType > MeshSourceType;<br>
<br><br> typedef itk::DeformableMesh3DFilter<MeshType,MeshType> DeformableFilterType;<br> <br> typedef itk::ImageFileReader< ImageType > ReaderType;<br> typedef itk::ImageFileReader< BinaryImageType > BinaryReaderType;<br>
ReaderType::Pointer imageReader = ReaderType::New();<br> BinaryReaderType::Pointer maskReader = BinaryReaderType::New();<br> <br> imageReader->SetFileName( argv[1] );<br> maskReader->SetFileName( argv[2] );<br>
<br><br> GradientMagnitudeFilterType::Pointer gradientMagnitudeFilter<br> = GradientMagnitudeFilterType::New();<br><br> gradientMagnitudeFilter->SetInput( imageReader->GetOutput() ); <br>
gradientMagnitudeFilter->SetSigma( 1.0 );<br> <br> GradientFilterType::Pointer gradientMapFilter = GradientFilterType::New();<br> <br> gradientMapFilter->SetInput( gradientMagnitudeFilter->GetOutput());<br> gradientMapFilter->SetSigma( 1.0 );<br>
<br><br> try<br> {<br> <br> gradientMapFilter->Update();<br><br> }<br> catch( itk::ExceptionObject & e )<br> {<br> std::cerr << "Exception caught when updating gradientMapFilter " << std::endl;<br>
std::cerr << e << std::endl;<br> return -1;<br> }<br> <br><br><br> std::cout << "The gradient map created!" << std::endl;<br><br><br> MeshSourceType::Pointer meshSource = MeshSourceType::New();<br>
<br><br> DeformableFilterType::Pointer deformableModelFilter = <br> DeformableFilterType::New();<br> deformableModelFilter->SetGradient( gradientMapFilter->GetOutput() );<br>
<br>
BinaryImageType::Pointer mask = maskReader->GetOutput();<br> meshSource->SetInput( mask );<br> meshSource->SetObjectValue( 200 );<br><br> std::cout << "Creating mesh..." << std::endl;<br>
try <br> {<br> meshSource->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception Caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>
}<br><br> deformableModelFilter->SetInput( meshSource->GetOutput() );<br> <br><br> meshSource->GetOutput()->Print(std::cout);<br><br> std::cout << "Deformable mesh created using Marching Cube!" << std::endl;<br>
<br><br> typedef itk::CovariantVector<double, 2> double2DVector;<br> typedef itk::CovariantVector<double, 3> double3DVector;<br><br> double2DVector stiffness;<br> stiffness[0] = 0.0001;<br>
stiffness[1] = 0.1;<br><br> double3DVector scale;<br> scale[0] = 1.0;<br> scale[1] = 1.0; <br> scale[2] = 1.0;<br><br> deformableModelFilter->SetStiffness( stiffness );<br> deformableModelFilter->SetScale( scale );<br>
<br> deformableModelFilter->SetGradientMagnitude( 0.8 );<br> deformableModelFilter->SetTimeStep( 0.01 );<br> deformableModelFilter->SetStepThreshold( 60 );<br><br><br> std::cout << "Deformable mesh fitting...";<br>
<br><br> try <br> {<br> deformableModelFilter->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception Caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>
}<br> <br><br> std::cout << "Mesh Source: " << meshSource;<br><br> <br> typedef itk::PointSetToImageFilter<MeshType,ImageType> MeshFilterType;<br> MeshFilterType::Pointer meshFilter = MeshFilterType::New();<br>
meshFilter->SetOrigin(mask->GetOrigin());<br> meshFilter->SetSize(mask->GetLargestPossibleRegion().GetSize());<br> meshFilter->SetSpacing(mask->GetSpacing());<br> meshFilter->SetInput(meshSource->GetOutput());<br>
try <br> {<br> meshFilter->Update();<br> }<br> catch( itk::ExceptionObject & excep )<br> {<br> std::cerr << "Exception Caught !" << std::endl;<br> std::cerr << excep << std::endl;<br>
}<br><br> typedef itk::ImageFileWriter<ImageType> WriterType;<br> WriterType::Pointer writer = WriterType::New();<br> writer->SetInput(meshFilter->GetOutput());<br> writer->SetFileName(argv[3]);<br>
writer->Update();<br><br><br> return EXIT_SUCCESS;<br>}</div>