Пример #1
0
 def test_alti_mesh(self):
     proj = self.load_project(osp.join('projects-panel', 'fresnel.xml'))
     model = Model.from_project(proj)
     length = 75
     width = 75
     height = 75
     intersected_triangles = model.fresnel_zone_intersection(width, height,
                                                             Point3D(-length/2., 0, 0),
                                                             Point3D(length/2., 0, 0))
     all_triangles = model.triangles
     self.assertEqual(len(all_triangles), 51)
     for tri_idx, triangle in enumerate(all_triangles):
         node_inside_box = False
         for node in triangle.nodes:
             x, y, z = model.node_coords(node)
             if abs(x) <= length/2 and abs(y) <= width/2 and abs(z) <= height/2:
                 node_inside_box = True
         # If one of the node of the triangle is inside the box, make sure it is part of
         # the intersected triangles
         if node_inside_box:
             self.assertIn(tri_idx, intersected_triangles)
         # If the triangle isn't part of the intersected triangles, make sure it has no node
         # inside the box.
         if tri_idx not in intersected_triangles:
             self.assertFalse(node_inside_box)
Пример #2
0
 def append_triangle_to_scene(self, point1, point2, point3):
     point1 = Point3D(*point1)
     point2 = Point3D(*point2)
     point3 = Point3D(*point3)
     i1 = self._simulation.add_vertex_to_scene(point1)
     i2 = self._simulation.add_vertex_to_scene(point2)
     i3 = self._simulation.add_vertex_to_scene(point3)
     self._simulation.add_triangle_to_scene(i1, i2, i3)
Пример #3
0
 def test_floating_volume_above_scene(self):
     model = Model()
     model.add_node(0, 0, 0)
     model.add_node(0, 1, 0)
     model.add_node(1, 1, 0)
     model.add_node(1, 0, 0)
     model.add_triangle(0, 1, 2)
     model.add_triangle(1, 2, 3)
     intersected_triangles = model.fresnel_zone_intersection(1, 1, Point3D(-0.5, 0, 2),
                                                             Point3D(0.5, 0, 1))
     self.assertEqual(intersected_triangles, [])
Пример #4
0
 def test_volume_inside_scene(self):
     """Simple test with a planar scene and a cube on top of it"""
     # build a model with two triangles (z=0)
     model = Model()
     model.add_node(0, 0, 0)
     model.add_node(0, 1, 0)
     model.add_node(1, 1, 0)
     model.add_node(1, 0, 0)
     model.add_triangle(0, 1, 2)
     model.add_triangle(1, 2, 3)
     intersected_triangles = model.fresnel_zone_intersection(1, 1, Point3D(-0.5, 0, 0),
                                                             Point3D(0.5, 0, 0))
     self.assertEqual(intersected_triangles, [0, 1])
Пример #5
0
 def test_volume_on_scene(self):
     """Simple test with a squared planar scene and a cube on top of it"""
     model = Model()
     model.add_node(0, 0, 0)
     model.add_node(0, 1, 0)
     model.add_node(1, 1, 0)
     model.add_node(2, 1, 0)
     model.add_node(1, 2, 0)
     model.add_triangle(0, 1, 2)
     model.add_triangle(2, 3, 4)
     # It is on the first triangle but not on the second one
     intersected_triangles = model.fresnel_zone_intersection(1, 1, Point3D(-0.5, 0, 0),
                                                             Point3D(0.5, 0, 0))
     self.assertEqual(intersected_triangles, [0])
Пример #6
0
def main(tympan_xml,
         receptors_csv,
         output_xml,
         output_txt='Niveau_sonore_moyen.txt'):
    """
        Main
    """
    # load project
    project = Project.from_xml(tympan_xml)

    # Case receptors are read in a CSV file
    if receptors_csv != "":
        # Import and add receptor positions
        x, y, z = import_xyz_csv(receptors_csv, project)
        for i in range(len(x)):
            height = z[i]
            position = Point3D()
            position.set_x(x[i])
            position.set_y(y[i])
            position.set_z(height)
            project.add_user_receptor(position, height, "Position_" + str(i))

    # Run the calculations
    run_calculations(project)

    # Choose current computation, get receptors list and sources list
    list_calc = []
    list_calc.append(project.current_computation.name)
    list_src = get_sources_list(project, list_calc)
    list_rec = get_receptors_list(project, list_calc)

    # Get receptor number
    N = len(list_rec)

    # Get spectrums
    valeurs, nom_spectres = get_rec_spec(project, list_src, list_rec)
    del nom_spectres

    # Calculate mean value and set spectrum name
    val_result = np.sum(valeurs, axis=0) / N
    nom_spectre = ['Niveau sonore moyen sur parcours']

    # Write results to a .txt file
    print('\nFile created: ' + output_txt)
    write_results(val_result, nom_spectre, output_txt)

    # Save to output_xml
    if output_xml != "":
        project.to_xml(output_xml)
        print('Result saved to', output_xml)

    return project
