meshmagick.mesh module¶
This module concerns mesh data structures.
TODO: mettre des examples d’utilisation
- class meshmagick.mesh.Mesh(vertices, faces, name=None)[source]¶
Bases:
object
A class to handle unstructured meshes.
- Parameters
vertices (array_like) – (nv x 3) Array of mesh vertices coordinates. Each line of the array represents one vertex coordinates
faces (array_like) – Arrays of mesh connectivities for faces. Each line of the array represents indices of vertices that form the face, expressed in counterclockwise order to ensure outward normals description.
name (str, optional) – The mesh’s name. If None, mesh is given an automatic name based on its internal ID.
- __add__(mesh_to_add)[source]¶
Adds two meshes
- Parameters
mesh_to_add (Mesh) – The other mesh instance to add to the current instance
- Returns
The composite mesh
- Return type
Note
This method should not be called as is but it overides the + binary operator for convenience.
- property axis_aligned_bbox¶
Get the axis aligned bounding box of the mesh.
- Returns
(xmin, xmax, ymin, ymax, zmin, zmax)
- Return type
- property boundaries¶
Get the list of boundaries of the mesh.
- Returns
list that stores lists of boundary connected vertices
- Return type
Note
The computation of boundaries should be in the future computed with help of VTK
- eval_plain_mesh_inertias(rho_medium=1023.0)[source]¶
Evaluates the mesh inertia under the assumption of an enclosed volume made of an homogeneous medium of the given density.
- Parameters
rho_medium (float, optional) – The medium density (kg/m**3). Default is 1023 kg.m**3 (salt water)
- Returns
The mesh inertia instance expressed at origin (0, 0, 0)
- Return type
- eval_shell_mesh_inertias(rho_medium=7850.0, thickness=0.02)[source]¶
Evaluates the mesh inertia under the assumption of an enclosed volume made of an homogeneous medium of the given density.
- Parameters
rho_medium (float, optional) – The medium density (kg/m**3). Default is 7850 kg/m**3 (Steel density)
thickness (flaot, optional) – The hull thickness (m). Default is 0.02 m.
- Returns
The mesh inertia instance expressed at origin (0, 0, 0)
- Return type
- extract_faces(id_faces_to_extract, return_index=False)[source]¶
Extracts a new mesh from a selection of faces ids
- property faces¶
Get the faces connectivity array of the mesh
- Returns
- Return type
ndarray
- property faces_areas¶
Get the array of faces areas of the mesh
- Returns
- Return type
ndarray
- property faces_centers¶
Get the array of faces centers of the mesh
- Returns
- Return type
ndarray
- property faces_normals¶
Get the array of faces normals of the mesh
- Returns
- Return type
ndarray
- get_face(face_id)[source]¶
Get the face described by its vertices connectivity
- Parameters
face_id (int) – Face id
- Returns
If the face is a triangle, the array has 3 components, else it has 4 (quadrangle)
- Return type
ndarray
- get_surface_integrals()[source]¶
Get the mesh surface integrals
- Returns
The mesh surface integrals array
- Return type
ndarray
- heal_mesh()[source]¶
Heals the mesh for different tests available.
It applies:
Unused vertices removal
Degenerate faces removal
Duplicate vertices merging
Triangles healing
Normal healing
- heal_normals()[source]¶
Heals the mesh’s normals orientations so that they have a consistent orientation and try to make them outward.
- heal_triangles()[source]¶
Makes the triangle connectivity consistent.
A general face is stored internally as a 4 integer array. It allows to describe indices of a quadrangle’s vertices. For triangles, the first index should be equal to the last. This method ensures that this rule is applied everywhere and correct bad triangles description.
- is_mesh_closed()[source]¶
Returns if the mesh is a closed manifold.
- Returns
True if the mesh is closed (i.e. it has no boundaries)
- Return type
- is_mesh_conformal()[source]¶
Returns if the mesh is conformal.
- Returns
True if the mesh is conformal.
- Return type
Warning
This method is experimental. Use at your own risk !
- property max_edge_length¶
The mesh’s maximum edge length
- property mean_edge_length¶
The mesh’s mean edge length
- merge_duplicates(atol=1e-08, return_index=False)[source]¶
Merges the duplicate vertices of the mesh.
- property min_edge_length¶
The mesh’s minimum edge length
- mirror(plane)[source]¶
Mirrors the mesh instance with respect to a plane.
- Parameters
plane (Plane) – The mirroring plane
- property name¶
Get the name of the mesh
- property nb_boundaries¶
Get the number of boundaries in the mesh
- Returns
Number of boundaries
- Return type
- print_quality()[source]¶
Returns data on the mesh quality
It uses VTK and is reproduced from http://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/Verdict/Testing/Python/MeshQuality.py
- property quadrangles_ids¶
Get the array of ids of qudrangle shaped faces
- Returns
- Return type
ndarray
- quick_save(filename=None)[source]¶
Saves the current mesh instance in a VTK file.
It is mainly for debugging purpose.
- Parameters
filename (str) – If None, the file is automatically saved under the name quick_save.vtp. If the name given does not have a .vtp extension, the latter is appended automatically.
- remove_degenerated_faces(rtol=1e-05)[source]¶
Removes tiny triangles from the mesh.
Tiny triangles are those whose area is lower than the mean triangle area in the mesh times the relative tolerance given.
- Parameters
rtol (float, optional) – Positive relative tolerance
- remove_unused_vertices()[source]¶
Removes unused vertices in the mesh.
Those are vertices that are not used by any face connectivity.
- rotate(angles)[source]¶
Rotates the mesh in 3D giving the 3 rotation angles that are defined around fixed axes.
- Parameters
angles (array_like) – The 3 angles of the 3D rotation (rad)
- Returns
The (3x3) rotation matrix that has been applied to rotate the mesh
- Return type
ndarray
- rotate_x(thetax)[source]¶
Rotates the mesh around Ox axis.
- Parameters
thetax (float) – Angle (rad)
- Returns
The (3x3) rotation matrix that has been applied to rotate the mesh
- Return type
ndarray
- rotate_y(thetay)[source]¶
Rotates the mesh around Oy axis.
- Parameters
thetay (float) – Angle (rad)
- Returns
The (3x3) rotation matrix that has been applied to rotate the mesh
- Return type
ndarray
- rotate_z(thetaz)[source]¶
Rotates the mesh around Oz axis.
- Parameters
thetaz (float) – Angle (rad)
- Returns
The (3x3) rotation matrix that has been applied to rotate the mesh
- Return type
ndarray
- scalex(alpha)[source]¶
Scales the mesh along the x axis.
- Parameters
alpha (float) – A positive scaling factor
- scaley(alpha)[source]¶
Scales the mesh along the y axis.
- Parameters
alpha (float) – A positive scaling factor
- scalez(alpha)[source]¶
Scales the mesh along the z axis.
- Parameters
alpha (float) – A positive scaling factor
- property squared_axis_aligned_bbox¶
Get a squared axis aligned bounding box of the mesh.
- Returns
(xmin, xmax, ymin, ymax, zmin, zmax)
- Return type
Note
This method differs from axis_aligned_bbox() by the fact that the bounding box that is returned is squared but have the same center as the AABB
- symmetrize(plane)[source]¶
Symmetrize the mesh with respect to a plane.
- Parameters
plane (Plane) – The plane of symmetry
- translate(t)[source]¶
Translates the mesh in 3D giving the 3 distances along coordinate axes.
- Parameters
t (array_like) – translation vector
- property triangles_ids¶
Get the array of ids of triangle shaped faces
- Returns
- Return type
ndarray
- triangulate_quadrangles()[source]¶
Triangulates every quadrangles of the mesh by simple spliting.
Each quadrangle gives two triangles.
Note
No checking is made on the triangle quality is done.
- property vertices¶
Get the vertices array coordinate of the mesh
- Returns
- Return type
np.ndarray
- class meshmagick.mesh.Plane(normal=(0.0, 0.0, 1.0), scalar=0.0, name=None)[source]¶
Bases:
object
Class to handle plane geometry.
A plane is represented by the equation \(\vec{n}.\vec{x} = c\) where \(\vec{n}\) is the plane’s normal, \(\vec{x}\) a point in the space and \(c\) a scalar parameter being the signed distance between the reference frame origin and the its otrhogonal projection on the plane.
- Parameters
normal (array_like) – 3 component vector of the plane normal
scalar (float) – The scalar parameter of the plane
- property c¶
Get the plane’s scalar parameter
- coord_in_plane(points)[source]¶
Return the coordinates of points in the frame of the plane
- Parameters
points (ndarray) – Array of points coordinates
- Returns
output – Array of points coordinates in the frame of the plane
- Return type
ndarray
- get_edge_intersection(p0, p1)[source]¶
Returns the coordinates of the intersection point between the plane and the edge P0P1.
- Parameters
p0 (ndarray) – Coordinates of point p0
p1 (ndarray) – Coordinates of point P1
- Returns
I – Coordinates of intersection point
- Return type
ndarray
- get_normal_orientation_wrt_z()[source]¶
Returns the angles theta_x and theta_y giving the orientation of the plane normal
- get_point_dist_wrt_plane(points)[source]¶
Return the orthogonal distance of points with respect to the plane
- Parameters
points (ndarray) – Array of points coordinates
- Returns
dist – Array of distances of points with respect to the plane
- Return type
ndarray
- property normal¶
Get the plane’s normal
- orthogonal_projection_on_plane(points)[source]¶
Returns the coordinates of the orthogonal projection of points
- Parameters
points (ndarray) – Coordinates of the points to be projected
- Returns
projected_points – Coordinates of the projection points
- Return type
ndarray
- rotate_normal(theta_x, theta_y)[source]¶
Rotates the current plane normal by fixed angles theta_x and theta_y.