[Insight-users] Trouble reading mesh from meta-file

Dominique Zosso zosso at tele.ucl.ac.be
Thu Dec 8 18:17:13 EST 2005


Hi Julien,

I still encounter trouble when trying to read the mesh from the file, now. I
try to read "mesh.meta" (in attachment in separate mail) with the code
snippet given below.
The reader crashes with a seg fault in the mittle of execution, no itk
exception being thrown. See console output below.

Normally, the file contains a MeshSpatialObject. However, there seems to be
a problem with some MetaTags? Am I missing something? Are there some errors
in the code below?

Further, assume we COULD read the SpatialObject from the file, we first get
a GroupSpatialObject, is this correct? [at least I read this in the
SoftwareGuide]
We can then extract the children of this group via its GetChildren method
and STL-List dereferencing. Now we have a SmartPointer to a SpatialObject.
But how call the GetMesh-method of the initial MeshSpatialObject? I tried to
typecast the SpatialObject-SmartPointer into a
MeshSpatialObject-SmartPointer, but this looks very ugly to me... Is there
another (an more elegant) way to access the GetMesh-method for this
child-Object? In fact, I cannot find any suitable example in the
SoftwareGuide. Those examples are limited to virtual methods only, that are
already known in SpatialObject.

Thank you in advance,

Dominique

Code snippet:
***********

const unsigned short int Dimension = 3;

// Derive other types from this Base type traits
typedef itk::IndexedTriangleMesh< short int > MeshType;

// typedefs for the mesh reader and writer
typedef itk::Mesh< MeshType::PixelType, Dimension, MeshType::MeshTraits >
NormalMeshType;
typedef itk::MeshSpatialObject< NormalMeshType > MeshSpatialObjectType;
typedef itk::SpatialObject< Dimension > SpatialObjectType;
typedef itk::GroupSpatialObject< Dimension > GroupSpatialObjectType;
typedef itk::SpatialObjectReader< Dimension, NormalMeshType::PixelType,
NormalMeshType::MeshTraits > MeshReaderType;

...

  std::cout << " Reading input mesh " << argv[1] << " ... " << std::endl;

  MeshReaderType::Pointer meshReader = MeshReaderType::New();
  meshReader->SetFileName( argv[1] );

  try
  {
    meshReader->Update();
  }
  catch ( itk::ExceptionObject & err )
  {
    std::cerr << " Could not read input mesh " << argv[1] << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
  }

  std::cout << " SpatialObject read, unwrapping... " << std::endl;

  MeshReaderType::SceneType * scene = meshReader->GetScene();
  MeshReaderType::GroupType * group = meshReader->GetGroup();

  std::cout << " #objects : " << scene->GetNumberOfObjects() << " #children
: " << group->GetNumberOfChildren() << std::endl;

  SpatialObjectType::ChildrenListType * children = group->GetChildren();

  // get first element int the children list
  std::cout << " First child : " << (*(children->begin()));

  // very ugly typecast SpatialObject::Pointer -->
MeshSpatialObject::Pointer
  MeshSpatialObjectType::Pointer inputMeshSpatialObject = *
(MeshSpatialObjectType::Pointer *)(&(*(children->begin())));
  NormalMeshType::Pointer inputMesh = inputMeshSpatialObject->GetMesh();

  delete children;


Console output:
************

 Reading input mesh mesh.meta ...
Skipping unrecognized field NCellData
Skipping unrecognized field CellDataSize
Skipping unrecognized field CellData
Skipping unrecognized field
Skipping unrecognized field
Erreur de segmentation

---
Dominique Zosso
cand. ing. el. EPFL




More information about the Insight-users mailing list