Convert Polyhedron_3 Vertex_handles to integers

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

Convert Polyhedron_3 Vertex_handles to integers

Robert Sage
Hello, 
We need to convert Polyhedron_3 facet vertices from Vertex_handle to integer ids exactly like I see in:
So we have adapted this code but are observing each std::distance operation runs at O(n) and thus the whole conversion takes a long time for Polyhedron with many facets. Is there a more efficient way?  
Thank you!
Robert
Reply | Threaded
Open this post in threaded view
|

Re: Convert Polyhedron_3 Vertex_handles to integers

andreas.fabri

Hello,

On what do you want to apply std::distance ?

You can add an int field to vertices as described here: https://doc.cgal.org/latest/Polyhedron/index.html#title12

You might switch to Surface_mesh   https://doc.cgal.org/latest/Surface_mesh/index.html
as the Vertex_index   is fundamentally an int

Andreas

On 2/26/2019 5:50 AM, Robert Sage wrote:
Hello, 
We need to convert Polyhedron_3 facet vertices from Vertex_handle to integer ids exactly like I see in:
So we have adapted this code but are observing each std::distance operation runs at O(n) and thus the whole conversion takes a long time for Polyhedron with many facets. Is there a more efficient way?  
Thank you!
Robert
-- 
Andreas Fabri, PhD
Chief Officer, GeometryFactory
Editor, The CGAL Project

phone: +33.492.954.912    skype: andreas.fabri
Reply | Threaded
Open this post in threaded view
|

Re: Convert Polyhedron_3 Vertex_handles to integers

Sebastien Loriot (GeometryFactory)
In reply to this post by Robert Sage
You can use a vertex type with id like:
   typedef CGAL::Polyhedron_3<Kernel, CGAL::Polyhedron_items_with_id_3>
Polyhedron_3;
https://doc.cgal.org/latest/BGL/classCGAL_1_1Polyhedron__items__with__id__3.html
In particular with this type, any face/vertex/face handle has a id()
field that can be set and access:

vh->id()=33;
std::cout << vh->id() << "\n";

Another option is to use the class Surface_mesh that have descriptor
being index (not necessarily contiguous if some removal were done and
collect_garbage() has not been called).

https://doc.cgal.org/latest/Surface_mesh/

Sebastien.


On 2/26/19 5:50 AM, Robert Sage wrote:
> Hello,
> We need to convert Polyhedron_3 facet vertices from Vertex_handle to
> integer ids exactly like I see in:
> https://doc.cgal.org/latest/Polyhedron/Polyhedron_2polyhedron_prog_off_8cpp-example.html
> So we have adapted this code but are observing each std::distance
> operation runs at O(n) and thus the whole conversion takes a long time
> for Polyhedron with many facets. Is there a more efficient way?
> Thank you!
> Robert

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