added core functionnalities
This commit is contained in:
parent
b5186aabed
commit
ecccb0f8cb
1
.gitignore
vendored
1
.gitignore
vendored
@ -161,3 +161,4 @@ cython_debug/
|
||||
#.idea/
|
||||
|
||||
*.DS_Store
|
||||
.vscode
|
||||
|
@ -1,4 +1,4 @@
|
||||
X (mm) Y (mm) Z (mm) téta (radian) rayon (mm) (xi-xmoy) (yi-ymoy)
|
||||
X (mm) Y (mm) Z (mm) teta (radian) rayon (mm) (xi-xmoy) (yi-ymoy)
|
||||
3,682017 -1,419335 0,000000 1,545182 11,430734 -11,426985 -0,292755
|
||||
3,643013 -1,418564 0,008820 1,545337 11,469706 -11,465989 -0,291984
|
||||
22,829306 -0,698036 0,009224 1,515344 7,732189 7,720304 0,428544
|
||||
|
@ -1,4 +1,4 @@
|
||||
Xmoy (mm) Ymoy (mm) Zmoy (mm) rayon moyen (mm) rayon écart type (mm)
|
||||
Xmoy (mm) Ymoy (mm) Zmoy (mm) rayon moyen (mm) rayon ecart type (mm)
|
||||
15,109002 -1,126580 0,525629 6,530663 3,607419
|
||||
14,759011 -1,362535 1,507908 6,832951 3,816242
|
||||
14,399647 -1,876646 2,519127 7,203922 3,839974
|
||||
|
5
main.py
5
main.py
@ -1,3 +1,8 @@
|
||||
from utils.math import utils
|
||||
from utils.files import file_data
|
||||
from utils.files import output
|
||||
from utils.files import parsers
|
||||
|
||||
def main():
|
||||
pass
|
||||
|
||||
|
120867
output.txt
Normal file
120867
output.txt
Normal file
File diff suppressed because it is too large
Load Diff
80
utils/files/file_data.py
Normal file
80
utils/files/file_data.py
Normal file
@ -0,0 +1,80 @@
|
||||
"""
|
||||
This module contains the File class.
|
||||
"""
|
||||
class FaceNotGiven(Exception):
|
||||
"""
|
||||
Exception raised when no faces was given.
|
||||
"""
|
||||
|
||||
class Object:
|
||||
"""
|
||||
This class is used to manage the data of the 3D object.
|
||||
"""
|
||||
def __init__(self, vertices, faces=None):
|
||||
self.vertices = vertices
|
||||
self.faces = faces
|
||||
self.x = [vertex[0] for vertex in vertices]
|
||||
self.y = [vertex[1] for vertex in vertices]
|
||||
self.z = [vertex[2] for vertex in vertices]
|
||||
|
||||
def get_x(self)->list:
|
||||
"""
|
||||
Get the x coordinates of the object.
|
||||
return: x coordinates
|
||||
"""
|
||||
return self.x
|
||||
|
||||
def get_y(self)->list:
|
||||
"""
|
||||
Get the y coordinates of the object.
|
||||
return: y coordinates
|
||||
"""
|
||||
return self.y
|
||||
|
||||
def get_z(self)->list:
|
||||
"""
|
||||
Get the z coordinates of the object.
|
||||
return: z coordinates
|
||||
"""
|
||||
return self.z
|
||||
|
||||
def get_vertices(self, sort:bool = False):
|
||||
"""
|
||||
Get the vertices of the object.
|
||||
:param sort: Sort the vertices by z coordinate
|
||||
:return: vertices
|
||||
"""
|
||||
vertices = self.vertices if not sort else sorted(self.vertices, key=lambda vertex: vertex[2])
|
||||
return vertices
|
||||
|
||||
def get_discrete_vertices(self, step:float = 0.1):
|
||||
"""
|
||||
Discretize the vertices of the object.
|
||||
:param step: Step of the discretization
|
||||
:return: Discretized vertices
|
||||
"""
|
||||
current_interval = int(min(self.get_z()))
|
||||
splitted_data = [[]]
|
||||
for line in self.get_vertices(sort=True):
|
||||
# TODO check distance instead of equality
|
||||
if line[2] >= current_interval:
|
||||
splitted_data.append([])
|
||||
current_interval += step
|
||||
splitted_data[-1].append(line)
|
||||
return splitted_data
|
||||
|
||||
def get_faces(self)->list:
|
||||
"""
|
||||
Get the faces of the object.
|
||||
:return: faces
|
||||
"""
|
||||
if self.faces is None:
|
||||
raise FaceNotGiven('No faces was given')
|
||||
return self.faces
|
||||
|
||||
def get_data(self)->dict:
|
||||
"""
|
||||
Get the data of the object.
|
||||
:return: Data of the object
|
||||
"""
|
||||
return {'verticies': self.vertices, 'faces': self.faces, 'x': self.x, 'y': self.y, 'z': self.z}
|
13
utils/files/output.py
Normal file
13
utils/files/output.py
Normal file
@ -0,0 +1,13 @@
|
||||
"""
|
||||
This module is used to manage the output files of the program.
|
||||
"""
|
||||
|
||||
def save_output_file(output_file:str, content:str):
|
||||
"""
|
||||
Save the output file.
|
||||
|
||||
:param output_file: Path to the output file
|
||||
:param content: Content of the output file
|
||||
"""
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(content)
|
@ -1,4 +1,9 @@
|
||||
def parseOBJfiles(filePath:str,ratio:float = 1,cornered:bool = False)->dict:
|
||||
"""
|
||||
This module contains functions to parse files.
|
||||
"""
|
||||
from utils.files.file_data import Object
|
||||
|
||||
def parse_obj_files(file_path:str,ratio:float = 1,normalised:bool = False)->Object:
|
||||
"""
|
||||
Parse an OBJ file and return a dict with the vertices and faces
|
||||
|
||||
@ -7,7 +12,7 @@ def parseOBJfiles(filePath:str,ratio:float = 1,cornered:bool = False)->dict:
|
||||
:param cornered: If True, the vertices will be cornered
|
||||
:return: A dict with the vertices and faces
|
||||
"""
|
||||
with open(filePath, 'r') as f:
|
||||
with open(file_path, 'r') as f:
|
||||
x, y, z = [], [], []
|
||||
triangles = []
|
||||
data = f.readlines()
|
||||
@ -19,19 +24,24 @@ def parseOBJfiles(filePath:str,ratio:float = 1,cornered:bool = False)->dict:
|
||||
x.append(float(line.split()[1]) * ratio)
|
||||
y.append(float(line.split()[2]) * ratio)
|
||||
z.append(float(line.split()[3]) * ratio)
|
||||
if cornered:
|
||||
if normalised:
|
||||
"""
|
||||
xmin = min(x)
|
||||
for i in range(len(x)):
|
||||
x[i] -= xmin
|
||||
ymin = min(y)
|
||||
for i in range(len(y)):
|
||||
y[i] -= ymin
|
||||
zmin = min(z)
|
||||
for i in range(len(z)):
|
||||
z[i] -= zmin
|
||||
return {'x':x, 'y':y, 'z':z, 'faces':triangles, "verticies": zip(x,y,z)}
|
||||
for count, value in enumerate(x):
|
||||
x[count] -= xmin
|
||||
|
||||
def parseXYZfiles(filePath: str, delimiter: str = ' ') -> dict:
|
||||
ymin = min(y)
|
||||
for count, value in enumerate(y):
|
||||
y[count] -= ymin
|
||||
"""
|
||||
|
||||
zmin = min(z)
|
||||
for count, value in enumerate(z):
|
||||
z[count] -= zmin
|
||||
|
||||
return Object(list(zip(x,y,z)), triangles)
|
||||
|
||||
def parse_xyz_files(file_path: str, delimiter: str = ' ') -> dict:
|
||||
"""
|
||||
Parses an xyz file and returns a dict containing the coordinates.
|
||||
|
||||
@ -40,9 +50,9 @@ def parseXYZfiles(filePath: str, delimiter: str = ' ') -> dict:
|
||||
:return: A dictionary containing the coordinates.
|
||||
"""
|
||||
x , y , z = [], [], []
|
||||
with open(filePath, 'r') as f:
|
||||
with open(file_path, 'r') as f:
|
||||
data = f.readlines()
|
||||
x = [float(line.split(delimiter)[0]) for line in data]
|
||||
y = [float(line.split(delimiter)[1]) for line in data]
|
||||
z = [float(line.split(delimiter)[2]) for line in data]
|
||||
return {'x':x, 'y':y, 'z':z, "verticies": zip(x,y,z)}
|
||||
return Object(zip(x,y,z))
|
49
utils/math/utils.py
Normal file
49
utils/math/utils.py
Normal file
@ -0,0 +1,49 @@
|
||||
"""
|
||||
This module contains some utility functions for math operations.
|
||||
"""
|
||||
import numpy as np
|
||||
|
||||
def get_mean(values:list):
|
||||
"""
|
||||
Get the mean of the values.
|
||||
"""
|
||||
return np.mean(values)
|
||||
|
||||
|
||||
def get_x_y_mean(discrete_values:list):
|
||||
"""
|
||||
Get the mean of the x and y coordinates in the discrete range.
|
||||
|
||||
:param x: x coordinates
|
||||
:param y: y coordinates
|
||||
:return: mean of x and y coordinates in the discrete range
|
||||
"""
|
||||
x = [vertex[0] for vertex in discrete_values]
|
||||
y = [vertex[1] for vertex in discrete_values]
|
||||
z = [vertex[2] for vertex in discrete_values]
|
||||
return get_mean(x), get_mean(y), get_mean(z)
|
||||
|
||||
def get_radius_from_x_y(xi:float, yi:float, x_mean:float, y_mean:float):
|
||||
"""
|
||||
Get the radius from the x and y coordinates.
|
||||
|
||||
:param xi: x coordinate
|
||||
:param yi: y coordinate
|
||||
:param x_mean: mean of x coordinates in the discrete range
|
||||
:param y_mean: mean of y coordinates in the discrete range
|
||||
:return: radius for this point
|
||||
"""
|
||||
return np.sqrt((xi - x_mean) ** 2 + (yi - y_mean) ** 2)
|
||||
|
||||
|
||||
def get_teta_from_x_y(xi:float, yi:float, x_mean:float, y_mean:float):
|
||||
"""
|
||||
Get the teta from the x and y coordinates.
|
||||
|
||||
:param xi: x coordinate
|
||||
:param yi: y coordinate
|
||||
:param x_mean: mean of x coordinates in the discrete range
|
||||
:param y_mean: mean of y coordinates in the discrete range
|
||||
:return: teta for this point
|
||||
"""
|
||||
return np.arctan2((xi - x_mean)/(yi - y_mean))
|
Loading…
Reference in New Issue
Block a user