def test_multipolygon_infrastructure_landtake(self): site_rect = rect(1, 1, 12, 12) mainsite = SiteNode(site_rect, id="{Main site}") rec, tri = rect(9, 9, 10, 10), [(2, 2), (2, 4), (3, 4)] building = InfrastructureLandtake(rec, tri, parent_site=mainsite, id="{multipolygon building}") coords = list(map(list, building._coords)) expected_coords = [ [(9, 9), (10, 9), (10, 10), (9, 10), (9, 9)], [(2, 2), (2, 4), (3, 4), (2, 2)], ] self.assertEqual(coords, expected_coords) cleaner = builder.recursively_merge_all_subsites(mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) alti = mbuilder._build_altimetric_base() bmesh = mbuilder._build_triangulation(alti) mbuilder._compute_informations(bmesh) vertices = [ list(map(bmesh.py_vertex, vertices_groups)) for vertices_groups in mbuilder.vertices_for_feature[building.id] ] assert_array_equal(vertices, expected_coords)
def test_build_altimetric_base(self): cleaner = builder.recursively_merge_all_subsites(self.mainsite) for id_ in ["{Mainsite ref altitude}", "{Subsub level curve}"]: self.assertIn(id_, cleaner.equivalent_site.features_by_id) self.assertIn(id_, cleaner.geom) msite = cleaner.merged_site() alti = builder.MeshBuilder(msite)._build_altimetric_base() common_expectations = [((0, 0), {'altitude': self.altitude_A})] self.check_vertices_props(alti, common_expectations)
def test_build_triangulation(self): cleaner = builder.recursively_merge_all_subsites(self.mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) alti = mbuilder._build_altimetric_base() bmesh = mbuilder._build_triangulation(alti) mbuilder._compute_informations(bmesh) self.check_vertices_props(bmesh, [ ((1, 1), { 'altitude': self.altitude_A, 'ids': set(['{Grass area}', '{Level curve A}']) }), ((1, 9), { 'altitude': mesh.UNSPECIFIED_ALTITUDE, 'ids': set(['{Grass area}']) }), ])
def test_vertices_by_feature(self): coords = rect(9, 9, 10, 10) self.building = InfrastructureLandtake(coords, parent_site=self.mainsite, id="{some building}") cleaner = builder.recursively_merge_all_subsites(self.mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) alti = mbuilder._build_altimetric_base() bmesh = mbuilder._build_triangulation(alti) mbuilder._compute_informations(bmesh) vertices = mbuilder.vertices_for_feature[self.building.id] for i, v in enumerate(vertices): self.assertEquals(v.point(), mesh.to_cgal_point(coords[i % len(coords)]))
def test_intersecting_level_curves_error(self): # build a new level curve that intersects site landtake level curve and # has a different altitude other_level_curve_coords = [(-2, -3), (1, 2)] level_curve = LevelCurve(other_level_curve_coords, altitude=20., parent_site=self.mainsite, id="{Other level curve}") cleaner = builder.recursively_merge_all_subsites(self.mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) with self.assertRaises(InconsistentGeometricModel) as cm: bmesh = mbuilder.build_mesh(refine=False) self.assertEqual( str(cm.exception), "Intersecting constraints with different altitudes: " "['{Mainsite ref altitude}', '{Other level curve}'] at (0.0, 0.33333333333333337)" )
def test_compute_elevations(self): cleaner = builder.recursively_merge_all_subsites(self.mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) alti = mbuilder._build_altimetric_base() bmesh = mbuilder._build_triangulation(alti) mbuilder._compute_informations(bmesh) pM = (8.5, 6.5) # in the corner of Level curve B vM = bmesh.insert_point(pM) mbuilder._compute_elevations(bmesh, alti) self.check_vertices_props(bmesh, [ ((1, 1), { 'altitude': self.altitude_A, 'ids': set(['{Grass area}', '{Level curve A}']) }), (pM, { 'altitude': self.level_curve_B.altitude, }), ])
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()