Пример #7
0
def create_calculations(fichier_xml, objects, output_xml):
    """
        Place the objects at the positions
        and save the project in output_xml file
    """

    # load project
    project = Project.from_xml(fichier_xml, verbose=False)

    # altimetry must be updated to get right the source position.z
    altim = AltimetryMesh.from_site(project.site)
    project.update_site_altimetry(altim)

    # Get the calculation
    Model.from_project(project, set_sources=True, set_receptors=True)

    # Get the initial number of computations in the project:
    nb_computations = len(project.computations)
    nb_points = 0
    # Get data from the list of objects
    for object_type, object_xml, object_positions in objects:
        # Import element (engine or building) from XML file:
        elements = import_infra(object_xml, object_type)
        element = elements.engines[
            0] if object_type == "engine" else elements.buildings[0]
        element_name = element.name

        # Get the mesh
        meshes = project.meshes
        if len(meshes) == 0:
            print("Error, no mesh found in the XML file !")
            sys.exit(-1)

        # Retrieve positions from CSV file and direction vect and
        # add the element and do the calculation at each step
        position_x, position_y, position_z, position_angle = import_xyz_angle_csv(
            object_positions, project)

        # Loop on points:
        point = 0
        print("Number of points in " + object_positions + ": " +
              str(len(position_x)))
        if nb_points != 0 and nb_points != len(position_x):
            print(
                "Error, the number of points in CSV files should be the same !"
            )
            sys.exit(-1)
        nb_points = len(position_x)
        for point in range(nb_points):

            x = position_x[point]
            y = position_y[point]
            z = position_z[point]
            angle = position_angle[point]

            # Create the position for the element on the current position:
            pos_element = Point3D()
            pos_element.set_x(x)
            pos_element.set_y(y)
            pos_element.set_z(z)

            rot_element = Point3D()
            rot_element.set_z(angle)  # rotation sur l'axe z

            # Add a computation if necessary
            num_computation = nb_computations + point
            if num_computation >= len(project.computations):
                # New computation needed
                project.add_computation()
                print("Add computation number ", num_computation)
                last_calc = project.computations[num_computation]
                last_calc.add_noise_map(meshes[0])
                project.select_computation(last_calc)
                project.current_computation.set_name(
                    'Position {0}'.format(point))
            else:
                last_calc = project.computations[num_computation]
                project.select_computation(last_calc)
                print("Select computation number ", )

            # select receptors in the current calculation
            for rec in project.user_receptors:
                last_calc.addReceptor(rec)

            # Add a element at the current position pos_element
            site = project.site
            # Change name
            element.setName(element_name + " at position " + str(point))
            if object_type == "engine":
                print("Adding an engine...")
                site.add_engine(element, pos_element, rot_element, 0.)
            elif object_type == "building":
                print("Adding a building...")
                site.add_building(element, pos_element, rot_element, 0.)
            else:
                print("Error: Unknown object type: ", object_type)
                sys.exit(-1)
            print("Point ", point, " :", x, y, angle)

    project.to_xml(output_xml)
    print('Project saved to', output_xml)
Пример #8
0
def main(object_file_list, object_positions_file_list, object_type_list,
         object_name_list, input_xml, output_xml):
    """
    Import csv file with TYMPAN coordinates and create new project with objects
    Or add objects to an existing project
    """
    # Create new project if no project entered by user
    project = Project.create() if input_xml == '' else Project.from_xml(
        input_xml)

    # Loop on objects
    for object_file, object_positions_file, object_type, object_name in zip(
            object_file_list, object_positions_file_list, object_type_list,
            object_name_list):
        # Import the object read in the xml file:
        if object_file != "":
            # Import the elements from XML file:
            elements = import_infra(object_file, object_type)

        # Create numpy array with csv file containing TYMPAN coordinates of the objects
        my_data = np.genfromtxt(object_positions_file,
                                dtype='float',
                                delimiter=';',
                                skip_header=1)
        if my_data.shape[1] < 3:
            print("Error! Should read x,y,z or x,y,z,angle in " +
                  object_positions_file)
            sys.exit(-1)
        # Add object to project site for each position
        site = project.site
        rotation = Point3D(0, 0, 0)
        for i in range(len(my_data[:, 0])):
            position = Point3D()
            height = my_data[i, 2]
            position.set_x(my_data[i, 0])
            position.set_y(my_data[i, 1])
            position.set_z(height)
            # Add rotation if found
            if my_data.shape[1] == 4:
                rotation.set_z(my_data[i, 3])
            name = object_name + str(i)
            # Add object:
            if object_type == "source":
                # Source
                src = User_source(height, name, position)
                site.add_user_source(src, position, height)
            elif object_type == "receptor":
                # Receptor
                project.add_user_receptor(position, height, name)
            elif object_type == "engine":
                # Engine
                site.add_engine(elements.engines[0], position, rotation,
                                height)
            elif object_type == "building":
                # Building
                site.add_building(elements.buildings[0], position, rotation,
                                  height)
            else:
                print("Error: Unknown object type: ", object_type)
                sys.exit(-1)

        # Add project user_receptors to the last computation
        if object_type == "receptor":
            calcul = project.computations[-1]
            for rec in project.user_receptors:
                calcul.addReceptor(rec)

    # Write the project
    project.to_xml(output_xml)
    print('Project saved to ', output_xml)