Skip to content

Commit 1402988

Browse files
committed
WIP: working version with cmake pybind
1 parent 96ee93f commit 1402988

File tree

6 files changed

+162
-83
lines changed

6 files changed

+162
-83
lines changed

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.16.)
2-
project(DiffCheck VERSION 1.0.0 LANGUAGES CXX C)
2+
project(diffCheck VERSION 1.0.0 LANGUAGES CXX C)
33
set(CMAKE_CXX_STANDARD 17)
44

55
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
@@ -122,4 +122,16 @@ target_include_directories(${APP_NAME_EXE}
122122
# include(CTest)
123123
# enable_testing()
124124

125-
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/global_registrations)
125+
# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests/global_registrations)
126+
127+
#--------------------------------------------------------------------------
128+
# pybind11
129+
#--------------------------------------------------------------------------
130+
set(PYBINDMODULE_NAME diffCheckBindings)
131+
132+
download_submodule_project(pybind11)
133+
add_subdirectory(deps/pybind11)
134+
135+
pybind11_add_module(${PYBINDMODULE_NAME} src/diffCheckBindings.cc)
136+
target_link_libraries(${PYBINDMODULE_NAME} PRIVATE ${SHARED_LIB_NAME})
137+
target_include_directories(${PYBINDMODULE_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src)

deps/eigen

Submodule eigen updated from 34967b0 to dcceb9a

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ namespace diffCheck::geometry
1212
{
1313
public:
1414
DFPointCloud() = default;
15+
DFPointCloud(std::vector<Eigen::Vector3d> points,
16+
std::vector<Eigen::Vector3d> colors,
17+
std::vector<Eigen::Vector3d> normals)
18+
: Points(points), Colors(colors), Normals(normals) {}
19+
1520
~DFPointCloud() = default;
1621

1722

@@ -82,7 +87,7 @@ namespace diffCheck::geometry
8287
std::vector<Eigen::Vector3d> Colors;
8388
/// @brief Eigen vector of 3D normals
8489
std::vector<Eigen::Vector3d> Normals;
85-
/// @brief Eigen vector of two 3D vectors forming the bounnding box.
90+
/// @brief Eigen vector of two 3D vectors forming the bounding box.
8691
std::vector<Eigen::Vector3d> BoundingBox;
8792
};
8893
} // namespace diffCheck::geometry

src/diffCheckApp.cc

Lines changed: 103 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -4,89 +4,113 @@
44
#include <iostream>
55
#include <fstream>
66

7+
#include <Eigen/Core>
8+
79

