Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New/pybind #6

Merged
merged 34 commits into from
Mar 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
70b96bb
Add pybind11 library
qianyizh Feb 15, 2017
a11ab96
first test of python binding
qianyizh Feb 16, 2017
2cb57e4
Working on python binding
qianyizh Feb 16, 2017
8109810
Minor edits
qianyizh Feb 16, 2017
3b9f8bc
Massively improve performance of KDTreeFlann::RadiusSearch
qianyizh Feb 17, 2017
0c9b354
Improve ICP performance
qianyizh Feb 17, 2017
a9f5874
A bunch of changes to python binding
qianyizh Feb 17, 2017
f10894f
Add functions to draw geometry in pybinding
qianyizh Feb 17, 2017
db0061a
Fix OS X compile issue
qianyizh Feb 17, 2017
2868fcc
Fix Ubuntu build
qianyizh Feb 17, 2017
28c2560
Add TriangleMesh to pybind
qianyizh Feb 18, 2017
b0377fe
Add Image to pybind
qianyizh Feb 18, 2017
b12ef92
bug fix
qianyizh Feb 18, 2017
a125ea8
Create test for py3d
qianyizh Feb 19, 2017
8e85b4d
bug fix
qianyizh Feb 19, 2017
e37c71d
Minor edits
qianyizh Feb 19, 2017
2eadd0e
Add python test code
qianyizh Feb 20, 2017
af2475d
Working on pybind_eigen
qianyizh Feb 20, 2017
3540341
A major upgrade on Eigen handling
qianyizh Feb 20, 2017
51d075c
Minor edits and fixes
qianyizh Feb 20, 2017
768bafc
A bunch of changes
qianyizh Feb 21, 2017
135f32f
Working on camera
qianyizh Feb 21, 2017
184cb46
CreatePointCloudFromDepth/RGBDImage
qianyizh Feb 21, 2017
56decf9
bug fix
qianyizh Feb 21, 2017
b7c8226
minor tweak
qianyizh Feb 21, 2017
95e246e
Add PinholeCameraTrajectory
qianyizh Feb 22, 2017
04dfbfe
minor
qianyizh Mar 16, 2017
ab5d9ce
bug fix
qianyizh Mar 7, 2017
dbdd85e
RANSAC registration
qianyizh Mar 23, 2017
987e85c
Add python binding for registration
qianyizh Mar 23, 2017
e11d30b
SelectionPolygonVolume
qianyizh Mar 23, 2017
2be6a1c
Fix VS2015 compile warning
qianyizh Mar 24, 2017
4358e7d
bug fix
qianyizh Mar 24, 2017
e6ae72c
start working on using native dependencies
qianyizh Mar 24, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ build14/
build15/
build-xcode/
build-gcc/
build-dep/
build14-rdp/
src/Sandbox/
src/Visualization/Shader/Shader.h
25 changes: 18 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
option(Open3D_BUILD_TESTS "Build the Open3D test programs" ON)
option(Open3D_BUILD_LIBREALSENSE "Build support for Intel RealSense camera" ON)
option(Open3D_USE_OPENMP "Use OpenMP multi-threading" ON)
option(Open3D_BUILD_PYTHON_BINDING "Build Python binding for Open3D" ON)
option(Open3D_BUILD_PYTHON_BINDING_TESTS "Copy Test files for Open3D Python binding" ON)
option(Open3D_USE_NATIVE_DEPENDENCY_BUILD "Prioritize using native dependency build" ON)

# default built type
if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -26,7 +29,6 @@ include_directories(
${Open3D_SOURCE_DIR}/External
${Open3D_SOURCE_DIR}/External/Eigen
${Open3D_SOURCE_DIR}/External/GLFW/include
${Open3D_SOURCE_DIR}/External/glew/include
${Open3D_SOURCE_DIR}/External/librealsense/include
)

Expand Down Expand Up @@ -58,17 +60,14 @@ elseif(CYGWIN)
elseif(APPLE)
add_definitions(-DUNIX)
# enable c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fvisibility=hidden")
# compile speed optimization for clang
add_definitions(-O3)
# disable OpenMP since it is not currently supported on OSX
message(STATUS "Compiling on OSX")
message(STATUS "Disable OpenMP since it is not supported on OSX.")
set(Open3D_USE_OPENMP OFF)
elseif(UNIX)
add_definitions(-DUNIX)
# enable c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-unused-result)
add_definitions(-O3)
Expand All @@ -92,7 +91,14 @@ if (Open3D_USE_OPENMP)
endif()

