@@ -12,54 +12,94 @@ int main()
1212 auto initTime = std::chrono::high_resolution_clock::now ();
1313
1414 std::shared_ptr<diffCheck::geometry::DFPointCloud> pcdSrc = std::make_shared<diffCheck::geometry::DFPointCloud>();
15- std::vector<std::shared_ptr<diffCheck::geometry::DFMesh>> meshSrc = std::vector<std::shared_ptr<diffCheck::geometry::DFMesh>>();
15+ std::vector<std::vector<std:: shared_ptr<diffCheck::geometry::DFMesh>>> meshSrc = std::vector<std::vector<std:: shared_ptr<diffCheck::geometry::DFMesh> >>();
1616 std::vector<std::shared_ptr<diffCheck::geometry::DFPointCloud>> segments;
1717 std::vector<std::string> meshPaths;
1818
19- std::string meshesFolderPath = R"( C:\Users\localuser\Desktop\meshes_for_diffCheck\9 \)" ;
19+ std::string meshesFolderPath = R"( C:\Users\localuser\Desktop\meshes_for_diffCheck\joints \)" ;
2020
21- for (int i = 1 ; i <= 7 ; i++)
21+ for (int i = 1 ; i <= 3 ; i++)
2222 {
23- std::string meshPath = meshesFolderPath + std::to_string (i) + " .ply" ;
24- std::shared_ptr<diffCheck::geometry::DFMesh> mesh = std::make_shared<diffCheck::geometry::DFMesh>();
25- mesh->LoadFromPLY (meshPath);
26- meshSrc.push_back (mesh);
23+ std::vector<std::shared_ptr<diffCheck::geometry::DFMesh>> fullJoint;
24+ for (int j = 1 ; j <= 3 ; j++)
25+ {
26+ std::string meshPath = meshesFolderPath + std::to_string (i) + " /" + std::to_string (j) + " .ply" ;
27+ std::shared_ptr<diffCheck::geometry::DFMesh> mesh = std::make_shared<diffCheck::geometry::DFMesh>();
28+ mesh->LoadFromPLY (meshPath);
29+ fullJoint.push_back (mesh);
30+ }
31+ meshSrc.push_back (fullJoint);
2732 }
2833
29- std::string pathPcdSrc = R"( C:\Users\localuser\Desktop\meshes_for_diffCheck\source_pc_2 .ply)" ;
34+ std::string pathPcdSrc = R"( C:\Users\localuser\Desktop\meshes_for_diffCheck\joints\full_beam .ply)" ;
3035
3136 pcdSrc->LoadFromPLY (pathPcdSrc);
3237
3338 pcdSrc->EstimateNormals (false , 100 );
34- pcdSrc->VoxelDownsample (0.01 );
39+ pcdSrc->VoxelDownsample (0.007 );
3540 auto intermediateTime = std::chrono::high_resolution_clock::now ();
3641 segments = diffCheck::segmentation::DFSegmentation::NormalBasedSegmentation (
3742 pcdSrc,
38- 6 .0f ,
39- 25 ,
43+ 15 .0f ,
44+ 15 ,
4045 true ,
41- 20 ,
46+ 50 ,
4247 0 .5f ,
4348 false );
4449 std::cout << " number of segments:" << segments.size ()<< std::endl;
4550
46- std::shared_ptr<diffCheck::geometry::DFPointCloud> unifiedSegments =
47- diffCheck::segmentation::DFSegmentation::AssociateClustersToMeshes (
48- meshSrc,
51+ std::vector<std::shared_ptr<diffCheck::geometry::DFPointCloud>> unifiedSegments;
52+ for (int i = 0 ; i < meshSrc.size (); i++)
53+ {
54+ std::shared_ptr<diffCheck::geometry::DFPointCloud> unifiedSegment = std::make_shared<diffCheck::geometry::DFPointCloud>();
55+ unifiedSegment = diffCheck::segmentation::DFSegmentation::AssociateClustersToMeshes (
56+ meshSrc[i],
4957 segments,
50- .1 ,
51- .9 );
52-
53- std::cout << " Association done. refinement in progress " << std::endl;
58+ .2 ,
59+ .05 );
60+ unifiedSegments. push_back (unifiedSegment);
61+ }
5462
5563 diffCheck::segmentation::DFSegmentation::CleanUnassociatedClusters (segments,
56- std::vector<std::shared_ptr<diffCheck::geometry::DFPointCloud>>{unifiedSegments},
57- std::vector<std::vector<std::shared_ptr<diffCheck::geometry::DFMesh>>>{meshSrc},
58- .1 ,
59- .9 );
60-
61- std::cout << " number of points in unified segments:" << unifiedSegments->Points .size () << std::endl;
62-
64+ unifiedSegments,
65+ meshSrc,
66+ .2 ,
67+ .05 );
68+
69+ // Perform a registration per joint
70+ for (int i = 0 ; i < meshSrc.size (); i++)
71+ {
72+ std::shared_ptr<diffCheck::geometry::DFPointCloud> referencePointCloud = std::make_shared<diffCheck::geometry::DFPointCloud>();
73+ for (auto jointFace : meshSrc[i])
74+ {
75+ std::shared_ptr<diffCheck::geometry::DFPointCloud> facePointCloud = jointFace->SampleCloudUniform (1000 );
76+ referencePointCloud->Points .insert (referencePointCloud->Points .end (), facePointCloud->Points .begin (), facePointCloud->Points .end ());
77+ }
78+ referencePointCloud->EstimateNormals (false , 100 );
79+
80+ diffCheck::transformation::DFTransformation transformation = diffCheck::registrations::DFRefinedRegistration::O3DICP (
81+ unifiedSegments[i],
82+ referencePointCloud);
83+
84+ std::cout << " Transformation matrix:" << std::endl;
85+ std::cout << transformation.TransformationMatrix << std::endl;
86+
87+ diffCheck::visualizer::Visualizer deVisu = diffCheck::visualizer::Visualizer (" DiffCheckApp" , 1000 , 800 , 50 , 50 , false , true , false );
88+ for (int i = 0 ; i < segments.size (); i++)
89+ {
90+ segments[i]->ApplyTransformation (transformation);
91+ deVisu.AddPointCloud (segments[i]);
92+ }
93+ for (auto joint : meshSrc)
94+ {
95+ for (auto face : joint)
96+ {
97+ deVisu.AddMesh (face);
98+ }
99+ }
100+ deVisu.Run ();
101+ }
102+
63103 diffCheck::visualizer::Visualizer vis (std::string (" DiffCheckApp" ), 1000 , 800 , 50 , 50 , false , true , false );
64104 for (auto segment : segments)
65105 {
@@ -74,18 +114,25 @@ int main()
74114 segment->Colors .push_back (Eigen::Vector3d (0 , 0 , 0 ));
75115 }
76116 vis.AddPointCloud (segment);
77-
78117 }
79- for (auto mesh : meshSrc)
118+ for (auto joint : meshSrc)
80119 {
81- // vis.AddMesh(mesh);
120+ for ( auto mesh : joint){ vis.AddMesh (mesh);}
82121 }
83122
84- for (int i = 0 ; i < unifiedSegments->Points .size (); i++)
123+ int numSegments = unifiedSegments.size ();
124+
125+ for (int i = 0 ; i < numSegments; i++)
85126 {
86- unifiedSegments->Colors .push_back (Eigen::Vector3d (0 , 0 , 1 ));
127+ for (int j = 0 ; j < unifiedSegments[i]->Points .size (); j++)
128+ {
129+ unifiedSegments[i]->Colors .push_back (Eigen::Vector3d ((double (numSegments) - double (i))/double (numSegments), 1 , double (i) / double (numSegments)));
130+ }
131+ }
132+ for (auto seg : unifiedSegments)
133+ {
134+ vis.AddPointCloud (seg);
87135 }
88- vis.AddPointCloud (unifiedSegments);
89136
90137 auto endTime = std::chrono::high_resolution_clock::now ();
91138 auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - initTime);
@@ -95,6 +142,5 @@ int main()
95142
96143 vis.Run ();
97144
98-
99145 return 0 ;
100146}
0 commit comments