我正在使用the CGAL Python bindings for alpha shape。
我有8个CGAL.Triangulations_2.Vertex
个对象数组,如下所示:
In [5]: len(alphaShapeVertices)
Out[5]: 8
In [6]: for i, asv in enumerate(alphaShapeVertices):
...: print i
...: print asv
0
[<CGAL.Triangulations_2.Vertex object at 0x03C423E8>, <CGAL.Triangulations_2.Vertex object at 0x03C42420>, <CGAL.Triangulations_2.Vertex object at 0x03C42458>, <CGAL.Triangulations_2.Vertex object at 0x03C42490>, <CGAL.Triangulations_2.Vertex object at 0x03C424C8>, <CGAL.Triangulations_2.Vertex object at 0x03C42500>, <CGAL.Triangulations_2.Vertex object at 0x03C42538>, <CGAL.Triangulations_2.Vertex object at 0x03C42570>, <CGAL.Triangulations_2.Vertex object at 0x03C425A8>, <CGAL.Triangulations_2.Vertex object at 0x03C425E0>, <CGAL.Triangulations_2.Vertex object at 0x03C42618>, <CGAL.Triangulations_2.Vertex object at 0x03C42650>, <CGAL.Triangulations_2.Vertex object at 0x03C42688>, <CGAL.Triangulations_2.Vertex object at 0x03C426C0>, <CGAL.Triangulations_2.Vertex object at 0x03C426F8>, <CGAL.Triangulations_2.Vertex object at 0x03C42730>, <CGAL.Triangulations_2.Vertex object at 0x03C42768>, <CGAL.Triangulations_2.Vertex object at 0x03C427A0>, <CGAL.Triangulations_2.Vertex object at 0x03C427D8>, <CGAL.Triangulations_2.Vertex object at 0x03C42810>, <CGAL.Triangulations_2.Vertex object at 0x03C42848>]
1
[<CGAL.Triangulations_2.Vertex object at 0x03C42880>, <CGAL.Triangulations_2.Vertex object at 0x03C428B8>, <CGAL.Triangulations_2.Vertex object at 0x03C428F0>, <CGAL.Triangulations_2.Vertex object at 0x03C42928>, <CGAL.Triangulations_2.Vertex object at 0x03C42960>, <CGAL.Triangulations_2.Vertex object at 0x03C42998>, <CGAL.Triangulations_2.Vertex object at 0x03C429D0>, <CGAL.Triangulations_2.Vertex object at 0x03C42A08>, <CGAL.Triangulations_2.Vertex object at 0x03C42A40>, <CGAL.Triangulations_2.Vertex object at 0x03C42A78>, <CGAL.Triangulations_2.Vertex object at 0x03C42AB0>, <CGAL.Triangulations_2.Vertex object at 0x03C42AE8>]
2
[<CGAL.Triangulations_2.Vertex object at 0x03C42B20>, <CGAL.Triangulations_2.Vertex object at 0x03C42B58>, <CGAL.Triangulations_2.Vertex object at 0x03C42B90>, <CGAL.Triangulations_2.Vertex object at 0x03C42BC8>, <CGAL.Triangulations_2.Vertex object at 0x03C42C00>, <CGAL.Triangulations_2.Vertex object at 0x03C42C38>, <CGAL.Triangulations_2.Vertex object at 0x03C42C70>, <CGAL.Triangulations_2.Vertex object at 0x03C42CA8>, <CGAL.Triangulations_2.Vertex object at 0x03C42CE0>, <CGAL.Triangulations_2.Vertex object at 0x03C42D18>, <CGAL.Triangulations_2.Vertex object at 0x03C42D50>]
3
[<CGAL.Triangulations_2.Vertex object at 0x03C42D88>, <CGAL.Triangulations_2.Vertex object at 0x03C42DC0>, <CGAL.Triangulations_2.Vertex object at 0x03C42DF8>, <CGAL.Triangulations_2.Vertex object at 0x03C42E30>, <CGAL.Triangulations_2.Vertex object at 0x03C42E68>, <CGAL.Triangulations_2.Vertex object at 0x03C42EA0>, <CGAL.Triangulations_2.Vertex object at 0x03C42ED8>, <CGAL.Triangulations_2.Vertex object at 0x03C42F10>, <CGAL.Triangulations_2.Vertex object at 0x03C42F48>, <CGAL.Triangulations_2.Vertex object at 0x03C42F80>, <CGAL.Triangulations_2.Vertex object at 0x03C42FB8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D030>, <CGAL.Triangulations_2.Vertex object at 0x03C4D068>, <CGAL.Triangulations_2.Vertex object at 0x03C4D0A0>]
4
[<CGAL.Triangulations_2.Vertex object at 0x03C4D0D8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D110>, <CGAL.Triangulations_2.Vertex object at 0x03C4D148>, <CGAL.Triangulations_2.Vertex object at 0x03C4D180>, <CGAL.Triangulations_2.Vertex object at 0x03C4D1B8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D1F0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D228>, <CGAL.Triangulations_2.Vertex object at 0x03C4D260>, <CGAL.Triangulations_2.Vertex object at 0x03C4D298>, <CGAL.Triangulations_2.Vertex object at 0x03C4D2D0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D308>, <CGAL.Triangulations_2.Vertex object at 0x03C4D340>, <CGAL.Triangulations_2.Vertex object at 0x03C4D378>, <CGAL.Triangulations_2.Vertex object at 0x03C4D3B0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D3E8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D420>, <CGAL.Triangulations_2.Vertex object at 0x03C4D458>]
5
[<CGAL.Triangulations_2.Vertex object at 0x03C4D490>, <CGAL.Triangulations_2.Vertex object at 0x03C4D4C8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D500>, <CGAL.Triangulations_2.Vertex object at 0x03C4D538>, <CGAL.Triangulations_2.Vertex object at 0x03C4D570>, <CGAL.Triangulations_2.Vertex object at 0x03C4D5A8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D5E0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D618>, <CGAL.Triangulations_2.Vertex object at 0x03C4D650>]
6
[<CGAL.Triangulations_2.Vertex object at 0x03C4D688>, <CGAL.Triangulations_2.Vertex object at 0x03C4D6C0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D6F8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D730>, <CGAL.Triangulations_2.Vertex object at 0x03C4D768>, <CGAL.Triangulations_2.Vertex object at 0x03C4D7A0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D7D8>]
7
[<CGAL.Triangulations_2.Vertex object at 0x03C4D810>, <CGAL.Triangulations_2.Vertex object at 0x03C4D848>, <CGAL.Triangulations_2.Vertex object at 0x03C4D880>, <CGAL.Triangulations_2.Vertex object at 0x03C4D8B8>, <CGAL.Triangulations_2.Vertex object at 0x03C4D8F0>, <CGAL.Triangulations_2.Vertex object at 0x03C4D928>]
我正在尝试访问每个对象的方法point()
。
但是,我只能在第二个阵列之前完成。从第3起起,我遇到了例外。
In [7]: alphaShapeVertices[0][0].point()
Out[7]: Point_2(1.00000001401,2.90491385964e-290)
In [8]: alphaShapeVertices[1][0].point()
Out[8]: Point_2(3.96551377978e-164,3.05578113171e-151)
In [9]: alphaShapeVertices[2][0].point()
# HERE: python.exe has stopped working
发生异常时屏幕截图:
正如您所看到的,异常可能并非总是发生在第3个数组中。截图中,它发生在7日。我认为它有一些内容分配。
调试器告诉我
python.exe中0x00000002的第一次机会异常:0xC0000005:Access 违规读取位置0x00000002。
如果存在此异常的处理程序,则程序可能是安全的 继续进行。
我已经挣扎了几天。任何人都可以帮助我解决原因和方法吗?
如果您没有,可能需要安装CGAL-Python (bindings for the Computational Geometry Algorithms Library)( CTRL + F CGAL-Python)。
clusters
data can be found here on pastie。
准备好数据和库后,运行以下Python脚本:
from sys import *
path.append("../../cgal_package")
from CGAL.Alpha_shapes_2 import *
from CGAL.Triangulations_2 import Delaunay_triangulation_2
from CGAL.Kernel import *
from random import *
import matplotlib.pyplot as plt
from matplotlib.font_manager import FontProperties
import constants
def Point_2_str(self):
return 'Point_2'+str((self.x(), self.y()))
# now we turn it into a member function
Point_2.__str__ = Point_2_str
def getAlphaShape(cluster):
list_of_points = [Point_2(e[0], e[1]) for e in cluster]
L = []
verbose = True
a = Alpha_shape_2()
a.make_alpha_shape(list_of_points)
a.set_mode(Alpha_shape_2.Mode.REGULARIZED)
a.set_alpha(1000)
alpha_shape_edges = []
alpha_shape_vertices = []
for it in a.alpha_shape_edges:
alpha_shape_edges.append(a.segment(it))
for it in a.alpha_shape_vertices:
alpha_shape_vertices.append(it)
return alpha_shape_vertices
# get alpha-shape of each cluster
alphaShapeVertices = []
for cluster in clusters:
alphaShapeVertices.append(alphashape.getAlphaShape(cluster))
# start testing
print alphaShapeVertices[0][0].point()
print alphaShapeVertices[1][0].point()
print alphaShapeVertices[2][0].point()
print alphaShapeVertices[3][0].point()
# somewhere around here the exception occurs
print alphaShapeVertices[4][0].point()
print alphaShapeVertices[5][0].point()
print alphaShapeVertices[6][0].point()