Skip to content

Commit 3885182

Browse files
WIP: ApplyTransformation method
1 parent 7b3d16d commit 3885182

File tree

3 files changed

+22
-23
lines changed

3 files changed

+22
-23
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ namespace diffCheck::geometry
4949
{
5050
auto O3DPointCloud = this->Cvt2O3DPointCloud();
5151
O3DPointCloud->Transform(transformation.TransformationMatrix);
52+
this->Points.clear();
53+
this->Colors.clear();
54+
this->Normals.clear();
5255
this->Cvt2DFPointCloud(O3DPointCloud);
5356
}
5457

src/diffCheck/registrations/DFGlobalRegistrations.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,10 @@ namespace diffCheck::registrations
7171
int maxNeighborKDTreeSearch = 50,
7272
double maxCorrespondenceDistance = 0.05,
7373
open3d::pipelines::registration::TransformationEstimationPointToPoint transformationEstimation = open3d::pipelines::registration::TransformationEstimationPointToPoint(false),
74-
int ransacN = 3,
74+
int ransacN = 5,
7575
double correspondenceCheckerDistance = 0.05,
7676
int ransacMaxIteration = 1000,
77-
double ransacConfidenceThreshold = 0.999);
77+
double ransacConfidenceThreshold = 0.99);
7878

7979
private: ///< o3d utilities to evaluate registration errors
8080
/**
@@ -86,7 +86,6 @@ namespace diffCheck::registrations
8686
* @param transform The vector of transformation matrix we want to evaluate. they are applied to the source point cloud.
8787
* @return std::vector<double> A vector of mean distances, one for each transform.
8888
*/
89-
9089
static std::vector<double> EvaluateRegistrations(std::shared_ptr<geometry::DFPointCloud> source,
9190
std::shared_ptr<geometry::DFPointCloud> target,
9291
std::vector<Eigen::Matrix<double, 4, 4>> transforms);

src/diffCheckApp.cc

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,54 @@ int main()
99
{
1010
// import clouds
1111
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtr = std::make_shared<diffCheck::geometry::DFPointCloud>();
12-
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrAfterTrans = std::make_shared<diffCheck::geometry::DFPointCloud>();
1312
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruthNoNormals = std::make_shared<diffCheck::geometry::DFPointCloud>();
1413
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrGroundTruth = std::make_shared<diffCheck::geometry::DFPointCloud>();
1514
std::shared_ptr<diffCheck::geometry::DFMesh> dfMeshPtr = std::make_shared<diffCheck::geometry::DFMesh>();
1615

17-
std::string pathCloud = R"(C:\Users\andre\Downloads\00_pt.ply)";
18-
std::string pathMesh = R"(C:\Users\andre\Downloads\00_mesh.ply)";
16+
std::string pathCloud = R"(C:\Users\localuser\Downloads\04_pt.ply)";
17+
std::string pathMesh = R"(C:\Users\localuser\Downloads\04_mesh.ply)";
1918

2019
dfMeshPtr->LoadFromPLY(pathMesh);
2120
dfPointCloudPtr->LoadFromPLY(pathCloud);
22-
2321
// add noise to dfPointCloudPtr
2422
for (int i = 0; i < dfPointCloudPtr->Points.size(); i++)
2523
{
26-
dfPointCloudPtr->Points[i] += Eigen::Vector3d::Random() * 0.1 ;
24+
dfPointCloudPtr->Points[i] += Eigen::Vector3d::Random() * 0.01 ;
2725
}
2826

2927
// populate the mesh with points and store it in dfPointCloudPtrGroundTruth
30-
dfPointCloudPtrGroundTruthNoNormals->Cvt2DFPointCloud(dfMeshPtr->Cvt2O3DTriangleMesh()->SamplePointsUniformly(10000));
28+
dfPointCloudPtrGroundTruthNoNormals->Cvt2DFPointCloud(dfMeshPtr->Cvt2O3DTriangleMesh()->SamplePointsUniformly(1000));
3129
std::shared_ptr<open3d::geometry::PointCloud> pcd = dfPointCloudPtrGroundTruthNoNormals->Cvt2O3DPointCloud();
3230
pcd->EstimateNormals();
3331
dfPointCloudPtrGroundTruth->Cvt2DFPointCloud(pcd);
34-
32+
3533
// create a rigid rotation matrix
3634
Eigen::Matrix4d T = Eigen::Matrix4d::Identity();
37-
T.block<3, 3>(0, 0) = Eigen::AngleAxisd(0.3, Eigen::Vector3d::UnitX()).toRotationMatrix();
38-
T(0, 3) = 5;
39-
T(1, 3) = -10;
40-
T(2, 3) = 10;
35+
T.block<3, 3>(0, 0) = Eigen::AngleAxisd(3, Eigen::Vector3d::UnitX()).toRotationMatrix();
36+
T(0, 3) = 50;
37+
T(1, 3) = -100;
38+
T(2, 3) = 100;
4139
dfPointCloudPtr->ApplyTransformation(diffCheck::transformation::DFTransformation(T));
42-
dfPointCloudPtrAfterTrans = dfPointCloudPtr;
40+
std::shared_ptr<diffCheck::geometry::DFPointCloud> dfPointCloudPtrCopy = std::make_shared<diffCheck::geometry::DFPointCloud>(*dfPointCloudPtr);
4341

4442
// test global registrations Fast and RANSAC-based
4543
std::vector<diffCheck::transformation::DFTransformation> registrationResults;
46-
4744
diffCheck::transformation::DFTransformation transformationA =
48-
diffCheck::registrations::DFGlobalRegistrations::O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtr, dfPointCloudPtrAfterTrans);
49-
std::cout << "Fast transformation: " << transformationA.TransformationMatrix << std::endl;
50-
dfPointCloudPtrAfterTrans->ApplyTransformation(transformationA);
45+
diffCheck::registrations::DFGlobalRegistrations::O3DFastGlobalRegistrationFeatureMatching(dfPointCloudPtr, dfPointCloudPtrGroundTruth, true, 0.01, 1, 50, 1, 500, 500);
46+
std::cout << "Fast transformation: " << transformationA.TransformationMatrix << std::flush;
47+
dfPointCloudPtr->ApplyTransformation(transformationA);
5148
registrationResults.push_back(transformationA);
52-
5349
diffCheck::transformation::DFTransformation transformationB =
54-
diffCheck::registrations::DFGlobalRegistrations::O3DRansacOnFeatureMatching(dfPointCloudPtr, dfPointCloudPtrAfterTrans);
50+
diffCheck::registrations::DFGlobalRegistrations::O3DRansacOnFeatureMatching(dfPointCloudPtrCopy, dfPointCloudPtrGroundTruth);
5551
std::cout << "Ransac transformation: " << transformationB.TransformationMatrix << std::endl;
56-
dfPointCloudPtrAfterTrans->ApplyTransformation(transformationB);
52+
dfPointCloudPtrCopy->ApplyTransformation(transformationB);
5753
registrationResults.push_back(transformationB);
5854

5955
// visualize cloud
6056
std::shared_ptr<diffCheck::visualizer::Visualizer> visualizer = std::make_shared<diffCheck::visualizer::Visualizer>();
6157
visualizer->AddPointCloud(dfPointCloudPtr);
62-
visualizer->AddPointCloud(dfPointCloudPtrAfterTrans);
58+
visualizer->AddPointCloud(dfPointCloudPtrCopy);
59+
visualizer->AddMesh(dfMeshPtr);
6360
visualizer->Run();
6461

6562
return 0;

0 commit comments

Comments
 (0)