【问题标题】:CGAL add data to face handleCGAL 将数据添加到人脸句柄
【发布时间】:2018-06-17 18:36:34
【问题描述】:

我在 Python 中使用 CGAL,我希望能够在三角测量中将数据添加到面部句柄。似乎 Python 允许我存储这些信息,但它不会持久存在,例如:

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)

运行上述结果

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

是否可以在三角测量中存储信息,如果可以,如何存储?

【问题讨论】:

  • C++ 代码可以处理,但模板参数不同,需要重新编译,这意味着 python 接口不太可能让您访问它。您可能想要维护某种地图(尽管我认为您没有对面孔进行散列或排序,所以这可能不是微不足道的)。
  • 面、顶点和边都实现了__hash__,我现在正在做类似的事情作为一种解决方法

标签: python cgal triangulation delaunay face


【解决方案1】:

我对这些库一无所知,但我想finite_faces() 每次都会创建一组新对象。您应该将它们保存在一个列表中,然后迭代该列表而不是再次调用该方法。

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

for f in faces:
    print(f.data)

【讨论】:

  • D.finite_faces() 返回一个迭代器。做类似于你建议的事情faces = [f for f in D.finite_faces()] 但对我来说不是一个好选择,因为我需要随后做类似for e in D.finite_edges(): if face(e).data == 0: do something
猜你喜欢
  • 2023-04-06
  • 1970-01-01
  • 2017-04-14
  • 1970-01-01
  • 2011-08-28
  • 2011-01-05
  • 2021-11-09
  • 2020-01-22
  • 2019-05-24
相关资源
最近更新 更多