[Insight-users] how to copy a mesh? newbie

Dan Mueller dan.muel at gmail.com
Mon Jun 8 15:51:06 EDT 2009


Hi Marion,

    Welcome to ITK!

One way to copy your mesh is to iterate and copy the points/cells

#include "itkCellInterface.h"
#include "itkDefaultStaticMeshTraits.h"
#include "itkMesh.h"

int main( int argc, char *argv[] )
{
    typedef itk::Mesh < float,3,itk::DefaultStaticMeshTraits<
float,3,3,float > > MeshType;
    MeshType::Pointer mesh = MeshType::New(); // You need to
initialise the mesh to copy
    MeshType::Pointer copy = MeshType::New(); // This is the copied mesh
    MeshType::PointsContainerPointer points = mesh->GetPoints( );
    MeshType::PointsContainerConstIterator it = points->Begin();
    MeshType::PointsContainerConstIterator itEnd = points->End();
    unsigned int i = 0;
    while ( it != itEnd )
    {
        MeshType::PointType point = it.Value();
        copy->SetPoint( i++, point );
    }

    i = 0;
    MeshType::CellsContainerPointer cells = mesh->GetCells( );
    MeshType::CellsContainerConstIterator itCells = cells->Begin();
    MeshType::CellsContainerConstIterator itCellsEnd = cells->End();
    while ( itCells != itCellsEnd )
    {
        MeshType::CellType::CellAutoPointer cellCopy;
        itCells.Value()->MakeCopy( cellCopy );
        copy->SetCell( i++, cellCopy );
    }
}

Disclaimer: I haven't fully tested the above code, but it should get
you started.

Hope this helps.

Cheers, Dan


2009/6/8  <marion.rizet at yahoo.fr>:
> Hi all,
>
> I would like to create a new mesh from an existing mesh(which is an input to
> my code). The new mesh that I want to create should has the same data except
> the values (the points value) which are different. How can I do that? Is
> there way or method to copy a mesh (points , cells,..) ?. please could you
> give me help, I’m a bit lost with itk as I’m  new.
>
>
>
> Thank you
>
> Marion
>
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users
>
>


More information about the Insight-users mailing list