def Query(self, q_point): """Return triangle coordinates (3-tuple of 2-tuples) for bottom layer triangle containing q_point. If __debug__, also displays query progress layer by layer. """ green_spotter_box = [(q_point[0] - 1, q_point[1] - 1), (q_point[0] - 1, q_point[1] + 1), (q_point[0] + 1, q_point[1] + 1), (q_point[0] + 1, q_point[1] - 1)] search_faces = self.links_.iterkeys() cur_layer = self while cur_layer is not None: # O(lg n) layers for tri in search_faces: # O(1) search_faces at each layer if (tri is not None) and (DCEL.Contains( q_point, tri)): # O(1) per Contains() check # if __debug__: # print "At height {}, within face {}.".format(cur_layer.Depth(), tri) if not BENCHMARKING: cur_layer.Display( red_polys=[tri], blue_polys=[ x for x in search_faces if x is not None ], green_polys=[green_spotter_box], caption="{} within face {}".format(q_point, tri)) if cur_layer.getNext() is not None: search_faces = cur_layer.getLink(tri) cur_layer = cur_layer.getNext() break # for loop else: # Did not break for loop, i.e. return None # q_point not within the bounding box return tri
def __init__(self, G, pos=None): assert nx.number_of_selfloops(G) == 0 assert nx.is_connected(G) if pos is None: is_planar, self.embedding = nx.check_planarity(G) assert is_planar pos = nx.combinatorial_embedding_to_pos(self.embedding) else: assert number_of_cross(G, pos) == 0 self.embedding = convert_pos_to_embdeding(G, pos) self.G = G.copy() self.pos = pos # is only used to find the ext_face now. self.dcel = DCEL.Dcel(G, self.embedding) self.ext_face = self.get_external_face()
from DCEL import * dcel = DCEL() # Create the six vertices A--F: A = dcel.newVertex(Vector(0, 0, 0)) B = dcel.newVertex(Vector(100, 0, 0)) C = dcel.newVertex(Vector(100, 100, 0)) D = dcel.newVertex(Vector(0, 100, 0)) # Create a face for the inner face; Note: the outer face is dcel.outerFace f = dcel.newFace() # Create the six half-edges for inner face AB = dcel.newHalfEdge(A, f) BC = dcel.newHalfEdge(B, f) CD = dcel.newHalfEdge(C, f) DA = dcel.newHalfEdge(D, f) # Make sure you set an incident half edge for f: f.incidentEdge = AB # Set up the next/prev pointers correctly for the face: AB.next = BC BC.prev = AB BC.next = CD CD.prev = BC CD.next = DA DA.prev = CD DA.next = AB AB.prev = DA
assert len( first_tri.coplanar) == 0 # Ensure qhull didnt omit any points # Back to our point-tuple structure print "shape: {}".format(first_tri.simplices.shape) tri_points = [[(pt[0], pt[1]) for pt in tri] for tri in points[first_tri.simplices]] if __debug__: # Ensure qhull didnt mutate any points tri_points_check = set() for tri in tri_points: tri_points_check.update(tri) assert input_pts == tri_points_check labeled_tris = [(LabelTriangle(tri), tri) for tri in tri_points] start_time = time.time() ds_start = time.time() first_layer = KP_Layer(None, DCEL.Triangled_DCEL(labeled_tris, BBOX)) top_layer = first_layer.ProduceHierarchy() print "DS took {} seconds.".format(time.time() - ds_start) queries_start = time.time() for i in range(QUERIES): query_start = time.time() q_point = (random.randint(1, BOXSIZE - 1), random.randint(1, BOXSIZE - 1)) print "Query {}: {} contained within: ".format( i, q_point), top_layer.Query(q_point) print "Query {} took {} seconds.".format(i, time.time() - query_start) print "All {} queries took {} seconds.".format(QUERIES, time.time() - queries_start)
# single loaded starter kit from DCEL import * dcel = DCEL() # Create the six vertices A--F: A = dcel.newVertex(Vector(0, 0, 0)) B = dcel.newVertex(Vector(100, 0, 0)) C = dcel.newVertex(Vector(100, 100, 0)) D = dcel.newVertex(Vector(0, 100, 0)) # Create a face for the inner face; Note: the outer face is dcel.outerFace f = dcel.newFace() # Create the six half-edges for inner face AB = dcel.newHalfEdge(A, f) BC = dcel.newHalfEdge(B, f) CD = dcel.newHalfEdge(C, f) DA = dcel.newHalfEdge(D, f) # Make sure you set an incident half edge for f: f.incidentEdge = AB # Set up the next/prev pointers correctly for the face: AB.next = BC BC.prev = AB BC.next = CD CD.prev = BC CD.next = DA DA.prev = CD DA.next = AB
from DCEL import * dcel = DCEL() # Create the six vertices A--F: A = dcel.newVertex(Vector(0, 0, 0)) B = dcel.newVertex(Vector(100, 0, 0)) C = dcel.newVertex(Vector(100, 100, 0)); D = dcel.newVertex(Vector(0, 100, 0)); # Create a face for the inner face; Note: the outer face is dcel.outerFace f = dcel.newFace() # Create the six half-edges for inner face AB = dcel.newHalfEdge(A, f); BC = dcel.newHalfEdge(B, f); CD = dcel.newHalfEdge(C, f); DA = dcel.newHalfEdge(D, f); # Make sure you set an incident half edge for f: f.incidentEdge = AB; # Set up the next/prev pointers correctly for the face: AB.next = BC BC.prev = AB BC.next = CD CD.prev = BC CD.next = DA DA.prev = CD DA.next = AB AB.prev = DA
from DCEL import * # from generation import FaceReq dcel = DCEL() # Create the six vertices A--F: A = dcel.newVertex(Vector(0, 0, 0)) B = dcel.newVertex(Vector(100, 0, 0)) C = dcel.newVertex(Vector(100, 100, 0)) D = dcel.newVertex(Vector(0, 100, 0)) # Create a face for the inner face; Note: the outer face is dcel.outerFace f = dcel.newFace() # Create the six half-edges for inner face AB = dcel.newHalfEdge(A, f) BC = dcel.newHalfEdge(B, f) CD = dcel.newHalfEdge(C, f) DA = dcel.newHalfEdge(D, f) # Make sure you set an incident half edge for f: f.incidentEdge = AB # Set up the next/prev pointers correctly for the face: AB.next = BC BC.prev = AB BC.next = CD CD.prev = BC CD.next = DA DA.prev = CD DA.next = AB AB.prev = DA
nums = nums + [float(s) for s in re.findall(r'-?\d+\.?\d*', line) ] #use regular expression #print(nums,len(nums)) sitesfile.close() num_sites = int(len(nums) / 2) sites = np.zeros((num_sites, 2)) #be careful! Don't forget the () for i in range(0, num_sites): sites[i] = nums[i * 2:i * 2 + 2] print("sites coordinates:") print(sites) #initiailize Q Q = queue_swx.queue_v(sites) #Q.printall() T = status_swx.statustree() D = DCEL.DCEL() print("Voronoi diagram computation process: ") n = 1 #create len(sites) faces to DCEL and store it to DCEL Facelist = [] for i in range(0, num_sites): Fnode = D.addFace(i + 1) Facelist.append(Fnode) D.Flist = Facelist Fzero = D.addFace(0) # print(D.Flist) allVorVer = np.zeros([100, 2]) numver = 0 plt.ion() #Turn interactive mode on.
nums = nums + [float(s) for s in re.findall(r'-?\d+\.?\d*', line) ] #use regular expression #print(nums,len(nums)) sitesfile.close() num_sites = int(len(nums) / 2) sites = np.zeros((num_sites, 2)) #be careful! Don't forget the () for i in range(0, num_sites): sites[i] = nums[i * 2:i * 2 + 2] print("sites coordinates:") print(sites) #initiailize Q Q = queue_swx.queue_v(sites) #Q.printall() T = status_swx.statustree() D = DCEL.DCEL() print("Voronoi diagram computation process: ") #create len(sites) faces to DCEL and store it to DCEL Facelist = [] for i in range(0, num_sites): Fnode = D.addFace(i + 1) Facelist.append(Fnode) D.Flist = Facelist Fzero = D.addFace(0) # print(D.Flist) ################test # site1=np.array([1., 1.]) # site2=np.array([3.666, 5.444]) # site3=np.array([14. , 4.5]) # handle_event.checktriple_test(site1,site2,site3)