[ITK] Get the list of Points, Edges and Cells of a Mesh

Dženan Zukić dzenanz at gmail.com
Tue Sep 13 10:14:47 EDT 2016


Hi Rodolfo,

faces are one type of cells for a mesh. For examples how to access them,
you can take a look at:
https://itk.org/Doxygen/html/Examples_2DataRepresentation_
2Mesh_2MeshCellsIteration_8cxx-example.html
https://itk.org/ITKExamples/src/Core/QuadEdgeMesh/CutMesh/Documentation.html

Regards,
Dženan

On Tue, Sep 13, 2016 at 5:54 AM, Oliveira, Rodolfo <
r.oliveira16 at imperial.ac.uk> wrote:

> Hi Matt,
>
>
> It did helped a lot!
>
>
> I modified the example to display what's been written to file in terms of
> what I need but I'm struggling to access the edges of a particular face.
> For now all I can do is to iterate over the points and cell's ids. There
> are some examples to write data to cells but I either don't find it that
> useful for my case or completely understood it.
>
>
> Please find my code below:
>
>
>
> #include "itkQuadEdgeMesh.h"
> #include "itkMeshFileWriter.h"
> #include "itkMeshFileReader.h"
>
> int main(int argc, char* argv[])
> {
>     if (argc != 2)
>     {
>         std::cerr << "Usage: " << std::endl;
>         std::cerr << argv[0];
>         std::cerr << " <OutputFileName>";
>         std::cerr << std::endl;
>         return EXIT_FAILURE;
>     }
>
>     const char * outputFileName = argv[1];
>
>     //
>     // Definitions
>     //
>     const unsigned int Dimension = 3;
>
>     typedef double                                    CoordType;
>     typedef itk::QuadEdgeMesh< CoordType, Dimension > MeshType;
>
>     MeshType::Pointer mesh = MeshType::New();
>
>     typedef MeshType::PointsContainer         PointsContainer;
>     typedef MeshType::PointsContainerPointer  PointsContainerPointer;
>
>     //
>     // Create points
>     //
>     PointsContainerPointer points = PointsContainer::New();
>     points->Reserve(9);
>
>     typedef MeshType::PointType               PointType;
>     PointType p;
>     p[2] = 0.;
>
>     typedef MeshType::PointIdentifier         PointIdentifier;
>     PointIdentifier k = 0;
>
>     for (int i = 0; i < 3; i++)
>     {
>         p[0] = static_cast< CoordType >(i);
>
>         for (int j = 0; j < 3; j++)
>         {
>             p[1] = static_cast< CoordType >(j);
>             points->SetElement(k, p);
>             k++;
>         }
>     }
>
>     mesh->SetPoints(points);
>
>     //
>     // Create faces
>     //
>     k = 0;
>
>     for (int i = 0; i < 2; i++)
>     {
>         for (int j = 0; j < 2; j++)
>         {
>             mesh->AddFaceTriangle(k, k + 1, k + 4);
>             mesh->AddFaceTriangle(k, k + 4, k + 3);
>             k++;
>         }
>         k++;
>     }
>
>     //
>     // Write mesh to file
>     //
>     typedef itk::MeshFileWriter< MeshType > WriterType;
>     WriterType::Pointer writer = WriterType::New();
>     writer->SetFileName(outputFileName);
>     writer->SetInput(mesh);
>     try
>     {
>         writer->Update();
>     }
>     catch (itk::ExceptionObject & error)
>     {
>         std::cerr << "Error: " << error << std::endl;
>         return EXIT_FAILURE;
>     }
>
>     //
>     // Read mesh to file
>     //
>     typedef itk::MeshFileReader< MeshType > ReaderType;
>     ReaderType::Pointer reader = ReaderType::New();
>     reader->SetFileName(outputFileName);
>     try
>     {
>         reader->Update();
>     }
>     catch (itk::ExceptionObject & error)
>     {
>         std::cerr << "Error: " << error << std::endl;
>         return EXIT_FAILURE;
>     }
>
>     mesh = reader->GetOutput();
>
>     //
>     // Print data
>     //
>     typedef MeshType::PointsContainer::ConstIterator PointIterator;
>     PointIterator pointIterator = mesh->GetPoints()->Begin();
>     PointIterator pointEnd = mesh->GetPoints()->End();
>
>     MeshType::PointIdentifier pid;
>
>     while (pointIterator != pointEnd)
>     {
>         p = pointIterator.Value();
>         pid = pointIterator.Index();
>
>         std::cout << pid << ": "
>             << p[0] << " "
>             << p[1] << " "
>             << p[2] << std::endl;
>
>         ++pointIterator;
>     }
>
>     //
>     // Print edges
>     //
>     typedef MeshType::CellsContainer::ConstIterator CellIterator;
>     CellIterator cellIterator = mesh->GetCells()->Begin();
>     CellIterator cellEnd = mesh->GetCells()->End();
>
>     MeshType::CellType *c;
>     MeshType::CellIdentifier cid;
>
>     while (cellIterator != cellEnd)
>     {
>         c = cellIterator.Value();
>         cid = cellIterator.Index();
>
>         std::cout << cid << ": "
>             // The face's edge list?
>             << std::endl;
>
>         ++cellIterator;
>     }
>
>     return EXIT_SUCCESS;
> }
>
>
>
> Thanks again!
>
>
> Rodolfo
> ------------------------------
> *From:* Matt McCormick <matt.mccormick at kitware.com>
> *Sent:* 07 September 2016 21:30:18
> *To:* Oliveira, Rodolfo
> *Cc:* Community at itk.org
> *Subject:* Re: [ITK] Get the list of Points, Edges and Cells of a Mesh
>
> Hi Rodolfo,
>
> Here is an example of how to manually create a mesh:
>
>   https://itk.org/ITKExamples/src/Core/QuadEdgeMesh/CreateTria
> ngularQuadEdgeMesh/Documentation.html
>
> HTH,
> Matt
>
> On Wed, Sep 7, 2016 at 12:36 PM, Oliveira, Rodolfo
> <r.oliveira16 at imperial.ac.uk> wrote:
> > Hi,
> >
> >
> > I need to get the list of points, edges and cells of an itk mesh to
> file. I
> > have to write the points, the edges as a reference of two points' indexes
> > and the faces as three edges' indexes.
> >
> >
> > So far I only managed to get the points from a mesh, using a point
> iterator
> > and writing its value and indexes. I still haven't figure it out how to
> get
> > the linking indexes of the edges and faces.
> >
> >
> > For illustration purposes, say I have a mesh containing a single
> triangle,
> > defined this:
> >
> >
> > 0,1 - 2 - 1,1
> >
> >  |       /
> >
> >  |      /
> >
> >  |  1  /
> >
> >  1    3
> >
> >  |   /
> >
> >  |  /
> >
> >  | /
> >
> > 0,0
> >
> >
> > The structure would be like this:
> >
> > Points:
> > 1: 0,0
> > 2: 0,1
> > 3: 1,1
> >
> > Edges:
> > 1: 1 2 (Point 1 to Point 2)
> > 2: 2 3
> > 3: 3 1
> >
> > Faces:
> > 1: 1 2 3 (Edge 1, to Edge 2 and Edge 3)
> >
> > This is a rather simplistic example, but there is no difference for the
> case
> > of more than one triangle. But they might share some of the same indexes
> > when neighbours.
> >
> > Any help would be much appreciated!
> >
> >
> > Thanks,
> >
> >
> > Rodolfo
> >
> >
> > _______________________________________________
> > Community mailing list
> > Community at itk.org
> > http://public.kitware.com/mailman/listinfo/community
> >
>
> _______________________________________________
> Community mailing list
> Community at itk.org
> http://public.kitware.com/mailman/listinfo/community
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20160913/6d0777e9/attachment-0001.html>


More information about the Community mailing list