Example #1
0
 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'])
Example #2
0
 def test_join_with_landtakes(self):
     equivalent_site, mesh, feature_by_face = builder.build_altimetry(
         self.mainsite)
     landtake_faces = (fh for fh, feature in feature_by_face.iteritems()
                       if isinstance(feature, InfrastructureLandtake))
     altitudes = [
         mesh.vertices_info[fh.vertex(i)].altitude for fh in landtake_faces
         for i in range(3)
     ]
     assert_allclose(altitudes, altitudes[0])
Example #3
0
    def test_plot(self):
        equivalent_site, mesh, _ = 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()

        fh, expected_None = mesh.locate_point((4, 4))
        self.assertIsNone(expected_None)
        plotter.plot_face(fh, material_id='concrete')
        plotter.show()
Example #4
0
    def from_site(cls, site, use_vol_landtakes=False, **kwargs):
        """Build an altimetry mesh from a tympan Site.

        Extra keyword arguments are passed to the mesh builder (see
        tympan.altimetry.builder.build_altimetry).
        """

        asite = builder.build_sitenode(
            site, use_vol_landtakes=use_vol_landtakes)
        # Compute altimetry and retrieve the resulting mesh
        merged_site, mesh, feature_by_face = builder.build_altimetry(
            asite, **kwargs)
        return cls(merged_site, mesh, feature_by_face)
Example #5
0
 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_building_outside_landtake(self):
     # outside landtake
     InfrastructureLandtake(rect(13, 12, 15, 17),
                            parent_site=self.mainsite,
                            id="{external building}")
     # intersecting with landtake
     InfrastructureLandtake(rect(10, 10, 13, 15),
                            parent_site=self.mainsite,
                            id="{intersecting building}")
     equivalent_site, mesh, feature_by_face = builder.build_altimetry(
         self.mainsite)
     # it makes no sense having a site intersecting a building. Make sure
     # none of these buildings will be taken into account.
     self.assertEqual(len(equivalent_site.landtakes), 1)
     self.assertEqual(equivalent_site.landtakes[0].id, '{Building}')
Example #7
0
 def test_process_vegetation_area(self):
     fpath = osp.join(TEST_PROBLEM_DIR,
                      'Site_avec_2_terrain_1_avec_veget_1_sans.xml')
     project = Project.from_xml(fpath)
     asite = builder.build_sitenode(project.site)
     _, _, feature_by_face = builder.build_altimetry(asite)
     matarea = list(asite.material_areas)
     self.assertEqual(len(matarea), 2)
     try:
         vegarea = asite.features_by_id['{60260543-0297-4cec-aacc-cb63492d1171}']
     except KeyError:
         self.fail('vegetation area not found in altimetry site')
     self.assertEqual(vegarea.height, 10)
     self.assertTrue(vegarea.foliage)
     self.assertEqual(vegarea.variety, 'aspen')
     vegfaces = [fh for fh, feature in feature_by_face.items()
                 if isinstance(feature, VegetationArea)]
     # Just check there are faces in the vegetation area.
     self.assertTrue(vegfaces)
Example #8
0
 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)
Example #9
0
 def from_site(cls, site):
     """Build an altimetry mesh from a tympan Site"""
     asite = builder.build_sitenode(site)
     # Compute altimetry and retrieve the resulting mesh
     merged_site, mesh, feature_by_face = builder.build_altimetry(asite)
     return cls(merged_site, mesh, feature_by_face)