Skip to content

Commit

Permalink
Fix Open3D import
Browse files Browse the repository at this point in the history
  • Loading branch information
amogh7joshi committed May 18, 2023
1 parent cb6b1d1 commit 5e5541d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
16 changes: 8 additions & 8 deletions agml/data/point_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,6 @@
from agml.utils.general import is_float, is_int
from agml.utils.logging import log

try:
import open3d as o3d
except:
log("Open3D is not installed. If you want to have high-res point cloud "
"visualizations, please install Open3D using `pip install open3d`. "
"For now, defaulting to using 3D matplotlib visualizations.")
o3d = None


class PointCloud(object):
"""Represents a 3D point cloud object, with utilities for format + visualization."""
Expand Down Expand Up @@ -183,6 +175,14 @@ def _read_point_cloud(self, contents):
def _build_3d_object(self):
"""Function to construct the point cloud as a open3d point cloud object
"""
try:
import open3d as o3d
except:
log("Open3D is not installed. If you want to have high-res point cloud "
"visualizations, please install Open3D using `pip install open3d`. "
"For now, defaulting to using 3D matplotlib visualizations.")
o3d = None

# Construct the point cloud with the points and colors.
if o3d is not None:
self._structure_3d = o3d.geometry.PointCloud()
Expand Down
11 changes: 10 additions & 1 deletion agml/viz/point_clouds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import matplotlib.pyplot as plt

from agml.data.point_cloud import PointCloud, o3d
from agml.data.point_cloud import PointCloud
from agml.utils.logging import log


def show_point_cloud(point_cloud, format = 'default'):
Expand All @@ -33,6 +34,14 @@ def show_point_cloud(point_cloud, format = 'default'):
done using Open3D. If 'matplotlib', then the visualization will be
done using matplotlib. Defaults to 'default'.
"""
try:
import open3d as o3d
except:
log("Open3D is not installed. If you want to have high-res point cloud "
"visualizations, please install Open3D using `pip install open3d`. "
"For now, defaulting to using 3D matplotlib visualizations.")
o3d = None

# We need to hard-code this check because this method isn't designed to
# run with regular point cloud arrays, only `point_cloud` objects.
if not isinstance(point_cloud, PointCloud):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ numpy
matplotlib
tqdm
scikit-learn
requests>=2.0.0
opencv-python; sys.platform != 'linux'
opencv-python-headless; sys.platform == 'linux'
pyyaml>=5.4.1
Expand Down

0 comments on commit 5e5541d

Please sign in to comment.