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

Marion Rizet marion.rizet at yahoo.fr
Wed Jun 10 09:25:55 EDT 2009


Hi Dan,
Thank you for your help. the code is working I've just added pointer incrementation statment in both loops.
Regards
Marion

--- En date de : Lun 8.6.09, Dan Mueller <dan.muel at gmail.com> a écrit :


De: Dan Mueller <dan.muel at gmail.com>
Objet: Re: [Insight-users] how to copy a mesh? newbie
À: marion.rizet at yahoo.fr
Cc: insight-users at itk.org
Date: Lundi 8 Juin 2009, 19h51


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
>
>



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090610/b5622ce2/attachment.htm>


More information about the Insight-users mailing list