From f55cdae99a57ce139739aaf787638279cc931ad4 Mon Sep 17 00:00:00 2001 From: Djalim Simaila <DjalimS.pro@outlook.fr> Date: Wed, 19 Apr 2023 13:41:42 +0200 Subject: [PATCH] General progression --- main.py | 9 ++++---- obj.py | 23 +++++++++++++++++++++ outputchecker.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ test.py | 48 ++++++++++++++++++++++++++++++------------- 4 files changed, 115 insertions(+), 18 deletions(-) create mode 100644 obj.py create mode 100644 outputchecker.py diff --git a/main.py b/main.py index 850e6a3..37eb7b1 100644 --- a/main.py +++ b/main.py @@ -22,7 +22,7 @@ def get_raw_data(obj:Object, ndigits:int)->dict: data = {} for colone in colones: data[colone] = [] - for discrete_values in obj.get_discrete_vertices(1): + for discrete_values in obj.get_discrete_vertices(): mean_x ,mean_y, mean_z = utils.get_x_y_z_mean(discrete_values) for x,y,z in discrete_values: data["X (en mm)"].append(round(x, ndigits)) @@ -34,7 +34,7 @@ def get_raw_data(obj:Object, ndigits:int)->dict: data["Yi-Ymoy"].append(round(y-mean_y, ndigits)) return data -def get_discrete_data(obj, ndigits)->dict: +def get_discrete_data(obj:Object, ndigits:int)->dict: """ Calculates data from the given object @@ -51,7 +51,8 @@ def get_discrete_data(obj, ndigits)->dict: data = {} for colone in colones: data[colone] = [] - for discrete_values in obj.get_discrete_vertices(1): + cpt = 0 + for discrete_values in obj.get_discrete_vertices(): x,y,z = utils.get_x_y_z_mean(discrete_values) data["X moy (en mm)"].append(round(x, ndigits)) data["Y moy (en mm)"].append(round(y, ndigits)) @@ -63,7 +64,7 @@ def get_discrete_data(obj, ndigits)->dict: def main(): # Create an object from the given file - obj = parsers.parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised='z') + obj = parsers.parse_xyz_file("test_cylindre.xyz",normalised='z') # Calculate raw data and save it in a file data = get_raw_data(obj, 6) diff --git a/obj.py b/obj.py new file mode 100644 index 0000000..eaafdbe --- /dev/null +++ b/obj.py @@ -0,0 +1,23 @@ +import random +import math + +def circle_points(r, cx, cy): + cpt = 0 + angles = [] + while cpt < 2*math.pi: + angles.append(cpt) + cpt += 1/6*math.pi + return [[round(r * math.cos(angle) + cx,6), round(r * math.sin(angle) + cy,6)] for angle in angles] + +cylindre = [] +for i in range(10): + points = circle_points(random.randint(2,20),5,5) + for point in points: + point.append(i) + cylindre.append(points) + +with open("test_cylindre.xyz",'w') as f: + for couches in cylindre: + for points in couches: + x,y,z = points[0],points[1],points[2] + f.write(f"{x} {y} {z}\n") diff --git a/outputchecker.py b/outputchecker.py new file mode 100644 index 0000000..717819b --- /dev/null +++ b/outputchecker.py @@ -0,0 +1,53 @@ +from utils.files.parsers import parse_obj_file, parse_xyz_file +import numpy as np + +def parse_result_file(file_path): + lines = [] + x,y,z = [],[],[] + with open(file_path, "r") as f: + lines = f.readlines()[1:] + for line in lines: + line = line.replace(",", ".") + values = line.split("\t") + x.append(float(values[0])) + y.append(float(values[1])) + z.append(float(values[2])) + return x,y,z + +def verifier_coherance(): + obj = parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised='z') + obj.export("verification.txt") + #obj = parse_xyz_file("datasets/Barette/4 - BARETTE v1.xyz",normalised='') + cpt = 0 + L = [] + moyx, moyy, moyz = parse_result_file("datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt") + print(len(moyx),len(moyy),len(moyz)) + moy = moyx + verticies = obj.get_vertices(sort=True) + position = 0 + while position < len(verticies) and len(moy) > 0: + x = verticies[position][0] + y = verticies[position][1] + z = verticies[position][2] + L.append(x) + m = np.mean(L) + print(f"searching for {moy[0]}, currently at {position}",end="\r") + if abs(m - moy[0]) < 0.000001: + moy.pop(0) + L = [] + copyposition = position + if int(verticies[copyposition][2]) >= int(verticies[copyposition+1][2]): + while int(verticies[copyposition][2]) == int(verticies[copyposition-1][2]): + copyposition -= 1 + """ + if verticies[position][2] - verticies[copyposition][2] > 1: + copyposition = position + 1 + break + """ + # Position +1 pour l'allignement des indices avec le numero de ligne + # Position - copyposition + 1 car on se deplace seulement si, la condition est fasse aka, on bouge pas si on est aussi de la ou on doit etre + print("index :",position,"|should have stoped :",position - copyposition + 1,"position higher| Z difference :",verticies[position][2] - verticies[copyposition-1][2]) + position += 1 + +if __name__ == "__main__": + verifier_coherance() \ No newline at end of file diff --git a/test.py b/test.py index 9c93d1b..ec276e3 100644 --- a/test.py +++ b/test.py @@ -1,17 +1,16 @@ +import numpy as np from main import get_raw_data, get_discrete_data from utils.files.file_data import Object from utils.files.output import save_output_file, format_data -from utils.files.parsers import parse_obj_file +from utils.files.parsers import parse_obj_file, parse_xyz_file from integration_tests import data_test import time - import os -def test_get_raw_data(obj_path:Object,expected_file:str, ndigits:int = 6, eps:float = 0.0001): +def test_get_raw_data(obj:Object, expected_file:str, ndigits:int = 6, eps:float = 0.0001): """ Test the get_raw_data function """ - obj = parse_obj_file(obj_path,normalised='z') # Calculate raw data and save it in a file now = time.time() @@ -22,11 +21,10 @@ def test_get_raw_data(obj_path:Object,expected_file:str, ndigits:int = 6, eps:fl data_test.check_raw_data(expected_file, 'tmp_analyse_brute.txt', ndigits, eps) os.remove('tmp_analyse_brute.txt') -def test_get_discrete_data(obj_path:Object,expected_file:str, ndigits:int = 6, eps:float = 0.0001): +def test_get_discrete_data(obj: Object,expected_file:str, ndigits:int = 6, eps:float = 0.0001): """ Test the get_discrete_data function """ - obj = parse_obj_file(obj_path,normalised='z') # Calculate discrete data and save it in a file now = time.time() @@ -37,14 +35,36 @@ def test_get_discrete_data(obj_path:Object,expected_file:str, ndigits:int = 6, e data_test.check_discrete_data(expected_file, 'tmp_analyse_discrete.txt', ndigits, eps) os.remove('tmp_analyse_discrete.txt') +def test(): + eps = 0.000001 -if __name__ == '__main__': - eps = 0.0001 - - #obj = ("datasets/Barette/3 - BARETTE v1.obj","datasets/Barette/BARETTE_Delta 1,0_analyse brute.txt","datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt") - obj = ("datasets/Cylindre/3 - CYLINDRE v1.obj","datasets/Cylindre/Cylindre_Delta 1,0_analyse brute.txt","datasets/Cylindre/Cylindre_Delta 1,0_analyse rayon.txt") - #obj = ("datasets/Echantillon/3 - KA50HN50_98% fusion v1.obj","datasets/Echantillon/30-03-2023_Delta 1,0_analyse brute.txt","datasets/Echantillon/30-03-2023_Delta 1,0_analyse rayon.txt") + #obj = parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised='z') + #obj = parse_xyz_file("datasets/Barette/4 - BARETTE v1.xyz",normalised='z') + obj = parse_xyz_file("datasets/Barette/4 - BARETTE v1.xyz","datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt",normalised='z') - test_get_raw_data(obj[0],obj[1],eps=eps) + test_get_raw_data(obj, + "datasets/Barette/BARETTE_Delta 1,0_analyse brute.txt", + eps=eps) - test_get_discrete_data(obj[0],obj[2],eps=eps) \ No newline at end of file + test_get_discrete_data(obj, + "datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt", + eps=eps) + +def show_diff_between_obj_and_xyz(): + obj1 = parse_obj_file("datasets/Barette/3 - BARETTE v1.obj",normalised='z') + obj2 = parse_xyz_file("datasets/Barette/4 - BARETTE v1.xyz",normalised='z') + obj2verts = obj2.get_vertices(sort=True) + for count, values in enumerate(obj1.get_vertices(sort=True)): + L = [abs(values[i] - obj2verts[count][i]) for i in range(len(values))] + print(*L,sep="\t") + + +def count_elements_in_discrete_array(): + obj = parse_xyz_file("datasets/Barette/4 - BARETTE v1.xyz","datasets/Barette/BARETTE_Delta 1,0_analyse rayon.txt",normalised='z') + cpt = 0 + for i in obj.bruteforce_discretization(): + print(f"nb of element in z{cpt} to z{cpt+1}:",len(i)) + cpt += 1 + +if __name__ == "__main__": + test() \ No newline at end of file -- GitLab