def ps_line_cmd(ps_line): #Parse this line, space seperator toks = gen_utils.split_and_remove(ps_line, " ", "") l = None l = geometry.Line() l.p1 = geometry.Point() l.p2 = geometry.Point() l.p1.x = float(toks[0].strip()) l.p1.y = float(toks[1].strip()) l.p2.x = float(toks[2].strip()) l.p2.y = float(toks[3].strip()) return l
def ps_polygon(ps_polygon_lines): points = [] #Do not include last point for i in range(0,len(ps_polygon_lines)-1): line = ps_polygon_lines[i].strip() toks = gen_utils.split_and_remove(line, " ", "") x = float(toks[0].strip()) y = float(toks[1].strip()) tmp_p = None tmp_p = geometry.Point() tmp_p.x = x tmp_p.y = y points = points + [tmp_p] poly = geometry.Polygon() poly.vertices = points return poly
def build_from_file(self, filename): # Open file f = open(filename, "r") # Get all lines lines = f.readlines() # Loop over lines for line in lines: toks = gen_utils.split_and_remove(line, " ", "") # Vertex line if VERTEX_LINE_MARKER in line: new_v = None new_v = geometry.Point() new_v.x = float(toks[1]) new_v.y = float(toks[2]) new_v.z = float(toks[3]) self.vertices = self.vertices + [new_v] # Face line elif FACE_LINE_MARKER in line: new_f = None new_f = geometry.Polygon() v1_index = int(toks[1]) - 1 v2_index = int(toks[2]) - 1 v3_index = int(toks[3]) - 1 new_f.vertices = new_f.vertices + [ self.vertices[v1_index], self.vertices[v2_index], self.vertices[v3_index], ] self.faces = self.faces + [new_f] # Relationship between vertices self.face_vertex_indices = self.face_vertex_indices + [(v1_index, v2_index, v3_index)] else: # Ignore unknown line continue f.close()