Skip to content

Commit 07667a4

Browse files
WIP-ADD: Fast Global Registration added
1 parent a6bac3f commit 07667a4

File tree

4 files changed

+69
-8
lines changed

4 files changed

+69
-8
lines changed

src/diffCheck.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
#include "diffCheck/geometry/DFPointCloud.hh"
88
#include "diffCheck/geometry/DFMesh.hh"
99
#include "diffCheck/IOManager.hh"
10-
#include "diffCheck/visualizer.hh"
10+
#include "diffCheck/visualizer.hh"
11+
#include "diffCheck/registration/registration.hh"
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "registration.hh"
2+
3+
namespace diffCheck::registration
4+
{
5+
open3d::pipelines::registration::RegistrationResult Registration::o3dFastGlobalRegistrationFeatureMatching(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target)
6+
{
7+
auto sourceO3d = source->Cvt2O3DPointCloud();
8+
auto targetO3d = target->Cvt2O3DPointCloud();
9+
10+
sourceO3d->RandomDownSample(0.1);
11+
targetO3d->RandomDownSample(0.1);
12+
13+
std::shared_ptr<open3d::pipelines::registration::Feature> sourceFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*sourceO3d,
14+
open3d::geometry::KDTreeSearchParamHybrid(0.25, 30));
15+
std::shared_ptr<open3d::pipelines::registration::Feature> targetFPFHFeatures = open3d::pipelines::registration::ComputeFPFHFeature(*targetO3d,
16+
open3d::geometry::KDTreeSearchParamHybrid(0.25, 30));
17+
std::shared_ptr<open3d::pipelines::registration::FastGlobalRegistrationOption> option = std::make_shared<open3d::pipelines::registration::FastGlobalRegistrationOption>();
18+
option->maximum_correspondence_distance_ = 0.05;
19+
option->iteration_number_ = 100;
20+
option->maximum_tuple_count_ = 500;
21+
22+
auto result = open3d::pipelines::registration::FastGlobalRegistrationBasedOnFeatureMatching(*sourceO3d,
23+
*targetO3d,
24+
*sourceFPFHFeatures,
25+
*targetFPFHFeatures,
26+
*option);
27+
28+
return result;
29+
}
30+
} // namespace diffCheck::registration
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#pragma once
2+
3+
#include "diffCheck.hh"
4+
#include <open3d/pipelines/registration/Registration.h>
5+
6+
namespace diffCheck::registration{
7+
8+
class Registration
9+
{
10+
public:
11+
12+
open3d::pipelines::registration::RegistrationResult o3dFastGlobalRegistrationFeatureMatching(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target);
13+
};
14+
}

src/diffCheckApp.cc

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,39 @@
1212
int main()
1313
{
1414
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr = std::make_shared<diffCheck::geometry::DFPointCloud>();
15+
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrAfterTrans = std::make_shared<diffCheck::geometry::DFPointCloud>();
16+
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrAfterReg = std::make_shared<diffCheck::geometry::DFPointCloud>();
1517
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr = std::make_shared<diffCheck::geometry::DFMesh>();
1618

17-
std::string pathCloud = R"(C:\Users\andre\Downloads\scan_data_normals.ply\scan_data_normals.ply)";
18-
std::string pathMesh = R"(F:\diffCheck\assets\dataset\mesh_fromRh_unfixedLength.ply)";
19+
std::string pathCloud = R"(C:\Users\localuser\Downloads\00_pt.ply)";
20+
std::string pathMesh = R"(C:\Users\localuser\Downloads\00_mesh.ply)";
1921
// std::string pathMesh = R"(F:\diffCheck\temp\03_mesh.ply)";
2022

21-
// create a sphere from o3d
22-
auto mesh = open3d::geometry::TriangleMesh::CreateSphere(1.0, 4);
2323
dfMeshPtr->LoadFromPLY(pathMesh);
24+
dfPointCloudPtr->LoadFromPLY(pathCloud);
2425

26+
// create a rigid rotation matrix
27+
Eigen::Matrix4d T = Eigen::Matrix4d::Identity();
28+
T.block<3, 3>(0, 0) = Eigen::AngleAxisd(3 , Eigen::Vector3d::UnitZ()).toRotationMatrix(); // Yes, Pi = 3 in this case
29+
T(0, 3) = 1;
30+
T(1, 3) = 4;
2531

26-
dfMeshPtr->Cvt2DFMesh(mesh);
32+
std::shared_ptr<open3d::geometry::PointCloud> o3DPC = std::make_shared<open3d::geometry::PointCloud>(dfPointCloudPtr->Cvt2O3DPointCloud()->Transform(T));
33+
dfPointCloudPtrAfterTrans->Cvt2DFPointCloud(o3DPC);
34+
35+
std::shared_ptr<diffCheck::registration::Registration> reg = std::make_shared<diffCheck::registration::Registration>();
36+
auto result = reg->o3dFastGlobalRegistrationFeatureMatching(dfPointCloudPtrAfterTrans, dfPointCloudPtr);
37+
38+
// apply the transformation to the source point cloud
39+
Eigen::Matrix
40+
<double, 4, 4> transformation = result.transformation_;
41+
std::shared_ptr<open3d::geometry::PointCloud> o3DPCReg = std::make_shared<open3d::geometry::PointCloud>(dfPointCloudPtrAfterTrans->Cvt2O3DPointCloud()->Transform(transformation));
42+
dfPointCloudPtrAfterReg->Cvt2DFPointCloud(o3DPCReg);
2743

28-
// dfPointCloudPtr->LoadFromPLY(pathCloud);
2944

3045
std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
31-
// vis->AddPointCloud(dfPointCloudPtr);
46+
//vis->AddPointCloud(dfPointCloudPtrAfterTrans);
47+
vis->AddPointCloud(dfPointCloudPtrAfterReg);
3248
vis->AddMesh(dfMeshPtr);
3349
vis->Run();
3450

0 commit comments

Comments
 (0)