-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Re-organize code * Use delayed typing/TYPE_CHECKING to avoid circular imports (https://stackoverflow.com/a/69427502) * Use relative imports where possible * Fix bugs in notebooks
- Loading branch information
1 parent
4b7adb1
commit 766dd35
Showing
24 changed files
with
246 additions
and
3,240 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
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
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,10 @@ | ||
from .helpers import compare_mesh_with_image, pad, simple_triangulate | ||
from .mesher import Mesher2D, generate_2d_mesh | ||
|
||
__all__ = [ | ||
'compare_mesh_with_image', | ||
'generate_2d_mesh', | ||
'Mesher2D', | ||
'pad', | ||
'simple_triangulate', | ||
] |
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
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
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,10 @@ | ||
from .bounding_box import BoundingBox | ||
from .helpers import pad | ||
from .mesher import Mesher3D, generate_3d_mesh, get_region_markers | ||
|
||
__all__ = [ | ||
'BoundingBox', | ||
'generate_3d_mesh', | ||
'Mesher3D', | ||
'pad', | ||
] |
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,73 @@ | ||
from dataclasses import dataclass | ||
from typing import Tuple | ||
|
||
import numpy as np | ||
|
||
|
||
@dataclass | ||
class BoundingBox: | ||
"""Container for bounding box coordinates.""" | ||
xmin: float | ||
xmax: float | ||
ymin: float | ||
ymax: float | ||
zmin: float | ||
zmax: float | ||
|
||
@classmethod | ||
def from_shape(cls, shape: tuple): | ||
"""Generate bounding box from data shape.""" | ||
xmin, ymin, zmin = 0, 0, 0 | ||
xmax, ymax, zmax = np.array(shape) - 1 | ||
return cls(xmin=xmin, | ||
ymin=ymin, | ||
zmin=zmin, | ||
xmax=xmax, | ||
ymax=ymax, | ||
zmax=zmax) | ||
|
||
@property | ||
def dimensions(self) -> Tuple[float, float, float]: | ||
"""Return dimensions of bounding box.""" | ||
return ( | ||
self.xmax - self.xmin, | ||
self.ymax - self.ymin, | ||
self.zmax - self.zmin, | ||
) | ||
|
||
@classmethod | ||
def from_points(cls, points: np.array): | ||
"""Generate bounding box from set of points or coordinates.""" | ||
xmax, ymax, zmax = np.max(points, axis=0) | ||
xmin, ymin, zmin = np.min(points, axis=0) | ||
|
||
return cls( | ||
xmin=xmin, | ||
xmax=xmax, | ||
ymin=ymin, | ||
ymax=ymax, | ||
zmin=zmin, | ||
zmax=zmax, | ||
) | ||
|
||
def to_points(self) -> np.ndarray: | ||
"""Return (m,3) array with corner points.""" | ||
return np.array([ | ||
[self.xmin, self.ymin, self.zmin], | ||
[self.xmin, self.ymin, self.zmax], | ||
[self.xmin, self.ymax, self.zmin], | ||
[self.xmin, self.ymax, self.zmax], | ||
[self.xmax, self.ymin, self.zmin], | ||
[self.xmax, self.ymin, self.zmax], | ||
[self.xmax, self.ymax, self.zmin], | ||
[self.xmax, self.ymax, self.zmax], | ||
]) | ||
|
||
@property | ||
def center(self) -> np.ndarray: | ||
"""Return center of the bounding box.""" | ||
return np.array(( | ||
(self.xmin + self.xmax) / 2, | ||
(self.ymin + self.ymax) / 2, | ||
(self.zmin + self.zmax) / 2, | ||
)) |
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
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
Oops, something went wrong.