810
int main()
911
{
10-
// import clouds
11-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr = std::make_shared<diffCheck::geometry::DFPointCloud>();
12-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr_1 = std::make_shared<diffCheck::geometry::DFPointCloud>();
13-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr_2 = std::make_shared<diffCheck::geometry::DFPointCloud>();
14-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrWithoutNormals = std::make_shared<diffCheck::geometry::DFPointCloud>();
15-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruth = std::make_shared<diffCheck::geometry::DFPointCloud>();
16-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruthFromMesh = std::make_shared<diffCheck::geometry::DFPointCloud>();
17-
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr = std::make_shared<diffCheck::geometry::DFMesh>();
18-
19-
// std::string pathCloud = R"(C:\Users\andre\Downloads\scan_data_normals.ply\scan_data_normals.ply)";
20-
// std::string pathMesh = R"(F:\diffCheck\assets\dataset\mesh_fromRh_unfixedLength.ply)";
21-
// std::string pathMesh = R"(F:\diffCheck\temp\03_mesh.ply)";
22-
23-
// create a sphere from o3d
24-
auto mesh = open3d::geometry::TriangleMesh::CreateSphere(1.0, 4);
25-
26-
DIFFCHECK_INFO("test");
27-
DIFFCHECK_WARN("test");
28-
DIFFCHECK_ERROR("test");
29-
DIFFCHECK_FATAL("test");
30-
std::string pathCloud = R"(C:\Users\localuser\Downloads\04_pt.ply)";
31-
std::string pathCloud_1 = R"(C:\Users\localuser\Downloads\part_1_module.ply)";
32-
std::string pathCloud_2 = R"(C:\Users\localuser\Downloads\part_2_module.ply)";
33-
std::string pathMesh = R"(C:\Users\localuser\Downloads\04_mesh.ply)";
34-
35-
dfMeshPtr->LoadFromPLY(pathMesh);
36-
dfPointCloudPtr->LoadFromPLY(pathCloud);
37-
dfPointCloudPtr_1->LoadFromPLY(pathCloud_1);
38-
dfPointCloudPtr_2->LoadFromPLY(pathCloud_2);
39-
dfPointCloudPtrGroundTruth->LoadFromPLY(pathCloud);
40-
41-
// add noise to dfPointCloudPtr
42-
std::vector<Eigen::Vector3d> boundingBoxPoints = dfPointCloudPtr->ComputeBoundingBox();
43-
double meanInterval = (boundingBoxPoints[0] - boundingBoxPoints[1]).norm();
44-
for (int i = 0; i < dfPointCloudPtr->Points.size(); i++)
45-
{
46-
dfPointCloudPtr->Points[i] += Eigen::Vector3d::Random() * 0.002 * meanInterval;
47-
}
48-
49-
std::shared_ptr<open3d::geometry::PointCloud> pcd_1 = dfPointCloudPtr->Cvt2O3DPointCloud();
50-
if (pcd_1->normals_.size() > 0)
51-
{
52-
pcd_1->normals_.clear();
53-
}
54-
dfPointCloudPtrWithoutNormals->Cvt2DFPointCloud(pcd_1);
12+
std::vector<Eigen::Vector3d> points;
13+
std::vector<Eigen::Vector3d> normals;
14+
std::vector<Eigen::Vector3d> colors;
15+
points.push_back(Eigen::Vector3d(0, 0, 0));
16+
points.push_back(Eigen::Vector3d(1, 0, 0));
17+
points.push_back(Eigen::Vector3d(0, 1, 0));
18+
19+
normals.push_back(Eigen::Vector3d(0, 0, 1));
20+
normals.push_back(Eigen::Vector3d(0, 0, 1));
21+
normals.push_back(Eigen::Vector3d(0, 0, 1));
22+
23+
colors.push_back(Eigen::Vector3d(1, 0, 0));
24+
colors.push_back(Eigen::Vector3d(0, 1, 0));
25+
colors.push_back(Eigen::Vector3d(0, 0, 1));
26+
27+
diffCheck::geometry::DFPointCloud dfPointCloud(points, colors, normals);
28+
29+
30+
31+
32+
33+
34+
// // import clouds
35+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr = std::make_shared<diffCheck::geometry::DFPointCloud>();
36+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr_1 = std::make_shared<diffCheck::geometry::DFPointCloud>();
37+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr_2 = std::make_shared<diffCheck::geometry::DFPointCloud>();
38+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrWithoutNormals = std::make_shared<diffCheck::geometry::DFPointCloud>();
39+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruth = std::make_shared<diffCheck::geometry::DFPointCloud>();
40+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruthFromMesh = std::make_shared<diffCheck::geometry::DFPointCloud>();
41+
// std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr = std::make_shared<diffCheck::geometry::DFMesh>();
42+
43+
// // std::string pathCloud = R"(C:\Users\andre\Downloads\scan_data_normals.ply\scan_data_normals.ply)";
44+
// // std::string pathMesh = R"(F:\diffCheck\assets\dataset\mesh_fromRh_unfixedLength.ply)";
45+
// // std::string pathMesh = R"(F:\diffCheck\temp\03_mesh.ply)";
46+
47+
// // create a sphere from o3d
48+
// auto mesh = open3d::geometry::TriangleMesh::CreateSphere(1.0, 4);
49+
50+
// DIFFCHECK_INFO("test");
51+
// DIFFCHECK_WARN("test");
52+
// DIFFCHECK_ERROR("test");
53+
// DIFFCHECK_FATAL("test");
54+
// std::string pathCloud = R"(C:\Users\localuser\Downloads\04_pt.ply)";
55+
// std::string pathCloud_1 = R"(C:\Users\localuser\Downloads\part_1_module.ply)";
56+
// std::string pathCloud_2 = R"(C:\Users\localuser\Downloads\part_2_module.ply)";
57+
// std::string pathMesh = R"(C:\Users\localuser\Downloads\04_mesh.ply)";
58+
59+
// dfMeshPtr->LoadFromPLY(pathMesh);
60+
// dfPointCloudPtr->LoadFromPLY(pathCloud);
61+
// dfPointCloudPtr_1->LoadFromPLY(pathCloud_1);
62+
// dfPointCloudPtr_2->LoadFromPLY(pathCloud_2);
63+
// dfPointCloudPtrGroundTruth->LoadFromPLY(pathCloud);
64+
65+
// // add noise to dfPointCloudPtr
66+
// std::vector<Eigen::Vector3d> boundingBoxPoints = dfPointCloudPtr->ComputeBoundingBox();
67+
// double meanInterval = (boundingBoxPoints[0] - boundingBoxPoints[1]).norm();
68+
// for (int i = 0; i < dfPointCloudPtr->Points.size(); i++)
69+
// {
70+
// dfPointCloudPtr->Points[i] += Eigen::Vector3d::Random() * 0.002 * meanInterval;
71+
// }
72+
73+
// std::shared_ptr<open3d::geometry::PointCloud> pcd_1 = dfPointCloudPtr->Cvt2O3DPointCloud();
74+
// if (pcd_1->normals_.size() > 0)
75+
// {
76+
// pcd_1->normals_.clear();
77+
// }
78+
// dfPointCloudPtrWithoutNormals->Cvt2DFPointCloud(pcd_1);
5579

56-
// populate the mesh with points and store it in dfPointCloudPtrGroundTruthFromMesh
57-
std::shared_ptr<open3d::geometry::PointCloud> pcd_2 = dfMeshPtr->Cvt2O3DTriangleMesh()->SamplePointsUniformly(50000);
58-
dfPointCloudPtrGroundTruthFromMesh->Cvt2DFPointCloud(pcd_2);
59-
60-
// create a rigid rotation matrix
61-
Eigen::Matrix4d T = Eigen::Matrix4d::Identity();
62-
T.block<3, 3>(0, 0) = Eigen::AngleAxisd(1.57, Eigen::Vector3d::UnitX()).toRotationMatrix();
63-
T(0, 3) = 50;
64-
T(1, 3) = -100;
65-
T(2, 3) = 100;
66-
dfPointCloudPtrWithoutNormals->ApplyTransformation(diffCheck::transformation::DFTransformation(T));
67-
68-
// create a copy of the point cloud so we can test both global registrations
69-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrCopy = std::make_shared<diffCheck::geometry::DFPointCloud>(*dfPointCloudPtrWithoutNormals);
70-
71-
// test global registrations Fast and RANSAC-based
72-
std::vector<diffCheck::transformation::DFTransformation> registrationResults;
73-
diffCheck::transformation::DFTransformation transformationA =
74-
diffCheck::registrations::DFGlobalRegistrations::O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtr_1, dfPointCloudPtr_2);
75-
std::cout << "Fast transformation: " << transformationA.TransformationMatrix << std::endl;
76-
//dfPointCloudPtr_1->ApplyTransformation(transformationA);
77-
registrationResults.push_back(transformationA);
78-
diffCheck::transformation::DFTransformation transformationB =
79-
diffCheck::registrations::DFGlobalRegistrations::O3DRansacOnFeatureMatching(dfPointCloudPtr_1, dfPointCloudPtr_2);
80-
std::cout << "Ransac transformation: " << transformationB.TransformationMatrix << std::endl;
81-
dfPointCloudPtr_1->ApplyTransformation(transformationB);
82-
registrationResults.push_back(transformationB);
83-
84-
// visualize cloud
85-
std::shared_ptr<diffCheck::visualizer::Visualizer> visualizer = std::make_shared<diffCheck::visualizer::Visualizer>();
86-
visualizer->AddPointCloud(dfPointCloudPtr_1);
87-
visualizer->AddPointCloud(dfPointCloudPtr_2);
88-
// visualizer->AddMesh(dfMeshPtr);
89-
visualizer->Run();
80+
// // populate the mesh with points and store it in dfPointCloudPtrGroundTruthFromMesh
81+
// std::shared_ptr<open3d::geometry::PointCloud> pcd_2 = dfMeshPtr->Cvt2O3DTriangleMesh()->SamplePointsUniformly(50000);
82+
// dfPointCloudPtrGroundTruthFromMesh->Cvt2DFPointCloud(pcd_2);
83+
84+
// // create a rigid rotation matrix
85+
// Eigen::Matrix4d T = Eigen::Matrix4d::Identity();
86+
// T.block<3, 3>(0, 0) = Eigen::AngleAxisd(1.57, Eigen::Vector3d::UnitX()).toRotationMatrix();
87+
// T(0, 3) = 50;
88+
// T(1, 3) = -100;
89+
// T(2, 3) = 100;
90+
// dfPointCloudPtrWithoutNormals->ApplyTransformation(diffCheck::transformation::DFTransformation(T));
91+
92+
// // create a copy of the point cloud so we can test both global registrations
93+
// std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrCopy = std::make_shared<diffCheck::geometry::DFPointCloud>(*dfPointCloudPtrWithoutNormals);
94+
95+
// // test global registrations Fast and RANSAC-based
96+
// std::vector<diffCheck::transformation::DFTransformation> registrationResults;
97+
// diffCheck::transformation::DFTransformation transformationA =
98+
// diffCheck::registrations::DFGlobalRegistrations::O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtr_1, dfPointCloudPtr_2);
99+
// std::cout << "Fast transformation: " << transformationA.TransformationMatrix << std::endl;
100+
// //dfPointCloudPtr_1->ApplyTransformation(transformationA);
101+
// registrationResults.push_back(transformationA);
102+
// diffCheck::transformation::DFTransformation transformationB =
103+
// diffCheck::registrations::DFGlobalRegistrations::O3DRansacOnFeatureMatching(dfPointCloudPtr_1, dfPointCloudPtr_2);
104+
// std::cout << "Ransac transformation: " << transformationB.TransformationMatrix << std::endl;
105+
// dfPointCloudPtr_1->ApplyTransformation(transformationB);
106+
// registrationResults.push_back(transformationB);
107+
108+
// // visualize cloud
109+
// std::shared_ptr<diffCheck::visualizer::Visualizer> visualizer = std::make_shared<diffCheck::visualizer::Visualizer>();
110+
// visualizer->AddPointCloud(dfPointCloudPtr_1);
111+
// visualizer->AddPointCloud(dfPointCloudPtr_2);
112+
// // visualizer->AddMesh(dfMeshPtr);
113+
// visualizer->Run();
90114

