[Insight-developers] Writing a SimplexMesh with SpatialObjectWriter

Julien Jomier jjomier at cs.unc.edu
Thu Jul 14 12:01:09 EDT 2005


Hi Jim,

Thanks for the report.
How about replacing the dynamic_cast by a static_cast in MetaSceneConverter?

This option seems to work for me,
Let me know,

Julien

Miller, James V (Research) wrote:
> The following code:
> 
> SpatialObjectWriter<N, T, Traits>::Pointer writer = SpatialObjectWriter<N, T, Traits>::New();
> MeshSpatialObject<SimplexMeshType>::Pointer so = MeshSpatialObject<SimplexMeshType>::New();
> so->SetMesh( simplexMesh );
> writer->SetFileName( "foo");
> writer->SetInput( so );
> writer->Update();
> 
> will crash because the MetaSceneConverter assumes that a MeshSpatialObject is always templated
> over a Mesh and not a subclass of Mesh.  At line 508, there is code that essentially does
> 
> 	dynamic_cast<MeshSpatialObject<Mesh<T, N, Traits> >( so );
> 
> When the SpatialObject, so, is a MeshSpatialObject<SimplexMesh<T, N, Traits> >, then the dynamic_cast
> will fail because C++ cannot convert between MeshSpatialObjects templated over different types (even though 
> the two type are related by inheritance).
> 
> This can be fixed on the user end by passing in MeshSpatialObjects templated over a Mesh instead of a 
> SimplexMesh.  Then the user calls SetMesh() on the MeshSpatialObject, the pointer to the SimplexMesh
> will be cast back to a pointer to a Mesh and the writer will work.  But this is a little clunky.  
> 
> Another solution would be to create a SimplexMeshSpatialObject class that is used for wrapping
> a SimplexMesh.  But this is also clunky. I don't see why one shouldn't be able to use a MeshSpatialObject
> to wrap a SimplexMesh.
> 
> 
> It would be best if this is fixed at the MetaSceneConverter level.  I think the following code
> 
>     if(!strncmp((*it)->GetTypeName(),"MeshSpatialObject",17))
>       {
>       typedef itk::Mesh<PixelType,NDimensions,TMeshTraits> MeshType;
>       MetaMeshConverter<NDimensions,PixelType,TMeshTraits> converter;
>       MetaMesh* mesh = converter.MeshSpatialObjectToMetaMesh(
>           dynamic_cast<itk::MeshSpatialObject<MeshType>*>((*it).GetPointer()));
>       if((*it)->GetParent())
>         {
>         mesh->ParentID((*it)->GetParent()->GetId());
>         }
>       mesh->Name((*it)->GetProperty()->GetName().c_str());
>       this->SetTransform(mesh, (*it)->GetObjectToParentTransform()) ;
>       metaScene->AddObject(mesh);
>       }
> 
> needs to somehow cast the mesh that is internal to the SpatialObject back to a Mesh.  So even if a
> MeshSpatialObject is wrapping a subclass of Mesh, it could still be written to disk.
> 
> 
> 
> Jim Miller 
> _____________________________________
> Visualization & Computer Vision
> GE Research
> Bldg. KW, Room C218B
> 1 Research Circle, Schenectady NY 12309-1027
> 
> millerjv at reserch.ge.com <mailto:millerjv at reserch.ge.com>
> (518) 387-4005, Dial Comm: 8*833-4005
> Cell: (518) 505-7065, Fax: (518) 387-6981
> 
> 
> _______________________________________________
> Insight-developers mailing list
> Insight-developers at itk.org
> http://www.itk.org/mailman/listinfo/insight-developers
> 
> 
> 



More information about the Insight-developers mailing list