@@ -125,7 +125,7 @@ def __init__(self,
125125
126126
127127 @classmethod
128- def from_file (cls , ori_file : str , add_file : str ):
128+ def from_file (cls , ori_file : str , add_file : str | None ):
129129 """
130130 Read exterior and interior orientation, and if available, parameters for distortion corrections.
131131
@@ -145,36 +145,18 @@ def from_file(cls, ori_file: str, add_file: str):
145145 ret = cls ()
146146
147147 with open (ori_file , "r" , encoding = "utf-8" ) as fp :
148- # Exterior
149- ret .set_pos (np .array ([float (x ) for x in fp .readline ().split ()]))
150- ret .set_angles (np .array ([float (x ) for x in fp .readline ().split ()]))
148+ data = fp .read ()
151149
152- # ret.ext_par.set_pos( np.fromstring(fp.readline() , dtype=float, sep="\t") )
153- # ret.ext_par.set_angles(np.fromstring(fp.readline(), dtype=float, sep="\t") )
150+ data = np .fromstring (data , dtype = float , sep = " " )
151+ # print(data )
154152
155- # Exterior rotation matrix
156- # skip line
157- fp .readline ()
153+ ret .set_pos (data [:3 ])
154+ ret .set_angles (data [3 :6 ])
155+ # no need. set_angles updates rotation matrix automatically
156+ # ret.set_rotation_matrix(data[6:15].reshape(3, 3))
157+ ret .set_primary_point (data [15 :18 ]) # xh, yh, cc
158+ ret .glass_par = data [18 :] # glass position vector from the water side
158159
159- # read 3 lines of rotation matrix, but recalculate it from angles
160- _ = [[float (x ) for x in fp .readline ().split ()] for _ in range (3 )]
161-
162- # I skip reading rotation matrix as it's set up by set_angles.
163- # self.set_rotation_matrix(np.array(float_list).reshape(3, 3))
164-
165- # Interior
166- # skip
167- fp .readline ()
168-
169- tmp = [float (x ) for x in fp .readline ().split ()] # xh,yh
170- tmp += [float (x ) for x in fp .readline ().split ()] # cc
171- ret .set_primary_point (np .array (tmp ))
172- # self.int_par.set_back_focal_distance(float(fp.readline()))
173-
174- # Glass
175- # skip
176- fp .readline ()
177- ret .glass_par = np .array ([float (x ) for x in fp .readline ().split ()])
178160
179161 # double-check that we have the correct rotation matrix
180162 # self.ext_par.rotation_matrix()
@@ -183,16 +165,18 @@ def from_file(cls, ori_file: str, add_file: str):
183165 # self.mmlut.data = None # no multimedia data yet
184166
185167 # Additional parameters
186- try :
168+ if add_file is not None :
187169 with open (add_file , "r" , encoding = "utf-8" ) as fp :
188170 tmp = list (map (float , fp .readline ().split ()))
189171
190172 ret .set_radial_distortion (np .array (tmp [:3 ]))
191173 ret .set_decentering (np .array (tmp [3 :5 ]))
192174 ret .set_affine_distortion (np .array (tmp [5 :]))
193175
194- except FileNotFoundError :
195- print ("no addpar fallback used" ) # Waits for proper logging.
176+ # except FileNotFoundError:
177+ else :
178+ # print("no addpar fallback used") # Waits for proper logging.
179+ print ("No addpar file found. Using default values for radial distortion" )
196180 ret .added_par .k1 = ret .added_par .k2 = ret .added_par .k3 \
197181 = ret .added_par .p1 = ret .added_par .p2 = ret .added_par .she = 0.0
198182 ret .added_par .scx = 1.0
0 commit comments