Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add reading of the connecting points #4

Merged
merged 9 commits into from
Jan 3, 2024
4 changes: 2 additions & 2 deletions .github/workflows/lint_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
3. Reading a camera file (XML and txt)
4. Reading connecting point (mes)
17 changes: 13 additions & 4 deletions pink_lady.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()

Expand All @@ -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:
Expand Down
20 changes: 19 additions & 1 deletion src/datastruct/shot.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Acquisition data class module
"""
from dataclasses import dataclass
from dataclasses import dataclass, field
import numpy as np


Expand All @@ -20,3 +20,21 @@ class Shot:
pos_shot: np.array
ori_shot: np.array
name_cam: str
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_rot = rx @ ry @ rz
54 changes: 44 additions & 10 deletions src/datastruct/worksite.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,8 +19,9 @@ def __init__(self, name: str) -> None:
name (str): Name of the worksite.
"""
self.name = name
self.shots = []
self.cameras = []
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:
Expand All @@ -32,10 +34,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:
Expand All @@ -48,7 +50,39 @@ 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)

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)
Empty file removed src/reader/camera/__init__.py
Empty file.
File renamed without changes.
20 changes: 20 additions & 0 deletions src/reader/reader_copoints.py
Original file line number Diff line number Diff line change
@@ -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))
5 changes: 4 additions & 1 deletion src/writer/writer_opk.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Photogrammetry site file reader module
"""
import os
import numpy as np
from src.datastruct.worksite import Worksite


Expand All @@ -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]) + " " +
Expand Down
8 changes: 8 additions & 0 deletions test/data/23FD1305_alt_test.opk
Original file line number Diff line number Diff line change
@@ -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
9 changes: 0 additions & 9 deletions test/data/Sommets_hEllips_test.opk

This file was deleted.

16 changes: 16 additions & 0 deletions test/data/all_liaisons.mes
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading