def create_opaque_srf_shape_attribute(occ_face, uvalue, srf_type): """ This function creates the opaque surface ShapeAttributes class and its attributes. Parameters ---------- occ_face : list of OCCfaces The faces to be appended with the opaque surface attributes. uvalue : float The value of the "uvalue" attribute to be appended to the surface. srf_type : str The type of the surface, srf_type can be either "wall" or "roof". Returns ------- srfs_shp_attribs_obj_list : list of ShapeAttributes objects List of ShapeAttributes objects appended with the "uvalue" and "type" attributes. """ shp_attribs = shapeattributes.ShapeAttributes() shp_attribs.set_shape(occ_face) shp_attribs.set_key_value("uvalue", uvalue) shp_attribs.set_key_value("type", srf_type) return shp_attribs
def create_glazing_shape_attribute(occ_face, uvalue, shading_coefficient1, srf_type): """ This function creates the glazing ShapeAttributes class and its attributes. Parameters ---------- occ_face : list of OCCfaces The faces to be appended with the glazing attributes. uvalue : float The value of the "uvalue" attribute to be appended to the surface. sc1 : float The value of the "sc1" attribute to be appended to the surface. srf_type : str The type of the surface, srf_type can be either "window" or "skylight". Returns ------- srfs_shp_attribs_obj_list : list of ShapeAttributes objects List of ShapeAttributes objects appended with the "uvalue", "sc1" and "type" attributes. """ shp_attribs = shapeattributes.ShapeAttributes() shp_attribs.set_shape(occ_face) shp_attribs.set_key_value("uvalue", uvalue) shp_attribs.set_key_value("sc1", shading_coefficient1) shp_attribs.set_key_value("type", srf_type) return shp_attribs
def create_shading_srf_shape_attribute(occ_face, srf_type): """ This function creates the shading surface ShapeAttributes class and its attributes. Parameters ---------- occ_face : list of OCCfaces The faces to be appended with the shading attributes. srf_type : str The type of the surface, srf_type can be either "footprint", "shade" or "surrounding". Returns ------- srfs_shp_attribs_obj_list : list of ShapeAttributes objects List of ShapeAttributes objects appended with the "type" attributes. """ shp_attribs = shapeattributes.ShapeAttributes() shp_attribs.set_shape(occ_face) shp_attribs.set_key_value("type", srf_type) return shp_attribs
def read_collada(self,dae_filepath): ''' the dae file must be modelled as such: close_shells = buildings open_shells = terrain & plots(land-use) edges = street network #TODO: a function that will convert collada to citygml base on the visual scenes and library nodes (groups and layers) dae = Collada(collada_file) nodes = dae.scene.nodes #this loops thru the visual scene #loop thru the library nodes for node in nodes: name = node.xmlnode.get('name') children_nodes = node.children if children_nodes: for node2 in children_nodes: name2 = node2.xmlnode.get('name') print 'name2', name2 children_node2 = node2.children if children_node2: if type(children_node2[0]) == scene.NodeNode: print children_node2[0].children ''' tolerance = 1e-04 edgelist = [] shelllist = [] mesh = Collada(dae_filepath) unit = mesh.assetInfo.unitmeter or 1 geoms = mesh.scene.objects('geometry') geoms = list(geoms) gcnt = 0 for geom in geoms: if gcnt >= 0: #and gcnt <= 45: prim2dlist = list(geom.primitives()) for primlist in prim2dlist: spyptlist = [] epyptlist = [] faces = [] edges = [] if primlist: for prim in primlist: if type(prim) == polylist.Polygon or type(prim) == triangleset.Triangle: pyptlist = prim.vertices.tolist() sorted_pyptlist = sorted(pyptlist) if sorted_pyptlist not in spyptlist: spyptlist.append(sorted_pyptlist) occpolygon = py3dmodel.construct.make_polygon(pyptlist) if not py3dmodel.fetch.is_face_null(occpolygon): faces.append(occpolygon) elif type(prim) == lineset.Line: pyptlist = prim.vertices.tolist() pyptlist.sort() if pyptlist not in epyptlist: epyptlist.append(pyptlist) occedge = py3dmodel.construct.make_edge(pyptlist[0], pyptlist[1]) edges.append(occedge) if faces: n_unique_faces = len(faces) if n_unique_faces == 1: shell = py3dmodel.construct.make_shell(faces) shelllist.append(shell) if n_unique_faces >1: shell = py3dmodel.construct.make_shell_frm_faces(faces, tolerance = tolerance) if shell: shelllist.append(shell[0]) else: edgelist.extend(edges) gcnt +=1 cmpd_shell = py3dmodel.construct.make_compound(shelllist) cmpd_edge = py3dmodel.construct.make_compound(edgelist) cmpd_list = [cmpd_shell, cmpd_edge] #find the midpt of all the geometry compound = py3dmodel.construct.make_compound(cmpd_list) xmin,ymin,zmin,xmax,ymax,zmax = py3dmodel.calculate.get_bounding_box(compound) ref_pt = py3dmodel.calculate.get_centre_bbox(compound) ref_pt = (ref_pt[0],ref_pt[1],zmin) #scale all the geometries into metre scaled_shell_shape = py3dmodel.modify.uniform_scale(cmpd_shell, unit, unit, unit,ref_pt) scaled_edge_shape = py3dmodel.modify.uniform_scale(cmpd_edge, unit, unit, unit,ref_pt) scaled_shell_compound = py3dmodel.fetch.shape2shapetype(scaled_shell_shape) scaled_edge_compound = py3dmodel.fetch.shape2shapetype(scaled_edge_shape) recon_shell_compound = gml3dmodel.redraw_occ_shell(scaled_shell_compound, tolerance) recon_edge_compound = gml3dmodel.redraw_occ_edge(scaled_edge_compound, tolerance) #sort and recompose the shells shells = py3dmodel.fetch.geom_explorer(recon_shell_compound,"shell") sewed_shells = gml3dmodel.reconstruct_open_close_shells(shells) nw_edges = py3dmodel.fetch.geom_explorer(recon_edge_compound,"edge") occshp_attribs_obj_list = [] for sewed_shell in sewed_shells: occshp_attribs_obj = shapeattributes.ShapeAttributes() occshp_attribs_obj.set_shape(sewed_shell) occshp_attribs_obj_list.append(occshp_attribs_obj) for nw_edge in nw_edges: occshp_attribs_obj = shapeattributes.ShapeAttributes() occshp_attribs_obj.set_shape(nw_edge) occshp_attribs_obj_list.append(occshp_attribs_obj) print len(shells), len(sewed_shells) self.occshp_attribs_obj_list = occshp_attribs_obj_list
def read_collada(self,dae_filepath): """ This function reads the Collada (.dae) file to be converted and convert the geometries to ShapeAttributes objects. Parameters ---------- dae_filepath : str The file path of the Collada file to be converted. """ #TODO: a function that will convert collada to citygml base on the visual scenes and library nodes (groups and layers) #dae = Collada(collada_file) #nodes = dae.scene.nodes #this loops thru the visual scene #loop thru the library nodes #for node in nodes: # name = node.xmlnode.get('name') # children_nodes = node.children # if children_nodes: # for node2 in children_nodes: # name2 = node2.xmlnode.get('name') # print 'name2', name2 # children_node2 = node2.children # if children_node2: # if type(children_node2[0]) == scene.NodeNode: # print children_node2[0].children tolerance = 1e-04 edgelist = [] shelllist = [] mesh = collada.Collada(dae_filepath) unit = mesh.assetInfo.unitmeter or 1 geoms = mesh.scene.objects('geometry') geoms = list(geoms) gcnt = 0 for geom in geoms: if gcnt >= 0: #and gcnt <= 45: prim2dlist = list(geom.primitives()) for primlist in prim2dlist: spyptlist = [] epyptlist = [] faces = [] edges = [] if primlist: for prim in primlist: if type(prim) == polylist.Polygon or type(prim) == triangleset.Triangle: pyptlist = prim.vertices.tolist() sorted_pyptlist = sorted(pyptlist) if sorted_pyptlist not in spyptlist: spyptlist.append(sorted_pyptlist) occpolygon = py3dmodel.construct.make_polygon(pyptlist) if not py3dmodel.fetch.is_face_null(occpolygon): faces.append(occpolygon) elif type(prim) == lineset.Line: pyptlist = prim.vertices.tolist() pyptlist.sort() if pyptlist not in epyptlist: epyptlist.append(pyptlist) occedge = py3dmodel.construct.make_edge(pyptlist[0], pyptlist[1]) edges.append(occedge) if faces: n_unique_faces = len(faces) if n_unique_faces == 1: shell = py3dmodel.construct.make_shell(faces) shelllist.append(shell) if n_unique_faces >1: shell = py3dmodel.construct.sew_faces(faces, tolerance = tolerance) if shell: shelllist.append(shell[0]) else: edgelist.extend(edges) gcnt +=1 cmpd_shell = py3dmodel.construct.make_compound(shelllist) cmpd_edge = py3dmodel.construct.make_compound(edgelist) cmpd_list = [cmpd_shell, cmpd_edge] #find the midpt of all the geometry compound = py3dmodel.construct.make_compound(cmpd_list) xmin,ymin,zmin,xmax,ymax,zmax = py3dmodel.calculate.get_bounding_box(compound) #ref_pt = py3dmodel.calculate.get_centre_bbox(compound) #ref_pt = (ref_pt[0],ref_pt[1],zmin) ref_pt = (0,0,0) #scale all the geometries into metre #TO DO: THIS HAS A PROBLEM WHEN YOU HAVE TWO FILES WITH DIFF MIDPTS #scaled_shell_shape = py3dmodel.modify.uniform_scale(cmpd_shell, unit, unit, unit,ref_pt) #scaled_edge_shape = py3dmodel.modify.uniform_scale(cmpd_edge, unit, unit, unit,ref_pt) scaled_shell_shape = py3dmodel.modify.scale(cmpd_shell, unit,ref_pt) scaled_edge_shape = py3dmodel.modify.scale(cmpd_edge, unit,ref_pt) scaled_shell_compound = py3dmodel.fetch.topo2topotype(scaled_shell_shape) scaled_edge_compound = py3dmodel.fetch.topo2topotype(scaled_edge_shape) recon_shell_compound = urbangeom.redraw_occshell(scaled_shell_compound, tolerance) recon_edge_compound = urbangeom.redraw_occedge(scaled_edge_compound, tolerance) #sort and recompose the shells shells = py3dmodel.fetch.topo_explorer(recon_shell_compound,"shell") sewed_shells = urbangeom.reconstruct_open_close_shells(shells) nw_edges = py3dmodel.fetch.topo_explorer(recon_edge_compound,"edge") occshp_attribs_obj_list = [] for sewed_shell in sewed_shells: occshp_attribs_obj = shapeattributes.ShapeAttributes() occshp_attribs_obj.set_shape(sewed_shell) occshp_attribs_obj_list.append(occshp_attribs_obj) for nw_edge in nw_edges: occshp_attribs_obj = shapeattributes.ShapeAttributes() occshp_attribs_obj.set_shape(nw_edge) occshp_attribs_obj_list.append(occshp_attribs_obj) print len(shells), len(sewed_shells) self.occshp_attribs_obj_list = occshp_attribs_obj_list