Skip to content

Commit

Permalink
changed open3d requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanacelii committed Jun 17, 2024
1 parent a1c595b commit 79116ca
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 2 deletions.
77 changes: 77 additions & 0 deletions mesh_tools/trimesh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import trimesh
from trimesh.path.exchange.misc import faces_to_path
from trimesh import triangles
import itertools

try:
import cgal_Segmentation_Module as csm
Expand Down Expand Up @@ -7122,6 +7123,78 @@ def query_meshes_from_restrictions(
else:
return return_meshes



def bbox_mesh(
arr = None,
bbox_corners=None,
bbox_coords=None,
verbose = False,
debug = False,
plot = False,
):
"""
compute the faces of the bouding box mesh: it is the size 3 sliding window across a path (for all paths)
- but there is some redundancy paths then
How to efficiently determine all paths?
1) node can only move from point with one element greater
- could get edge matrix easily
"""

if bbox_coords is None:
if bbox_corners is None:
bbox_corners = nu.bounding_box_corners(arr)
bbox_coords = nu.bounding_box_vertices(bbox_corners,plot=False)


A = np.array([(np.sum(bbox_coords - k > 0 ,axis = 1) == 1) & (~np.any(bbox_coords - k < 0,axis = 1))
for k in bbox_coords])
AT = A.T

G = dict([(i,np.where(A[i,:])[0].astype('int')) for i in range(len(A))])
GT = dict([(i,np.where(AT[i,:])[0].astype('int')) for i in range(len(AT))])


faces = []

for u in G:
upstream = GT[u]
downstream = G[u]
if len(upstream) == 0 or len(downstream) == 0:
continue

combs = itertools.product(upstream,downstream)
paths = [[k[0],u,k[1]] for k in combs]

if debug:
print(f"Working on node {u}:")
print(f" upstream = {upstream}, downstream = {downstream}")
path_str = '\n'.join([str(k) for k in paths])
print(f" All paths: {path_str}")

faces += paths


if verbose:
print(f"# of faces = {len(faces)}")

bbox_mesh = trimesh.Trimesh(
vertices = bbox_coords,
faces = np.array(faces),
)

if plot:
ipvu.plot_objects(
bbox_mesh,
scatters=[bbox_coords],
scatter_size=1,
buffer = 1,
axis_box_off=False
)

return bbox_mesh


from datasci_tools import mesh_utils as meshu
clear_mesh_cache = meshu.clear_mesh_cache
Expand Down Expand Up @@ -7153,4 +7226,8 @@ def query_meshes_from_restrictions(
from datasci_tools import system_utils as su
from datasci_tools.tqdm_utils import tqdm





from . import trimesh_utils as tu
5 changes: 3 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ h5py>=3.1.0
ipyvolume>=0.5.2
matplotlib>=3.3.4
networkx>=2.5
open3d==0.11.2
open3d
#open3d==0.11.2
#open3d==0.13.0
pymeshfix>=0.13.4
datasci-stdlib-tools>=1.0.1
Expand All @@ -17,4 +18,4 @@ scipy>=1.5.4
tqdm>=4.62.2
trimesh>=3.9.0
ipython
ipython_genutils
ipython_genutils

0 comments on commit 79116ca

Please sign in to comment.