message(STATUS "Open3D_BUILD_LIBREALSENSE=${Open3D_BUILD_LIBREALSENSE}")
message(STATUS "Open3D_BUILD_PYTHON_BINDING=${Open3D_BUILD_PYTHON_BINDING}")
message(STATUS "Open3D_BUILD_PYTHON_BINDING_TESTS=${Open3D_BUILD_PYTHON_BINDING_TESTS}")

# Handling dependencies
add_subdirectory(External)
include_directories(${GLEW_INCLUDE_DIRS})

# Open3D libraries
add_subdirectory(Core)
add_subdirectory(Tools)
add_subdirectory(IO)
Expand All @@ -112,3 +118,8 @@ if(EXISTS "${Open3D_SOURCE_DIR}/Sandbox/CMakeLists.txt")
message(STATUS "Build projects in Sandbox")
add_subdirectory(Sandbox)
endif(EXISTS "${Open3D_SOURCE_DIR}/Sandbox/CMakeLists.txt")

# Python binding
if (Open3D_BUILD_PYTHON_BINDING)
add_subdirectory(Python)
endif(Open3D_BUILD_PYTHON_BINDING)
1 change: 1 addition & 0 deletions src/Core/Geometry/EstimateNormals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ bool EstimateNormals(PointCloud &cloud,
cloud.normals_[i] = normal;
}
}

return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/Core/Geometry/Geometry2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#pragma once

#include <Eigen/Core>
#include <Core/Geometry/Geometry.h>

namespace three {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Geometry/Geometry3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Geometry3D : public Geometry
bool IsEmpty() const override = 0;
virtual Eigen::Vector3d GetMinBound() const = 0;
virtual Eigen::Vector3d GetMaxBound() const = 0;
virtual void Transform(const Eigen::Matrix4d & transformation) = 0;
virtual void Transform(const Eigen::Matrix4d &transformation) = 0;
};

} // namespace three
4 changes: 2 additions & 2 deletions src/Core/Geometry/Image.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class Image : public Geometry2D
public:
void Clear() override;
bool IsEmpty() const override;
Eigen::Vector2d GetMinBound() const final;
Eigen::Vector2d GetMaxBound() const final;
Eigen::Vector2d GetMinBound() const override;
Eigen::Vector2d GetMaxBound() const override;

