Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 46fe6aa
Merge: 6b2a13d 60d436b
Author: jrb20008 <joseph.bellemare@uconn.edu>
Date:   Tue Mar 25 12:23:57 2025 -0400

    Merge branch 'main' of https://github.uconn.edu/tjs20011/SDP-37-Model

commit 60d436b
Author: Joseph R Bellemare <joseph.bellemare@uconn.edu>
Date:   Tue Mar 25 12:21:55 2025 -0400

    Dataset generation (#4)

    * Squashed commit of the following:

    commit 4acc015
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Sun Mar 9 18:00:03 2025 -0400

        Added normalize function

        Added function to normalize the scale of meshes

    commit e685ab2
    Merge: 968cbac cc38025
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 21:28:20 2025 -0500

        Merge branch 'main' into shipgen-integration

    commit 968cbac
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:58:29 2025 -0500

        Added conversion

        Added helper functions to convert stl.Mesh's to triangle arrays

    commit 13a589f
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:47:02 2025 -0500

        Cleaned up Generate

    commit 22876e9
    Merge: f92334b adb4ab8
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:08:58 2025 -0500

        Merge branch 'main' into shipgen-integration

    commit f92334b
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:39:31 2025 -0500

        Renamed parameters

    commit f261895
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:37:13 2025 -0500

        Stopped warning message

    commit bf90105
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:26:12 2025 -0500

        Fixed unused parameter

    commit f79dbc1
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:14:46 2025 -0500

        Removed need to save stl's

    commit c640f6c
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:05:02 2025 -0500

        Improved typing

    commit 19cf09b
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 18:48:43 2025 -0500

        Added hull generator

    commit e8845c8
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 16:18:36 2025 -0500

        Uploaded streamlined ShipGen

        Uploaded a version of ShipGen modified from https://www.dropbox.com/sh/jg98r425v7ly89l/AAA49uMr7_mhaVmRDrPq0NU_a?dl=0 with all non-essential files removed

    * Added Custom Types

    Everything runs abut half as fast but it is much less error prone and more readable

    * Changed Raytrace Imports

    Change the Raytrace library so that mesh classes can be imported directly

    * Restructured Raytrace Library

    Moved the mesh classes into their own folder

    * Fixed Typo Related Bug

    Passing a Vector3 to the Vector3 constructor no longer causes an error

    * Redid Custom Types

    Custom types are now better integrated with numpy to get speed back to around where they were (well, 2/3rds the speed but whos counting)

    * Added Triangle output to Raytrace

    Raytracing functions now return a distance and a triangle. Subclasses now overwrite the raytrace_as_tri method

    * Added Explicate Reexports

    Added reexports to AUVSim

    * Created Generate Folder

    * Created Scan Utilities

    Added functions to help position AUVs and scan paths

    * Made CompositeMesh.triangles getter

    Modified CompositeMesh to make instantiating large quantities less intensive

    * Renamed AUV Utilities

    * Added Parallelism to AUV Utilities

    Made functions in the AUV utilities that take arrays in addition to their single value counter-parts

    * Added Hull Utilities

    Added utilities for generating hulls and placing anomalies

    * Created Outline

    Added an outline notebook that walks through how to create items for the dataset

    * Fixed Point Randomizer

    Fixed bug where random point had a 50% chance of not being on the triangle

    * Fixed Surface Normal

    * Fixed Outline

commit fd0b115
Author: Joseph R Bellemare <joseph.bellemare@uconn.edu>
Date:   Tue Mar 25 12:13:59 2025 -0400

    Typing Overhaul (#3)

    * Added Custom Types

    Everything runs abut half as fast but it is much less error prone and more readable

    * Changed Raytrace Imports

    Change the Raytrace library so that mesh classes can be imported directly

    * Restructured Raytrace Library

    Moved the mesh classes into their own folder

    * Fixed Typo Related Bug

    Passing a Vector3 to the Vector3 constructor no longer causes an error

    * Redid Custom Types

    Custom types are now better integrated with numpy to get speed back to around where they were (well, 2/3rds the speed but whos counting)

commit 6b2a13d
Author: jrb20008 <joseph.bellemare@uconn.edu>
Date:   Thu Mar 20 15:49:43 2025 -0400

    Squashed commit of the following:

    commit 4acc015
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Sun Mar 9 18:00:03 2025 -0400

        Added normalize function

        Added function to normalize the scale of meshes

    commit e685ab2
    Merge: 968cbac cc38025
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 21:28:20 2025 -0500

        Merge branch 'main' into shipgen-integration

    commit 968cbac
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:58:29 2025 -0500

        Added conversion

        Added helper functions to convert stl.Mesh's to triangle arrays

    commit 13a589f
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:47:02 2025 -0500

        Cleaned up Generate

    commit 22876e9
    Merge: f92334b adb4ab8
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 20:08:58 2025 -0500

        Merge branch 'main' into shipgen-integration

    commit f92334b
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:39:31 2025 -0500

        Renamed parameters

    commit f261895
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:37:13 2025 -0500

        Stopped warning message

    commit bf90105
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:26:12 2025 -0500

        Fixed unused parameter

    commit f79dbc1
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:14:46 2025 -0500

        Removed need to save stl's

    commit c640f6c
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 19:05:02 2025 -0500

        Improved typing

    commit 19cf09b
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 18:48:43 2025 -0500

        Added hull generator

    commit e8845c8
    Author: JoeBell <joe@onmyhonor.com>
    Date:   Tue Mar 4 16:18:36 2025 -0500

        Uploaded streamlined ShipGen

        Uploaded a version of ShipGen modified from https://www.dropbox.com/sh/jg98r425v7ly89l/AAA49uMr7_mhaVmRDrPq0NU_a?dl=0 with all non-essential files removed

commit 0405a26
Author: jrb20008 <joseph.bellemare@uconn.edu>
Date:   Sun Mar 9 19:59:52 2025 -0400

    Created AUVSim

    Created a module to generate basic AUV paths to follow the face of hulls

commit cc38025
Author: JoeBell <joe@onmyhonor.com>
Date:   Tue Mar 4 21:27:42 2025 -0500

    Fixed numpy version compatibility

commit adb4ab8
Author: JoeBell <joe@onmyhonor.com>
Date:   Tue Mar 4 20:03:31 2025 -0500

    Downgraded numpy

    Downgraded from numpy 2.x to numy 1.x for compatibility

commit 8eeecef
Merge: 4840eeb 373cc45
Author: JoeBell <joe@onmyhonor.com>
Date:   Tue Mar 4 17:40:20 2025 -0500

    Merge branch 'raytrace-update'

commit 4840eeb
Merge: 3ffe3b9 446bc2d
Author: Joseph R Bellemare <joseph.bellemare@uconn.edu>
Date:   Sun Mar 2 23:03:01 2025 -0500

    Merge pull request #2 from tjs20011/raytrace-update

    Raytrace update

commit 3ffe3b9
Merge: 9cc7468 4c24da0
Author: Joseph R Bellemare <joseph.bellemare@uconn.edu>
Date:   Thu Feb 20 19:11:19 2025 -0500

    Merge pull request #1 from tjs20011/raytrace-update

    Raytrace update
  • Loading branch information
jrb20008 committed Mar 25, 2025
1 parent 373cc45 commit a1151f1
Show file tree
Hide file tree
Showing 54 changed files with 5,398 additions and 114 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Created by venv; see https://docs.python.org/3/library/venv.html
ShipD/
ShipGen/
Scripts/
Lib/
Include/
Expand Down
1 change: 1 addition & 0 deletions AUVSim/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
5 changes: 5 additions & 0 deletions AUVSim/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .auv import (
AUV as AUV,
AUVPath as AUVPath,
AUVPathGen as AUVPathGen,
)
65 changes: 65 additions & 0 deletions AUVSim/auv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from Raytrace import TriangleMesh
from Raytrace.SideScan import SideScan
import numpy as np
from typing import Any
from CustomTypes import Ray, Vector3, Vector3Array

class AUV:
ideal_distance:float # Currently unused
start_pos:Vector3
start_facing:Vector3
def __init__(self,
position:Vector3,
facing:Vector3,
ideal_distance:float = -1,
):
self.start_pos = position
self.start_facing = facing
self.ideal_distance = ideal_distance
class AUVPath:
positions:Vector3Array
facings:Vector3Array

def __init__(self, positions:Vector3Array, facings:Vector3Array):
self.positions = positions
self.facings = facings
@property
def rays(self) -> list[Ray]:
return list(map(Ray, self.facings, self.positions))

class AUVPathGen:
mesh:TriangleMesh
auv:AUV
def __init__(self, mesh:TriangleMesh, auv:AUV):
self.mesh = mesh
self.auv = auv
def get_path(self, travel_distance:float, samples:int) -> AUVPath:
travel_step = travel_distance / (samples - 1)
positions = [self.auv.start_pos]
facings = [self.auv.start_facing]

# Utility functions
# HACK: There should be a function to generate one side ray
# instead of generating a list with length one.
get_side_ray = lambda face, pos:\
SideScan.generate_rays(Ray(face, pos), 0, 1, 2)[0]
get_dist = lambda ray: self.mesh.raytrace(ray)
normalize = lambda vector: vector / np.sqrt(np.dot(vector, vector))

for _ in range(samples - 1):
# find distance at current state
prev_dist = get_dist(get_side_ray(facings[-1], positions[-1]))
# move frowards
positions.append(positions[-1] + facings[-1] * travel_step)
# shoot side ray
# NOTE: facing has not yet been updated
side_ray = get_side_ray(facings[-1], positions[-1])
ray_dist = self.mesh.raytrace(side_ray)
# point in the direction that the hull is sloping
rise = (ray_dist - prev_dist) * side_ray.direction
if not (np.isfinite(ray_dist) and np.isfinite(prev_dist)):
rise = Vector3(0, 0, 0)
new_facing = normalize(facings[-1] + rise)
facings.append(new_facing)

return AUVPath(Vector3Array(positions), Vector3Array(facings))
1 change: 1 addition & 0 deletions CustomTypes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
11 changes: 11 additions & 0 deletions CustomTypes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .custom_np import CustomNP as CustomNP
from .custom_types import (
Vector3 as Vector3,
Triangle as Triangle,
Ray as Ray,
)
from .custom_arrays import (
FloatArray as FloatArray,
TriangleArray as TriangleArray,
Vector3Array as Vector3Array,
)
54 changes: 54 additions & 0 deletions CustomTypes/custom_arrays.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from typing import Any, Iterable, Literal, overload
import numpy as np

from . import CustomNP, Triangle, Vector3

class FloatArray(CustomNP):
def __new__(cls,
content: Iterable[float]|np.ndarray|None = None,
):
if isinstance(content, np.ndarray):
if content.ndim != 1: raise ValueError(content.shape) # must be 1d
return content.view(cls)
if content is None:
return np.ndarray((0,), float).view(cls)
return np.array(content).view(cls)
def __getitem__(self, index):
if isinstance(index, slice): return super().__getitem__(index).view(type(self))
return super().__getitem__(index)

class Vector3Array(CustomNP):
def __new__(cls,
content: Iterable[Vector3]|np.ndarray|None = None,
):
if isinstance(content, np.ndarray):
if content.ndim == 1: content = content.reshape((1,) + content.shape)
if content.ndim != 2: raise ValueError(content.shape) # must be 1d or 2d
if content.shape[1] != 3: raise ValueError(content.shape) # must be shape (n, 3)
return content.view(cls)
if content is None:
return np.ndarray((0, 3), float).view(cls)
return np.array(content).view(cls)
def __getitem__(self, index):
if isinstance(index, slice): return super().__getitem__(index).view(type(self))
return super().__getitem__(index)

class TriangleArray(CustomNP):
def __new__(cls,
content: Iterable[Triangle]|np.ndarray|None = None,
):
if isinstance(content, np.ndarray):
if content.ndim == 2: content = content.reshape((1,) + content.shape)
if content.ndim != 3: raise ValueError(content.shape) # must be 2d or 3d
if content.shape[1] != 3 or content.shape[2] != 3: raise ValueError(content.shape) # must be shape (n, 3, 3)
return content.view(cls)
if content is None:
return np.ndarray((0, 3, 3), float).view(cls)
return np.array(content).view(cls)
def __getitem__(self, index):
if isinstance(index, slice): return super().__getitem__(index).view(type(self))
return super().__getitem__(index)
@property
def verticies(self) -> tuple[Vector3Array, Vector3Array, Vector3Array]:
v0, v1, v2 = self.swapaxes(0, 1)
return (v0.view(Vector3Array), v1.view(Vector3Array), v2.view(Vector3Array))
53 changes: 53 additions & 0 deletions CustomTypes/custom_arrays.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import numpy as np
from typing import Any, Iterable, Literal, Self, Type, TypeVar, overload

from . import CustomNP, Triangle, Vector3

class FloatArray(CustomNP[tuple[int, Literal[3]], np.dtype[np.float_]]):
@overload
def __new__(cls) -> FloatArray:...
@overload
def __new__(cls, content: Iterable[float]) -> FloatArray:...
@overload
def __new__(cls, content: np.ndarray[tuple[int], np.dtype[np.float_]]) -> FloatArray:...

@overload # type: ignore
def __getitem__(self, index:int) -> float: ...
@overload
def __getitem__(self, index:slice) -> Self: ...

class Vector3Array(CustomNP[tuple[int, Literal[3]], np.dtype[np.float_]]):
@overload
def __new__(cls) -> Vector3Array:...
@overload
def __new__(cls, content: Iterable[Vector3]) -> Vector3Array:...
@overload
def __new__(cls, content: np.ndarray[tuple[int, Literal[3]], np.dtype[np.float_]]) -> Vector3Array:...

@overload # type: ignore
def __getitem__(self, index:int) -> Vector3: ...
@overload
def __getitem__(self, index:tuple[int, Literal[0, 1, 2]]) -> float: ...
@overload
def __getitem__(self, index:slice) -> Self: ...

class TriangleArray(CustomNP[tuple[int, Literal[3], Literal[3]], np.dtype[np.float_]]):
@overload
def __new__(cls) -> TriangleArray:...
@overload
def __new__(cls, content: Iterable[Triangle]) -> TriangleArray:...
@overload
def __new__(cls, content: np.ndarray[tuple[int, Literal[3], Literal[3]], np.dtype[np.float_]]) -> TriangleArray:...

@overload # type: ignore
def __getitem__(self, index:int) -> Triangle: ...
@overload
def __getitem__(self, index:tuple[int, Literal[0, 1, 2]]) -> Vector3: ...
@overload
def __getitem__(self, index:tuple[int, Literal[0, 1, 2], Literal[0, 1, 2]]) -> float: ...
@overload
def __getitem__(self, index:slice) -> Self: ...

@property
def verticies(self) -> tuple[Vector3Array, Vector3Array, Vector3Array]: ...

21 changes: 21 additions & 0 deletions CustomTypes/custom_np.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

from typing import Generic, TypeVar, Self
import numpy as np


_S = TypeVar('_S', bound=tuple)
_T = TypeVar('_T', bound=np.dtype)
class CustomNP(np.ndarray[_S, _T]):
def __add__(self, other):
return super().__add__(other).view(type(self))
def __sub__(self, other):
return super().__sub__(other).view(type(self))
def __mul__(self, other):
return super().__mul__(other).view(type(self))
def __truediv__(self, other):
return super().__truediv__(other).view(type(self))
def __rtruediv__(self, other):
return super().__rtruediv__(other).view(type(self))
@property
def nd(self):
return self.view(np.ndarray)
15 changes: 15 additions & 0 deletions CustomTypes/custom_np.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import TypeVar, Self
import numpy as np


_S = TypeVar('_S', bound=tuple)
_T = TypeVar('_T', bound=np.dtype)
class CustomNP(np.ndarray[_S, _T]):
def __add__(self, other:Self) -> Self: ... # type: ignore
def __sub__(self, other:Self) -> Self: ... # type: ignore
def __mul__(self, other:Self|float) -> Self: ... # type: ignore
def __truediv__(self, other:Self|float) -> Self: ... # type: ignore
def __rtruediv__(self, other:float) -> Self: ... # type: ignore

@property
def nd(self) -> np.ndarray: ...
42 changes: 42 additions & 0 deletions CustomTypes/custom_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from typing import Any, Iterable, Literal, Self, overload
import numpy as np
from . import CustomNP

class Vector3(CustomNP):
def __new__(cls,
x: float | tuple[float, float, float] | Self, y = 0, z = 0):
if isinstance(x, tuple):
x, y, z = x
elif isinstance(x, Vector3):
x, y, z = x
assert isinstance(x, (float, int, np.floating))
return np.array([x, y, z]).view(cls)
def __str__(self):
return f"({self[0]}, {self[1]}, {self[2]})"
def __repr__(self):
return f"Vector3({self[0]}, {self[1]}, {self[2]})"

class Triangle(CustomNP):
def __new__(cls,
v0: Vector3 | tuple[Vector3, Vector3, Vector3],
v1: Vector3 = Vector3(0, 0, 0),
v2: Vector3 = Vector3(0, 0, 0),
) -> 'Triangle':
if isinstance(v0, tuple):
v0, v1, v2 = v0
return np.array([v0, v1, v2]).view(cls)

def __str__(self) -> str:
return f"({self[0]}, {self[1]}, {self[2]})"
def __repr__(self) -> str:
return f"Vector3({self[0]}, {self[1]}, {self[2]})"

class Ray:
direction:Vector3
origin:Vector3
def __init__(self,
direction:Vector3,
origin:Vector3,
) -> None:
self.direction = direction
self.origin = origin
40 changes: 40 additions & 0 deletions CustomTypes/custom_types.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from typing import Any, Iterable, Iterator, Literal, TypeAlias, TypeVar, overload
import numpy as np
from . import CustomNP

class Vector3(CustomNP[tuple[Literal[3]], np.dtype[np.float_]]):
@overload
def __new__(cls, x: float, y: float, z: float) -> Vector3: ...
@overload
def __new__(cls, x: tuple[float, float, float]) -> Vector3: ...
@overload
def __new__(cls, x: Vector3) -> Vector3: ...

def __getitem__(self, index:Literal[0, 1, 2]) -> float: ... # type: ignore

class Triangle(CustomNP[tuple[Literal[3], Literal[3]], np.dtype[np.float_]], Iterable[Vector3]):
@overload
def __new__(cls, v0: Vector3, v1: Vector3, v2: Vector3) -> Triangle: ...
@overload
def __new__(cls, v0: tuple[Vector3, Vector3, Vector3]) -> Triangle: ...
@overload
def __new__(cls, v0: Triangle) -> Triangle: ...

@overload # type: ignore
def __getitem__(self, index:Literal[0, 1, 2]) -> Vector3: ...
@overload
def __getitem__(self, index:tuple[Literal[0, 1, 2], Literal[0, 1, 2]]) -> float: ...

def __add__(self, other:Triangle) -> Triangle: ... # type: ignore
def __sub__(self, other:Triangle) -> Triangle: ... # type: ignore

def __iter__(self) -> Iterator[Vector3]: ...
class Ray:
direction:Vector3
origin:Vector3
def __init__(self,
direction:Vector3,
origin:Vector3,
) -> None:
self.direction = direction
self.origin = origin
1 change: 1 addition & 0 deletions Generate/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
13 changes: 13 additions & 0 deletions Generate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .auv import(
place_auvs_over_points as place_auvs_over_points,
generate_paths as generate_paths,
scan_paths as scan_paths,
)
from .hull import (
generate_hulls as generate_hulls,
generate_points_on_hull as generate_points_on_hull,
generate_vertical_bounds as generate_vertical_bounds,
load_anomalies as load_anomalies,
pick_anomalies as pick_anomalies,
place_anomalies_at_points as place_anomalies_at_points,
)
Loading

0 comments on commit a1151f1

Please sign in to comment.