Skip to content

Commit

Permalink
simplified API
Browse files Browse the repository at this point in the history
  • Loading branch information
greenm01 committed Jan 31, 2010
1 parent 8888a21 commit 60de0b9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 19 deletions.
5 changes: 3 additions & 2 deletions poly2tri/sweep/cdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class CDT

/// Constructor
CDT(std::vector<Point*> polyline);
/// Destructor
~CDT();

/// Add a hole
void AddHole(std::vector<Point*> polyline);
/// Triangulate points
Expand All @@ -54,8 +57,6 @@ std::list<Triangle*> GetMap();
SweepContext* sweep_context_;
Sweep* sweep_;

/// Destructor
~CDT();
};

}
23 changes: 10 additions & 13 deletions src/cdt.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,22 @@ cdef class CDT:
self.me = new_CDT(self.polyline)

def triangulate(self):
cdef Point a,b,c
self.me.Triangulate()
cdef triangle_vec tri_list = self.me.GetTriangles()
cdef list tris = []
for i in range(tri_list.size()):
a = Point(tri_list.get(i).GetPoint(0).x, tri_list.get(i).GetPoint(0).y)
b = Point(tri_list.get(i).GetPoint(1).x, tri_list.get(i).GetPoint(1).y)
c = Point(tri_list.get(i).GetPoint(2).x, tri_list.get(i).GetPoint(2).y)
tris.append(Triangle(a, b, c))
return tris

def add_hole(self, polyline):
cdef point_vec hole = pointvec_factory(0)
for point in polyline:
hole.push_back(new_Point(point.x, point.y))
self.me.AddHole(hole)

property triangles:
def __get__(self):
cdef triangle_vec tri_list = self.me.GetTriangles()
tris = []
for i in range(tri_list.size()):
a = Point(tri_list.get(i).GetPoint(0).x, tri_list.get(i).GetPoint(0).y)
b = Point(tri_list.get(i).GetPoint(1).x, tri_list.get(i).GetPoint(1).y)
c = Point(tri_list.get(i).GetPoint(2).x, tri_list.get(i).GetPoint(2).y)
tris.append(Triangle(a, b, c))
return tris

def __dealloc__(self):
pass
#del_CDT(self.me)
del_CDT(self.me)
8 changes: 4 additions & 4 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
head_hole = [[325, 437],[320, 423], [329, 413], [332, 423]]
chest_hole = [[320.72342,480],[338.90617,465.96863],[347.99754,480.61584],
[329.8148,510.41534], [339.91632,480.11077],[334.86556,478.09046]]

def load_points(file_name):
infile = open(file_name, "r")
points = []
Expand Down Expand Up @@ -47,8 +47,9 @@ def main(file_name, translate, zoom):
p[1] = p[1]*zoom + translate[1]
polyline.append(Point(p[0],p[1]))

# initialize clock
t0 = clock()

##
## Step 1: Initialize
##
Expand All @@ -74,10 +75,9 @@ def main(file_name, translate, zoom):
##
## Step 3: Triangulate
##
cdt.triangulate()
triangles = cdt.triangulate()

print "Elapsed time (ms) = " + str(clock()*1000.0)
triangles = cdt.triangles

# The Main Event Loop
done = False
Expand Down

0 comments on commit 60de0b9

Please sign in to comment.