def LoadData(self, fileName): planar = triPackage.get_data(fileName) vertices = [] segments = [] segmentsMark = [] for vertex in planar['vertices']: vertices.append((vertex[0], vertex[1])) for segment in planar['segments']: segments.append((segment[0], segment[1])) segmentsMark.append(((segment[0], segment[1]), 1)) self.ruper = Ruper.Ruper(vertices, segments, segmentsMark)
def tri(x, y): # plot the plan box = triangle.get_data('box') # # ax1 = plt.subplot(121, aspect='equal') # triangle.plot.plot(ax1, **box) t = triangle.triangulate(box, 'pc') ax2 = plt.subplot(111) # , sharex=ax1, sharey=ax1) plot.plot(ax2, **t) plt.plot(x, y, 'yo-') plt.show()
def foo2(): # From http://dzhelil.info/triangle/delaunay.html # (not my code) import triangle import triangle.plot as plot face = triangle.get_data('face') print face ax1 = mpl.subplot(121, aspect='equal') plot.plot(ax1, **face) t = triangle.triangulate(face, 'p') ax2 = mpl.subplot(122, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **t) mpl.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt box = triangle.get_data('box') ax1 = plt.subplot(121, aspect='equal') triangle.plot.plot(ax1, **box) t = triangle.triangulate(box, 'pc') ax2 = plt.subplot(122, sharex=ax1, sharey=ax1) plot.plot(ax2, **t) plt.show()
import matplotlib.pyplot as plt import triangle as tr plt.figure(figsize=(8, 7)) la = tr.get_data('la') ax1 = plt.subplot(311) tr.plot(ax1, **la) t = tr.triangulate(la, 'pq') ax2 = plt.subplot(312, sharex=ax1, sharey=ax1) tr.plot(ax2, **t) t = tr.triangulate(la, 'pqa') ax2 = plt.subplot(313, sharex=ax1, sharey=ax1) tr.plot(ax2, **t) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt ax = plt.axes() A = triangle.get_data('A') t = triangle.triangulate(A, 'p') plot.plot(ax, **t) plt.show()
import matplotlib.pyplot as plt import triangle import triangle.plot spiral = triangle.get_data("spiral") t = triangle.triangulate(spiral, "a.2") ax1 = plt.subplot(111, aspect="equal") triangle.plot.plot(ax1, **t) plt.show()
import triangle import triangle.plot import matplotlib.pyplot as plt la = triangle.get_data("la") ax1 = plt.subplot(311, aspect="equal") triangle.plot.plot(ax1, **la) t = triangle.triangulate(la, "pq") ax2 = plt.subplot(312, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **t) t = triangle.triangulate(la, "pqa") ax2 = plt.subplot(313, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **t) plt.show()
import matplotlib.pyplot as plt import triangle as tr box = tr.get_data('box') t = tr.triangulate(box, 'pc') tr.compare(plt, box, t) plt.show()
elif os.operation == 'remove': print 'remove' else: print os.operation def Show(self): planar = {'vertices' : np.array(self.vertices), 'segments' : np.array(self.segments.keys())} tri = {'vertices' : np.array(self.vertices), 'triangles' : np.array(self.triangles.keys())} plot(plt.axes(), **planar) plot(plt.axes(), **tri) plt.plot(self.vertices[-1][0], self.vertices[-1][1], 'bo') plt.show() plt.clf() if __name__ == '__main__': planar = triPackage.get_data('happy') vertices = [] segments = [] segmentsMark = [] for vertex in planar['vertices']: vertices.append((vertex[0], vertex[1])) for segment in planar['segments']: segments.append((segment[0], segment[1])) segmentsMark.append(((segment[0], segment[1]), 1)) ruper = Ruper(vertices, segments, segmentsMark) while ruper.stage != 4: os = ruper.NextStep() ruper.Show()
while len(self.queueT) > 0: tri = self.queueT.popleft() if self.IsSkinny(tri): self.InsertCircleCenter(self.vertices[tri[0]], self.vertices[tri[1]], self.vertices[tri[2]]) def Start(self): self.Triangulate() self.Show() self.InitializeSegmentQueue() self.InitializeTriangleQueue() self.EliminateSegment() self.Show() self.RemoveOutside() self.Show() self.InitializeTriangleQueue() self.EliminateAngle() if __name__ == '__main__': planar = triangle.get_data('layers') planar['segments_type'] = {} for segment in planar['segments']: a, b = sorted((segment[0], segment[1])) planar['segments_type'][(a, b)] = 1 ruper = Ruper(planar) now = time.time() ruper.Start() print time.time() - now ruper.Show()
import triangle import triangle.plot import matplotlib.pyplot as plt box1 = triangle.get_data('bbox.1') box2 = triangle.triangulate(box1, 'rpaa.5') triangle.plot.plot(plt.axes(), **box2) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt spiral = triangle.get_data('spiral') ax1 = plt.subplot(121, aspect='equal') plot.plot(ax1, **spiral) t = triangle.triangulate(spiral) ax2 = plt.subplot(122, sharex=ax1, sharey=ax1) plot.plot(ax2, **t) plt.show()
def EliminateAngle(self): while len(self.queueT) > 0: tri = self.queueT.popleft() if self.IsSkinny(tri): self.InsertCircleCenter(self.vertices[tri[0]], self.vertices[tri[1]], self.vertices[tri[2]]) def Start(self): self.Triangulate() self.Show() self.InitializeSegmentQueue() self.InitializeTriangleQueue() self.EliminateSegment() self.Show() self.RemoveOutside() self.Show() self.InitializeTriangleQueue() self.EliminateAngle() if __name__ == '__main__': planar = triangle.get_data('layers') planar['segments_type'] = {} for segment in planar['segments']: a, b = sorted((segment[0], segment[1])) planar['segments_type'][(a, b)] = 1 ruper = Ruper(planar) now = time.time() ruper.Start() print time.time() - now ruper.Show()
import matplotlib.pyplot as plt import triangle as tr def bndry(dict): return {k: dict[k] for k in ('vertices', 'segments')} face = tr.get_data('face.1') A = tr.triangulate(face, 'rc') B = tr.triangulate(face, 'rpc') tr.compare(plt, bndry(A), bndry(B)) plt.show()
import triangle import triangle.plot import matplotlib.pyplot as plt la = triangle.get_data('la') ax1 = plt.subplot(311, aspect='equal') triangle.plot.plot(ax1, **la) t = triangle.triangulate(la, 'pq') ax2 = plt.subplot(312, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **t) t = triangle.triangulate(la, 'pqa') ax2 = plt.subplot(313, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **t) plt.show()
import matplotlib.pyplot as plt import triangle as tr box1 = tr.get_data('bbox.1') box2 = tr.triangulate(box1, 'rpa') tr.plot(plt.axes(), **box2) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt dots = triangle.get_data('dots') pts = dots['vertices'] segs = triangle.convex_hull(pts) plot.plot(plt.axes(), vertices=pts, segments=segs) plt.show()
import matplotlib.pyplot as plt import triangle as tr face = tr.get_data('face') t = tr.triangulate(face, 'p') tr.compare(plt, face, t) plt.show()
import matplotlib.pyplot as plt import triangle as tr spiral = tr.get_data('spiral') t = tr.triangulate(spiral) tr.compare(plt, spiral, t) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt A = triangle.get_data('A') t = triangle.triangulate(A, 'pq0D') plot.plot(plt.axes(), **t) plt.show()
import triangle import triangle.plot import matplotlib.pyplot as plt pts = triangle.get_data('dots')['vertices'] ax1 = plt.subplot(121, aspect='equal') triangle.plot.plot(ax1, vertices=pts) lim = ax1.axis() points, edges, ray_origin, ray_direct = triangle.voronoi(pts) d = dict(vertices=points, edges=edges, ray_origins=ray_origin, ray_directions=ray_direct) ax2 = plt.subplot(122, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **d) ax2.axis(lim) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt spiral = triangle.get_data('spiral') ax1 = plt.subplot(221, aspect='equal') triangle.plot.plot(ax1, vertices=spiral['vertices']) a = triangle.triangulate(spiral) ax2 = plt.subplot(222, sharex=ax1, sharey=ax1) plot.plot(ax2, **a) b = triangle.triangulate(spiral, 'q') ax3 = plt.subplot(223, sharex=ax1, sharey=ax1) plot.plot(ax3, **b) c = triangle.triangulate(spiral, 'q32.5') ax4 = plt.subplot(224, sharex=ax1, sharey=ax1) plot.plot(ax4, **c) plt.show()
def stl(string,fname,coarseness,pos,angle,label_cnt): global printSize import triangle import triangle.plot import matplotlib.pyplot as plt import numpy as np from shapely.geometry import box, LineString #buildBasePolyFile(string,pos,fname,coarseness,angle) print '/Users/bttaylor/Documents/TactileMap/PolyFiles/b_' + fname + '_frame' frames = triangle.get_data('/Users/bttaylor/Documents/TactileMap/PolyFiles/b_' + fname + '_frame'); framesT = triangle.triangulate(frames,'p'); for tri in framesT['triangles']: pt1 = Point(framesT['vertices'][tri[0]][0],framesT['vertices'][tri[0]][1]) pt2 = Point(framesT['vertices'][tri[1]][0],framesT['vertices'][tri[1]][1]) pt3 = Point(framesT['vertices'][tri[2]][0],framesT['vertices'][tri[2]][1]) tri_v1 = [pt1.x,pt1.y,base_height] tri_v2 = [pt2.x,pt2.y,base_height] tri_v3 = [pt3.x,pt3.y,base_height] elevation2stl.printTriangle(tri_v1,tri_v2,tri_v3,fname) for i in range(1,label_cnt + 1): print '/Users/bttaylor/Documents/TactileMap/PolyFiles/b_' + fname + '_' + str(i) nondot = triangle.get_data('/Users/bttaylor/Documents/TactileMap/PolyFiles/b_' + fname + '_' + str(i)); non = triangle.triangulate(nondot,'p'); for tri in non['triangles']: pt1 = Point(non['vertices'][tri[0]][0],non['vertices'][tri[0]][1]) pt2 = Point(non['vertices'][tri[1]][0],non['vertices'][tri[1]][1]) pt3 = Point(non['vertices'][tri[2]][0],non['vertices'][tri[2]][1]) tri_v1 = [pt1.x,pt1.y,base_height] tri_v2 = [pt2.x,pt2.y,base_height] tri_v3 = [pt3.x,pt3.y,base_height] elevation2stl.printTriangle(tri_v1,tri_v2,tri_v3,fname) # nondot = triangle.get_data('/Users/bttaylor/Documents/TactileMap/PolyFiles/b_' + fname); # #print nondot # edges = box(0,0,printSize,printSize); # edge_pts = [] # non = triangle.triangulate(nondot,'p'); # for tri in non['triangles']: # pt1 = Point(non['vertices'][tri[0]][0],non['vertices'][tri[0]][1]) # pt2 = Point(non['vertices'][tri[1]][0],non['vertices'][tri[1]][1]) # pt3 = Point(non['vertices'][tri[2]][0],non['vertices'][tri[2]][1]) # tri_v1 = [pt1.x,pt1.y,base_height] # tri_v2 = [pt2.x,pt2.y,base_height] # tri_v3 = [pt3.x,pt3.y,base_height] # elevation2stl.printTriangle(tri_v1,tri_v2,tri_v3,fname) # for seg in non['segments']: # line = LineString(non['vertices'][seg]) # if line.touches(edges): # XYpt1 = Point(non['vertices'][seg[0]]) # XYpt2 = Point(non['vertices'][seg[1]]) # edge_pts.append(XYpt1.coords[0]); # edge_pts.append(XYpt2.coords[0]); # #print edge_pts # edge_pts.append([0,0]) # edge_pts.append([0,printSize]) # edge_pts.append([printSize,0]) # edge_pts.append([printSize,printSize]) # edge_pt_array = np.array(edge_pts) # base = dict(vertices=edge_pt_array); # baseT = triangle.triangulate(base); # #triangle.plot.compare(plt,base,baseT); # for tri in baseT['triangles']: # pt1 = Point(baseT['vertices'][tri[0]][0],baseT['vertices'][tri[0]][1]) # pt2 = Point(baseT['vertices'][tri[1]][0],baseT['vertices'][tri[1]][1]) # pt3 = Point(baseT['vertices'][tri[2]][0],baseT['vertices'][tri[2]][1]) # tri_v1 = [pt1.x,pt1.y,floor] # tri_v2 = [pt2.x,pt2.y,floor] # tri_v3 = [pt3.x,pt3.y,floor] # elevation2stl.printTriangle(tri_v1,tri_v2,tri_v3,fname) #print edges pt1 = [0, 0, floor] pt2 = [0, 0, base_height] pt3 = [0, printSize, floor] pt4 = [0, printSize, base_height] elevation2stl.printTriangle(pt1,pt2,pt4,fname) elevation2stl.printTriangle(pt1,pt3,pt4,fname) pt3 = [printSize, 0, floor] pt4 = [printSize, 0, base_height] elevation2stl.printTriangle(pt1,pt2,pt4,fname) elevation2stl.printTriangle(pt1,pt3,pt4,fname) pt1 = [printSize, printSize, floor] pt2 = [printSize, printSize, base_height] elevation2stl.printTriangle(pt1,pt2,pt4,fname) elevation2stl.printTriangle(pt1,pt3,pt4,fname) pt3 = [0, printSize, floor] pt4 = [0, printSize, base_height] elevation2stl.printTriangle(pt1,pt2,pt4,fname) elevation2stl.printTriangle(pt1,pt3,pt4,fname) #print bottom pt1 = [0, 0, floor] pt2 = [0, printSize, floor] pt3 = [printSize, printSize, floor] pt4 = [printSize, 0, floor] elevation2stl.printTriangle(pt1,pt3,pt2,fname) elevation2stl.printTriangle(pt1,pt4,pt3,fname)
if rmBool == True: rmKeys.append(tuple(sorted((tri[0], tri[1], tri[2])))) for rm in rmKeys: self.delaunay_triangles.pop(rm) def Start(self): self.Triangulate() self.EliminateSegment() self.RemoveOutside() self.Show() # self.RemoveOutside() # self.delaunay = self.Triangulate(rem = True) # self.EliminateAngle() if __name__ == '__main__': planar = triangle.get_data('A') planar['segments_type'] = {} for segment in planar['segments']: a, b = sorted((segment[0], segment[1])) planar['segments_type'][(a, b)] = 1 ruper = Ruper(planar) # now = time.time() ruper.Start() # print time.time() - now # ruper.Show()
import triangle import triangle.plot import matplotlib.pyplot as plt pts = triangle.get_data('diamond_02_00009')['vertices'] ax1 = plt.subplot(121, aspect='equal') triangle.plot.plot(ax1, vertices=pts) lim = ax1.axis() d = triangle.get_data('diamond_02_00009.1.v') ax2 = plt.subplot(122, sharex=ax1, sharey=ax1) triangle.plot.plot(ax2, **d) ax2.axis(lim) plt.show()
import matplotlib.pyplot as plt import triangle as tr d0 = tr.get_data('dots') d1 = tr.triangulate(d0) tr.compare(plt, d0, d1) plt.show()
import triangle from triangle.plot import plot import matplotlib.pyplot as plt A = triangle.get_data("A") ax = plt.axes() plot(ax, **A) plt.show()
import matplotlib.pyplot as plt import triangle as tr pts = tr.get_data('dots')['vertices'] A = dict(vertices=pts) points, edges, ray_origin, ray_direct = tr.voronoi(pts) B = dict(vertices=points, edges=edges, ray_origins=ray_origin, ray_directions=ray_direct) tr.compare(plt, A, B) plt.show()
import matplotlib.pyplot as plt import triangle as tr face = tr.get_data('corridor') t = tr.triangulate(face, 'p') tr.compare(plt, face, t) plt.show()
import matplotlib.pyplot as plt import triangle as tr box = tr.get_data('double_hex3') print(box) t = tr.triangulate(box, 'p') v = t['vertices'].tolist() # print(box) tList = t['triangles'].tolist() tCoords = [] ## coordinates of the triangles: [[[0,0], [0,1], [1,0]], [...]] for tL in tList: tCoords.append([v[tL[0]], v[tL[1]], v[tL[2]]]) print(tCoords) tr.compare(plt, box, t) plt.show()
import triangle import triangle.plot as plot import matplotlib.pyplot as plt face = triangle.get_data('face') ax1 = plt.subplot(121, aspect='equal') plot.plot(ax1, **face) t = triangle.triangulate(face, 'pq10') ax2 = plt.subplot(122, sharex=ax1, sharey=ax1) plot.plot(ax2, **t) plt.show()
import matplotlib.pyplot as plt import triangle as tr A = tr.get_data('A') t = tr.triangulate(A, 'pq30') tr.plot(plt.axes(), **t) plt.show()
rm = [0] * len(delaunay['triangles']) for ind, triangle in enumerate(delaunay['triangles']): a, b, c = self.vertices[triangle[0]], self.vertices[ triangle[1]], self.vertices[triangle[2]] u = (a + b + c) / 3.0 for delta in [-1e-9, 0, 1e-9]: v = np.array([1e5, u[1] + delta]) count = self.CrossCount(u, v) if count != None and count % 2 == 0: rm[ind] = 1 ind = map(lambda x: x[0], filter(lambda x: x[1] == 0, list(enumerate(rm)))) delaunay['triangles'] = delaunay['triangles'][ind] return delaunay def Start(self): self.delaunay = self.Triangulate() self.EliminateSegment() self.delaunay = self.Triangulate(rem=True) self.EliminateAngle() if __name__ == '__main__': planar = triangle.get_data('A') planar['segments_type'] = {} for segment in planar['segments']: planar['segments_type'][(segment[0], segment[1])] = 1 ruper = Ruper(planar) ruper.Start() ruper.Show()