def smart_add_vertex(self, path): v = Vertex() v.name = path v.x = choice(range(self.width)) v.y = choice(range(self.height)) if not v in self.V: self.V.append(v)
def smart_add_edge(self, v1_name, v2_name): for name in (v1_name, v2_name): v = Vertex() v.name = name v.x = choice(range(self.width)) v.y = choice(range(self.height)) v_seen = False for vertex in self.V: if v == vertex: v_seen = True if not v_seen: self.V.append(v) v1 = v1_name for vert in self.V: if v1 == vert.name: v1 = vert break v2 = v2_name for vert2 in self.V: if v2 == vert2.name: v2 = vert2 break e = self.edges_class(v1, v2) edge_seen = False for edge in self.E: if edge == e: edge_seen = True if not edge_seen: self.E.append(e)
def add_vertex(self): #reset dampening self.dampen = self.original_dampen v = Vertex() v.x = choice(range(self.width)) v.y = choice(range(self.height)) self.V.append(v)
def __getCenterPoint(self, slice): ''' Get center point like center of mass for input collection slice (usually it should be 4 point) ''' x=y=z=0 for p in range(4): x += self.vertices[slice[p].point].x y += self.vertices[slice[p].point].y z += self.vertices[slice[p].point].z if not self.checked_points.__contains__(slice[p].point): self.checked_points.append(slice[p].point) center_point = Vertex(x/4,y/4,z/4) center_point.diametr = 2 * center_point.len_between_point(self.vertices[slice[0].point]) slice.printSlice() return center_point
def test_vertex(): v1 = Vertex() print v1.term_weight_tf v1.term_weight_tf = 3 v1.term_weight_tf = 6 print v1._termWeightOldTF print v1.term_weight_tf print v1.term_weight_rw v1.term_weight_rw = 10 v1.term_weight_rw = 12 print v1.term_weight_rw print v1._termWeightOldRW print v1.term_value v1.term_value = 'some term' print v1.term_value
def newGraph(self, numVertices): #First, tear down the old graph self.currentVertex = -1 self.currentEdge = 0 for e in range(0, len(self.listOfEdges)): self.remove_widget(self.listOfEdges[e]) for v in range(0, len(self.listOfVertices)): self.remove_widget(self.listOfVertices[v]) self.listOfEdges = [] self.listOfVertices = [] #Now initialize the new graph for x in range(0, numVertices): vertex = Vertex() vertex.setID(x) vertex.pos = self.pos vertex.setID(x) self.listOfVertices.append(vertex) self.add_widget(vertex)
from Edge import Edge; from Vertex import Vertex; from Algorithm import Algorithm; vertex1 = Vertex("a"); vertex2 = Vertex("b"); vertex3 = Vertex("c"); vertex4 = Vertex("d"); vertex5 = Vertex("e"); vertex6 = Vertex("f"); edge1 = Edge(2,vertex1,vertex2); edge2 = Edge(4,vertex1,vertex4); edge3 = Edge(4,vertex2,vertex3); edge4 = Edge(4,vertex2,vertex4); edge5 = Edge(3,vertex2,vertex5); edge6 = Edge(1,vertex2,vertex6); edge7 = Edge(5,vertex3,vertex6); edge8 = Edge(2,vertex4,vertex5); edge9 = Edge(5,vertex5,vertex6); vertexList = []; vertexList.append(vertex1); vertexList.append(vertex2); vertexList.append(vertex3); vertexList.append(vertex4); vertexList.append(vertex5); vertexList.append(vertex6); edgeList = []; edgeList.append(edge1);
def addVertex(self, name): self.numVertices += 1 # 新顶点对象 newVertex = Vertex(name) self.vertList[name] = newVertex return newVertex
def newVertex(self, point, _edge): self.numOfVertex += 1 self.vertexes.append(Vertex(self.vertexes, self.faces, self.hedges, point, _edge)) self.vertexes[-1].index = self.numOfVertex - 1 return len(self.vertexes) - 1
def build_test_graph(): """ A --> B <-> ^ | | D <-> C -> E """ v1 = Vertex("A") v2 = Vertex("B") v3 = Vertex("C") v4 = Vertex("D") v5 = Vertex("E") v1.add_neighbor(v2) v2.add_neighbors([v3,v5]) v3.add_neighbors([v2,v4,v5]) v4.add_neighbors([v1,v3]) v5.add_neighbors([v2]) return Graph({"A":v1,"B":v2,"C":v3,"D":v4,"E":v5})
def set_vertex(self, val): tmpV = Vertex(self.L, self.b, val) index = int(tmpV.val_to_index()) #print("Index:", index) self.vertice[index] = Vertex(self.L, self.b, val)
def ComputeMidVector (self, a, b, center, r): temp = vt.sum(vt.diff(a, center), vt.diff(b, center)) temp = vt.normalize(temp) temp = vt.scale(temp, r) temp = vt.sum(center, temp) return temp
def create_graph_for_queens(size): domain = np.arange(size) return [Vertex(x, [vertex_no for vertex_no in domain if vertex_no != x], Variable(domain)) for x in domain]
from Vertex import Vertex from Edge import Edge from Algorithm import Algorithm # create the vertices vertexA = Vertex("A") vertexB = Vertex("B") vertexC = Vertex("C") vertexD = Vertex("D") vertexE = Vertex("E") vertexF = Vertex("F") vertexG = Vertex("G") vertexH = Vertex("H") # create the edges edge1 = Edge(5, vertexA, vertexB) edge2 = Edge(8, vertexA, vertexH) edge3 = Edge(9, vertexA, vertexE) edge4 = Edge(15, vertexB, vertexD) edge5 = Edge(4, vertexB, vertexH) edge6 = Edge(12, vertexB, vertexC) edge7 = Edge(6, vertexH, vertexF) edge8 = Edge(7, vertexH, vertexC) edge9 = Edge(5, vertexE, vertexH) edge10 = Edge(4, vertexE, vertexF) edge11 = Edge(20, vertexE, vertexG) edge12 = Edge(9, vertexD, vertexG) edge13 = Edge(3, vertexC, vertexD) edge14 = Edge(11, vertexC, vertexG) edge15 = Edge(1, vertexF, vertexC) edge16 = Edge(13, vertexF, vertexG)
def createVertex(self, index): return self.addVertex(Vertex(self), index)
def add_vertex(self, label): if label not in self.vertex_set.keys(): v = Vertex(label) self.vertex_set[label] = v else: return f'{label} already exists in this graph.'
def addVertex(self, key, weight): self.numVertices = self.numVertices + 1 newVertex = Vertex(key, weight) self.vertList[key] = newVertex return newVertex
def add_edge(self, startV, symbol, addValues): tmpV = Vertex(self.L, self.b, startV.val) tmpV.add(tmpV.multiply(addValues, symbol)) newE = Edge(self.L, startV, symbol, tmpV) self.edgelist.append(newE)
with open('variables.yaml') as f: variables = yaml.load(f) # Create directory to save files saveDir = '/'+'/'.join(os.getcwd().split('/')[1:-1])+'/'+datetime.datetime.now().strftime("%m_%d_%y_%H_%M_%S")+'_'+\ variables['obstacleType']+'_obstacle_alpha_'+str(variables['alpha'])+'/' try: os.makedirs(saveDir) except OSError as e: if e.errno != errno.EEXIST: raise # call('rm '+saveDir+'*',shell=True) variables['saveDir'] = saveDir plotStore = plotStore(Vertex(*variables['vInit']), Vertex(*variables['vGoal']), saveDir) for i in range(10): if variables['runType'] == 'rrt': if variables['useRRTStar']: rrt = RRTStar(variables, plotStore) else: rrt = RRT(variables, plotStore) rrt.extractPath() # dill.dump(rrt,open(saveDir+'RRT_'+str(i)+'.p','wb')) if variables['runType'] == 'rrtloop': if variables['useRRTStar']: for o in variables['obstacleTypes']: for a in variables['alphas']:
def create_vertex(self, data): v = Vertex(data) self.add_vertex(v) return v
def add_edge(self, from_vertex_id, to_vertex_id, edge_type, edge_id): """ Adds an edge to the DNA graph, ensuring internal consistency. The parameters are decided by Addedgemutaion in Mutation.py """ # ‘EdgeProto‘ defines defaults for other attributes. old_edge = 0 for old_edge_id in self.vertex[from_vertex_id].edge_out: if self.edge[old_edge_id].type != 'skip_connection': old_edge = old_edge_id if edge_type == 'conv': """ Insert convolution layer in two step: 1. Insert a new vertex between from_vertex and the identity or convolution edge. 2. Insert a convolution edge between from_vertex and new vertex 3. add the new vertex and new edge to dna graph """ # 1.add a new vertex first new_vertex_proto = Vertex_Protocol() new_vertex_proto.type = random.choice(['relu_bn', 'linear']) new_vertex = Vertex(new_vertex_proto) # 2.add conv edge new_edge_proto = Edge_Protocol() new_edge_proto.type = 'conv' new_edge = Edge(new_edge_proto) new_edge.type = edge_type new_edge.ID = edge_id # config input and output for new_edge and new_vertex new_edge.from_vertex = from_vertex_id new_edge.to_vertex = new_vertex.ID new_vertex.input_mutable = True new_vertex.output_mutable = True new_vertex.edge_in.add(new_edge.ID) new_vertex.edge_out.add(old_edge) self.edge[old_edge].from_vertex = new_vertex.ID self.vertex[new_vertex.ID] = new_vertex self.edge[new_edge.ID] = new_edge elif edge_type == 'identity': """ Insert convolution layer in two step: 1. Insert a new vertex between from_vertex and the identity or convolution edge. 2. Insert an identity edge between from_vertex and new vertex 3. add the new vertex and new edge to dna graph """ # 1.add a new vertex first new_vertex_proto = Vertex_Protocol() new_vertex_proto.type = 'linear' new_vertex = Vertex(new_vertex_proto) # 2.add identity edge new_edge = Edge(Edge_Protocol()) new_edge.type = edge_type new_edge.ID = edge_id new_vertex.input_mutable = True new_vertex.output_mutable = True new_vertex.edge_in.add(new_edge.ID) new_vertex.edge_out.add(old_edge) self.edge[old_edge].from_vertex = new_vertex.ID self.vertex[new_vertex.ID] = new_vertex self.edge[new_edge.ID] = new_edge elif edge_type == 'skip_connection': """ Add a skip connection between from_vertex and to_vertex """ self.vertex[from_vertex_id].edge_out.add(edge_id) self.vertex[to_vertex_id].edge_in.add(edge_id) edge_proto = Protocol_Buffer.Edge_Protocol() edge_proto.type = edge_type edge_proto.ID = edge_id edge_proto.from_vertex = from_vertex_id edge_proto.to_vertex = to_vertex_id self.edge[edge_id] = Edge(edge_proto)
def add_vertex(self, key): if key not in self.vertlist: self.num_vertices += 1 new_vertex = Vertex(key) self.vertlist[key] = new_vertex
def decrease_priority(self, vertex, priority): "Decrease the vertex's priority to the new 'priority' value" for i in range(len(self)): if self[i].num == vertex: self[i] = Vertex(vertex, priority)
def check(suggested_vertex, neighbour, newfront): """ Performs the following checks on a suggestes vertex and the suggested connection between this vertex and his last neighbour: 1) Is the vertex out of bounds If yes, dont add this Vertex 2) Is the vertex too close to an existing vertex If yes, change the vector that is checked in 4 and 5 from [neighbor-suggested_vertex] to [neighbor-closest_existing_point] 3) Does the the vector intersect an existing connection (road) If yes, only create the connection up until that intersection. Add that intersection to the Global_lists and fix the neighbor attribute of the existing connection that was "intersected". 4) Does the vector stop shortly before an existing connection If yes, extend the connection up until that intersection. Add that intersection to the Global_lists and fix the neighbor attribute of the existing connection that was "intersected". If none of the above, simply add this vertex to the global_lists and the new front and return the newfront. This is the only place aftert config, where Vertices get added to the Global Lists. Every Time A vertex is added, the cKDTree used to find the closest vertices has to be updated. Parameters ---------- suggested_vertex : Vertex object neighbour : Vertex object newfront : list<Vertex> Returns ------- newfront : list<Vertex> """ #Checks if Neighborbar is in Bounds if (abs(suggested_vertex.coords[0]) > singleton.border[0] - singleton.maxLength) or ( abs(suggested_vertex.coords[1]) > singleton.border[1] - singleton.maxLength): return newfront #Finds all nearby Vertex and their distances distances, nearvertex = singleton.global_lists.tree.query( suggested_vertex.coords, 10, distance_upper_bound=singleton.maxLength) l = len(singleton.global_lists.vertex_list) nearvertex = [ singleton.global_lists.vertex_list[x] for x in nearvertex if x < l ] #Distances[0] is the distance to the nearest Vertex, nearve: if distances[0] < singleton.min_distance: #If the nearest Vertex is not a neighbor if nearvertex[0] not in neighbour.neighbours: #Find the best solution - as in the closest intersection bestsol = np.inf solvertex = None for k in nearvertex: for n in k.neighbours: if n in nearvertex: #and not in doneliste sol = get_intersection( neighbour.coords, nearvertex[0].coords - neighbour.coords, k.coords, n.coords - k.coords) if sol[0] > 0.00001 and sol[0] < 0.99999 and sol[ 1] > 0.00001 and sol[1] < 0.99999 and sol[ 0] < bestsol: bestsol = sol[0] solvertex = [n, k] # If there is at least one solution, intersect that solution # See docstring #3 and #4 if solvertex is not None: solvertex[1].neighbours.remove(solvertex[0]) solvertex[0].neighbours.remove(solvertex[1]) newk = Vertex(neighbour.coords + bestsol * (nearvertex[0].coords - neighbour.coords)) singleton.global_lists.vertex_list.append(newk) singleton.global_lists.coordsliste.append(newk.coords) singleton.global_lists.tree = cKDTree( singleton.global_lists.coordsliste, leafsize=160) neighbour.connection(newk) solvertex[1].connection(newk) solvertex[0].connection(newk) return newfront else: #If there is no solution, the Vertex is clear #See docstring finish nearvertex[0].connection(neighbour) return newfront bestsol = np.inf solvertex = None #If there is not an existing vertex too close, do the same thing but with # The vector between the suggested vertex and its neighbro for k in nearvertex: for n in k.neighbours: if n in nearvertex: #and not in doneliste sol = get_intersection( neighbour.coords, suggested_vertex.coords - neighbour.coords, k.coords, n.coords - k.coords) if sol[0] > 0.00001 and sol[0] < 1.499999 and sol[ 1] > 0.00001 and sol[1] < 0.99999 and sol[0] < bestsol: bestsol = sol[0] solvertex = [n, k] if solvertex is not None: solvertex[1].neighbours.remove(solvertex[0]) solvertex[0].neighbours.remove(solvertex[1]) newk = Vertex(neighbour.coords + bestsol * (suggested_vertex.coords - neighbour.coords)) singleton.global_lists.vertex_list.append(newk) singleton.global_lists.coordsliste.append(newk.coords) singleton.global_lists.tree = cKDTree( singleton.global_lists.coordsliste, leafsize=160) neighbour.connection(newk) solvertex[1].connection(newk) solvertex[0].connection(newk) return newfront #If the Vertex is clear to go, add him and return newfront. suggested_vertex.connection(neighbour) newfront.append(suggested_vertex) singleton.global_lists.vertex_list.append(suggested_vertex) singleton.global_lists.coordsliste.append(suggested_vertex.coords) singleton.global_lists.tree = cKDTree(singleton.global_lists.coordsliste, leafsize=160) return newfront
def add_with_priority(self, vertex, priority): "Add a vertex (or node) with its priority in the queue" self.append(Vertex(vertex, priority))
def add_vertex(self, key): vertex = Vertex(key) self.vertices[vertex.key] = vertex self.num_vertices+=1 return vertex
def addVertex(self, fileName): from Vertex import Vertex v = Vertex(fileName) self.vertices[fileName] = v
def PlaceTiles(self): numbers = [2, 3, 3, 4, 4, 5, 5, 6, 6, 8, 8, 9, 9, 10, 10, 11, 11, 12] resources = [ "ore", "ore", "ore", "wheat", "wheat", "wheat", "wheat", "sheep", "sheep", "sheep", "sheep", "brick", "brick", "brick", "wood", "wood", "wood", "wood" ] robberIndex = random.randint(0, 18) numberOrder = [0] * 19 for i in range(19): if not i == robberIndex: numberOrder[i] = random.choice(numbers) numbers.remove(numberOrder[i]) resourceOder = [0] * 19 for i in range(19): if not i == robberIndex: resourceOder[i] = random.choice(resources) resources.remove(resourceOder[i]) numberOrder[robberIndex] = 0 resourceOder[robberIndex] = "desert" """ numberOrder = [5, 10, 8, 2, 9, 3, 4, 6, 4, 11, 6, 11, 3, 5, 0, 12, 8, 10, 9] resourceOder = ["wheat", "brick", "brick", "sheep", "wood", "sheep", "ore", "ore", "wheat", "wood", "wood", "wheat", "brick", "sheep", "desert", "wheat", "ore", "sheep", "wood"] robberIndex = 14 """ row = 0 edgesTemp = [0, 1, 7, 12, 11, 6] verticesTemp = [0, 1, 2, 10, 9, 8] for i in range(len(numberOrder)): self.tiles[i] = Tile(numberOrder[i], resourceOder[i], verticesTemp.copy(), edgesTemp.copy()) for j in range(len(verticesTemp)): index = verticesTemp[j] if self.vertices[index] == None: self.vertices[index] = Vertex() self.vertices[index].AddTileConnection(i) if j == 0: self.vertices[index].AddVertexConnection(verticesTemp[5]) else: self.vertices[index].AddVertexConnection(verticesTemp[j - 1]) if j == 5: self.vertices[index].AddVertexConnection(verticesTemp[0]) else: self.vertices[index].AddVertexConnection(verticesTemp[j + 1]) self.vertices[index].AddEdgeConnection(edgesTemp[j]) if j == 0: self.vertices[index].AddEdgeConnection(edgesTemp[5]) else: self.vertices[index].AddEdgeConnection(edgesTemp[j - 1]) for j in range(len(edgesTemp)): index = edgesTemp[j] if self.edges[index] == None: self.edges[index] = Edge() self.edges[index].tilesConnectedTo.append(i) self.edges[index].AddVertexConnection(verticesTemp[j]) if j == 5: self.edges[index].AddVertexConnection(verticesTemp[0]) else: self.edges[index].AddVertexConnection(verticesTemp[j + 1]) if j == 0: self.edges[index].AddEdgeConnection(edgesTemp[5]) else: self.edges[index].AddEdgeConnection(edgesTemp[j - 1]) if j == 5: self.edges[index].AddEdgeConnection(edgesTemp[0]) else: self.edges[index].AddEdgeConnection(edgesTemp[j + 1]) if row == 0 and i == 2: edgesTemp = [10, 11, 19, 25, 24, 18] verticesTemp = [7, 8, 9, 19, 18, 17] row += 1 elif row == 1 and i == 6: edgesTemp = [23, 24, 34, 40, 39, 33] verticesTemp = [16, 17, 18, 29, 28, 27] row += 1 elif row == 2 and i == 11: edgesTemp = [40, 41, 50, 55, 54, 49] verticesTemp = [28, 29, 30, 40, 39, 38] row += 1 elif row == 3 and i == 15: edgesTemp = [55, 56, 63, 67, 66, 62] verticesTemp = [39, 40, 41, 49, 48, 47] row += 1 else: edgesTemp[0] += 2 edgesTemp[1] += 2 edgesTemp[3] += 2 edgesTemp[4] += 2 edgesTemp[2] += 1 edgesTemp[5] += 1 verticesTemp[0] += 2 verticesTemp[1] += 2 verticesTemp[2] += 2 verticesTemp[3] += 2 verticesTemp[4] += 2 verticesTemp[5] += 2
anchors_raw = np.genfromtxt('anchors.csv', delimiter=',', dtype=float, missing_values=0, skip_header=1) anchors = [(x[1], x[2]) for x in anchors_raw] # read vertices vertices_raw = np.genfromtxt('nodes.csv', delimiter=',', dtype=float, missing_values=0, skip_header=1) vertices = {} for V in vertices_raw: vertices[int(V[0])] = Vertex(int(V[0]), (V[1], V[2])) # read polygons polygons_raw = {} with open('polygons.csv', 'r') as file: for line in file: a = np.array([int(v) for v in line.strip().split(",")]) poly_id = a[0] poly_nodes = a[1:] polygons_raw[poly_id] = poly_nodes polygons = [] for poly_id, poly_vertices_ids in polygons_raw.items(): poly_vertices = [vertices[i] for i in poly_vertices_ids] polygons.append(Polygon(poly_id, poly_vertices))
def add_vertex(self, node): node = node.split(" ") self.num_vertices += 1 new_vertex = Vertex(node[0], int(node[1]), int(node[2])) self.vert_dict[node[0]] = new_vertex return new_vertex
def BuildCylinder (self, center, radius, height, UVs): #------------------------------------------------------- cx = center[0] cy = center[1] cz = center[2] center = vt(cx, cy, cz) # Generate vertices on bottom surface btm_v = [None] * 16 # Compute btm_v0, 4, 8, 12 btm_v[0] = vt(cx+radius, cy, cz) btm_v[8] = vt(cx-radius, cy, cz) btm_v[4] = vt(cx, cy, cz+radius) btm_v[12] = vt(cx, cy, cz-radius) # Compute btm_v2, 6, 10, 14 for i in [0, 4]: btm_v[i+2] = self.ComputeMidVector(btm_v[i], btm_v[i+4], center, radius) btm_v[i+2+8] = vt.sum(center, vt.diff(center, btm_v[i+2])) # Compute vtm_1,3,5,7 and 9,11,13,15 for i in [0, 2, 4, 6]: btm_v[i+1] = self.ComputeMidVector(btm_v[i], btm_v[i+2], center, radius) btm_v[i+1+8] = vt.sum(center, vt.diff(center, btm_v[i+1])) # Generate vertices on top surface top_v = [] for i in range(16): temp = vt(btm_v[i].x, btm_v[i].y+height, btm_v[i].z) top_v.append(temp) # Generate all vertices from given # Vertex on one circle surface '''ver1 = vt.equal(center) ver2 = vt.equal(v2) ver3 = vt.sum(v1, vt.diff(v1, v2)) # Generate third&fourth vertices on verticle line temp = vt.cross(vt.diff(v2, v1), vt.diff(v3, v1)) temp = vt.normalize(temp) temp = vt.scale(temp, radius) ver4 = vt.sum(v1, temp) ver5 = vt.sum(v1, vt.diff(ver1, ver4)) ver6 = self.ComputeMidVector(ver2, ver5, ver1, radius) ver7 = vt.sum(v1, vt.diff(ver1, ver6)) ver8 = self.ComputeMidVector(ver2, ver4, ver1, radius) ver9 = vt.sum(v1, vt.diff(ver1, ver6))''' #------------------------------------------------------- # Store corresponding Texel coordinates print "----------------------------" tx1 = UVs[0].facePoints[0] #print tx1 tx2 = UVs[0].facePoints[1] #print tx2 tx3 = UVs[0].facePoints[2] #print tx3 tx4 = UVs[0].facePoints[3] #print tx4 dis_btm = [tx2[0]-tx1[0], tx2[1]-tx1[1]] dis_top = [tx3[0]-tx4[0], tx3[1]-tx4[1]] dis_left = [tx4[0]-tx1[0], tx4[1]-tx1[1]] dis_right = [tx3[0]-tx2[0], tx3[1]-tx2[1]] #print dis_btm #print dis_top tx_btm = [] # store all nice texels on bottom edge tx_top = [] # store all nice texels on top edge tx_left = [] # store all five texels on left edge tx_right = [] # store all five texels on right edge uv_front = [] uv_back = [] uv_top = [] uv_btm = [] # Divide two texels into 9 texels on top and btm edge for i in range(9): tx_btm.append(tx(tx1[0]+i*dis_btm[0]/8.0, tx1[1]+i*dis_btm[1]/8.0)) tx_top.append(tx(tx4[0]+i*dis_top[0]/8.0, tx4[1]+i*dis_top[1]/8.0)) # Divde two texels into 5 texels on left and right edge for i in range(4): tx_right.append(tx(tx2[0]+i*dis_right[0]/4.0, tx2[1]+i*dis_right[1]/4.0)) tx_left.append(tx(tx4[0]-i*dis_left[0]/4.0, tx4[1]-i*dis_left[1]/4.0)) # Generate the 16 side surfaces based on 18 texels for i in range(8): uv_front.append([tx_btm[i], tx_btm[i+1], tx_top[i+1], tx_top[i]]) uv_back.append([tx_btm[i], tx_btm[i+1], tx_top[i+1], tx_top[i]]) # Generate the top and btm surface's texels for i in range(4): uv_btm.append(tx_btm[2*i]) uv_top.append(tx_btm[2*i]) for i in range(4): uv_btm.append(tx_right[i]) uv_top.append(tx_right[i]) for i in range(4): uv_btm.append(tx_top[2*i]) uv_top.append(tx_top[8 - 2*i]) for i in range(4): uv_btm.append(tx_left[i]) uv_top.append(tx_left[i]) #------------------------------------------------------- # Generate polygons polyList = [] temp_top = [] temp_btm = [] # The two circle polygon on top and bot for i in range(16): temp_top.append(top_v[i]) temp_btm.append(btm_v[i]) #polyList.append(Polygon(temp_btm, uv_btm)) polyList.append(Polygon(temp_top, uv_top)) # The 16 polygons on side for i in range(16): if(i < 8): tempPolygon = Polygon([btm_v[i], btm_v[(i+1)%16], top_v[(i+1)%16], top_v[i]], uv_front[i]) else: tempPolygon = Polygon([btm_v[i], btm_v[(i+1)%16], top_v[(i+1)%16], top_v[i]], uv_back[i-8]) polyList.append(tempPolygon) #------------------------------------------------------- # Return list of polygons return polyList
def fill_flat_side_triangle_int(matriz, v1, v2, v3): vTmp1 = Vertex(v1.x, v1.y) vTmp2 = Vertex(v1.x, v1.y) changed1 = False changed2 = False dx1 = np.abs(v2.x - v1.x) dy1 = np.abs(v2.y - v1.y) dx2 = np.abs(v3.x - v1.x) dy2 = np.abs(v3.y - v1.y) signx1 = int(np.sign(v2.x - v1.x)) signx2 = int(np.sign(v3.x - v1.x)) signy1 = int(np.sign(v2.y - v1.y)) signy2 = int(np.sign(v3.y - v1.y)) if dy1 > dx1: tmp = dx1 dx1 = dy1 dy1 = tmp changed1 = True if dy2 > dx2: tmp = dx2 dx2 = dy2 dy2 = tmp changed2 = True e1 = 2 * dy1 - dx1 e2 = 2 * dy2 - dx2 for i in range(dx1 + 1): if vTmp1.x < vTmp2.x: draw_line(matriz, vTmp1.x, vTmp1.y, vTmp2.x, vTmp2.y) else: draw_line(matriz, vTmp2.x, vTmp2.y, vTmp1.x, vTmp1.y) while e1 >= 0: if changed1: vTmp1.x += signx1 else: vTmp1.y += signy1 e1 = e1 - 2 * dx1 if changed1: vTmp1.y += signy1 else: vTmp1.x += signx1 e1 = e1 + 2 * dy1 while vTmp2.y != vTmp1.y: while e2 >= 0: if changed2: vTmp2.x += signx2 else: vTmp2.y += signy2 e2 = e2 - 2 * dx2 if changed2: vTmp2.y += signy2 else: vTmp2.x += signx2 e2 = e2 + 2 * dy2
def add_vertex(self, key): self.num_vertices = self.num_vertices + 1 new_vertex = Vertex(key) self.vertex_list[key] = new_vertex return new_vertex
from Edge import Edge from Vertex import Vertex from Algorithm import Algorithm node1 = Vertex("1") node2 = Vertex("2") node3 = Vertex("3") node4 = Vertex("4") edge1 = Edge(1, node1, node2) edge2 = Edge(1, node1, node3) edge3 = Edge(0.01, node1, node4) edge4 = Edge(1, node3, node4) node1.adjacenciesList.append(edge1) node1.adjacenciesList.append(edge2) node1.adjacenciesList.append(edge3) node3.adjacenciesList.append(edge4) unvisitedList = [] unvisitedList.append(node1) unvisitedList.append(node2) unvisitedList.append(node3) unvisitedList.append(node4) algorithm = Algorithm(unvisitedList) algorithm.calculateSpanningTree(node1)
def add_vertex(self,node): self.num_vertices +=1 new_vertex = Vertex(node) self.vert_dict[node] = new_vertex return new_vertex
def add_vertex(self, name, info, type_is_movie): self.num_vertices = self.num_vertices + 1 new_vertex = Vertex(name, info, type_is_movie) self.vertices_dictionary[name] = new_vertex return new_vertex
def addVx(self, elem): v = Vertex(elem) if (v not in self.vert): self.vert.append(v)
#!/usr/bin/python from Vertex import Vertex from Graph import Graph a = Vertex('a') b = Vertex('b') c = Vertex('c') a.addNeighbor(b) a.addNeighbor(c,100) for v in a.getConnections(): print v print a.getId() print a.getWeight(b) print a.getWeight(c) print "ME: " , a g = Graph() for i in range(6): g.addVertex(i) g.addEdge(1,2,10) for vtx in g: for conn in vtx.getConnections():
def stripline(bone,linewidth,logname): fp = codecs.open(logname, "w", "utf_8" ) i = 0; segmentNum = len(bone)-1; elementNum=(segmentNum*2+2)*5; outVertexArray = [] #1線分につき4頂点 +終点に足した余分な分 vertexIdx = 0; #最初の頂点 start =bone[0]; end =bone[1]; lastRad=0 lastUsedRad=0 radY = widenDir(start,end) lineRad=lineDir(start,end) fp.write(u"0番目の頂点") printRadian(fp,u"lineRad",lineRad) originalRad=radY #曲がる方向を示す cornerDir=radY-lastRad printRadian(fp,u"radY",radY) diffRad=0 printRadian(fp,u"diffRad:",diffRad) printRadian(fp,u"radY-lineRad:",radY-lineRad) printRadian(fp,u"sin(radY-lineRad:)",math.sin(radY-lineRad)) adjustedRad=radY printRadian(fp,u"最初の描画角度",adjustedRad) fp.write("\n") direction=True lastRad=radY; lastUsedRad=adjustedRad LEFT=Vertex(linewidth,0) RIGHT=Vertex(-linewidth,0) #変数 v=Vertex(0,0) v.set(LEFT) v.rotate(adjustedRad) flag = False #if radY< 0 else False outVertexArray.append([start+v,flag]) v.set(RIGHT) v.rotate(adjustedRad) flag = True# if radY< 0 else False outVertexArray.append([start+v,flag]) for i in range(1,segmentNum): start =bone[i] end =bone[i+1] originalRad = widenDir(start,end) radY=(originalRad+lastRad)*0.5#0〜360度の値 fp.write(str(i)+u"番目の頂点") diffRad=(originalRad-lastRad) if math.fabs(math.fabs(diffRad)-math.pi)<=(45.0*math.pi/180.0):#Uターン時のとんがり三角形を消すため printRadian(fp,u"Uターン地点の補正:diffRad",diffRad) fp.write(u"差分"+str(math.fabs(math.fabs(diffRad)-math.pi))) radY=originalRad printRadian(fp,u"radY:",radY) printRadian(fp,u"diffRad:",diffRad) printRadian(fp,u"radY-lineRad:",radY-lineRad) printRadian(fp,u"sin(radY-lineRad:)",math.sin(radY-lineRad)) #ねじれ防止 if math.sin(radY-lineRad)>0: radY=invert(radY) lineRad=lineDir(start,end) printRadian(fp,u"lineRad:",lineRad) adjustedRad=radY printRadian(fp,u"diffRad:",diffRad) squareRad=lineDir(start,end) #printRadian(u"squareRad",squareRad) printRadian(fp,u"変換後描画角度:",radY) v.set(LEFT) #1〜√2 の範囲になってほしい coef=(1+0.41421356237*math.fabs(math.sin(diffRad*0.5))) fp.write("coef="+str(coef)) v.x*=coef v.rotate(adjustedRad) flag = False outVertexArray.append([start+v,flag]) v.set(RIGHT) v.x*=coef v.rotate(adjustedRad) flag = True outVertexArray.append([start+v,flag]) lastRad=originalRad; lastUsedRad=adjustedRad fp.write("\n") #最後の締めくくり fp.write(str(i)+u"番目の頂点") adjustedRad=originalRad printRadian(fp,u"最後の描画角度:",originalRad) v.set(LEFT) v.rotate(adjustedRad) flag = False# if originalRad< 0 else False outVertexArray.append([end+v,flag]) v.set(RIGHT) v.rotate(adjustedRad) flag = True# if originalRad< 0 else False outVertexArray.append([end+v,flag]) fp.close() return outVertexArray