Commit
·
a3afcbc
1
Parent(s):
19b8852
updates
Browse files- hoho/__init__.py +5 -4
- hoho/hoho.py +1 -0
- hoho/vis.py +87 -0
hoho/__init__.py
CHANGED
|
@@ -4,6 +4,7 @@ from . import read_write_colmap
|
|
| 4 |
|
| 5 |
import importlib
|
| 6 |
import sys
|
|
|
|
| 7 |
class LazyLoadModule:
|
| 8 |
def __init__(self, module_name):
|
| 9 |
self.module_name = module_name
|
|
@@ -19,7 +20,7 @@ class LazyLoadModule:
|
|
| 19 |
|
| 20 |
return getattr(self.module, attr)
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
|
|
|
| 4 |
|
| 5 |
import importlib
|
| 6 |
import sys
|
| 7 |
+
|
| 8 |
class LazyLoadModule:
|
| 9 |
def __init__(self, module_name):
|
| 10 |
self.module_name = module_name
|
|
|
|
| 20 |
|
| 21 |
return getattr(self.module, attr)
|
| 22 |
|
| 23 |
+
try:
|
| 24 |
+
import viz3d
|
| 25 |
+
except ImportError:
|
| 26 |
+
viz3d = LazyLoadModule('viz3d')
|
hoho/hoho.py
CHANGED
|
@@ -31,6 +31,7 @@ def setup(local_dir='./data/usm-training-data/data'):
|
|
| 31 |
print(f"Using {LOCAL_DATADIR} as the data directory (we are running locally)")
|
| 32 |
|
| 33 |
# os.system("ls -lahtr")
|
|
|
|
| 34 |
|
| 35 |
assert LOCAL_DATADIR.exists(), f"Data directory {LOCAL_DATADIR} does not exist"
|
| 36 |
return LOCAL_DATADIR
|
|
|
|
| 31 |
print(f"Using {LOCAL_DATADIR} as the data directory (we are running locally)")
|
| 32 |
|
| 33 |
# os.system("ls -lahtr")
|
| 34 |
+
# os.system(f"ls -lahtr {LOCAL_DATADIR}")
|
| 35 |
|
| 36 |
assert LOCAL_DATADIR.exists(), f"Data directory {LOCAL_DATADIR} does not exist"
|
| 37 |
return LOCAL_DATADIR
|
hoho/vis.py
CHANGED
|
@@ -1,2 +1,89 @@
|
|
| 1 |
import trimesh
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
|
|
|
| 1 |
import trimesh
|
| 2 |
+
import numpy as np
|
| 3 |
+
from copy import deepcopy
|
| 4 |
+
|
| 5 |
+
def line(p1, p2, c=(255,0,0), resolution=10, radius=0.05):
|
| 6 |
+
'''draws a 3d cylinder along the line (p1, p2)'''
|
| 7 |
+
# check colors
|
| 8 |
+
if len(c) == 1:
|
| 9 |
+
c = [c[0]]*4
|
| 10 |
+
elif len(c) == 3:
|
| 11 |
+
c = [*c, 255]
|
| 12 |
+
elif len(c) != 4:
|
| 13 |
+
raise ValueError(f'{c} is not a valid color (must have 1,3, or 4 elements).')
|
| 14 |
+
|
| 15 |
+
# compute length and direction of segment
|
| 16 |
+
p1, p2 = np.asarray(p1), np.asarray(p2)
|
| 17 |
+
l = np.linalg.norm(p2-p1)
|
| 18 |
+
|
| 19 |
+
direction = (p2 - p1) / l
|
| 20 |
+
|
| 21 |
+
# point z along direction of segment
|
| 22 |
+
T = np.eye(4)
|
| 23 |
+
T[:3, 2] = direction
|
| 24 |
+
T[:3, 3] = (p1+p2)/2
|
| 25 |
+
|
| 26 |
+
#reorthogonalize basis
|
| 27 |
+
b0, b1 = T[:3, 0], T[:3, 1]
|
| 28 |
+
if np.abs(np.dot(b0, direction)) < np.abs(np.dot(b1, direction)):
|
| 29 |
+
T[:3, 1] = -np.cross(b0, direction)
|
| 30 |
+
else:
|
| 31 |
+
T[:3, 0] = np.cross(b1, direction)
|
| 32 |
+
|
| 33 |
+
# generate and transform mesh
|
| 34 |
+
mesh = trimesh.primitives.Cylinder(radius=radius, height=l, transform=T)
|
| 35 |
+
|
| 36 |
+
# apply uniform color
|
| 37 |
+
mesh.visual.vertex_colors = np.ones_like(mesh.visual.vertex_colors)*c
|
| 38 |
+
|
| 39 |
+
return mesh
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def show_grid(edges, meshes=None, row_length=5):
|
| 43 |
+
'''
|
| 44 |
+
edges: list of list of meshes
|
| 45 |
+
meshes: optional corresponding list of meshes
|
| 46 |
+
row_length: number of meshes per row
|
| 47 |
+
|
| 48 |
+
returns trimesh.Scene()
|
| 49 |
+
'''
|
| 50 |
+
|
| 51 |
+
T = np.eye(4)
|
| 52 |
+
out = []
|
| 53 |
+
row_height = max(((sum(e[1:], e[0])).extents for e in edges), key=lambda e: e[2])[2]
|
| 54 |
+
col_width = max((sum(e[1:], e[0]).extents for e in edges), key=lambda e: e[0])[0]
|
| 55 |
+
# print(row_height, col_width)
|
| 56 |
+
|
| 57 |
+
if meshes is None:
|
| 58 |
+
meshes = [None]*len(edges)
|
| 59 |
+
|
| 60 |
+
for i, (gt, mesh) in enumerate(zip(edges, meshes), start=0):
|
| 61 |
+
mesh = deepcopy(mesh)
|
| 62 |
+
|
| 63 |
+
gt = sum(gt[1:], gt[0])
|
| 64 |
+
# gt = deepcopy(sum(gt[1:], gt[0]))
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if i%row_length != 0:
|
| 68 |
+
T[0, 3] += col_width
|
| 69 |
+
|
| 70 |
+
else:
|
| 71 |
+
T[0, 3] = 0
|
| 72 |
+
T[2, 3] += row_height
|
| 73 |
+
|
| 74 |
+
# print(T[0,3]/col_width, T[2,3]/row_height)
|
| 75 |
+
|
| 76 |
+
if mesh is not None:
|
| 77 |
+
mesh.apply_transform(T)
|
| 78 |
+
out.append(mesh)
|
| 79 |
+
|
| 80 |
+
gt.apply_transform(T)
|
| 81 |
+
out.append(gt)
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
out.extend([mesh, gt])
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
return trimesh.Scene(out)
|
| 88 |
+
|
| 89 |
|