Skip to content

Commit

Permalink
rpc visualization interface (#2090)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum authored Aug 12, 2020
1 parent b52035d commit beaf1b4
Show file tree
Hide file tree
Showing 39 changed files with 2,895 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
exclude_paths:
- CHANGELOG.md
12 changes: 12 additions & 0 deletions 3rdparty/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,15 @@ https://github.com/NVIDIA/cutlass
benchmark 1.5.0 Apache-2 license
A microbenchmark support library
https://github.com/google/benchmark
--------------------------------------------------------------------------------
msgpack-c da2fc25f8 Boost Software License 1.0
MessagePack implementation for C and C++
https://github.com/msgpack/msgpack-c/tree/cpp_master
--------------------------------------------------------------------------------
libzmq 4.3.2 LGPLv3 + static link exception license
ZeroMQ is a high-performance asynchronous messaging library
https://github.com/zeromq/libzmq
--------------------------------------------------------------------------------
cppzmq 4.6.0 MIT license
Header-only C++ binding for libzmq
https://github.com/zeromq/cppzmq
38 changes: 38 additions & 0 deletions 3rdparty/boost/boost.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Build system for header-only boost libraries.
#
# In general, we prefer avoiding boost or use header-only boost libraries.
# Compiling boost libraries can addup to the build time.
#
# Current boost libraries:
# - predef (header-only)

include(ExternalProject)

if(WIN32)
message(FATAL_ERROR "Win32 not supported.")
endif()

ExternalProject_Add(
ext_boost
PREFIX boost
GIT_REPOSITORY https://github.com/boostorg/boost.git
GIT_TAG boost-1.73.0
GIT_SUBMODULES tools/boostdep libs/predef # Only need a subset of boost
GIT_SHALLOW ON # git clone --depth 1
GIT_SUBMODULES_RECURSE OFF
BUILD_IN_SOURCE ON
CONFIGURE_COMMAND ""
BUILD_COMMAND echo "Running Boost build..."
COMMAND python tools/boostdep/depinst/depinst.py predef
COMMAND ./bootstrap.sh
COMMAND ./b2 headers
UPDATE_COMMAND ""
INSTALL_COMMAND ""
)

ExternalProject_Get_Property(ext_boost SOURCE_DIR)
message(STATUS "Boost source dir: ${SOURCE_DIR}")

# By default, BOOST_INCLUDE_DIRS should not have trailing "/".
# The actual headers files are located in `${SOURCE_DIR}/boost`.
set(BOOST_INCLUDE_DIRS ${SOURCE_DIR}/ext_boost)
36 changes: 36 additions & 0 deletions 3rdparty/find_dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ endfunction()
function(import_3rdparty_library name)
cmake_parse_arguments(arg "PUBLIC;HEADER" "LIB_DIR" "INCLUDE_DIRS;LIBRARIES" ${ARGN})
if(arg_UNPARSED_ARGUMENTS)
message(STATUS "Unparsed: ${arg_UNPARSED_ARGUMENTS}")
message(FATAL_ERROR "Invalid syntax: import_3rdparty_library(${name} ${ARGN})")
endif()
if(NOT arg_LIB_DIR)
Expand Down Expand Up @@ -865,6 +866,41 @@ if(BUILD_GUI)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS "${FILAMENT_TARGET}")
endif()

# RPC interface
# - boost: predef
# - zeromq
# - msgpack
if(BUILD_RPC_INTERFACE)
# boost: predef
include(${Open3D_3RDPARTY_DIR}/boost/boost.cmake)
import_3rdparty_library(3rdparty_boost
INCLUDE_DIRS ${BOOST_INCLUDE_DIRS}
)
set(BOOST_TARGET "3rdparty_boost")
add_dependencies(3rdparty_boost ext_boost)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS "${BOOST_TARGET}")

# zeromq
include(${Open3D_3RDPARTY_DIR}/zeromq/zeromq_build.cmake)
import_3rdparty_library(3rdparty_zeromq
INCLUDE_DIRS ${ZEROMQ_INCLUDE_DIRS}
LIB_DIR ${ZEROMQ_LIB_DIR}
LIBRARIES ${ZEROMQ_LIBRARIES}
)
set(ZEROMQ_TARGET "3rdparty_zeromq")
add_dependencies(${ZEROMQ_TARGET} ext_zeromq)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS "${ZEROMQ_TARGET}")

