[Insight-users] Removing points from itk::PointSet

Luis Ibanez luis . ibanez at kitware . com
Tue, 25 Nov 2003 10:19:17 -0500


Hi Thomas,

The underlying structures used as point containers in the
Mesh are the itk::VectorContainer and the itk::MapContainer.
These two containers derive respectively from the std::vector
and the std::map.

In order to use one or the other you should select the mesh
traits to be Static or Dynamic.

You do this by setting the template parameter of the PointSet
class one of the types:

    itkDefaultStaticMeshTraits
    itkDefaultDynamicMeshTraits

If you want to delete points from the PointSet,
your best option is to use the DynamicMeshTraits.

For an example on how to do this, you can look at the Morphogenesis
application in InsightApplicationos/Morphogenesis.

In the CellularAggregates.h file you will find:

>   /** Mesh Traits */
>   typedef itk::DefaultDynamicMeshTraits<  
>               PointPixelType,           // PixelType
>               Cell::PointDimension,     // Points Dimension
>               Cell::PointDimension,     // Max.Topological Dimension
>               double,                   // Type for coordinates
>               double,                   // Type for interpolation 
>               CellPixelType             // Type for values in the cells  
>               >  MeshTraits;
>   
>   /** Mesh Traits */
>   typedef itk::Mesh<  MeshTraits::PixelType,
>                       MeshTraits::PointDimension,
>                       MeshTraits  >               MeshType;

in your case, you will use itk::PointSet instead of itk::Mesh,
like:


 >   typedef itk::PointSet<  MeshTraits::PixelType,
 >                       MeshTraits::PointDimension,
 >                       MeshTraits  >               PointSetType;


If you look at the code of the itk::MapContainer, you'll find
that the DeleteIndex() method simply invokes the STL map::erase()
method.  While in the case of the itk::VectorContainer, the
DeleteIndex() assigns the index to the default element, therefore
not changing the total number of points. This is done because in
the StaticMesh setup you are not supposed to remove/add points.
This dual behavior of the mesh was designed in order to cope
with the conflicting memory/performance requirement of a dynamic
mesh versus a static mesh.


You will see the use of the DeleteIndex() method in the Morphogenesis
demo application, on the file CellularAggreate.cxx, line 329.
This is invoked when bio::cells are killed (due to the triggering of
their apoptosis mechanism).


Please let us know if you have any further questions,


Thanks


   Luis



-------------------------
Thomas Boettger wrote:

> Hi,
> 
> how do I remove points from my PoinSet or Mesh?
> 
> The following code:
> 
>   unsigned long testId = inputMesh->GetNumberOfPoints();
>   InputPointType testPoint;
>   testPoint.Fill(1.0);
>   std::cout << "# of points: "  <<  inputMesh->GetNumberOfPoints() << 
> std::endl;
>   inputMesh->SetPoint(testId, testPoint);
>   std::cout << "# of points: "  <<  inputMesh->GetNumberOfPoints() << 
> std::endl;
>   inputMesh->GetPoints()->DeleteIndex(testId);
>   std::cout << "# of points: "  <<  inputMesh->GetNumberOfPoints() << 
> std::endl;
> 
> 
> produced the following output:
> 
> # of points: 128
> # of points: 129
> # of points: 129
> 
> ...so the number of points did not decrease after the DeleteIndex() call.
> 
> How do I remove a point?
> 
> Thanks in advance,
> Thomas
> 
> 
>