[Insight-users] Surface extraction seg. fault at meshSource->Update()

Catherine Peloquin cepeloquin at gmail.com
Mon Apr 30 14:59:04 EDT 2007


I am trying to get a version of the example surface extraction code
running.  I had problems with the CMakeLists.txt file, but that has been
resolved.  My problem now is that I am getting a segmentation fault at the
line "meshSource->Update()".  I tried using .ima files, and .dcm files
located in the same directory as my .cxx and CMakeLists files.  I added a
try/catch block around this line as Luis suggested and re-built the example,
but the program still faults out at that location.  I am running the
executable with the command "SurfaceExtraction CT0001.dcm 400".

The relevant .cxx file code is as follows:

//Surface Extraction code modified from ITK Surface Extraction Example
included in ITK build
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif

#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif

#include "itkImageFileReader.h"
#include "itkBinaryMask3DMeshSource.h"
#include "itkImage.h"
#include "itkMesh.h"
#include <iostream>
using namespace std;

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

  if( argc < 3 )
    {
    std::cerr << "Usage: IsoSurfaceExtraction  inputImageFile   objectValue
" << std::endl;
    return EXIT_FAILURE;
    }

  const unsigned int Dimension = 3;
  typedef unsigned char  PixelType;

  typedef itk::Image< PixelType, Dimension >   ImageType;
  typedef itk::ImageFileReader< ImageType >    ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );

  try
    {
    reader->Update();
    }
  catch( itk::ExceptionObject & exp )
    {
    std::cerr << "Exception thrown while reading the input file " <<
std::endl;
    std::cerr << exp << std::endl;
    return EXIT_FAILURE;
    }

  typedef itk::Mesh<double>                         MeshType;
  typedef itk::BinaryMask3DMeshSource< ImageType, MeshType >
MeshSourceType;
  MeshSourceType::Pointer meshSource = MeshSourceType::New();

  const PixelType objectValue = static_cast<PixelType>( atof( argv[2] ) );

  meshSource->SetObjectValue( objectValue );

    cout << "Before meshSource input set." << endl;
    try
      {
          meshSource->SetInput( reader->GetOutput() );
        }
      catch( itk::ExceptionObject & exp )
      {
        std::cerr << "Exception thrown during setting mesh input() " <<
std::endl;
        std::cerr << exp << std::endl;
        return EXIT_FAILURE;
        }

    cout << "Before meshSource update" << endl;
  try
    {
    meshSource->Update();  //--------------------------SEGMENTATION FAULT
HERE--------------------------------------------
    }
  catch( itk::ExceptionObject & exp )
    {
    cerr << "Exception thrown during Update() " << std::endl;
    cerr << exp << std::endl;
    return EXIT_FAILURE;
    }

  cout << "Nodes = " << meshSource->GetNumberOfNodes() << std::endl;
  cout << "Cells = " << meshSource->GetNumberOfCells() << std::endl;

  return EXIT_SUCCESS;
}

Does anyone have any suggestions?

Thanks,
Catherine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070430/2f574092/attachment.htm


More information about the Insight-users mailing list