def test_materials(self): equivalent_site, bmesh, feature_by_face = builder.build_altimetry( self.mainsite) material_by_face = builder.material_by_face(feature_by_face) materials_id = set(mat.id for mat in material_by_face.values()) self.assertItemsEqual( materials_id, ['__default__', '__hidden__', 'grass', 'pine', 'Water'])
def test_plot_complete_processing(self): equivalent_site, mesh, feature_by_face = builder.build_altimetry( self.mainsite) plotter = visu.MeshedCDTPlotter(mesh, title=self._testMethodName) equivalent_site.plot(plotter.ax, alt_geom_map=equivalent_site._cleaner.geom) plotter.plot_edges() material_by_face = builder.material_by_face(feature_by_face) for fh in mesh.cdt.finite_faces(): material = material_by_face.get(fh) if material is None: continue plotter.plot_face(fh, material_id=material.id) plotter.show()
def test_ply_export(self): from plyfile import PlyData _, mesh, feature_by_face = builder.build_altimetry(self.mainsite) material_by_face = builder.material_by_face(feature_by_face) try: # delete=False and manual removal to avoid pb on windows platform # (though proper fix would imply stream based api) with tempfile.NamedTemporaryFile(delete=False) as f: export_to_ply(mesh, material_by_face, f.name) data = PlyData.read(f.name) vertices = data['vertex'] faces = data['face'] materials = data['material'] self.assertEqual(vertices.count, 119) self.assertEqual(faces.count, 198) materials_id = [ ''.join(map(chr, data)) for data, in materials.data ] self.assertItemsEqual( materials_id, ['__default__', '__hidden__', 'grass', 'pine', 'Water']) self.assertEqual(materials.count, 5) finally: os.remove(f.name)
def test_plot_landtake_flooding(self): cleaner = builder.recursively_merge_all_subsites(self.mainsite) site = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) bmesh = mbuilder.build_mesh(refine=False) mfiller = builder.MeshFiller(bmesh, mbuilder.vertices_for_feature) flood_seeds = mfiller._fill_polygonal_feature(self.building, mesh.LandtakeFaceFlooder) plotter = visu.MeshedCDTPlotter(bmesh, title=self._testMethodName) cleaner.equivalent_site.plot(plotter.ax, alt_geom_map=cleaner.geom) plotter.plot_edges() for fh in flood_seeds: marks = [bmesh.point_for_face(f) for f in flood_seeds] visu.plot_points_seq(plotter.ax, marks, marker='*') material_by_face = builder.material_by_face( mfiller.fill_material_and_landtakes(self.mainsite, cleaner)) for fh in bmesh.cdt.finite_faces(): material = material_by_face.get(fh) if material is None: continue plotter.plot_face(fh, material_id=material.id) plotter.show()
def material_by_face(self): """Return a material_by_face mapping""" if self._material_by_face is None: self._material_by_face = builder.material_by_face( self.feature_by_face) return self._material_by_face