1
CGAL을 사용하여 알파 모양을 얻고 싶습니다.CGAL 알파 모양의 파이썬 간단한 예제가 잘못 되었나요?
@sloriot는 an extremely relevant script 제공하고, 내 사용자 지정 후 : 나는 그것을 실행되면
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 show_alpha_values(AS):
print "Alpha spectrum"
for alpha_value in AS.alpha:
print alpha_value
def read_points(file):
result = []
dataFile = open(file, 'r')
for i, line in enumerate(dataFile):
coordinateList = [float(x) for x in line.strip().split()]
for j in range(0, len(coordinateList), 2):
result.append(Point_2(coordinateList[j], coordinateList[j+1]))
dataFile.close()
return result
def getAlphaShape():
L =[]
verbose = True
list_of_points = read_points(constants.PROJECT_PATH + '\\data\\clusters.txt')
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)
_showAlphaShape(list_of_points, alpha_shape_vertices)
print "alpha_shape_edges"
print len(alpha_shape_edges)
print "alpha_shape_vertices"
print len(alpha_shape_vertices)
print "Optimal alpha: "
print a.find_optimal_alpha(2).next()
def _showAlphaShape(points, vertices):
fig = plt.figure()
axes = fig.add_axes([0.1, 0.1, 0.8, 0.8]) # left, bottom, width, height (range 0 to 1)
axes.axis('equal')
axes.set_xlabel(r'$x (m)$')
axes.set_ylabel(r'$y (m)$')
axes.set_title(r'$\alpha$-shape of clusters')
# draw cluster points
x = [pt.x() for pt in points]
y = [pt.y() for pt in points]
axes.scatter(x, y, s=1)
# draw alpha shape
for i in range(len(vertices)-1):
x1 = vertices[i].point()[0]
x2 = vertices[i+1].point()[0]
y1 = vertices[i].point()[1]
y2 = vertices[i+1].point()[1]
axes.plot([[x1, x2], [y1, y2]], color='b')
fontP = FontProperties()
fontP.set_size('7')
axes.legend(loc=3, prop=fontP)
fig.savefig(constants.PROJECT_PATH + '\\data\\1.svg')
, 나는
이파란색 부분은 분명히 하지 알파 모양입니다 얻을 . 어디서 잘못 되었나요?
어떤 문서 페이지를 읽으십니까? C++ 예제를 파이썬으로 변환해야합니다. [Here] (http://doc.cgal.org/latest/Alpha_shapes_2/index.html#title4)는 하나입니다. 참고로, cgal-python의 웹 사이트에서 작성한 바와 같이이 패키지는 더 이상 유지 관리되지 않으며 [cgal-bindings] (http://code.google.com/p/cgal-bindings/)가 권장됩니다. – sloriot
@sloriot 여기에도 같은 질문이 있습니다. 나는 일련의 점들에 대해 알파 모양 만 있으면됩니다. 따라서 많은 요구 사항은 없습니다. 단지 cgal-python 패키지로 충분합니다. 제 목적에 대한 실천 사례를 친절하게 보여 주실 수 있습니까? 임의의 점 집합의 알파 모양만으로. 고마워요! 문서화가 정말 초라하기 때문에 다른 사람들에게도 도움이 될 것입니다. –
Look [여기] (https://gforge.inria.fr/scm/viewvc.php/trunk/cgal-python/test/Alpha_shapes_2/test_alpha_shape_2.py?view=markup&root=cgal-python) – sloriot