diff --git a/Raytrace/SideScan.py b/Raytrace/SideScan.py index 3896246..83db3b6 100644 --- a/Raytrace/SideScan.py +++ b/Raytrace/SideScan.py @@ -2,6 +2,7 @@ from typing import Self import numpy as np import time +import pickle class RawScanReading: distances:np.ndarray @@ -42,6 +43,16 @@ def print_summary(self) -> None: print('Time:', self.end_time - self.start_time, 'seconds') print('Speed:', len(self.distances)/(self.end_time - self.start_time), 'rays/seconds') + def save(self, filename, override = False) -> None: + with open(filename, 'wb' if override else 'xb') as file: + pickle.dump(self, file) + @staticmethod + def load(filename) -> 'RawScanReading': + with open(filename, 'rb') as file: + obj = pickle.load(file) + if isinstance(obj, RawScanReading): + return obj + raise TypeError(f'The object saved in {filename} is type {type(obj)} not RawScanReading') class ScanReading: raw:RawScanReading @@ -78,6 +89,20 @@ def process_raw(self) -> None: self.result = np.sum(lval, axis = 1) np.seterr(**old_error_state) + + def save(self, filename, override = False) -> None: + with open(filename, 'wb' if override else 'xb') as file: + pickle.dump(self, file) + @staticmethod + def load(filename) -> 'ScanReading': + with open(filename, 'rb') as file: + obj = pickle.load(file) + if isinstance(obj, ScanReading): + return obj + raise TypeError(f'The object saved in {filename} is type {type(obj)} not ScanReading') + + + class SideScan: mesh:TriangleMesh smooth_dist:float diff --git a/Raytrace/TriangleMesh.py b/Raytrace/TriangleMesh.py index 950671f..d1b8898 100644 --- a/Raytrace/TriangleMesh.py +++ b/Raytrace/TriangleMesh.py @@ -1,5 +1,5 @@ import numpy as np - +import pickle class Ray: direction:np.ndarray @@ -115,3 +115,14 @@ def batch_triangle_ray_intersection(triangle_array, ray:Ray, epsilon = 1e-10) -> np.seterr(**old_error_state) return t + + def save(self, filename, override = False) -> None: + with open(filename, 'wb' if override else 'xb') as file: + pickle.dump(self, file) + @staticmethod + def load(filename) -> 'TriangleMesh': + with open(filename, 'rb') as file: + obj = pickle.load(file) + if isinstance(obj, TriangleMesh): + return obj + raise TypeError(f'The object saved in {filename} is type {type(obj)} not TriangleMesh') \ No newline at end of file