|
4 | 4 | #include <iostream> |
5 | 5 | #include <fstream> |
6 | 6 |
|
| 7 | +#include <Eigen/Core> |
| 8 | + |
7 | 9 |
|
8 | 10 | int main() |
9 | 11 | { |
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); |
55 | 79 |
|
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(); |
90 | 114 |
|
91 | 115 |
|
92 | 116 | return 0; |
|
0 commit comments