[Insight-users] MeshSpatialObject in 2D
Julien Jomier
julien.jomier at kitware.com
Tue Aug 22 10:34:16 EDT 2006
Hi Gheorghe,
Two things:
1) The following line is wrong:
unsigned long tetraPoints[6] = {0,1,2,4,5};
and should be:
unsigned long tetraPoints[6] = {0,1,2,*3*,4,5};
2)
> for(unsigned idx = 0; idx<3; ++idx, ++count)
> testCell1->SetPointId(idx, tetraPoints[count]);
This is wrong and should be for(unsigned idx = 0; idx<*2*; ++idx,
++count). Because a line cell is described by two points.
With these fixes your code runs fine.
Hope that helps,
Julien
Gheorghe Postelnicu wrote:
> Hi again,
>
> Below is some code modified from
> Examples/SpatialObjects/MeshSpatialObject.cxx, which fails with a
> glib_detected.... exception. Below is my code and right after, the gdb
> bt. Thanks,
>
>
> =========================================================================*/
> #if defined(_MSC_VER)
> #pragma warning ( disable : 4786 )
> #endif
>
>
> #include <itkDefaultDynamicMeshTraits.h>
> #include <itkMesh.h>
> #include <itkLineCell.h>
>
> // Software Guide : BeginLatex
> //
> // \index{itk::MeshSpatialObject}
> //
> // A \doxygen{MeshSpatialObject} contains a pointer to an
> // notion of spatial transformations and parent-child hierarchy.
> // This example shows how to create an \doxygen{MeshSpatialObject},
> // use it to form a binary image and how to write the mesh on disk.
> //
> // Let's begin by including the appropriate header file.
> //
> // Software Guide : EndLatex
>
> // Software Guide : BeginCodeSnippet
> #include <itkMeshSpatialObject.h>
> #include <itkSpatialObjectReader.h>
> #include <itkSpatialObjectWriter.h>
> #include <itkSpatialObjectToImageFilter.h>
> // Software Guide : EndCodeSnippet
>
>
> int main(int, char * [] )
> {
> typedef itk::DefaultDynamicMeshTraits< float , 2, 2 > MeshTrait;
> typedef itk::Mesh<float,2,MeshTrait> MeshType;
> typedef MeshType::CellTraits CellTraits;
> typedef itk::CellInterface< float, CellTraits > CellInterfaceType;
> typedef itk::LineCell<CellInterfaceType> LineCellType;
> typedef MeshType::PointType PointType;
> typedef MeshType::CellType CellType;
> typedef CellType::CellAutoPointer CellAutoPointer;
> // Software Guide : EndCodeSnippet
>
> // Software Guide : BeginCodeSnippet
> MeshType::Pointer myMesh = MeshType::New();
>
> MeshType::CoordRepType testPointCoords[6][2]
> = { {0,0}, {9,0}, {9,9},
> {10,10}, {20,10}, {10,20} };
>
> unsigned long tetraPoints[6] = {0,1,2,4,5};
> int i;
> for(i=0; i < 6 ; ++i)
> {
> myMesh->SetPoint(i, PointType(testPointCoords[i]));
> }
>
> myMesh->SetCellsAllocationMethod(
>
> MeshType::CellsAllocatedDynamicallyCellByCell );
> unsigned int count = 0;
> for(unsigned int ui=0; ui <2; ++ui)
> {
> CellAutoPointer testCell1;
> testCell1.TakeOwnership( new LineCellType );
> for(unsigned idx = 0; idx<3; ++idx, ++count)
> testCell1->SetPointId(idx, tetraPoints[count]);
> myMesh->SetCell(ui, testCell1 );
> }
>
> typedef itk::MeshSpatialObject<MeshType> MeshSpatialObjectType;
> MeshSpatialObjectType::Pointer myMeshSpatialObject =
> MeshSpatialObjectType::New();
> myMeshSpatialObject->SetMesh(myMesh);
> myMeshSpatialObject->GetMesh();
> myMeshSpatialObject->ComputeBoundingBox();
> std::cout << "Mesh bounds : " <<
> myMeshSpatialObject->GetBoundingBox()->GetBounds() << std::endl;
> std::cout << " Mesh minimum : "
> << myMeshSpatialObject->GetBoundingBox()->GetMinimum() <<
> std::endl;
>
> MeshSpatialObjectType::PointType myPhysicalPoint;
> myPhysicalPoint.Fill(1);
> std::cout << "Is my physical point inside? : " <<
> myMeshSpatialObject->IsInside(myPhysicalPoint) << std::endl;
>
> return EXIT_SUCCESS;
>
> }
>
>
>
> (gdb) run
> Starting program:
> /autofs/space/asterix_001/users/postelni/code/mriScout/itkInside/build/line
> [Thread debugging using libthread_db enabled]
> [New Thread 182913315616 (LWP 26338)]
> Mesh bounds : [0, 20, 0, 20]
> Mesh minimum : [0, 0]
> Is my physical point inside? : 0
> *** glibc detected *** free(): invalid next size (fast):
> 0x000000000057b330 ***
>
> Program received signal SIGABRT, Aborted.
> [Switching to Thread 182913315616 (LWP 26338)]
> 0x0000003d1732e2ed in raise () from /lib64/tls/libc.so.6
> (gdb) bt
> #0 0x0000003d1732e2ed in raise () from /lib64/tls/libc.so.6
> #1 0x0000003d1732fa3e in abort () from /lib64/tls/libc.so.6
> #2 0x0000003d17362d41 in __libc_message () from /lib64/tls/libc.so.6
> #3 0x0000003d1736881e in _int_free () from /lib64/tls/libc.so.6
> #4 0x0000003d17368b66 in free () from /lib64/tls/libc.so.6
> #5 0x0000003d1a2ae19e in operator delete () from /usr/lib64/libstdc++.so.6
> #6 0x000000000044d516 in ~LineCell (this=0x57b330)
> at
> /space/asterix/1/users/postelni/packages/itk/current/Code/Common/itkLineCell.h:86
>
> #7 0x00000000004364f5 in itk::Mesh<float, 2u,
> itk::DefaultDynamicMeshTraits<float, 2u, 2u, floa
> , float, float> >::ReleaseCellsMemory (this=0x57ac60)
> at
> /space/asterix/1/users/postelni/packages/itk/current/Code/Common/itkMesh.txx:1142
>
> #8 0x000000000044da2d in ~Mesh (this=0x57ac60)
> at
> /space/asterix/1/users/postelni/packages/itk/current/Code/Common/itkMesh.txx:1058
>
> #9 0x0000002a9574aaf9 in itk::Object::UnRegister ()
> from
> /space/asterix/1/users/postelni/packages/itk/build/rls-dynamic/bin/libITKCommon.so.2.8
>
> #10 0x000000000043311a in itk::SmartPointer<itk::Mesh<float, 2u,
> itk::DefaultDynamicMeshTraits<f
> oat, 2u, 2u, float, float, float> > >::UnRegister (this=0x7fbffff2a0)
> at
> /space/asterix/1/users/postelni/packages/itk/current/Code/Common/itkSmartPointer.h:148
>
> #11 0x0000000000432663 in ~SmartPointer (this=0x7fbffff2a0)
> at
> /space/asterix/1/users/postelni/packages/itk/current/Code/Common/itkSmartPointer.h:65
>
> #12 0x00000000004323c0 in main ()
> at
> /autofs/homes/011/postelni/symAsterix/code/mriScout/itkInside/mainLine.cpp:101
>
>
>
More information about the Insight-users
mailing list