Skip to content

Commit

Permalink
Added save/load
Browse files Browse the repository at this point in the history
Added methods to save and load scan results and meshes using pickle
  • Loading branch information
JoeBell committed Mar 3, 2025
1 parent b1a383f commit f5f9fb1
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
25 changes: 25 additions & 0 deletions Raytrace/SideScan.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Self
import numpy as np
import time
import pickle

class RawScanReading:
distances:np.ndarray
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion Raytrace/TriangleMesh.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import numpy as np

import pickle

class Ray:
direction:np.ndarray
Expand Down Expand Up @@ -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')

0 comments on commit f5f9fb1

Please sign in to comment.