[Insight-users] problem in mesh fitting

john smith mkitkinsightuser at gmail.com
Thu Apr 14 05:53:22 EDT 2011


Hello,

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?

Thanks in advance


///////// code//////


#include <iostream>

#include "itkDeformableMesh3DFilter.h"

#include "
itkGradientRecursiveGaussianImageFilter.h"
#include "itkGradientMagnitudeRecursiveGaussianImageFilter.h"

#include "itkImage.h"
#include "itkMesh.h"


#include "itkCovariantVector.h"

#include "itkPointSetToImageFilter.h"

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

int main( int argc, char *argv[] )
{

  if( argc < 4 )
    {
    std::cerr << "Missing Parameters " << std::endl;
    std::cerr << "Usage: " << argv[0];
    std::cerr << " InputImage  BinaryImage DeformedMaskImage" << std::endl;
    return 1;
    }



  const     unsigned int    Dimension = 3;
  typedef   double                         PixelType;
  typedef itk::Image<PixelType, Dimension> ImageType;

  typedef itk::Image< unsigned char, Dimension >   BinaryImageType;

  typedef  itk::Mesh<double>     MeshType;

  typedef itk::CovariantVector< double, Dimension >  GradientPixelType;
  typedef itk::Image< GradientPixelType, Dimension > GradientImageType;

  typedef itk::GradientRecursiveGaussianImageFilter<ImageType,
GradientImageType>
    GradientFilterType;
  typedef
itk::GradientMagnitudeRecursiveGaussianImageFilter<ImageType,ImageType>
    GradientMagnitudeFilterType;


  typedef itk::BinaryMask3DMeshSource< BinaryImageType, MeshType >
MeshSourceType;


  typedef itk::DeformableMesh3DFilter<MeshType,MeshType>
DeformableFilterType;

  typedef itk::ImageFileReader< ImageType       >  ReaderType;
  typedef itk::ImageFileReader< BinaryImageType >  BinaryReaderType;
  ReaderType::Pointer       imageReader   =  ReaderType::New();
  BinaryReaderType::Pointer maskReader    =  BinaryReaderType::New();

  imageReader->SetFileName( argv[1] );
  maskReader->SetFileName(  argv[2] );


  GradientMagnitudeFilterType::Pointer  gradientMagnitudeFilter
                                          =
GradientMagnitudeFilterType::New();

  gradientMagnitudeFilter->SetInput( imageReader->GetOutput() );
  gradientMagnitudeFilter->SetSigma( 1.0 );

  GradientFilterType::Pointer gradientMapFilter = GradientFilterType::New();

  gradientMapFilter->SetInput( gradientMagnitudeFilter->GetOutput());
  gradientMapFilter->SetSigma( 1.0 );


  try
    {

    gradientMapFilter->Update();

    }
  catch( itk::ExceptionObject & e )
    {
    std::cerr << "Exception caught when updating gradientMapFilter " <<
std::endl;
    std::cerr << e << std::endl;
    return -1;
    }



  std::cout << "The gradient map created!" << std::endl;


  MeshSourceType::Pointer meshSource = MeshSourceType::New();


  DeformableFilterType::Pointer deformableModelFilter =
                                     DeformableFilterType::New();
  deformableModelFilter->SetGradient( gradientMapFilter->GetOutput() );

  BinaryImageType::Pointer mask = maskReader->GetOutput();
  meshSource->SetInput( mask );
  meshSource->SetObjectValue( 200 );

  std::cout << "Creating mesh..." << std::endl;
  try
    {
    meshSource->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception Caught !" << std::endl;
    std::cerr << excep << std::endl;
    }

  deformableModelFilter->SetInput(  meshSource->GetOutput() );


  meshSource->GetOutput()->Print(std::cout);

  std::cout << "Deformable mesh created using Marching Cube!" << std::endl;


  typedef itk::CovariantVector<double, 2>           double2DVector;
  typedef itk::CovariantVector<double, 3>           double3DVector;

  double2DVector stiffness;
  stiffness[0] = 0.0001;
  stiffness[1] = 0.1;

  double3DVector scale;
  scale[0] = 1.0;
  scale[1] = 1.0;
  scale[2] = 1.0;

  deformableModelFilter->SetStiffness( stiffness );
  deformableModelFilter->SetScale( scale );

  deformableModelFilter->SetGradientMagnitude( 0.8 );
  deformableModelFilter->SetTimeStep( 0.01 );
  deformableModelFilter->SetStepThreshold( 60 );


  std::cout << "Deformable mesh fitting...";


  try
    {
    deformableModelFilter->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception Caught !" << std::endl;
    std::cerr << excep << std::endl;
    }


  std::cout << "Mesh Source: " << meshSource;


  typedef itk::PointSetToImageFilter<MeshType,ImageType> MeshFilterType;
  MeshFilterType::Pointer meshFilter = MeshFilterType::New();
  meshFilter->SetOrigin(mask->GetOrigin());
  meshFilter->SetSize(mask->GetLargestPossibleRegion().GetSize());
  meshFilter->SetSpacing(mask->GetSpacing());
  meshFilter->SetInput(meshSource->GetOutput());
  try
    {
    meshFilter->Update();
    }
  catch( itk::ExceptionObject & excep )
    {
    std::cerr << "Exception Caught !" << std::endl;
    std::cerr << excep << std::endl;
    }

  typedef itk::ImageFileWriter<ImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetInput(meshFilter->GetOutput());
  writer->SetFileName(argv[3]);
  writer->Update();


  return EXIT_SUCCESS;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20110414/e9fc91e0/attachment.htm>


More information about the Insight-users mailing list