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

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


Skipped content of type multipart/alternative-------------- next part --------------

#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;
  }

-------------- next part --------------
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)



More information about the Insight-users mailing list