# msgpack
include(${Open3D_3RDPARTY_DIR}/msgpack/msgpack_build.cmake)
import_3rdparty_library(3rdparty_msgpack
INCLUDE_DIRS ${MSGPACK_INCLUDE_DIRS}
)
set(MSGPACK_TARGET "3rdparty_msgpack")
add_dependencies(3rdparty_msgpack ext_msgpack-c)
list(APPEND Open3D_3RDPARTY_PRIVATE_TARGETS "${MSGPACK_TARGET}")
endif()

# MKL, cuSOLVER, cuBLAS
# We link MKL statically. For MKL link flags, refer to:
# https://software.intel.com/content/www/us/en/develop/articles/intel-mkl-link-line-advisor.html
Expand Down
16 changes: 16 additions & 0 deletions 3rdparty/msgpack/msgpack_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
include(ExternalProject)

ExternalProject_Add(
ext_msgpack-c
PREFIX msgpack-c
URL https://github.com/msgpack/msgpack-c/releases/download/cpp-3.3.0/msgpack-3.3.0.tar.gz
URL_HASH MD5=e676575d52caae974e579c3d5f0ba6a2
# do not configure
CONFIGURE_COMMAND ""
# do not build
BUILD_COMMAND ""
# do not install
INSTALL_COMMAND ""
)
ExternalProject_Get_Property( ext_msgpack-c SOURCE_DIR )
set( MSGPACK_INCLUDE_DIRS "${SOURCE_DIR}/include/" )
41 changes: 41 additions & 0 deletions 3rdparty/zeromq/zeromq_build.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
include(ExternalProject)
include(FetchContent)

# ExternalProject seems to be the best solution for including zeromq.
# The projects defines options which clash with and pollute our CMake cache.

ExternalProject_Add(
ext_zeromq
PREFIX "${CMAKE_BINARY_DIR}/zeromq"
URL "https://github.com/zeromq/libzmq/releases/download/v4.3.2/zeromq-4.3.2.tar.gz"
URL_HASH MD5=2047e917c2cc93505e2579bcba67a573
# do not update
UPDATE_COMMAND ""
CMAKE_ARGS
-DBUILD_STATIC=ON
-DBUILD_SHARED=OFF
-DBUILD_TESTS=OFF
-DENABLE_CPACK=OFF
-DENABLE_CURVE=OFF
-DZMQ_BUILD_TESTS=OFF
-DWITH_DOCS=OFF
-DWITH_PERF_TOOL=OFF
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
)

# cppzmq is header only. we just need to download
FetchContent_Declare(
ext_cppzmq
URL "https://github.com/zeromq/cppzmq/archive/v4.6.0.tar.gz"
URL_HASH MD5=7cae1b3fbfeaddb9cf1f70e99a98add2
)
FetchContent_GetProperties(ext_cppzmq)
if(NOT ext_cppzmq_POPULATED)
FetchContent_Populate(ext_cppzmq)
# do not add subdirectory here
endif()

ExternalProject_Get_Property( ext_zeromq INSTALL_DIR )
set(ZEROMQ_LIBRARIES zmq)
set(ZEROMQ_LIB_DIR ${INSTALL_DIR}/lib)
set(ZEROMQ_INCLUDE_DIRS "${INSTALL_DIR}/include/;${ext_cppzmq_SOURCE_DIR}/")
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Added option BUILD_BENCHMARKS for building microbenchmarks
* Extend Python API of UniformTSDFVolume to allow setting the origin
* Corrected documentation of PointCloud.h
* Added an RPC interface for external visualizers running in a separate process

## 0.9.0

