0

I am using CGAL in Python and I'd like to be able to add data to the face handle in a triangulation. It seems like Python lets me store this information but it doesn't persist, for example:

from CGAL.CGAL_Kernel import Point_2
from CGAL.CGAL_Triangulation_2 import Delaunay_triangulation_2

#triangulate a square
points = [Point_2(0,0), Point_2(0,1), Point_2(1,0), Point_2(1,1)]
D = Delaunay_triangulation_2()
D.insert(points)

#attempt to store information in face handle
for f in D.finite_faces():
    f.data = 'my data'

#this information does not persist
for f in D.finite_faces():
    print(f.data)

Running the above results in

AttributeError: 'Delaunay_triangulation_2_Face_handle' object has no attribute 'data'

Is it possible to store information within the triangulation and if yes how?

mv3
  • 469
  • 5
  • 16
  • The C++ code can handle it, but with different template parameters, which requires recompiling, meaning that the python interface is unlikely to give you access to that. You might want to maintain some kind of map (though I don't think you have hashing or sorting on faces, so it may not be trivial). – Marc Glisse Jan 08 '18 at 20:14
  • The faces, vertices, and edges all implement `__hash__`, I'm working on something like this now as a workaround – mv3 Jan 08 '18 at 20:21

1 Answers1

0

I don't know anything about any of these libraries, but I would imagine that finite_faces() is creating a new set of objects each time. You should keep them in a list, then subsequently iterate over that list rather than calling the method again.

faces = D.finite_faces():
for f in faces:
    f.data = 'my data'

for f in faces:
    print(f.data)
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • `D.finite_faces()` returns an iterator. Doing something similar to what you suggest works `faces = [f for f in D.finite_faces()]` but is not a good option for me since I need to subsequently do something like `for e in D.finite_edges(): if face(e).data == 0: do something` – mv3 Jan 08 '18 at 18:44