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

Julien Jomier julien.jomier at kitware.com
Wed Apr 19 13:37:19 EDT 2006


Hi Ritesh,

Can you upgrade your ITK to 2.6.0 or even cvs? ITK 2.2.0 had issues 
writing meshes using SpatialObjects.

I just fixed the problem with pixel type conversion in ITK cvs. I think 
2.6.0 should work for you though.

Julien

Ritesh Bafna wrote:
> Hi Julien,
> 
> Thanks for your response.
> 
> I am using ITK 2.2.0 which I downloaded from sourceforge.net & MS.NET 2003 
> 
> Ritesh
> 
> -----Original Message-----
> From: Julien Jomier [mailto:julien.jomier at kitware.com] 
> Sent: Wednesday, April 19, 2006 11:20 AM
> To: Ritesh Bafna
> Cc: insight-users at itk.org
> Subject: Re: [Insight-users] Fault while writing Mesh Spatial Object to
> Spatial Object Writer
> 
> Hi Ritesh,
> 
> I just tested your test program on MSVC 8 with ITK cvs and it runs fine.
> What version of ITK are you using? Can you try the cvs version?
> 
> There is a small issue with the pixel type conversion. I'm looking into that
> right now. I'll keep you posted.
> 
> Julien
> 
> Ritesh Bafna wrote:
>> 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 ); ComputeLocalBoundingBox();
>>  
>> typedef itk::SpatialObjectWriter<3, unsigned long, MeshTraitType> 
>> WriterType; WriterType::Pointer writer = WriterType::New();
>> writer->SetInput( meshSpatialObject ); SetFileName( "myMesh.meta" );
>> try
>> {
>>    writer->Update( );
>> }
>>  
>> catch (itk::ExceptionObject &ex)
>> {
>>    std::cout << ex << std::endl;
>> }
>>  
>>  
>> Also, Please find attached a test program which I have written to test 
>> this functionality
>>  
>> Thanks
>> Ritesh
>>
>>
>> ----------------------------------------------------------------------
>> --
>>
>>
>> #if defined(_MSC_VER)
>> #pragma warning ( disable : 4786 )
>> #endif
>>
>> //  Software Guide : BeginLatex
>> //
>> //  This section illustrates the full power of //  
>> \href{http://www.boost.org/more/generic_programming.html}{Generic
>> //  Programming}.  This is sometimes perceived as \emph{too much of a 
>> good //  thing}!
>> //
>> //  The toolkit has been designed to offer flexibility while keeping 
>> the //  complexity of the code to a moderate level. This is achieved 
>> in the Mesh by //  hiding most of its parameters and defining reasonable
> defaults for them.
>> //
>> //  The generic concept of a mesh integrates many different elements. 
>> It is //  possible in principle to use independent types for every one 
>> of such //  elements. The mechanism used in generic programming for 
>> specifying the many
>>
>>
>>
>> // Software Guide : BeginCodeSnippet
>> #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;
>>   }
>>
>>
>>
>> ----------------------------------------------------------------------
>> --
>>
>> PROJECT(CellTraitTest)
>>
>> FIND_PACKAGE(ITK)
>> IF(ITK_FOUND)
>>   INCLUDE(${ITK_USE_FILE})
>> ELSE(ITK_FOUND)
>>   MESSAGE(FATAL_ERROR
>>             "Cannot build my program without ITK.  Please set 
>> ITK_DIR.")
>> ENDIF(ITK_FOUND)
>>
>> ADD_EXECUTABLE(CellTraitTest Test.cxx) 
>> TARGET_LINK_LIBRARIES(CellTraitTest ITKCommon ITKBasicFilters ITKIO)
>>
>>
>>
>> ----------------------------------------------------------------------
>> --
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users at itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 



More information about the Insight-users mailing list