From 38ab59bd51468a98e590ac659766c4952503896c Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 08:46:14 +0100 Subject: [PATCH 1/9] docs: add docs and function in the readme --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 02c25d60..02611b5c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,23 @@ Pink Lady is a photogrammetric conversion and acquisition program in .OPK format ### HTML documentation +Call the function in a terminal located in the directory of the pink_lady.py file. The command to run the function is: + +```python pink_lady.py``` + +Then add the parameters: + +| Symbol | Details | +| :----: | :------ | +| -f | File path of the workfile | +| -skip | Number of lines to be skipped before reading the file (optional) | +| -w | Worksite output file format ex:opk | +| -pr | Conversion path ex:test/tmp/ | +| -c | Files paths of cameras (xml or txt) | +| -cp | Files paths of connecting points (.mes) | + +Some settings are optional, depending on what you want to do with Pink Lady. + Html documentation in docs/_build/html/index.hmlt ### Functionality @@ -23,4 +40,5 @@ Html documentation in docs/_build/html/index.hmlt Structure file in reader folder: - name : reader_ext.py - function : def read(file: str) -> Worksite: -3. Reading a camera file (XML and txt) \ No newline at end of file +3. Reading a camera file (XML and txt) +4. Reading connecting point (mes) From 0cbf12fc2605757f5c2a5d2373f2e286280572f5 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 09:20:47 +0100 Subject: [PATCH 2/9] test: add data and update reader test --- test/data/23FD1305_alt_test.opk | 8 ++++ test/data/Sommets_hEllips_test.opk | 9 ---- test/data/all_liaisons.mes | 16 +++++++ test/test_reader.py | 68 +++++++++++++++--------------- 4 files changed, 58 insertions(+), 43 deletions(-) create mode 100644 test/data/23FD1305_alt_test.opk delete mode 100644 test/data/Sommets_hEllips_test.opk create mode 100644 test/data/all_liaisons.mes diff --git a/test/data/23FD1305_alt_test.opk b/test/data/23FD1305_alt_test.opk new file mode 100644 index 00000000..63f7e56c --- /dev/null +++ b/test/data/23FD1305_alt_test.opk @@ -0,0 +1,8 @@ +NOM X Y Z O P K CAMERA +23FD1305x00001_00003 798744.352 6262815.867 1778.451 0.157339710405 0.010129647126 -179.310680057325 UCE-M3-f120-s06 +23FD1305x00001_00006 798737.149 6263570.633 1782.000 0.187951173579 0.039073325314 -179.509133420814 UCE-M3-f120-s06 +23FD1305x00001_00004 798742.042 6263068.069 1779.315 0.185389354595 -0.088005488480 -179.006412492050 UCE-M3-f120-s06 +23FD1305x00001_00005 798739.554 6263319.299 1780.646 0.153027158586 -0.024264408666 -178.940489336420 UCE-M3-f120-s06 +23FD1305x00002_00051 799392.857 6263556.121 1786.084 -0.162274655063 -0.006532875903 0.008930227247 UCE-M3-f120-s06 +23FD1305x00002_00052 799390.337 6263304.421 1785.387 -0.189190287804 -0.021924060777 -0.097707634605 UCE-M3-f120-s06 +23FD1305x00002_00053 799387.667 6263051.508 1784.760 -0.146630494647 -0.031919390293 -0.209336104979 UCE-M3-f120-s06 diff --git a/test/data/Sommets_hEllips_test.opk b/test/data/Sommets_hEllips_test.opk deleted file mode 100644 index f7f84a87..00000000 --- a/test/data/Sommets_hEllips_test.opk +++ /dev/null @@ -1,9 +0,0 @@ -NOM X Y Z O P K CAMERA -22FD2405Ax00001_21104 546166.732 6504508.606 2081.626 -0.2015 -0.1173 61.0088 UCE-M3-f120-s06 -22FD2405Ax00001_21105 546359.919 6504400.573 2081.721 -0.1052 -0.1385 61.6629 UCE-M3-f120-s06 -22FD2405Ax00001_21106 546553.961 6504293.711 2081.811 -0.1181 -0.1348 61.8562 UCE-M3-f120-s06 -22FD2405Ax00001_21107 546748.147 6504188.309 2082.113 -0.0185 -0.1981 61.8381 UCE-M3-f120-s06 -22FD2405Ax00002_21118 548355.107 6502708.860 2083.366 0.0784 0.1049 -117.3728 UCE-M3-f120-s06 -22FD2405Ax00002_21119 548167.181 6502808.520 2082.653 0.1162 0.1425 -117.8557 UCE-M3-f120-s06 -22FD2405Ax00002_21120 547978.503 6502909.867 2081.699 0.1309 0.1431 -118.0644 UCE-M3-f120-s06 -22FD2405Ax00002_21121 547789.766 6503011.873 2080.564 0.1471 0.0971 -118.1551 UCE-M3-f120-s06 diff --git a/test/data/all_liaisons.mes b/test/data/all_liaisons.mes new file mode 100644 index 00000000..62fa424e --- /dev/null +++ b/test/data/all_liaisons.mes @@ -0,0 +1,16 @@ + +MES_0 23FD1305x00001_00003 4763.57 16960.5 +MES_0 23FD1305x00001_00004 4813.98 12509.25 +MES_1 23FD1305x00001_00003 6818.89 16625.93 +MES_1 23FD1305x00001_00004 6869.3 12187.65 +MES_1 23FD1305x00001_00005 6868.28 7823.23 +MES_1 23FD1305x00001_00006 6823.71 3492.24 +MES_1 23FD1305x00002_00051 8217.11 12998.83 +MES_1 23FD1305x00002_00052 8249.45 8627.46 +MES_1 23FD1305x00002_00053 8270.79 4265.72 +MES_2 23FD1305x00001_00003 6165.08 16873.72 +MES_2 23FD1305x00001_00005 6213.53 8058.22 +MES_2 23FD1305x00001_00006 6171.35 3729.29 +MES_2 23FD1305x00002_00051 8854.52 12756.99 +MES_2 23FD1305x00002_00052 8887.0 8380.0 +MES_2 23FD1305x00002_00053 8908.58 4012.49 \ No newline at end of file diff --git a/test/test_reader.py b/test/test_reader.py index 668ac287..6cdb110f 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -8,47 +8,47 @@ def test_reader_opk(): - obj = read_opk("test/data/Sommets_hEllips_test.opk", None) - assert obj.name == "Sommets_hEllips_test" - assert obj.shots[0].name_shot == "22FD2405Ax00001_21104" - assert obj.shots[0].pos_shot[0] == 546166.732 - assert obj.shots[0].pos_shot[1] == 6504508.606 - assert obj.shots[0].pos_shot[2] == 2081.626 - assert obj.shots[0].ori_shot[0] == -0.2015 - assert obj.shots[0].ori_shot[1] == -0.1173 - assert obj.shots[0].ori_shot[2] == 61.0088 + obj = read_opk("test/data/23FD1305_alt_test.opk", None) + assert obj.name == "23FD1305_alt_test" + assert obj.shots[0].name_shot == "23FD1305x00001_00003" + assert obj.shots[0].pos_shot[0] == 798744.352 + assert obj.shots[0].pos_shot[1] == 6262815.867 + assert obj.shots[0].pos_shot[2] == 1778.451 + assert obj.shots[0].ori_shot[0] == 0.157339710405 + assert obj.shots[0].ori_shot[1] == 0.010129647126 + assert obj.shots[0].ori_shot[2] == -179.310680057325 assert obj.shots[0].name_cam == "UCE-M3-f120-s06" - assert obj.shots[-1].name_shot == "22FD2405Ax00002_21121" - assert obj.shots[-1].pos_shot[0] == 547789.766 - assert obj.shots[-1].pos_shot[1] == 6503011.873 - assert obj.shots[-1].pos_shot[2] == 2080.564 - assert obj.shots[-1].ori_shot[0] == 0.1471 - assert obj.shots[-1].ori_shot[1] == 0.0971 - assert obj.shots[-1].ori_shot[2] == -118.1551 + assert obj.shots[-1].name_shot == "23FD1305x00002_00053" + assert obj.shots[-1].pos_shot[0] == 799387.667 + assert obj.shots[-1].pos_shot[1] == 6263051.508 + assert obj.shots[-1].pos_shot[2] == 1784.760 + assert obj.shots[-1].ori_shot[0] == -0.146630494647 + assert obj.shots[-1].ori_shot[1] == -0.031919390293 + assert obj.shots[-1].ori_shot[2] == -0.209336104979 assert obj.shots[-1].name_cam == "UCE-M3-f120-s06" - assert len(obj.shots) == 8 + assert len(obj.shots) == 7 def test_reader_file(): - obj = reader_orientation("test/data/Sommets_hEllips_test.opk") - assert obj.name == "Sommets_hEllips_test" - assert obj.shots[0].name_shot == "22FD2405Ax00001_21104" - assert obj.shots[0].pos_shot[0] == 546166.732 - assert obj.shots[0].pos_shot[1] == 6504508.606 - assert obj.shots[0].pos_shot[2] == 2081.626 - assert obj.shots[0].ori_shot[0] == -0.2015 - assert obj.shots[0].ori_shot[1] == -0.1173 - assert obj.shots[0].ori_shot[2] == 61.0088 + obj = reader_orientation("test/data/23FD1305_alt_test.opk") + assert obj.name == "23FD1305_alt_test" + assert obj.shots[0].name_shot == "23FD1305x00001_00003" + assert obj.shots[0].pos_shot[0] == 798744.352 + assert obj.shots[0].pos_shot[1] == 6262815.867 + assert obj.shots[0].pos_shot[2] == 1778.451 + assert obj.shots[0].ori_shot[0] == 0.157339710405 + assert obj.shots[0].ori_shot[1] == 0.010129647126 + assert obj.shots[0].ori_shot[2] == -179.310680057325 assert obj.shots[0].name_cam == "UCE-M3-f120-s06" - assert obj.shots[-1].name_shot == "22FD2405Ax00002_21121" - assert obj.shots[-1].pos_shot[0] == 547789.766 - assert obj.shots[-1].pos_shot[1] == 6503011.873 - assert obj.shots[-1].pos_shot[2] == 2080.564 - assert obj.shots[-1].ori_shot[0] == 0.1471 - assert obj.shots[-1].ori_shot[1] == 0.0971 - assert obj.shots[-1].ori_shot[2] == -118.1551 + assert obj.shots[-1].name_shot == "23FD1305x00002_00053" + assert obj.shots[-1].pos_shot[0] == 799387.667 + assert obj.shots[-1].pos_shot[1] == 6263051.508 + assert obj.shots[-1].pos_shot[2] == 1784.760 + assert obj.shots[-1].ori_shot[0] == -0.146630494647 + assert obj.shots[-1].ori_shot[1] == -0.031919390293 + assert obj.shots[-1].ori_shot[2] == -0.209336104979 assert obj.shots[-1].name_cam == "UCE-M3-f120-s06" - assert len(obj.shots) == 8 + assert len(obj.shots) == 7 def test_read_camera_xml(): From b738b0a75ccbb073a3811ba49e78cbbe2f37b479 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 10:03:38 +0100 Subject: [PATCH 3/9] build: change structure reader_camera and add reader_copoints --- src/reader/{camera => }/reader_camera.py | 0 src/reader/{camera/__init__.py => reader_copoints.py} | 0 test/test_reader.py | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename src/reader/{camera => }/reader_camera.py (100%) rename src/reader/{camera/__init__.py => reader_copoints.py} (100%) diff --git a/src/reader/camera/reader_camera.py b/src/reader/reader_camera.py similarity index 100% rename from src/reader/camera/reader_camera.py rename to src/reader/reader_camera.py diff --git a/src/reader/camera/__init__.py b/src/reader/reader_copoints.py similarity index 100% rename from src/reader/camera/__init__.py rename to src/reader/reader_copoints.py diff --git a/test/test_reader.py b/test/test_reader.py index 6cdb110f..7db17521 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -3,7 +3,7 @@ """ from src.reader.orientation.manage_reader import reader_orientation from src.reader.orientation.reader_opk import read as read_opk -from src.reader.camera.reader_camera import read_camera, camera_txt, camera_xml +from src.reader.reader_camera import read_camera, camera_txt, camera_xml from src.datastruct.worksite import Worksite From bfe1b02faa01874eeac56239aa84fb1dd0705fb2 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 10:04:44 +0100 Subject: [PATCH 4/9] build: add new functionality copoints reader in pink_lady --- pink_lady.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pink_lady.py b/pink_lady.py index 7e84d95e..2a63dadb 100644 --- a/pink_lady.py +++ b/pink_lady.py @@ -4,7 +4,8 @@ import argparse import importlib from src.reader.orientation.manage_reader import reader_orientation -from src.reader.camera.reader_camera import read_camera +from src.reader.reader_camera import read_camera +from src.reader.reader_copoints import read_copoints parser = argparse.ArgumentParser(description='photogrammetric site conversion' + ' and manipulation software') @@ -16,13 +17,16 @@ help='Number of lines to be skipped before reading the file') parser.add_argument('-w', '--writer', type=str, default='', - help='Worksite output file format') + help='Worksite output file format ex:opk') parser.add_argument('-pr', '--pathreturn', type=str, default='test/tmp/', nargs=1, - help='Conversion path ex:"test/tmp/"') + help='Conversion path ex:test/tmp/') parser.add_argument('-c', '--camera', type=str, default='', nargs='*', - help='Files paths of cameras') + help='Files paths of cameras (xml or txt)') +parser.add_argument('-cp', '--connecting_points', + type=str, default='', nargs='*', + help='Files paths of connecting points (.mes)') args = parser.parse_args() @@ -38,6 +42,11 @@ read_camera(args.camera, work) print("Camera file reading done") +# Reading connecting point +if args.connecting_points != '': + read_copoints(args.connecting_points, work) + print("Connecting point reading done") + # Writing data if args.writer != '': try: From 8eb937fdf2b6f05e655e9cae4cc13277e4c9c0c2 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 14:24:37 +0100 Subject: [PATCH 5/9] build: change struct list to dict --- src/datastruct/shot.py | 19 ++++++++++++++++++- src/datastruct/worksite.py | 20 ++++++++++---------- src/writer/writer_opk.py | 5 ++++- 3 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/datastruct/shot.py b/src/datastruct/shot.py index 63ad687b..497aa1f1 100644 --- a/src/datastruct/shot.py +++ b/src/datastruct/shot.py @@ -1,7 +1,7 @@ """ Acquisition data class module """ -from dataclasses import dataclass +from dataclasses import dataclass, field import numpy as np @@ -20,3 +20,20 @@ class Shot: pos_shot: np.array ori_shot: np.array name_cam: str + copoints: dict = field(default_factory = dict) + mat_R: np.array = field(init = False) + + def __post_init__(self) -> np.array: + """ + Build the rotation matrix with omega phi kappa + """ + Rx = np.array([[1,0,0], + [0,np.cos(self.ori_shot[0]*np.pi/180),-np.sin(self.ori_shot[0]*np.pi/180)], + [0,np.sin(self.ori_shot[0]*np.pi/180),np.cos(self.ori_shot[0]*np.pi/180)]]) + Ry = np.array([[np.cos(self.ori_shot[1]*np.pi/180),0,np.sin(self.ori_shot[1]*np.pi/180)], + [0,1,0], + [-np.sin(self.ori_shot[1]*np.pi/180),0,np.cos(self.ori_shot[1]*np.pi/180)]]) + Rz = np.array([[np.cos(self.ori_shot[2]*np.pi/180),-np.sin(self.ori_shot[2]*np.pi/180),0], + [np.cos(self.ori_shot[2]*np.pi/180),np.cos(self.ori_shot[2]*np.pi/180),0], + [0,0,1]]) + self.mat_R = Rx @ Ry @ Rz diff --git a/src/datastruct/worksite.py b/src/datastruct/worksite.py index 8c4858a9..1accd083 100644 --- a/src/datastruct/worksite.py +++ b/src/datastruct/worksite.py @@ -18,8 +18,8 @@ def __init__(self, name: str) -> None: name (str): Name of the worksite. """ self.name = name - self.shots = [] - self.cameras = [] + self.shots = {} + self.cameras = {} def add_shot(self, name_shot: str, pos_shot: np.array, ori_shot: np.array, name_cam: str) -> None: @@ -32,10 +32,10 @@ def add_shot(self, name_shot: str, pos_shot: np.array, ori_shot (numpy.array): Array of orientation of the shot [Omega, Phi, Kappa]. name_cam (str): Name of the camera. """ - self.shots.append(Shot(name_shot=name_shot, - pos_shot=pos_shot, - ori_shot=ori_shot, - name_cam=name_cam)) + self.shots[name_shot] = Shot(name_shot=name_shot, + pos_shot=pos_shot, + ori_shot=ori_shot, + name_cam=name_cam) def add_camera(self, name_camera: str, ppax: float, ppay: float, focal: float) -> None: @@ -48,7 +48,7 @@ def add_camera(self, name_camera: str, ppax: float, ppay (float): Center of distortion in y. focal (float): Focal of the camera. """ - self.cameras.append(Camera(name_camera=name_camera, - ppax=ppax, - ppay=ppay, - focal=focal)) + self.cameras[name_camera] = Camera(name_camera=name_camera, + ppax=ppax, + ppay=ppay, + focal=focal) diff --git a/src/writer/writer_opk.py b/src/writer/writer_opk.py index 4cbf13f0..230bc90b 100644 --- a/src/writer/writer_opk.py +++ b/src/writer/writer_opk.py @@ -2,6 +2,7 @@ Photogrammetry site file reader module """ import os +import numpy as np from src.datastruct.worksite import Worksite @@ -18,7 +19,9 @@ def write(path_opk: str, work: Worksite) -> None: try: with open(path_opk, "w", encoding="utf-8") as file: file.write("NOM X Y Z O P K CAMERA") - for shot in work.shots: + keys = np.sort(list(work.shots)) + for k in keys: + shot = work.shots[k] file.write("\n") file.write(shot.name_shot + " " + str(shot.pos_shot[0]) + " " + From b7d3e174c86c6d4b6fcaf6f193b7bdbe922e8007 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 14:25:11 +0100 Subject: [PATCH 6/9] test: change test for the new struct dict --- test/test_reader.py | 96 ++++++++++++++++++++++----------------------- test/test_struct.py | 27 +++++++------ test/test_writer.py | 16 ++++---- 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/test/test_reader.py b/test/test_reader.py index 7db17521..06722161 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -10,73 +10,73 @@ def test_reader_opk(): obj = read_opk("test/data/23FD1305_alt_test.opk", None) assert obj.name == "23FD1305_alt_test" - assert obj.shots[0].name_shot == "23FD1305x00001_00003" - assert obj.shots[0].pos_shot[0] == 798744.352 - assert obj.shots[0].pos_shot[1] == 6262815.867 - assert obj.shots[0].pos_shot[2] == 1778.451 - assert obj.shots[0].ori_shot[0] == 0.157339710405 - assert obj.shots[0].ori_shot[1] == 0.010129647126 - assert obj.shots[0].ori_shot[2] == -179.310680057325 - assert obj.shots[0].name_cam == "UCE-M3-f120-s06" - assert obj.shots[-1].name_shot == "23FD1305x00002_00053" - assert obj.shots[-1].pos_shot[0] == 799387.667 - assert obj.shots[-1].pos_shot[1] == 6263051.508 - assert obj.shots[-1].pos_shot[2] == 1784.760 - assert obj.shots[-1].ori_shot[0] == -0.146630494647 - assert obj.shots[-1].ori_shot[1] == -0.031919390293 - assert obj.shots[-1].ori_shot[2] == -0.209336104979 - assert obj.shots[-1].name_cam == "UCE-M3-f120-s06" + assert obj.shots["23FD1305x00001_00003"].name_shot == "23FD1305x00001_00003" + assert obj.shots["23FD1305x00001_00003"].pos_shot[0] == 798744.352 + assert obj.shots["23FD1305x00001_00003"].pos_shot[1] == 6262815.867 + assert obj.shots["23FD1305x00001_00003"].pos_shot[2] == 1778.451 + assert obj.shots["23FD1305x00001_00003"].ori_shot[0] == 0.157339710405 + assert obj.shots["23FD1305x00001_00003"].ori_shot[1] == 0.010129647126 + assert obj.shots["23FD1305x00001_00003"].ori_shot[2] == -179.310680057325 + assert obj.shots["23FD1305x00001_00003"].name_cam == "UCE-M3-f120-s06" + assert obj.shots["23FD1305x00002_00053"].name_shot == "23FD1305x00002_00053" + assert obj.shots["23FD1305x00002_00053"].pos_shot[0] == 799387.667 + assert obj.shots["23FD1305x00002_00053"].pos_shot[1] == 6263051.508 + assert obj.shots["23FD1305x00002_00053"].pos_shot[2] == 1784.760 + assert obj.shots["23FD1305x00002_00053"].ori_shot[0] == -0.146630494647 + assert obj.shots["23FD1305x00002_00053"].ori_shot[1] == -0.031919390293 + assert obj.shots["23FD1305x00002_00053"].ori_shot[2] == -0.209336104979 + assert obj.shots["23FD1305x00002_00053"].name_cam == "UCE-M3-f120-s06" assert len(obj.shots) == 7 def test_reader_file(): obj = reader_orientation("test/data/23FD1305_alt_test.opk") assert obj.name == "23FD1305_alt_test" - assert obj.shots[0].name_shot == "23FD1305x00001_00003" - assert obj.shots[0].pos_shot[0] == 798744.352 - assert obj.shots[0].pos_shot[1] == 6262815.867 - assert obj.shots[0].pos_shot[2] == 1778.451 - assert obj.shots[0].ori_shot[0] == 0.157339710405 - assert obj.shots[0].ori_shot[1] == 0.010129647126 - assert obj.shots[0].ori_shot[2] == -179.310680057325 - assert obj.shots[0].name_cam == "UCE-M3-f120-s06" - assert obj.shots[-1].name_shot == "23FD1305x00002_00053" - assert obj.shots[-1].pos_shot[0] == 799387.667 - assert obj.shots[-1].pos_shot[1] == 6263051.508 - assert obj.shots[-1].pos_shot[2] == 1784.760 - assert obj.shots[-1].ori_shot[0] == -0.146630494647 - assert obj.shots[-1].ori_shot[1] == -0.031919390293 - assert obj.shots[-1].ori_shot[2] == -0.209336104979 - assert obj.shots[-1].name_cam == "UCE-M3-f120-s06" + assert obj.shots["23FD1305x00001_00003"].name_shot == "23FD1305x00001_00003" + assert obj.shots["23FD1305x00001_00003"].pos_shot[0] == 798744.352 + assert obj.shots["23FD1305x00001_00003"].pos_shot[1] == 6262815.867 + assert obj.shots["23FD1305x00001_00003"].pos_shot[2] == 1778.451 + assert obj.shots["23FD1305x00001_00003"].ori_shot[0] == 0.157339710405 + assert obj.shots["23FD1305x00001_00003"].ori_shot[1] == 0.010129647126 + assert obj.shots["23FD1305x00001_00003"].ori_shot[2] == -179.310680057325 + assert obj.shots["23FD1305x00001_00003"].name_cam == "UCE-M3-f120-s06" + assert obj.shots["23FD1305x00002_00053"].name_shot == "23FD1305x00002_00053" + assert obj.shots["23FD1305x00002_00053"].pos_shot[0] == 799387.667 + assert obj.shots["23FD1305x00002_00053"].pos_shot[1] == 6263051.508 + assert obj.shots["23FD1305x00002_00053"].pos_shot[2] == 1784.760 + assert obj.shots["23FD1305x00002_00053"].ori_shot[0] == -0.146630494647 + assert obj.shots["23FD1305x00002_00053"].ori_shot[1] == -0.031919390293 + assert obj.shots["23FD1305x00002_00053"].ori_shot[2] == -0.209336104979 + assert obj.shots["23FD1305x00002_00053"].name_cam == "UCE-M3-f120-s06" assert len(obj.shots) == 7 def test_read_camera_xml(): work = Worksite("Test") camera_xml("test/data/s07_UC_Eagle_M3_120.xml", work) - assert work.cameras[0].name_camera == "UCE-M3-f120-s07" - assert work.cameras[0].ppax == 13230.00 - assert work.cameras[0].ppay == 8502.00 - assert work.cameras[0].focal == 30975.00 + assert work.cameras["UCE-M3-f120-s07"].name_camera == "UCE-M3-f120-s07" + assert work.cameras["UCE-M3-f120-s07"].ppax == 13230.00 + assert work.cameras["UCE-M3-f120-s07"].ppay == 8502.00 + assert work.cameras["UCE-M3-f120-s07"].focal == 30975.00 def test_read_camera_txt(): work = Worksite("Test") camera_txt("test/data/Camera.txt", work) - assert work.cameras[0].name_camera == "UCE-M3-f120-s06" - assert work.cameras[0].ppax == 13210.00 - assert work.cameras[0].ppay == 8502.00 - assert work.cameras[0].focal == 30975.00 + assert work.cameras["UCE-M3-f120-s06"].name_camera == "UCE-M3-f120-s06" + assert work.cameras["UCE-M3-f120-s06"].ppax == 13210.00 + assert work.cameras["UCE-M3-f120-s06"].ppay == 8502.00 + assert work.cameras["UCE-M3-f120-s06"].focal == 30975.00 def test_read_camera(): work = Worksite("Test") read_camera(["test/data/s07_UC_Eagle_M3_120.xml", "test/data/Camera.txt"], work) - assert work.cameras[0].name_camera == "UCE-M3-f120-s07" - assert work.cameras[0].ppax == 13230.00 - assert work.cameras[0].ppay == 8502.00 - assert work.cameras[0].focal == 30975.00 - assert work.cameras[1].name_camera == "UCE-M3-f120-s06" - assert work.cameras[1].ppax == 13210.00 - assert work.cameras[1].ppay == 8502.00 - assert work.cameras[1].focal == 30975.00 \ No newline at end of file + assert work.cameras["UCE-M3-f120-s07"].name_camera == "UCE-M3-f120-s07" + assert work.cameras["UCE-M3-f120-s07"].ppax == 13230.00 + assert work.cameras["UCE-M3-f120-s07"].ppay == 8502.00 + assert work.cameras["UCE-M3-f120-s07"].focal == 30975.00 + assert work.cameras["UCE-M3-f120-s06"].name_camera == "UCE-M3-f120-s06" + assert work.cameras["UCE-M3-f120-s06"].ppax == 13210.00 + assert work.cameras["UCE-M3-f120-s06"].ppay == 8502.00 + assert work.cameras["UCE-M3-f120-s06"].focal == 30975.00 \ No newline at end of file diff --git a/test/test_struct.py b/test/test_struct.py index a5494012..48b807d3 100644 --- a/test/test_struct.py +++ b/test/test_struct.py @@ -11,7 +11,8 @@ def test_worksite(): obj = Worksite(name = "Test") assert obj.name == "Test" - assert obj.shots == [] + assert obj.shots == {} + assert obj.cameras == {} def test_shot(): @@ -37,20 +38,20 @@ def test_camera(): def test_addshot(): obj = Worksite(name = "Test") obj.add_shot("test_shot", np.array([1,2,3]), np.array([3,2,1]), "test_cam") - assert obj.shots[0].name_shot == "test_shot" - assert obj.shots[0].pos_shot[0] == 1 - assert obj.shots[0].pos_shot[1] == 2 - assert obj.shots[0].pos_shot[2] == 3 - assert obj.shots[0].ori_shot[0] == 3 - assert obj.shots[0].ori_shot[1] == 2 - assert obj.shots[0].ori_shot[2] == 1 - assert obj.shots[0].name_cam == "test_cam" + assert obj.shots["test_shot"].name_shot == "test_shot" + assert obj.shots["test_shot"].pos_shot[0] == 1 + assert obj.shots["test_shot"].pos_shot[1] == 2 + assert obj.shots["test_shot"].pos_shot[2] == 3 + assert obj.shots["test_shot"].ori_shot[0] == 3 + assert obj.shots["test_shot"].ori_shot[1] == 2 + assert obj.shots["test_shot"].ori_shot[2] == 1 + assert obj.shots["test_shot"].name_cam == "test_cam" def test_addcam(): obj = Worksite(name = "Test") obj.add_camera("test_cam", 13210.00, 8502.00, 30975.00) - assert obj.cameras[0].name_camera == "test_cam" - assert obj.cameras[0].ppax == 13210.00 - assert obj.cameras[0].ppay == 8502.00 - assert obj.cameras[0].focal == 30975.00 + assert obj.cameras["test_cam"].name_camera == "test_cam" + assert obj.cameras["test_cam"].ppax == 13210.00 + assert obj.cameras["test_cam"].ppay == 8502.00 + assert obj.cameras["test_cam"].focal == 30975.00 diff --git a/test/test_writer.py b/test/test_writer.py index 793e670d..1a0f14e8 100644 --- a/test/test_writer.py +++ b/test/test_writer.py @@ -32,12 +32,12 @@ def test_writer(): write(OUTPUT, obj) obj2 = read_opk(os.path.join(OUTPUT,f"{FILENAME}.opk"), None) assert obj2.name == "Test" - assert obj2.shots[0].name_shot == "test_shot" - assert obj2.shots[0].pos_shot[0] == 1 - assert obj2.shots[0].pos_shot[1] == 2 - assert obj2.shots[0].pos_shot[2] == 3 - assert obj2.shots[0].ori_shot[0] == 3 - assert obj2.shots[0].ori_shot[1] == 2 - assert obj2.shots[0].ori_shot[2] == 1 - assert obj2.shots[0].name_cam == "test_cam" + assert obj2.shots["test_shot"].name_shot == "test_shot" + assert obj2.shots["test_shot"].pos_shot[0] == 1 + assert obj2.shots["test_shot"].pos_shot[1] == 2 + assert obj2.shots["test_shot"].pos_shot[2] == 3 + assert obj2.shots["test_shot"].ori_shot[0] == 3 + assert obj2.shots["test_shot"].ori_shot[1] == 2 + assert obj2.shots["test_shot"].ori_shot[2] == 1 + assert obj2.shots["test_shot"].name_cam == "test_cam" teardown_module() From a2d49deeaeac72eb623fc187c2855659ace35359 Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 16:04:17 +0100 Subject: [PATCH 7/9] lint: add new file in workflows lint_python --- .github/workflows/lint_python.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/lint_python.yml b/.github/workflows/lint_python.yml index c8c5f19d..8d8c539e 100644 --- a/.github/workflows/lint_python.yml +++ b/.github/workflows/lint_python.yml @@ -26,9 +26,9 @@ jobs: - name: Analysing the code with pylint run: | - pylint pink_lady.py src/reader/camera/reader_camera.py src/reader/orientation/manage_reader.py src/reader/orientation/reader_opk.py src/datastruct/shot.py src/datastruct/worksite.py src/datastruct/camera.py src/writer/writer_opk.py + pylint pink_lady.py src/reader/reader_camera.py src/reader/reader_copoints.py src/reader/orientation/manage_reader.py src/reader/orientation/reader_opk.py src/datastruct/shot.py src/datastruct/worksite.py src/datastruct/camera.py src/writer/writer_opk.py - name: Analysing the code with flake8 run: | - flake8 --max-line-length 100 pink_lady.py src/reader/camera/reader_camera.py src/reader/orientation/manage_reader.py src/reader/orientation/reader_opk.py src/datastruct/shot.py src/datastruct/worksite.py src/datastruct/camera.py src/writer/writer_opk.py + flake8 --max-line-length 100 pink_lady.py src/reader/reader_camera.py src/reader/reader_copoints.py src/reader/orientation/manage_reader.py src/reader/orientation/reader_opk.py src/datastruct/shot.py src/datastruct/worksite.py src/datastruct/camera.py src/writer/writer_opk.py From 5024fde357f951789430e5b7054615226307dc3e Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 16:17:19 +0100 Subject: [PATCH 8/9] test: add new test to reader connecting point mes and new function add --- test/test_reader.py | 18 +++++++++++++++++- test/test_struct.py | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/test/test_reader.py b/test/test_reader.py index 06722161..8ca74cef 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -4,6 +4,7 @@ from src.reader.orientation.manage_reader import reader_orientation from src.reader.orientation.reader_opk import read as read_opk from src.reader.reader_camera import read_camera, camera_txt, camera_xml +from src.reader.reader_copoints import read_copoints from src.datastruct.worksite import Worksite @@ -79,4 +80,19 @@ def test_read_camera(): assert work.cameras["UCE-M3-f120-s06"].name_camera == "UCE-M3-f120-s06" assert work.cameras["UCE-M3-f120-s06"].ppax == 13210.00 assert work.cameras["UCE-M3-f120-s06"].ppay == 8502.00 - assert work.cameras["UCE-M3-f120-s06"].focal == 30975.00 \ No newline at end of file + assert work.cameras["UCE-M3-f120-s06"].focal == 30975.00 + + +def test_read_copoints(): + work = reader_orientation("test/data/23FD1305_alt_test.opk") + read_copoints(["test/data/all_liaisons.mes"], work) + assert work.copoints["MES_0"] == ["23FD1305x00001_00003", "23FD1305x00001_00004"] + assert work.copoints["MES_1"] == ["23FD1305x00001_00003", "23FD1305x00001_00004", "23FD1305x00001_00005", "23FD1305x00001_00006", "23FD1305x00002_00051", "23FD1305x00002_00052", "23FD1305x00002_00053"] + assert work.copoints["MES_2"] == ["23FD1305x00001_00003", "23FD1305x00001_00005", "23FD1305x00001_00006", "23FD1305x00002_00051", "23FD1305x00002_00052", "23FD1305x00002_00053"] + assert work.shots["23FD1305x00001_00003"].copoints["MES_0"] == [4763.57, 16960.5] + assert work.shots["23FD1305x00001_00003"].copoints["MES_1"] == [6818.89, 16625.93] + assert work.shots["23FD1305x00001_00003"].copoints["MES_2"] == [6165.08, 16873.72] + assert work.shots["23FD1305x00001_00004"].copoints["MES_0"] == [4813.98, 12509.25] + assert work.shots["23FD1305x00001_00004"].copoints["MES_1"] == [6869.3, 12187.65] + assert work.shots["23FD1305x00002_00053"].copoints["MES_1"] == [8270.79, 4265.72] + assert work.shots["23FD1305x00002_00053"].copoints["MES_2"] == [8908.58, 4012.49] diff --git a/test/test_struct.py b/test/test_struct.py index 48b807d3..6cf5537e 100644 --- a/test/test_struct.py +++ b/test/test_struct.py @@ -25,6 +25,7 @@ def test_shot(): assert obj.ori_shot[1] == 2 assert obj.ori_shot[2] == 1 assert obj.name_cam == "test_cam" + assert obj.copoints == {} def test_camera(): @@ -55,3 +56,20 @@ def test_addcam(): assert obj.cameras["test_cam"].ppax == 13210.00 assert obj.cameras["test_cam"].ppay == 8502.00 assert obj.cameras["test_cam"].focal == 30975.00 + + +def test_add_copoint(): + obj = Worksite(name = "Test") + obj.add_shot("t1", np.array([1,2,3]), np.array([3,2,1]), "test_cam") + obj.add_shot("t2", np.array([1,2,3]), np.array([3,2,1]), "test_cam") + obj.add_shot("t3", np.array([1,2,3]), np.array([3,2,1]), "test_cam") + obj.add_copoint("p0", "t1", 50, 30) + obj.add_copoint("p0", "t2", 40, 40) + obj.add_copoint("p1", "t1", 70, 10) + obj.add_copoint("p1", "t3", 50, 90) + assert obj.copoints["p0"] == ["t1", "t2"] + assert obj.copoints["p1"] == ["t1", "t3"] + assert obj.shots["t1"].copoints["p0"] == [50, 30] + assert obj.shots["t1"].copoints["p1"] == [70, 10] + assert obj.shots["t2"].copoints["p0"] == [40, 40] + assert obj.shots["t3"].copoints["p1"] == [50, 90] From 8d55ef3b8f0990c7b04b46d795fba629a1ebd1fe Mon Sep 17 00:00:00 2001 From: ACornuIGN Date: Tue, 2 Jan 2024 16:18:04 +0100 Subject: [PATCH 9/9] build: add function to read and store data to connecting point mes --- src/datastruct/shot.py | 25 +++++++++++++------------ src/datastruct/worksite.py | 34 ++++++++++++++++++++++++++++++++++ src/reader/reader_copoints.py | 20 ++++++++++++++++++++ 3 files changed, 67 insertions(+), 12 deletions(-) diff --git a/src/datastruct/shot.py b/src/datastruct/shot.py index 497aa1f1..5aec1b47 100644 --- a/src/datastruct/shot.py +++ b/src/datastruct/shot.py @@ -20,20 +20,21 @@ class Shot: pos_shot: np.array ori_shot: np.array name_cam: str - copoints: dict = field(default_factory = dict) - mat_R: np.array = field(init = False) + copoints: dict = field(default_factory=dict) + mat_rot: np.array = field(init=False) def __post_init__(self) -> np.array: """ Build the rotation matrix with omega phi kappa """ - Rx = np.array([[1,0,0], - [0,np.cos(self.ori_shot[0]*np.pi/180),-np.sin(self.ori_shot[0]*np.pi/180)], - [0,np.sin(self.ori_shot[0]*np.pi/180),np.cos(self.ori_shot[0]*np.pi/180)]]) - Ry = np.array([[np.cos(self.ori_shot[1]*np.pi/180),0,np.sin(self.ori_shot[1]*np.pi/180)], - [0,1,0], - [-np.sin(self.ori_shot[1]*np.pi/180),0,np.cos(self.ori_shot[1]*np.pi/180)]]) - Rz = np.array([[np.cos(self.ori_shot[2]*np.pi/180),-np.sin(self.ori_shot[2]*np.pi/180),0], - [np.cos(self.ori_shot[2]*np.pi/180),np.cos(self.ori_shot[2]*np.pi/180),0], - [0,0,1]]) - self.mat_R = Rx @ Ry @ Rz + rx = np.array([[1, 0, 0], + [0, np.cos(self.ori_shot[0]*np.pi/180), -np.sin(self.ori_shot[0]*np.pi/180)], + [0, np.sin(self.ori_shot[0]*np.pi/180), np.cos(self.ori_shot[0]*np.pi/180)]]) + ry = np.array([[np.cos(self.ori_shot[1]*np.pi/180), 0, np.sin(self.ori_shot[1]*np.pi/180)], + [0, 1, 0], + [-np.sin(self.ori_shot[1]*np.pi/180), 0, + np.cos(self.ori_shot[1]*np.pi/180)]]) + rz = np.array([[np.cos(self.ori_shot[2]*np.pi/180), -np.sin(self.ori_shot[2]*np.pi/180), 0], + [np.cos(self.ori_shot[2]*np.pi/180), np.cos(self.ori_shot[2]*np.pi/180), 0], + [0, 0, 1]]) + self.mat_rot = rx @ ry @ rz diff --git a/src/datastruct/worksite.py b/src/datastruct/worksite.py index 1accd083..559f6cfa 100644 --- a/src/datastruct/worksite.py +++ b/src/datastruct/worksite.py @@ -1,6 +1,7 @@ """ Worksite data class module """ +import sys import numpy as np from src.datastruct.shot import Shot from src.datastruct.camera import Camera @@ -20,6 +21,7 @@ def __init__(self, name: str) -> None: self.name = name self.shots = {} self.cameras = {} + self.copoints = {} def add_shot(self, name_shot: str, pos_shot: np.array, ori_shot: np.array, name_cam: str) -> None: @@ -52,3 +54,35 @@ def add_camera(self, name_camera: str, ppax: float, ppax=ppax, ppay=ppay, focal=focal) + + def add_copoint(self, name_point: str, name_shot: str, x: float, y: float) -> None: + """ + Add linking point between acquisition in two part + One in self.copoints a dict with name_point the key and list of acquisition the result + And One in self.shot[name_shot].copoints a dict whit + name_point the key and list of coordinate x (column) y (line) the result in list + + Agrs: + name_point (str): Name of the connecting point + name_shot (str): Name of the acquisition + x (float): pixel position of the point in column + y (float): pixel position of the point in line + """ + if name_shot not in self.shots: + print(f"The shot {name_shot} doesn't exist in list of shots") + sys.exit() + + if name_point not in self.copoints: + self.copoints[name_point] = [] + + if name_point not in self.shots[name_shot].copoints: + self.shots[name_shot].copoints[name_point] = [x, y] + else: + print("\n :--------------------------:") + print("Warning : connecting point duplicate") + print(f"The point {name_point} already exists in the shot {name_shot}.") + print("Keep first point with coordinates " + + f"{self.shots[name_shot].copoints[name_point]}") + print(":--------------------------:") + + self.copoints[name_point].append(name_shot) diff --git a/src/reader/reader_copoints.py b/src/reader/reader_copoints.py index e69de29b..b986e93f 100644 --- a/src/reader/reader_copoints.py +++ b/src/reader/reader_copoints.py @@ -0,0 +1,20 @@ +""" +Script to read connecting point mes +""" +from src.datastruct.worksite import Worksite + + +def read_copoints(files: list, work: Worksite): + """ + Read all files of connecting points + + Agrs: + files (list): path list of files connecting points + work (Worksite): Worksite which needs camera data + """ + for file in files: + with open(file, 'r', encoding="utf-8") as file_copoints: + for copoint in file_copoints.readlines(): + if copoint != '\n': + name_point, name_shot, x, y = copoint.split() + work.add_copoint(name_point, name_shot, float(x), float(y))