Skip to content

Commit

Permalink
Merge branch 'main' of github.com:isl-org/Open3D into bu/support-pyth…
Browse files Browse the repository at this point in the history
…on-312-mirror
  • Loading branch information
ssheorey committed Sep 30, 2024
2 parents cc01512 + e88c7b1 commit 9856186
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 51 deletions.
9 changes: 9 additions & 0 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,7 @@ if(BUILD_GUI)
if (CPP_LIBRARY AND CPPABI_LIBRARY)
set(CLANG_LIBDIR ${llvm_lib_dir})
message(STATUS "CLANG_LIBDIR found in ubuntu-default: ${CLANG_LIBDIR}")
set(LIBCPP_VERSION ${llvm_ver})
break()
endif()
endforeach()
Expand All @@ -1363,7 +1364,10 @@ if(BUILD_GUI)
llvm-8/lib
llvm-7/lib
)
file(REAL_PATH ${CPPABI_LIBRARY} CPPABI_LIBRARY)
get_filename_component(CLANG_LIBDIR ${CPPABI_LIBRARY} DIRECTORY)
string(REGEX MATCH "llvm-([0-9]+)/lib" _ ${CLANG_LIBDIR})
set(LIBCPP_VERSION ${CMAKE_MATCH_1})
endif()

# Find clang libraries at the exact path ${CLANG_LIBDIR}.
Expand All @@ -1379,6 +1383,11 @@ if(BUILD_GUI)
target_link_libraries(3rdparty_filament INTERFACE -lstdc++
${CPP_LIBRARY} ${CPPABI_LIBRARY})
message(STATUS "Filament C++ libraries: ${CPP_LIBRARY} ${CPPABI_LIBRARY}")
if (LIBCPP_VERSION GREATER 11)
message(WARNING "libc++ (LLVM) version ${LIBCPP_VERSION} > 11 includes libunwind that "
"interferes with the system libunwind.so.8 and may crash Python code when exceptions "
"are used. Please consider using libc++ (LLVM) v11.")
endif()
endif()
if (APPLE)
find_library(CORE_VIDEO CoreVideo)
Expand Down
25 changes: 6 additions & 19 deletions cpp/open3d/core/nns/NanoFlannImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,6 @@ void _KnnSearchCPU(NanoFlannIndexHolderBase *holder,
return;
}

auto points_equal = [](const T *const p1, const T *const p2,
size_t dimension) {
std::vector<T> p1_vec(p1, p1 + dimension);
std::vector<T> p2_vec(p2, p2 + dimension);
return p1_vec == p2_vec;
};

