-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
JoeBell
committed
Feb 21, 2025
1 parent
e72b808
commit ddce711
Showing
1 changed file
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from Raytrace.TriangleMesh import TriangleMesh | ||
from Raytrace.SideScan import ScanReading | ||
import numpy as np | ||
try: | ||
import plotly.graph_objs as go # type: ignore | ||
except ModuleNotFoundError: | ||
print('plotly not installed, please run "pip install plotly"') | ||
exit() | ||
|
||
def plot_mesh(mesh:TriangleMesh, **kwargs) -> go.Mesh3d: | ||
x, y, z = mesh.triangles.reshape((-1,3)).swapaxes(0, 1) | ||
i, j, k = [list(range(i,x.shape[0],3)) for i in range(3)] | ||
return go.Mesh3d(x=x, y=y, z=z, i=i, j=j, k=k, **kwargs) | ||
|
||
def plot_rays(reading:ScanReading, **kwargs) -> go.Scatter3d: | ||
origin = reading.origins[reading.finite] | ||
inters = reading.intersections[reading.finite] | ||
|
||
x, y, z = np.stack((origin, inters, origin)).swapaxes(0,1).reshape((-1,3)).swapaxes(0,1) | ||
return go.Scatter3d(x=x, y=y, z=z, **kwargs) | ||
|
||
def plot_reading(reading:ScanReading) -> go.Figure: | ||
return go.Figure(data = [ | ||
go.Scatter({ | ||
'name': 'Smoothed', | ||
'showlegend': True, | ||
'mode': 'lines', | ||
'x': np.arange(reading.result_reselution)/reading.result_reselution*(reading.max_dist-reading.min_dist)+reading.min_dist, | ||
'y': reading.result, | ||
}), | ||
go.Scatter({ | ||
'mode': 'markers', | ||
'name': 'Raw', | ||
'showlegend': True, | ||
'x': reading.distances[reading.finite], | ||
'y': np.zeros(reading.intersection_count), | ||
}) | ||
]) | ||
def plot_intersections(reading:ScanReading, **kwargs) -> go.Scatter3d: | ||
inters = reading.intersections[reading.finite] | ||
|
||
x, y, z = inters.reshape((-1,3)).swapaxes(0,1) | ||
return go.Scatter3d(x=x, y=y, z=z, **kwargs) | ||
|
||
def plot_intersections_list(readings:list[ScanReading], **kwargs) -> list[go.Scatter3d]: | ||
return [plot_intersections(reading, **kwargs) for reading in readings] | ||
|
||
def plot_readings_heatmap(readings) -> go.Figure: | ||
return go.Figure(data = [ | ||
go.Heatmap({ | ||
'y': np.arange(readings[0].min_dist, readings[0].max_dist, (readings[0].max_dist - readings[0].min_dist) / readings[0].result_reselution), | ||
'z': np.array([reading.result for reading in readings]).swapaxes(0,1), | ||
}) | ||
], | ||
layout = { | ||
'xaxis_title' : 'Reading Index', | ||
'yaxis_title' : 'Distance (units)', | ||
} | ||
) |