diff --git a/main.py b/main.py index f2b288a18eec2e0691b881555c112af141caeac7..68097d37cc63103781f4bf78cebcfa060f57b8e7 100644 --- a/main.py +++ b/main.py @@ -20,10 +20,10 @@ def get_raw_data(obj:ScannedObject, ndigits:int, delta_z:int = 1)->dict: - Xi-Xmoy : list of Xi-Xmoy values - Yi-Ymoy : list of Yi-Ymoy values """ - colones = ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"] + columns = ["X (en mm)", "Y (en mm)", "Z (en mm)", "teta (en rad)", "rayon (en mm)","Xi-Xmoy","Yi-Ymoy"] data = {} - for colone in colones: - data[colone] = [] + for column in columns: + data[column] = [] for discrete_values in obj.get_discrete_vertices(delta_z): mean_x ,mean_y, mean_z = data_extraction.get_x_y_z_mean(discrete_values) for x,y,z in discrete_values: @@ -49,10 +49,10 @@ def get_discrete_data(obj:ScannedObject, ndigits:int,delta_z:int= 1)->dict: - Rayon moyen (en mm) : list of mean radius values - Rayon ecart type (en mm) : list of radius standard deviation values """ - colones = ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Delta z(en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"] + columns = ["X moy (en mm)", "Y moy (en mm)", "Z moy (en mm)","Delta z(en mm)","Rayon moyen (en mm)","Rayon ecart type (en mm)"] data = {} - for colone in colones: - data[colone] = [] + for column in columns: + data[column] = [] for discrete_values in obj.get_discrete_vertices(delta_z): x,y,z = data_extraction.get_x_y_z_mean(discrete_values) data["X moy (en mm)"].append(round(x, ndigits)) diff --git a/utils/files/input.py b/utils/files/input.py index 94412c881209295a6bbee935cdc30d2e3aad5199..bc6fd244808c3c21aef827e0cd7388b61b061991 100644 --- a/utils/files/input.py +++ b/utils/files/input.py @@ -19,9 +19,16 @@ class ScannedObject: """ This class is used to manage the data of the 3D object. - :param vertices: List of vertices - :param faces: List of faces + :param vertices: List of verticesm Ndarray of shape (n,2) + :param faces: List of faces, Ndarray of shape (n,2) :param result_file_path: Path to the result file (deprecated, used for the bruteforce discretization) + + :ivar vertices: List of vertices, Ndarray of shape (n,2) + :ivar faces: List of faces, Ndarray of shape (n,2) + :ivar result_file_path: Path to the result file (deprecated, used for the bruteforce discretization) + :ivar x: List of x values of the vertices + :ivar y: List of y values of the vertices + :ivar z: List of z values of the vertices :static method from_xyz_file(): Creates a ScannedObject from a .xyz file :static method from_obj_file(): Creates a ScannedObject from a .obj file diff --git a/utils/graph2D/mpl_render.py b/utils/graph2D/mpl_render.py index dd6450fdbce88f7b364018ffe93634e86ac9cda1..9f78215a20cd1f9a7aa8f562d1fe8e6ca42c302e 100644 --- a/utils/graph2D/mpl_render.py +++ b/utils/graph2D/mpl_render.py @@ -10,12 +10,13 @@ def render2D(values:list): ax.plot(values) plt.show() -def cross_section(x:list,y:list): +def cross_section(x_values:list, y_values:list): """ - Render a 2D model using matplotlib - :param values: A list with the values + Render a 2D cross section using matplotlib + :param x: A list with the x values + :param y: A list with the y values """ fig = plt.figure() ax = fig.add_subplot() - ax.scatter(x,y) + ax.scatter(x_values,y_values) plt.show() \ No newline at end of file diff --git a/utils/graph2D/visplot_render.py b/utils/graph2D/visplot_render.py index 81e2c2248d5e3e53649f5ca3655cb310449a2672..31925ab063e575d04d305f62f8b30c138b3e3bfe 100644 --- a/utils/graph2D/visplot_render.py +++ b/utils/graph2D/visplot_render.py @@ -2,6 +2,10 @@ import vispy.plot as vp import numpy as np def render2D(values:list): + """ + Render a 2D plot using vispy + :param values: A list with the values + """ fig = vp.Fig(size=(600, 500), show=False) plotwidget = fig[0, 0] fig.title = "bollu" @@ -9,10 +13,15 @@ def render2D(values:list): plotwidget.colorbar(position="top", cmap="autumn") fig.show(run=True) -def cross_section(x:list,y:list): +def cross_section(x_values:list, y_values:list): + """ + Render a 2D cross section using vispy + :param x: A list with the x values + :param y: A list with the y values + """ color = (0.3, 0.5, 0.8) fig = vp.Fig(show=False) - line = fig[0:4, 0:4].plot(np.column_stack((x,y)), symbol='o', width=0, + line = fig[0:4, 0:4].plot(np.column_stack((x_values,y_values)), symbol='o', width=0, face_color=color + (0.02,), edge_color=None, marker_size=8) line.set_gl_state(depth_test=False) diff --git a/utils/graph3D/mpl_render.py b/utils/graph3D/mpl_render.py index c4757fe36e03a2d20fa218cff61b668960bfcdda..1e2e32f50b3e372b59e0a0e8ec85f5cb50a63208 100644 --- a/utils/graph3D/mpl_render.py +++ b/utils/graph3D/mpl_render.py @@ -5,8 +5,8 @@ from utils.files.input import ScannedObject def render3D(obj:ScannedObject): """ - Render a 3D model using matplotlib poly3dcollection - :param data: A dict with the vertices and faces + Render a 3D model using matplotlib's Poly3dcollection + :param obj: A ScannedObject to be rendered """ fig = plt.figure() ax = fig.add_subplot(projection='3d') diff --git a/utils/graph3D/visplot_render.py b/utils/graph3D/visplot_render.py index 9392ee9a5ce93f73dbecd9a75240cbbc3396bc5a..2dccf7f72462fd9576fbaee03a284daf982f8d3c 100644 --- a/utils/graph3D/visplot_render.py +++ b/utils/graph3D/visplot_render.py @@ -6,6 +6,10 @@ from utils.files.input import ScannedObject def render3D(obj:ScannedObject): + """ + Render a 3D model using vispy + :param obj: A ScannedObject to be rendered + """ vertices = np.asarray(obj.get_vertices()) faces = np.asarray(obj.get_faces()) canvas = scene.SceneCanvas(keys='interactive', bgcolor='white') diff --git a/utils/math/position_manipulation.py b/utils/math/position_manipulation.py index 53af77c58c384a20cf78291f9daf687b8b451734..94055f366d2945d98da95b77b9696705d9eaac6a 100644 --- a/utils/math/position_manipulation.py +++ b/utils/math/position_manipulation.py @@ -3,15 +3,19 @@ from utils.files.input import ScannedObject from utils.math.data_extraction import get_mean -def get_mass_properties(obj:ScannedObject): +def get_mass_properties(obj:ScannedObject)->tuple: ''' Evaluate and return a tuple with the following elements: - the volume - the position of the center of gravity (COG) - the inertia matrix expressed at the COG + :param obj: Object to analyse + :return: tuple(float, numpy.array, numpy.array) + + From numpy-stl:(https://pypi.org/project/numpy-stl/) + Documentation can be found here: + http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf - Documentation can be found here: - http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf ''' verts = np.asarray(obj.get_vertices()) @@ -66,6 +70,10 @@ def get_mass_properties(obj:ScannedObject): return volume, cog, inertia def verticalise(obj:ScannedObject): + """ + Rotate the object so that the principal axis of inertia is vertical + :param obj: Object to analyse + """ cog = get_mass_properties(obj) cog, inertia = get_mass_properties(obj)[1:] [val,vect] = np.linalg.eig(inertia)