std::vector<std::vector<TIndex>> neighbors_indices(num_queries);
std::vector<std::vector<T>> neighbors_distances(num_queries);
std::vector<uint32_t> neighbors_count(num_queries, 0);
Expand All @@ -147,8 +140,9 @@ void _KnnSearchCPU(NanoFlannIndexHolderBase *holder,
for (size_t valid_i = 0; valid_i < num_valid; ++valid_i) {
TIndex idx = result_indices[valid_i];
if (ignore_query_point &&
points_equal(&queries[i * dimension],
&points[idx * dimension], dimension)) {
std::equal(&queries[i * dimension],
&queries[i * dimension] + dimension,
&points[idx * dimension])) {
continue;
}
neighbors_indices[i].push_back(idx);
Expand Down Expand Up @@ -222,13 +216,6 @@ void _RadiusSearchCPU(NanoFlannIndexHolderBase *holder,
return;
}

auto points_equal = [](const T *const p1, const T *const p2,
size_t dimension) {
std::vector<T> p1_vec(p1, p1 + dimension);
std::vector<T> p2_vec(p2, p2 + dimension);
return p1_vec == p2_vec;
};

std::vector<std::vector<TIndex>> neighbors_indices(num_queries);
std::vector<std::vector<T>> neighbors_distances(num_queries);
std::vector<uint32_t> neighbors_count(num_queries, 0);
Expand All @@ -255,9 +242,9 @@ void _RadiusSearchCPU(NanoFlannIndexHolderBase *holder,
int num_neighbors = 0;
for (const auto &idx_dist : search_result) {
if (ignore_query_point &&
points_equal(&queries[i * dimension],
&points[idx_dist.first * dimension],
dimension)) {
std::equal(&queries[i * dimension],
&queries[i * dimension] + dimension,
&points[idx_dist.first * dimension])) {
continue;
}
neighbors_indices[i].push_back(idx_dist.first);
Expand Down
3 changes: 3 additions & 0 deletions cpp/pybind/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ set(PYTHON_COMPILED_MODULE_DIR
if (APPLE)
set_target_properties(pybind PROPERTIES BUILD_RPATH "@loader_path;@loader_path/..")
elseif (UNIX)
# Use RPATH instead of RUNPATH in pybind so that needed libc++.so can find child dependant libc++abi.so in RPATH
# https://stackoverflow.com/questions/69662319/managing-secondary-dependencies-of-shared-libraries
target_link_options(pybind PRIVATE "LINKER:--disable-new-dtags")
set_target_properties(pybind PROPERTIES BUILD_RPATH "$ORIGIN;$ORIGIN/..")
endif()
set_target_properties(pybind PROPERTIES
Expand Down
7 changes: 7 additions & 0 deletions cpp/tests/t/geometry/TensorMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ TEST_P(TensorMapPermuteDevices, Constructor) {
// Primary key is required.
EXPECT_ANY_THROW(t::geometry::TensorMap());

// Delete primary key.
EXPECT_ANY_THROW(tm0.Erase("positions"));

// Reserved keys.
EXPECT_ANY_THROW(tm0.insert(
{"primary_key", core::Tensor::Zeros({2, 3}, dtype, device)}));

// Iterators.
std::map<std::string, core::Tensor> tensor_map(
{{"positions", core::Tensor::Zeros({10, 3}, dtype, device)},
Expand Down
45 changes: 29 additions & 16 deletions docker/Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -67,35 +67,48 @@ RUN if [ "${BUILD_SYCL_MODULE}" = "ON" ]; then \
rm -rf /etc/apt/sources.list.d/oneAPI.list; \
fi

# Dependencies: basic
# Dependencies: basic and python-build
RUN apt-get update && apt-get install -y \
git \
wget \
curl \
build-essential \
pkg-config \
zlib1g \
zlib1g-dev \
libssl-dev \
libbz2-dev \
libreadline-dev \
libsqlite3-dev \
libncursesw5-dev \
xz-utils \
tk-dev \
libxml2-dev \
libxmlsec1-dev \
libffi-dev \
liblzma-dev \
&& rm -rf /var/lib/apt/lists/*

# Miniforge or Intel conda
# The **/open3d/bin paths are used during docker run, in this way docker run
# pyenv or Intel Python
# The pyenv python paths are used during docker run, in this way docker run
# does not need to activate the environment again.
ENV PATH="/root/miniforge3/bin:${PATH}"
ENV PATH="/root/miniforge3/envs/open3d/bin:${PATH}"
# The soft link from the python patch level version to the python mino version
# ensures python wheel commands (i.e. open3d) are in PATH, since we don't know
# which patch level pyenv will install (latest).
ENV PYENV_ROOT=/root/.pyenv
ENV PATH="$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PYENV_ROOT/versions/$PYTHON_VERSION/bin:$PATH"
ENV PATH="/opt/intel/oneapi/intelpython/latest/bin:${PATH}"
ENV PATH="/opt/intel/oneapi/intelpython/latest/envs/open3d/bin:${PATH}"
RUN if [ "${BUILD_SYCL_MODULE}" = "OFF" ]; then \
wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"; \
bash Miniforge3-$(uname)-$(uname -m).sh -b; \
rm Miniforge3-$(uname)-$(uname -m).sh; \
curl https://pyenv.run | bash \
&& pyenv update \
&& pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION \
&& pyenv rehash \
&& ln -s $PYENV_ROOT/versions/${PYTHON_VERSION}* $PYENV_ROOT/versions/${PYTHON_VERSION}; \
fi
RUN python --version && pip --version

RUN conda --version \
&& conda create -y -n open3d python=${PYTHON_VERSION}

# Activate open3d virtualenv
# This works during docker build. It becomes the prefix of all RUN commands.
# Ref: https://stackoverflow.com/a/60148365/1255535
SHELL ["conda", "run", "-n", "open3d", "/bin/bash", "-o", "pipefail", "-c"]
SHELL ["/bin/bash", "-o", "pipefail", "-c"]

# Dependencies: cmake
ENV PATH=${HOME}/${CMAKE_VERSION}/bin:${PATH}
Expand Down
2 changes: 1 addition & 1 deletion docker/docker_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ cpp_python_linking_uninstall_test() {
# Python test
echo "pytest is randomized, add --randomly-seed=SEED to repeat the test sequence."
${docker_run} -i --rm "${DOCKER_TAG}" /bin/bash -c " \
python -m pytest python/test ${pytest_args} -s"
python -W default -m pytest python/test ${pytest_args} -s"
restart_docker_daemon_if_on_gcloud

# Command-line tools test
Expand Down
71 changes: 71 additions & 0 deletions examples/python/visualization/remote_visualizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# ----------------------------------------------------------------------------
# - Open3D: www.open3d.org -
# ----------------------------------------------------------------------------
# Copyright (c) 2018-2023 www.open3d.org
# SPDX-License-Identifier: MIT
# ----------------------------------------------------------------------------
"""This example shows Open3D's remote visualization feature using RPC
communication. To run this example, start the client first by running
python remote_visualizer.py client
and then run the server by running
python remote_visualizer.py server
Port 51454 is used by default for communication. For remote visualization (client
and server running on different machines), use ssh to forward the remote server
port to your local computer:
ssh -N -R 51454:localhost:51454 user@remote_host
See documentation for more details (e.g. to use a different port).
"""
import sys
import numpy as np
import open3d as o3d
import open3d.visualization as vis


def make_point_cloud(npts, center, radius, colorize):
pts = np.random.uniform(-radius, radius, size=[npts, 3]) + center
cloud = o3d.geometry.PointCloud()
cloud.points = o3d.utility.Vector3dVector(pts)
if colorize:
colors = np.random.uniform(0.0, 1.0, size=[npts, 3])
cloud.colors = o3d.utility.Vector3dVector(colors)
return cloud


def server_time_animation():
orig = make_point_cloud(200, (0, 0, 0), 1.0, True)
clouds = [{"name": "t=0", "geometry": orig, "time": 0}]
drift_dir = (1.0, 0.0, 0.0)
expand = 1.0
n = 20
ev = o3d.visualization.ExternalVisualizer()
for i in range(1, n):
amount = float(i) / float(n - 1)
cloud = o3d.geometry.PointCloud()
pts = np.asarray(orig.points)
pts = pts * (1.0 + amount * expand) + [amount * v for v in drift_dir]
cloud.points = o3d.utility.Vector3dVector(pts)
cloud.colors = orig.colors
ev.set(obj=cloud, time=i, path=f"points at t={i}")
print('.', end='', flush=True)
print()


def client_time_animation():
o3d.visualization.draw(title="Open3D - Remote Visualizer Client",
show_ui=True,
rpc_interface=True)


if __name__ == "__main__":
assert len(sys.argv) == 2 and sys.argv[1] in ('client', 'server'), (
"Usage: python remote_visualizer.py [client|server]")
if sys.argv[1] == "client":
client_time_animation()
elif sys.argv[1] == "server":
server_time_animation()
8 changes: 0 additions & 8 deletions python/open3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ def load_cdll(path):
if sys.platform == "win32": # Unix: Use rpath to find libraries
_win32_dll_dir = os.add_dll_directory(str(Path(__file__).parent))

if _build_config["BUILD_GUI"] and not (find_library("c++abi") or
find_library("c++")):
try: # Preload libc++.so and libc++abi.so (required by filament)
load_cdll(str(next((Path(__file__).parent).glob("*c++abi.*"))))
load_cdll(str(next((Path(__file__).parent).glob("*c++.*"))))
except StopIteration: # Not found: check system paths while loading
pass

__DEVICE_API__ = "cpu"
if _build_config["BUILD_CUDA_MODULE"]:
# Load CPU pybind dll gracefully without introducing new python variable.
Expand Down
7 changes: 7 additions & 0 deletions python/open3d/visualization/_external_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,23 @@ def set(self, obj=None, path='', time=0, layer='', connection=None):
Example:
To quickly send a single object just write::
ev.set(point_cloud)
To place the object at a specific location in the scene tree do::
ev.set(point_cloud, path='group/mypoints', time=42, layer='')
Note that depending on the visualizer some arguments like time or
layer may not be supported and will be ignored.
To set multiple objects use a list to pass multiple objects::
ev.set([point_cloud, mesh, camera])
Each entry in the list can be a tuple specifying all or some of the
location parameters::
ev.set(objs=[(point_cloud,'group/mypoints', 1, 'layer1'),
(mesh, 'group/mymesh'),
camera
Expand Down Expand Up @@ -147,6 +153,7 @@ def draw(self, geometry=None, *args, **kwargs):
Example:
Here we use draw with the default external visualizer::
import open3d as o3d
torus = o3d.geometry.TriangleMesh.create_torus()
Expand Down
11 changes: 7 additions & 4 deletions python/open3d/visualization/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,10 @@ def draw(geometry=None,
animation_time_step (float): Duration in seconds for each animation
frame.
animation_duration (float): Total animation duration in seconds.
rpc_interface (bool): Start an RPC interface at http://localhost:51454 and
listen for drawing requests. The requests can be made with
:class:`open3d.visualization.ExternalVisualizer`.
rpc_interface (bool or str): Start an RPC interface at this local
address and listen for drawing requests. If rpc_interface is True, the
default address "tcp://localhost:51454" is used. The requests can be
made with :class:`open3d.visualization.ExternalVisualizer`.
on_init (Callable): Extra initialization procedure for the underlying
GUI window. The procedure receives a single argument of type
:class:`open3d.visualization.O3DVisualizer`.
Expand Down Expand Up @@ -202,7 +203,9 @@ def add(g, n):
w.show_skybox(show_skybox)

if rpc_interface:
w.start_rpc_interface(address="tcp://127.0.0.1:51454", timeout=10000)
if not isinstance(rpc_interface, str):
rpc_interface = "tcp://127.0.0.1:51454"
w.start_rpc_interface(address=rpc_interface, timeout=10000)

def stop_rpc():
w.stop_rpc_interface()
Expand Down
11 changes: 8 additions & 3 deletions util/install_deps_ubuntu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ eval $(
echo DISTRIB_ID="$DISTRIB_ID";
echo DISTRIB_RELEASE="$DISTRIB_RELEASE"
)
# To avoid dependence on libunwind, we don't want to use clang / libc++ versions later than 11.
# Ubuntu 20.04's has versions 8, 10 or 12 while Ubuntu 22.04 has versions 11 and later.
if [ "$DISTRIB_ID" == "Ubuntu" -a "$DISTRIB_RELEASE" == "20.04" ]; then
# Ubuntu 20.04's clang/libc++-dev/libc++abi-dev are version 8, 10 or 12.
# To avoid dependence on libunwind, we don't want to use versions later than 10.
deps=("${deps[@]/clang/clang-10}")
deps=("${deps[@]/libc++-dev/libc++-10-dev}")
deps=("${deps[@]/libc++abi-dev/libc++abi-10-dev}")
fi
if [ "$DISTRIB_ID" == "Ubuntu" -a "$DISTRIB_RELEASE" == "22.04" ]; then
deps=("${deps[@]/clang/clang-11}")
deps=("${deps[@]/libc++-dev/libc++-11-dev}")
deps=("${deps[@]/libc++abi-dev/libc++abi-11-dev}")
fi

# Special case for ARM64
if [ "$(uname -m)" == "aarch64" ]; then
# For compling LAPACK in OpenBLAS
# For compiling LAPACK in OpenBLAS
deps+=("gfortran")
fi

Expand Down

0 comments on commit 9856186

Please sign in to comment.