-
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
Showing
12 changed files
with
487 additions
and
116 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# ruff: noqa: F401, F403 | ||
|
||
from .common import get_nth_newest_file_in_folder | ||
from .compas import box_from_corner_frame, get_linear_xform_between_2_boxes | ||
from .math import calculate_chance, remap, remap_trim | ||
from .numpy import ( | ||
NB_INDEX_DICT, | ||
clip_indices_to_grid_size, | ||
conditional_fill, | ||
convert_array_to_pts, | ||
create_random_array, | ||
crop_array, | ||
get_cube_array_indices, | ||
get_mask_zone_xxyyzz, | ||
get_sub_array, | ||
make_solid_box_xxyyzz, | ||
make_solid_box_xxz, | ||
make_solid_box_z, | ||
random_choice_index_from_best_n, | ||
random_choice_index_from_best_n_old, | ||
save_ndarray, | ||
sort_pts_by_values, | ||
) | ||
from .pointcloud import ( | ||
ply_to_compas, | ||
ply_to_numpy, | ||
pointcloud_from_ndarray, | ||
save_pointcloud, | ||
) | ||
from .savepaths import get_savepath | ||
from .vdb import xform_to_compas, xform_to_vdb |
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,33 @@ | ||
import compas.geometry as cg | ||
|
||
|
||
def box_from_corner_frame(frame: cg.Frame, xsize:float, ysize:float, zsize: float): | ||
"""Create a box from origin and size.""" | ||
center_pt = frame.point.copy() | ||
center_pt += cg.Vector(xsize / 2, ysize / 2, zsize / 2) | ||
|
||
center_frame = cg.Frame(center_pt, xaxis=frame.xaxis, yaxis=frame.yaxis) | ||
|
||
return cg.Box(xsize=xsize, ysize=ysize, zsize=zsize, frame=center_frame) | ||
|
||
|
||
def get_linear_xform_between_2_boxes(from_box: cg.Box, to_box: cg.Box): | ||
"""Get the linear transformation between two bounding boxes.""" | ||
f_pt = from_box.frame.point.copy() | ||
f_pt -= cg.Point(from_box.width / 2, from_box.height / 2, from_box.depth / 2) | ||
|
||
t_pt = to_box.frame.point.copy() | ||
t_pt -= cg.Point(to_box.width / 2, to_box.height / 2, to_box.depth / 2) | ||
|
||
Tr = cg.Translation.from_vector(t_pt - f_pt) | ||
|
||
R = cg.Rotation.from_frame_to_frame( | ||
frame_from=to_box.frame, frame_to=from_box.frame | ||
) | ||
|
||
xfactor = from_box.width / to_box.width | ||
yfactor =from_box.height / to_box.height | ||
zfactor = from_box.depth / to_box.depth | ||
S = cg.Scale.from_factors([xfactor, yfactor, zfactor]) | ||
|
||
return Tr * R * S |
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 was deleted.
Oops, something went wrong.
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,39 @@ | ||
import numpy as np | ||
import numpy.typing as npt | ||
import pytest | ||
|
||
|
||
@pytest.fixture | ||
def random_generator(): | ||
return np.random.default_rng(1000) | ||
|
||
|
||
@pytest.fixture | ||
def random_int_array(random_generator): | ||
shape = (10, 10, 10) | ||
return random_generator.integers(0, 2, size=shape) | ||
|
||
|
||
def _random_pts(n_pts: int, random_generator: np.random.Generator): | ||
shape = (n_pts, 3) | ||
return 100 * random_generator.random(shape) - 100 | ||
|
||
@pytest.fixture | ||
def random_pts(): | ||
return _random_pts | ||
|
||
|
||
def _activate_random_indices( | ||
array: npt.NDArray, random_generator: np.random.Generator | ||
) -> tuple[npt.NDArray, int]: | ||
"""Activate random voxels in the grid, return number activated.""" | ||
random_array = random_generator.integers(0, high=2, size=array.shape).astype( | ||
array.dtype | ||
) | ||
|
||
return random_array, len(np.flatnonzero(random_array)) | ||
|
||
|
||
@pytest.fixture | ||
def activate_random_indices(): | ||
return _activate_random_indices |
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
Empty file.
Oops, something went wrong.