Skip to content

Commit 7007eab

Browse files
ADD-WIP: Point to point error calculation method added to Registration class
1 parent bf1ccc6 commit 7007eab

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

src/diffCheck/registration/registration.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
namespace diffCheck::registration
44
{
5+
std::vector<double> Registration::ComputeP2PDistance(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target)
6+
{
7+
std::vector<double> errors;
8+
auto O3DSourcePointCloud = source->Cvt2O3DPointCloud();
9+
auto O3DTargetPointCloud = target->Cvt2O3DPointCloud();
10+
11+
std::vector<double> distances;
12+
13+
distances = O3DSourcePointCloud->ComputePointCloudDistance(*O3DTargetPointCloud);
14+
return distances;
15+
}
516
/*
617
Documentation on Fast Point Feature Historigrams: https://pcl.readthedocs.io/projects/tutorials/en/latest/fpfh_estimation.html
718

src/diffCheck/registration/registration.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ class Registration
1212
open3d::pipelines::registration::RegistrationResult O3DFastGlobalRegistrationFeatureMatching(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target);
1313

1414
open3d::pipelines::registration::RegistrationResult O3DFastGlobalRegistrationBasedOnCorrespondence(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target);
15+
16+
std::vector<double> ComputeP2PDistance(std::shared_ptr<geometry::DFPointCloud> source, std::shared_ptr<geometry::DFPointCloud> target);
1517
};
1618
}

src/diffCheckApp.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int main()
1414
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr = std::make_shared<diffCheck::geometry::DFPointCloud>();
1515
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrAfterTrans = std::make_shared<diffCheck::geometry::DFPointCloud>();
1616
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrAfterReg = std::make_shared<diffCheck::geometry::DFPointCloud>();
17+
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruth = std::make_shared<diffCheck::geometry::DFPointCloud>();
1718
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr = std::make_shared<diffCheck::geometry::DFMesh>();
1819

1920
std::string pathCloud = R"(C:\Users\localuser\Downloads\04_pt.ply)";
@@ -23,6 +24,9 @@ int main()
2324
dfMeshPtr->LoadFromPLY(pathMesh);
2425
dfPointCloudPtr->LoadFromPLY(pathCloud);
2526

27+
// populate the mesh with points and store it in dfPointCloudPtrGroundTruth
28+
dfPointCloudPtrGroundTruth->Cvt2DFPointCloud(dfMeshPtr->Cvt2O3DTriangleMesh()->SamplePointsUniformly(100000));
29+
2630
// create a rigid rotation matrix
2731
Eigen::Matrix4d T = Eigen::Matrix4d::Identity();
2832
T.block<3, 3>(0, 0) = Eigen::AngleAxisd(3 , Eigen::Vector3d::UnitZ()).toRotationMatrix(); // Yes, Pi = 3 in this world
@@ -33,17 +37,18 @@ int main()
3337
dfPointCloudPtrAfterTrans->Cvt2DFPointCloud(o3DPointCloudAfterTrans);
3438

3539
std::shared_ptr<diffCheck::registration::Registration> reg = std::make_shared<diffCheck::registration::Registration>();
36-
auto result = reg->O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtrAfterTrans, dfPointCloudPtr);
37-
//auto result = reg->O3DFastGlobalRegistrationBasedOnCorrespondence(dfPointCloudPtrAfterTrans, dfPointCloudPtr);
40+
//auto result = reg->O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtrAfterTrans, dfPointCloudPtr);
41+
auto result = reg->O3DFastGlobalRegistrationBasedOnCorrespondence(dfPointCloudPtrAfterTrans, dfPointCloudPtr);
3842

3943
// apply the transformation to the source point cloud
4044
Eigen::Matrix<double, 4, 4> transformation = result.transformation_;
4145
std::shared_ptr<open3d::geometry::PointCloud> o3DPointCloudPtrAfterReg = std::make_shared<open3d::geometry::PointCloud>(dfPointCloudPtrAfterTrans->Cvt2O3DPointCloud()->Transform(transformation));
4246
dfPointCloudPtrAfterReg->Cvt2DFPointCloud(o3DPointCloudPtrAfterReg);
43-
47+
std::vector<double> errors = reg->ComputeP2PDistance(dfPointCloudPtrAfterReg, dfPointCloudPtrGroundTruth);
48+
std::cout << "Mean distance: " << std::accumulate(errors.begin(), errors.end(), 0.0) / errors.size() << std::endl;
4449

4550
std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
46-
vis->AddPointCloud(dfPointCloudPtrAfterTrans);
51+
vis->AddPointCloud(dfPointCloudPtrGroundTruth);
4752
vis->AddPointCloud(dfPointCloudPtrAfterReg);
4853
vis->AddMesh(dfMeshPtr);
4954
vis->Run();

0 commit comments

Comments
 (0)