* Version bump to 0.9.0
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ option(BUILD_AZURE_KINECT "Build support for Azure Kinect sensor" OFF
# ML library options
option(BUILD_TENSORFLOW_OPS "Build ops for Tensorflow" OFF)
option(BUILD_PYTORCH_OPS "Build ops for Pytorch" OFF)
option(BUILD_RPC_INTERFACE "Build the RPC interface" OFF)

set(FILAMENT_PRECOMPILED_ROOT "" CACHE PATH "Path to precompiled Filament library (used if BUILD_FILAMENT_FROM_SOURCE=OFF)")
set(FILAMENT_SOURCE_ROOT "" CACHE PATH "Path to Filament library sources (used if BUILD_FILAMENT_FROM_SOURCE=ON)")
Expand Down Expand Up @@ -104,6 +105,10 @@ if(BUILD_GUI AND WIN32)
message(STATUS "New GUI is currently unsupported on Windows")
set(BUILD_GUI OFF)
endif()
if(BUILD_RPC_INTERFACE AND WIN32)
message(STATUS "The RPC interface is currently unsupported on Windows.")
set(BUILD_RPC_INTERFACE OFF)
endif()

# Parse Open3D version number
file(STRINGS "cpp/open3d/version.txt" OPEN3D_VERSION_READ)
Expand Down Expand Up @@ -301,6 +306,9 @@ function(open3d_set_global_properties target)
if(BUILD_CUDA_MODULE)
target_compile_definitions(${target} PRIVATE BUILD_CUDA_MODULE)
endif()
if(BUILD_RPC_INTERFACE)
target_compile_definitions(${target} PRIVATE BUILD_RPC_INTERFACE)
endif()
if(GLIBCXX_USE_CXX11_ABI)
target_compile_definitions(${target} PUBLIC _GLIBCXX_USE_CXX11_ABI=1)
else()
Expand Down Expand Up @@ -426,6 +434,7 @@ endif()
open3d_aligned_print("Build Tensorflow Ops" "${BUILD_TENSORFLOW_OPS}")
open3d_aligned_print("Build Pytorch Ops" "${BUILD_PYTORCH_OPS}")
open3d_aligned_print("Build Benchmarks" "${BUILD_BENCHMARKS}")
open3d_aligned_print("Build RPC interface" "${BUILD_RPC_INTERFACE}")
if(GLIBCXX_USE_CXX11_ABI)
set(usage "1")
else()
Expand Down
5 changes: 5 additions & 0 deletions cpp/open3d/io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ if (BUILD_AZURE_KINECT)
set(IO_ALL_SOURCE_FILES ${IO_ALL_SOURCE_FILES} ${SENSOR_SOURCE_FILES})
endif ()

if (BUILD_RPC_INTERFACE)
file(GLOB RPC_SOURCE_FILES "rpc/*.cpp")
set(IO_ALL_SOURCE_FILES ${IO_ALL_SOURCE_FILES} ${RPC_SOURCE_FILES})
endif()

# Create object library
add_library(io OBJECT
${IO_ALL_SOURCE_FILES}
Expand Down
61 changes: 61 additions & 0 deletions cpp/open3d/io/rpc/BufferConnection.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2020 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------

#include "open3d/io/rpc/BufferConnection.h"

#include <zmq.hpp>

#include "open3d/io/rpc/Messages.h"
#include "open3d/utility/Console.h"

using namespace open3d::utility;

namespace open3d {
namespace io {
namespace rpc {

std::shared_ptr<zmq::message_t> BufferConnection::Send(
zmq::message_t& send_msg) {
buffer_.write((char*)send_msg.data(), send_msg.size());

auto OK = messages::Status::OK();
msgpack::sbuffer sbuf;
messages::Reply reply{OK.MsgId()};
msgpack::pack(sbuf, reply);
msgpack::pack(sbuf, OK);
return std::shared_ptr<zmq::message_t>(
new zmq::message_t(sbuf.data(), sbuf.size()));
}

std::shared_ptr<zmq::message_t> BufferConnection::Send(const void* data,
size_t size) {
zmq::message_t send_msg(data, size);
return Send(send_msg);
}

} // namespace rpc
} // namespace io
} // namespace open3d
57 changes: 57 additions & 0 deletions cpp/open3d/io/rpc/BufferConnection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// ----------------------------------------------------------------------------
// - Open3D: www.open3d.org -
// ----------------------------------------------------------------------------
// The MIT License (MIT)
//
// Copyright (c) 2020 www.open3d.org
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
// ----------------------------------------------------------------------------

#pragma once

#include <memory>
#include <sstream>

#include "open3d/io/rpc/ConnectionBase.h"

namespace open3d {
namespace io {
namespace rpc {

/// Implements a connection writing to a buffer
class BufferConnection : public ConnectionBase {
public:
BufferConnection() {}

/// Function for sending data wrapped in a zmq message object.
std::shared_ptr<zmq::message_t> Send(zmq::message_t& send_msg);

/// Function for sending raw data. Meant for testing purposes
std::shared_ptr<zmq::message_t> Send(const void* data, size_t size);

std::stringstream& buffer() { return buffer_; }
const std::stringstream& buffer() const { return buffer_; }

private:
std::stringstream buffer_;
};
} // namespace rpc
} // namespace io
} // namespace open3d
Loading

0 comments on commit beaf1b4

Please sign in to comment.