[Insight-users] Fault while writing Mesh Spatial Object to Spatial Object Writer

Ritesh Bafna riteshramesh-bafna at uiowa.edu
Wed Apr 19 13:52:21 EDT 2006


Hi,
 
We are working mesh generation from image data. We would like to save the
meshes in meta format. However, when we use the SpatialObjectWriter a
segmentation fault is generated when writing on the cell traits. All of the
point location and connectivity information is written properly to the file.
We have code that is able to write the meshes appropriately in other another
format, but would like to include this is an option for loading the meshes
into VTK and paraview. Here is an example of the code generating the
problem:
 
typedef itk::DefaultStaticMeshTraits< unsigned long , 3, 3, double, double,
double > MeshTraitType; 
typedef itk::Mesh< unsigned long, 3, MeshTraitType > MeshType; .
.
.
finalMesh = MeshFilter->GetOutput();
 
typedef itk::MeshSpatialObject< MeshType > MeshSpatialObjectType; 
 
MeshSpatialObjectType::Pointer meshSpatialObject =
MeshSpatialObjectType::New();
meshSpatialObject->SetMesh( finalMesh ); 
meshSpatialObject->ComputeLocalBoundingBox();
 
typedef itk::SpatialObjectWriter<3, unsigned long, MeshTraitType>
WriterType; 
WriterType::Pointer writer = WriterType::New();
writer->SetInput( meshSpatialObject );
writer->SetFileName( "myMesh.meta" );
try
{
   writer->Update( );
}
 
catch (itk::ExceptionObject &ex)
{
   std::cout << ex << std::endl;
}

 
 
 The following is a test program that i have written to test out this
functionality
 
 
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
 
#include "itkMesh.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkAutomaticTopologyMeshSource.h"
#include <itkMeshSpatialObject.h>
#include <itkSpatialObjectWriter.h>
#include <itkSpatialObjectReader.h>
 
int main(int, char *[])
  {
    const unsigned int PointDimension = 3;
    const unsigned int MaxTopologicalDimension = 3;
    typedef unsigned long    PixelType;
    typedef double              CellDataType;
    typedef double              CoordinateType;
    typedef double              InterpolationWeightType;
 
    typedef itk::DefaultStaticMeshTraits< PixelType, PointDimension,
MaxTopologicalDimension,
                      CoordinateType, InterpolationWeightType, CellDataType
> MeshTraitType;
 
    typedef itk::Mesh< PixelType, PointDimension, MeshTraitType > MeshType; 
 
    typedef itk::AutomaticTopologyMeshSource< MeshType >   MeshSourceType;
    MeshSourceType::Pointer  meshSource;
 
    meshSource = MeshSourceType::New( );
    meshSource->AddHexahedron(
      meshSource->AddPoint( 13.5, -20.5, 10.5 ),
      meshSource->AddPoint( 13.5, -17.5, 10.5 ),
      meshSource->AddPoint( 16.5, -17.5, 10.5 ),
      meshSource->AddPoint( 16.5, -20.5, 10.5 ),
      meshSource->AddPoint( 13.5, -20.5, 7.5 ),
      meshSource->AddPoint( 13.5, -17.5, 7.5 ),
      meshSource->AddPoint( 16.5, -17.5, 7.5 ),
      meshSource->AddPoint( 16.5, -20.5, 7.5 ));
 
    std::cout << " Points = " <<
meshSource->GetOutput()->GetNumberOfPoints() << std::endl;
    std::cout << " Cells  = " << meshSource->GetOutput()->GetNumberOfCells()
<< std::endl;
 
    CellDataType value = 3000.50;
    meshSource->GetOutput()->SetCellData( 1, value );
 
    CellDataType cellData;
    meshSource->GetOutput()->GetCellData( 1, &cellData );
 
    std::cout << " cell data from GetCellData() method = " << cellData <<
std::endl;
 
    typedef itk::MeshSpatialObject< MeshType > MeshSpatialObjectType;  
 
    MeshSpatialObjectType::Pointer meshSpatialObject =
MeshSpatialObjectType::New();
    meshSpatialObject->SetMesh( meshSource->GetOutput() );
    meshSpatialObject->ComputeLocalBoundingBox();
 
    typedef itk::SpatialObjectWriter<3, unsigned long, MeshTraitType>
WriterType;
    WriterType::Pointer writer = WriterType::New();
    writer->SetInput( meshSpatialObject );
    writer->SetFileName( "myMesh.meta" );
    
    try
      {
        writer->Update( );
      }
    catch (itk::ExceptionObject &ex)
      {
        std::cout << ex << std::endl;
      }
    return 0;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060419/1aa72bde/attachment-0001.html


More information about the Insight-users mailing list