public:
virtual bool HasData() const {
Expand Down
69 changes: 56 additions & 13 deletions src/Core/Geometry/KDTreeFlann.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ KDTreeFlann::KDTreeFlann()
{
}

KDTreeFlann::KDTreeFlann(const Geometry &geometry)
{
SetGeometry(geometry);
}

KDTreeFlann::~KDTreeFlann()
{
}
Expand Down Expand Up @@ -88,9 +93,14 @@ int KDTreeFlann::Search(const T &query, const KDTreeSearchParam &param,
return SearchKNN(query, ((const KDTreeSearchParamKNN &)param).knn_,
indices, distance2);
case KDTreeSearchParam::SEARCH_RADIUS:
return SearchRadius(query,
((const KDTreeSearchParamRadius &)param).radius_, indices,
distance2, ((const KDTreeSearchParamRadius &)param).max_nn_);
return SearchRadius(query,
((const KDTreeSearchParamRadius &)param).radius_, indices,
distance2);
case KDTreeSearchParam::SEARCH_HYBRID:
return SearchHybrid(query,
((const KDTreeSearchParamHybrid &)param).radius_,
((const KDTreeSearchParamHybrid &)param).max_nn_,
indices, distance2);
default:
return -1;
}
Expand All @@ -101,9 +111,9 @@ template<typename T>
int KDTreeFlann::SearchKNN(const T &query, int knn, std::vector<int> &indices,
std::vector<double> &distance2) const
{
// This is optimized code for heavily repeated search
// This is optimized code for heavily repeated search.
// Other flann::Index::knnSearch() implementations lose performance due to
// memory allocation/deallocation
// memory allocation/deallocation.
if (data_.empty() || dataset_size_ <= 0 ||
query.rows() != dimension_ || knn < 0)
{
Expand All @@ -114,24 +124,27 @@ int KDTreeFlann::SearchKNN(const T &query, int knn, std::vector<int> &indices,
distance2.resize(knn);
flann::Matrix<int> indices_flann(indices.data(), query_flann.rows, knn);
flann::Matrix<double> dists_flann(distance2.data(), query_flann.rows, knn);
return flann_index_->knnSearch(query_flann, indices_flann, dists_flann, knn,
flann::SearchParams(-1, 0.0));
int k = flann_index_->knnSearch(query_flann, indices_flann, dists_flann,
knn, flann::SearchParams(-1, 0.0));
indices.resize(k);
distance2.resize(k);
return k;
}

template<typename T>
int KDTreeFlann::SearchRadius(const T &query, double radius,
std::vector<int> &indices, std::vector<double> &distance2,
int max_nn/* = -1*/) const
std::vector<int> &indices, std::vector<double> &distance2) const
{
// This is optimized code for heavily repeated search
// This is optimized code for heavily repeated search.
// Since max_nn is not given, we let flann to do its own memory management.
// Other flann::Index::radiusSearch() implementations lose performance due
// to memory management and CPU caching
// to memory management and CPU caching.
if (data_.empty() || dataset_size_ <= 0 || query.rows() != dimension_) {
return -1;
}
flann::Matrix<double> query_flann((double *)query.data(), 1, dimension_);
flann::SearchParams param(-1, 0.0);
param.max_neighbors = max_nn;
param.max_neighbors = -1;
std::vector<std::vector<int>> indices_vec(1);
std::vector<std::vector<double>> dists_vec(1);
int k = flann_index_->radiusSearch(query_flann, indices_vec, dists_vec,
Expand All @@ -141,6 +154,33 @@ int KDTreeFlann::SearchRadius(const T &query, double radius,
return k;
}

template<typename T>
int KDTreeFlann::SearchHybrid(const T &query, double radius, int max_nn,
std::vector<int> &indices, std::vector<double> &distance2) const
{
// This is optimized code for heavily repeated search.
// It is also the recommended setting for search.
// Other flann::Index::radiusSearch() implementations lose performance due
// to memory allocation/deallocation.
if (data_.empty() || dataset_size_ <= 0 || query.rows() != dimension_ ||
max_nn < 0) {
return -1;
}
flann::Matrix<double> query_flann((double *)query.data(), 1, dimension_);
flann::SearchParams param(-1, 0.0);
param.max_neighbors = max_nn;
indices.resize(max_nn);
distance2.resize(max_nn);
flann::Matrix<int> indices_flann(indices.data(), query_flann.rows, max_nn);
flann::Matrix<double> dists_flann(distance2.data(), query_flann.rows,
max_nn);
int k = flann_index_->radiusSearch(query_flann, indices_flann, dists_flann,
float(radius * radius), param);
indices.resize(k);
distance2.resize(k);
return k;
}

template int KDTreeFlann::Search<Eigen::Vector3d>(const Eigen::Vector3d &query,
const three::KDTreeSearchParam &param, std::vector<int> &indices,
std::vector<double> &distance2) const;
Expand All @@ -149,7 +189,10 @@ template int KDTreeFlann::SearchKNN<Eigen::Vector3d>(
std::vector<double> &distance2) const;
template int KDTreeFlann::SearchRadius<Eigen::Vector3d>(
const Eigen::Vector3d &query, double radius, std::vector<int> &indices,
std::vector<double> &distance2, int max_nn) const;
std::vector<double> &distance2) const;
template int KDTreeFlann::SearchHybrid<Eigen::Vector3d>(
const Eigen::Vector3d &query, double radius, int max_nn,
std::vector<int> &indices, std::vector<double> &distance2) const;

} // namespace three

Expand Down
9 changes: 7 additions & 2 deletions src/Core/Geometry/KDTreeFlann.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class KDTreeFlann
{
public:
KDTreeFlann();
virtual ~KDTreeFlann();
KDTreeFlann(const Geometry &geometry);
~KDTreeFlann();
KDTreeFlann(const KDTreeFlann &) = delete;
KDTreeFlann &operator=(const KDTreeFlann &) = delete;

Expand All @@ -61,7 +62,11 @@ class KDTreeFlann

template<typename T>
int SearchRadius(const T &query, double radius, std::vector<int> &indices,
std::vector<double> &distance2, int max_nn = -1) const;
std::vector<double> &distance2) const;

template<typename T>
int SearchHybrid(const T &query, double radius, int max_nn,
std::vector<int> &indices, std::vector<double> &distance2) const;

protected:
std::vector<double> data_;
Expand Down
16 changes: 13 additions & 3 deletions src/Core/Geometry/KDTreeSearchParam.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class KDTreeSearchParam
enum SearchType {
SEARCH_KNN = 0,
SEARCH_RADIUS = 1,
SEARCH_HYBRID = 2,
};

public:
Expand Down Expand Up @@ -61,9 +62,18 @@ class KDTreeSearchParamKNN : public KDTreeSearchParam
class KDTreeSearchParamRadius : public KDTreeSearchParam
{
public:
KDTreeSearchParamRadius(double radius, int max_nn = -1) :
KDTreeSearchParam(SEARCH_RADIUS),
radius_(radius), max_nn_(max_nn) {}
KDTreeSearchParamRadius(double radius) :
KDTreeSearchParam(SEARCH_RADIUS), radius_(radius) {}
public:
double radius_;
};

class KDTreeSearchParamHybrid : public KDTreeSearchParam
{
public:
KDTreeSearchParamHybrid(double radius, int max_nn) :
KDTreeSearchParam(SEARCH_HYBRID), radius_(radius),
max_nn_(max_nn) {}
public:
double radius_;
int max_nn_;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Geometry/PointCloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ PointCloud &PointCloud::operator+=(const PointCloud &cloud)
return (*this);
}

const PointCloud PointCloud::operator+(const PointCloud &cloud)
PointCloud PointCloud::operator+(const PointCloud &cloud) const
{
return (PointCloud(*this) += cloud);
}
Expand Down
24 changes: 20 additions & 4 deletions src/Core/Geometry/PointCloud.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class PointCloud : public Geometry3D
void Transform(const Eigen::Matrix4d &transformation) override;

public:
virtual PointCloud &operator+=(const PointCloud &cloud);
virtual const PointCloud operator+(const PointCloud &cloud);
PointCloud &operator+=(const PointCloud &cloud);
PointCloud operator+(const PointCloud &cloud) const;

public:
bool HasPoints() const {
Expand All @@ -72,6 +72,13 @@ class PointCloud : public Geometry3D
normals_[i].normalize();
}
}

void PaintUniformColor(const Eigen::Vector3d &color) {
colors_.resize(points_.size());
for (size_t i = 0; i < points_.size(); i++) {
colors_[i] = color;
}
}

public:
std::vector<Eigen::Vector3d> points_;
Expand All @@ -92,6 +99,15 @@ std::shared_ptr<PointCloud> CreatePointCloudFromDepthImage(
const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity(),
double depth_scale = 1000.0);

/// Factory function to create a pointcloud from a pair of RGB-D image and
/// a camera model (PointCloudFactory.cpp)
/// Return an empty pointcloud if the conversion fails.
std::shared_ptr<PointCloud> CreatePointCloudFromRGBDImage(
const Image &depth, const Image &color,
const PinholeCameraIntrinsic &intrinsic,
const Eigen::Matrix4d &extrinsic = Eigen::Matrix4d::Identity(),
double depth_scale = 1000.0);

/// Function to select points from input pointcloud into output pointcloud
/// Points with indices in \param indices are selected.
/// Input and output cannot be the same pointcloud.
Expand All @@ -110,7 +126,7 @@ bool VoxelDownSample(const PointCloud &input, double voxel_size,
/// \param every_k_points indicates the sample rate.
/// Input and output cannot be the same pointcloud.
bool UniformDownSample(const PointCloud &input, size_t every_k_points,
PointCloud &output_cloud);
PointCloud &output);

/// Function to crop input pointcloud into output pointcloud
/// All points with coordinates less than \param min_bound or larger than
Expand All @@ -133,7 +149,7 @@ bool OrientNormalsToAlignWithDirection(PointCloud &cloud,
const Eigen::Vector3d &orientation_reference =
Eigen::Vector3d(0.0, 0.0, 1.0));

/// Function to compute the normals of a point cloud
/// Function to orient the normals of a point cloud
/// \param cloud is the input point cloud. It also stores the output normals.
/// Normals are oriented with towards \param camera_location.
bool OrientNormalsTowardsCameraLocation(PointCloud &cloud,
Expand Down
Loading