Skip to content

Commit

Permalink
wrap load_path import in camera marker
Browse files Browse the repository at this point in the history
  • Loading branch information
mikedh committed Nov 29, 2018
1 parent 6eb51c5 commit 97a43ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 30 deletions.
10 changes: 7 additions & 3 deletions tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,17 @@ def test_spheres(self):
assert g.np.allclose(radii, 1.0)

def test_camera_marker(self):
"""
Create a marker including FOV for a camera object
"""
camera = g.trimesh.scene.Camera(resolution=(320, 240), fov=(60, 45))
meshes = g.trimesh.creation.camera_marker(
camera=camera, marker_height=0.04
)
camera=camera, marker_height=0.04)
assert isinstance(meshes, list)
# all meshes should be viewable type
for mesh in meshes:
assert isinstance(mesh, (g.trimesh.Trimesh, g.trimesh.path.Path3D))
assert isinstance(mesh, (g.trimesh.Trimesh,
g.trimesh.path.Path3D))

def test_axis(self):
# specify the size of the origin radius
Expand Down
63 changes: 39 additions & 24 deletions trimesh/creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from .triangles import normals
from .geometry import faces_to_edges
from .grouping import group_rows, unique_rows
from .io.load import load_path

from . import util
from . import transformations
Expand Down Expand Up @@ -923,46 +922,62 @@ def camera_marker(camera, marker_height=0.4, origin_size=None):
Parameters
---------------
camera : trimesh.scene.Camera
Camera object with FOV and transform defined
Camera object with FOV and transform defined
marker_height : float
How far along the camera Z should FOV indicators be
How far along the camera Z should FOV indicators be
origin_size : float
Sphere radius of the origin (default: marker_height / 10.0)
Sphere radius of the origin (default: marker_height / 10.0)
Returns
------------
meshes : list
Contains Trimesh and Path3D objects which can be visualized
Contains Trimesh and Path3D objects which can be visualized
"""

# append the visualizations to an array
meshes = [axis(origin_size=marker_height / 10.0)]
meshes[0].apply_transform(camera.transform)

try:
# path is a soft dependancy
from .io.load import load_path
except ImportError:
# they probably don't have shapely installed
log.warning('unable to create FOV visualization!',
exc_info=True)
return meshes

# create sane origin size from marker height
if origin_size is None:
origin_size = marker_height / 10.0

# calculate vertices from camera FOV angles
x = marker_height * np.tan(np.deg2rad(camera.fov[0]) / 2.0)
y = marker_height * np.tan(np.deg2rad(camera.fov[1]) / 2.0)
z = marker_height

points = [
(0, 0, 0), # origin
(-x, -y, z),
(x, -y, z),
(x, y, z),
(-x, y, z),
]
# combine the points into the vertices of an FOV visualization
points = [(0, 0, 0),
(-x, -y, z),
(x, -y, z),
(x, y, z),
(-x, y, z)]
# apply the camera extrinsic transform
points = transformations.transform_points(points, camera.transform)

point_origin = points[0]
points = points[1:]

meshes = []
mesh = axis(origin_size=marker_height / 10.0)
mesh.apply_transform(camera.transform)
meshes.append(mesh)
# create line segments for the FOV visualization
# a segment from the origin to each bound of the FOV
segments = np.column_stack((np.zeros_like(points), points)).reshape((-1, 3))

for point in points:
mesh = load_path([point_origin, point])
meshes.append(mesh)
# add a loop for the outside of the FOV then reshape
# the whole thing into multiple line segments
segments = np.vstack((segments,
points[[1, 2,
2, 3,
3, 4,
4, 1]])).reshape((-1, 2, 3))

mesh = load_path(np.r_[points, points[0:1]])
meshes.append(mesh)
# add a single Path3D object for all line segments
meshes.append(load_path(segments))

return meshes
7 changes: 4 additions & 3 deletions trimesh/io/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,11 @@ def parse_file_args(file_obj,
# JSON
file_type = 'json'
elif 'https://' in file_obj or 'http://' in file_obj:
# we've been passed a URL so retrieve it
raise ValueError('use load_remote to load URL: %s' % file_obj)
# we've been passed a URL, warn to use explicit function
# and don't do network calls via magical pipeline
raise ValueError('use load_remote to load URL: {}'.format(file_obj))
elif file_type is None:
raise ValueError('string is not a file: %s' % file_obj)
raise ValueError('string is not a file: {}'.format(file_obj))

if file_type is None:
file_type = file_obj.__class__.__name__
Expand Down

0 comments on commit 97a43ed

Please sign in to comment.