91115

92116
return 0;

src/diffCheckBindings.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// diffCheck_py.cc
2+
#include <pybind11/pybind11.h>
3+
#include <pybind11/eigen.h>
4+
#include <pybind11/stl.h>
5+
6+
#include "diffCheck.hh"
7+
8+
namespace py = pybind11;
9+
10+
11+
PYBIND11_MODULE(diffCheckBindings, m) {
12+
m.doc() = "diffCheck python bindings"; // optional module docstring
13+
14+
py::class_<diffCheck::geometry::DFPointCloud>(m, "DFPointCloud")
15+
.def(py::init<>())
16+
.def(py::init<std::vector<Eigen::Vector3d>, std::vector<Eigen::Vector3d>, std::vector<Eigen::Vector3d>>())
17+
.def("Cvt2DFPointCloud", &diffCheck::geometry::DFPointCloud::Cvt2DFPointCloud)
18+
.def("Cvt2O3DPointCloud", &diffCheck::geometry::DFPointCloud::Cvt2O3DPointCloud)
19+
.def("ComputeP2PDistance", &diffCheck::geometry::DFPointCloud::ComputeP2PDistance)
20+
.def("ComputeBoundingBox", &diffCheck::geometry::DFPointCloud::ComputeBoundingBox)
21+
22+
.def("get_num_points", &diffCheck::geometry::DFPointCloud::GetNumPoints);
23+
}
24+
25+
26+
// #include <pybind11/pybind11.h>
27+
28+
// int add(int i, int j) {
29+
// return i + j;
30+
// }
31+
32+
// PYBIND11_MODULE(diffCheckBindings, m) {
33+
// m.def("add", &add, "A function which adds two numbers");
34+
// }

src/gh/diffCheck/diffCheck_app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import diffCheck
1010
import diffCheck.df_geometries
1111

12+
import sys
13+
sys.path.append(R"F:\diffCheck\build\Release")
14+
import diffCheckBindings
15+
1216
print(diffCheck.__version__)
1317

1418

0 commit comments

Comments
 (0)