Surface Mesh indices are invalid during manual export

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Surface Mesh indices are invalid during manual export

Rash
Dear mailing list,

why are there invalid indices when using surface mesh? I have 2275
correct vertices in it. But somehow the mesh got 13637 vertices. Some of
may be invalid.

Lets have a look:

Data in mesh -> vpoints_ -> data:

[2] -0.532385 -2.32635 -0.1027

Data in my file:

Verts:
[0] -0.532385 -2.32635 -0.1027
Faces:
[0] 2 4 13273

The [0] 2 seems to refer to the internal mesh element address not to the
second good vertex which mesh.point(vd) delivers.

Strange why is the first vertex in my list the second in the mesh? Oh
this is a pattern. There seem to be 13637 vertices in mesh, but only
2275 good ones. You may ask why. Or why there is no offset, which would
correct for it when you write the data out. To be honest, it took me
some time find this out. How do I get the correct indices?

Here is some code.



std::to_string(mesh.number_of_vertices()); //2275


//2275 vertices, cool lets write them down to my debug file
    for(Vertex_index vd : mesh.vertices())
    {
        const Point p(mesh.point(vd));
        myfile << p.x() << " " << p.y() << " " << p.z() << std::endl;
    }


//cool now i go over all faces, save the vertex indices and have my nice
mesh

    for(auto it = faces.begin(); it != faces.end(); it++)
    {
        face_descriptor fd = *it;


        HalfEdgeIndex edge = mesh.halfedge(fd);

        Vertex_index vert1=source(edge, mesh);
        Vertex_index vert2=source(next(edge, mesh), mesh);
        Vertex_index vert3=source(next(next(edge, mesh), mesh), mesh);

        //save them to tris

    }

        //lets write the triangles into a file, easy we have Vertex_indices,
right? Oh no, of course not. THIS IS CGAL (image this with king leonidas
voice)
    for(size_t i = 0; i < tris.size(); i++)
    {
        myfile << tris[i] << std::endl; //and we got the wrong indices,
suprise!
    }

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Surface Mesh indices are invalid during manual export

Sebastien Loriot (GeometryFactory)
Can you provide a minimal example showing the pb?
With what you provide it is hard to guess what went wrong.

Sebastien.

On 6/6/19 10:47 PM, Rash wrote:

> Dear mailing list,
>
> why are there invalid indices when using surface mesh? I have 2275
> correct vertices in it. But somehow the mesh got 13637 vertices. Some of
> may be invalid.
>
> Lets have a look:
>
> Data in mesh -> vpoints_ -> data:
>
> [2] -0.532385 -2.32635 -0.1027
>
> Data in my file:
>
> Verts:
> [0] -0.532385 -2.32635 -0.1027
> Faces:
> [0] 2 4 13273
>
> The [0] 2 seems to refer to the internal mesh element address not to the
> second good vertex which mesh.point(vd) delivers.
>
> Strange why is the first vertex in my list the second in the mesh? Oh
> this is a pattern. There seem to be 13637 vertices in mesh, but only
> 2275 good ones. You may ask why. Or why there is no offset, which would
> correct for it when you write the data out. To be honest, it took me
> some time find this out. How do I get the correct indices?
>
> Here is some code.
>
>
>
> std::to_string(mesh.number_of_vertices()); //2275
>
>
> //2275 vertices, cool lets write them down to my debug file
>      for(Vertex_index vd : mesh.vertices())
>      {
>          const Point p(mesh.point(vd));
>          myfile << p.x() << " " << p.y() << " " << p.z() << std::endl;
>      }
>
>
> //cool now i go over all faces, save the vertex indices and have my nice
> mesh
>
>      for(auto it = faces.begin(); it != faces.end(); it++)
>      {
>          face_descriptor fd = *it;
>
>
>          HalfEdgeIndex edge = mesh.halfedge(fd);
>
>          Vertex_index vert1=source(edge, mesh);
>          Vertex_index vert2=source(next(edge, mesh), mesh);
>          Vertex_index vert3=source(next(next(edge, mesh), mesh), mesh);
>
> //save them to tris
>
>      }
>
> //lets write the triangles into a file, easy we have Vertex_indices,
> right? Oh no, of course not. THIS IS CGAL (image this with king leonidas
> voice)
>      for(size_t i = 0; i < tris.size(); i++)
>      {
>          myfile << tris[i] << std::endl; //and we got the wrong indices,
> suprise!
>      }
>

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss


Reply | Threaded
Open this post in threaded view
|

Re: Surface Mesh indices are invalid during manual export

Sebastien Loriot (GeometryFactory)
Reading again your post I think I understand where the confusion
comes from. Vertices are indeed indices but as indicated in the doc [1]
the indices might not be contiguous. It is the case for example if you
removed some vertices.
You can either call collect_garbage() if you want to have contiguous
indices or use an extra index map as documented here [2]

Sebastien

[1]
https://doc.cgal.org/latest/Surface_mesh/index.html#sectionSurfaceMesh_memory

[2]
https://doc.cgal.org/latest/Surface_mesh/index.html#sectionSurfaceMesh_properties

On 6/7/19 7:59 AM, Sebastien Loriot (GeometryFactory) wrote:

> Can you provide a minimal example showing the pb?
> With what you provide it is hard to guess what went wrong.
>
> Sebastien.
>
> On 6/6/19 10:47 PM, Rash wrote:
>> Dear mailing list,
>>
>> why are there invalid indices when using surface mesh? I have 2275
>> correct vertices in it. But somehow the mesh got 13637 vertices. Some of
>> may be invalid.
>>
>> Lets have a look:
>>
>> Data in mesh -> vpoints_ -> data:
>>
>> [2] -0.532385 -2.32635 -0.1027
>>
>> Data in my file:
>>
>> Verts:
>> [0] -0.532385 -2.32635 -0.1027
>> Faces:
>> [0] 2 4 13273
>>
>> The [0] 2 seems to refer to the internal mesh element address not to the
>> second good vertex which mesh.point(vd) delivers.
>>
>> Strange why is the first vertex in my list the second in the mesh? Oh
>> this is a pattern. There seem to be 13637 vertices in mesh, but only
>> 2275 good ones. You may ask why. Or why there is no offset, which would
>> correct for it when you write the data out. To be honest, it took me
>> some time find this out. How do I get the correct indices?
>>
>> Here is some code.
>>
>>
>>
>> std::to_string(mesh.number_of_vertices()); //2275
>>
>>
>> //2275 vertices, cool lets write them down to my debug file
>>      for(Vertex_index vd : mesh.vertices())
>>      {
>>          const Point p(mesh.point(vd));
>>          myfile << p.x() << " " << p.y() << " " << p.z() << std::endl;
>>      }
>>
>>
>> //cool now i go over all faces, save the vertex indices and have my nice
>> mesh
>>
>>      for(auto it = faces.begin(); it != faces.end(); it++)
>>      {
>>          face_descriptor fd = *it;
>>
>>
>>          HalfEdgeIndex edge = mesh.halfedge(fd);
>>
>>          Vertex_index vert1=source(edge, mesh);
>>          Vertex_index vert2=source(next(edge, mesh), mesh);
>>          Vertex_index vert3=source(next(next(edge, mesh), mesh), mesh);
>>
>>     //save them to tris
>>
>>      }
>>
>>     //lets write the triangles into a file, easy we have Vertex_indices,
>> right? Oh no, of course not. THIS IS CGAL (image this with king leonidas
>> voice)
>>      for(size_t i = 0; i < tris.size(); i++)
>>      {
>>          myfile << tris[i] << std::endl; //and we got the wrong indices,
>> suprise!
>>      }
>>

--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss