Skip to content

Commit c8e9ad5

Browse files
CAP: AssociateClusters function implemented in the back-end
1 parent 2503cfb commit c8e9ad5

File tree

4 files changed

+53
-40
lines changed

4 files changed

+53
-40
lines changed

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ namespace diffCheck::geometry
8181
*/
8282
void EstimateNormals(
8383
bool useCilantroEvaluator = false,
84-
std::optional<int> knn = 100,
84+
std::optional<int> knn = 50,
8585
std::optional<double> searchRadius = std::nullopt);
8686

8787
/**

src/diffCheck/segmentation/DFSegmentation.cc

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ namespace diffCheck::segmentation
9494
return segments;
9595
}
9696

97-
std::tuple<std::shared_ptr<geometry::DFPointCloud>, std::vector<std::shared_ptr<geometry::DFPointCloud>>> DFSegmentation::AssociateSegments(
98-
std::vector<std::shared_ptr<geometry::DFMesh>> meshFaces,
99-
std::vector<std::shared_ptr<geometry::DFPointCloud>> segments,
97+
std::shared_ptr<geometry::DFPointCloud> DFSegmentation::AssociateClusters(
98+
std::vector<std::shared_ptr<geometry::DFMesh>> referenceMesh,
99+
std::vector<std::shared_ptr<geometry::DFPointCloud>> &clusters,
100100
double associationThreshold)
101101
{
102102
std::shared_ptr<geometry::DFPointCloud> unifiedPointCloud = std::make_shared<geometry::DFPointCloud>();
103103
std::vector<std::shared_ptr<geometry::DFPointCloud>> segmentsRemainder;
104104

105105
// iterate through the mesh faces given as function argument
106-
for (std::shared_ptr<diffCheck::geometry::DFMesh> face : meshFaces)
106+
for (std::shared_ptr<diffCheck::geometry::DFMesh> face : referenceMesh)
107107
{
108108
std::shared_ptr<geometry::DFPointCloud> correspondingSegment;
109109
std::shared_ptr<open3d::geometry::TriangleMesh> o3dFace;
@@ -131,7 +131,7 @@ namespace diffCheck::segmentation
131131
Eigen::Vector3d segmentCenter;
132132
Eigen::Vector3d segmentNormal;
133133
double faceDistance = std::numeric_limits<double>::max();
134-
for (auto segment : segments)
134+
for (auto segment : clusters)
135135
{
136136
for (auto point : segment->Points)
137137
{
@@ -154,7 +154,7 @@ namespace diffCheck::segmentation
154154
}
155155
}
156156

157-
// get the triangles of the face. This is to check if the point is in the face
157+
// get the triangles of the face.
158158
std::vector<Eigen::Vector3i> faceTriangles = o3dFace->triangles_;
159159

160160
for (Eigen::Vector3d point : correspondingSegment->Points)
@@ -197,15 +197,36 @@ namespace diffCheck::segmentation
197197
if (pointInFace)
198198
{
199199
unifiedPointCloud->Points.push_back(point);
200+
unifiedPointCloud->Normals.push_back(
201+
correspondingSegment->Normals[std::distance(
202+
correspondingSegment->Points.begin(),
203+
std::find(correspondingSegment->Points.begin(),
204+
correspondingSegment->Points.end(),
205+
point))]
206+
);
200207
}
201208
}
202209
// removing points from the segment that are in the face
203210
for(Eigen::Vector3d point : unifiedPointCloud->Points)
204211
{
205-
correspondingSegment->Points.erase(std::remove(correspondingSegment->Points.begin(), correspondingSegment->Points.end(), point), correspondingSegment->Points.end());
212+
correspondingSegment->Points.erase(
213+
std::remove(
214+
correspondingSegment->Points.begin(),
215+
correspondingSegment->Points.end(),
216+
point),
217+
correspondingSegment->Points.end());
218+
}
219+
if (correspondingSegment->GetNumPoints() == 0)
220+
{
221+
clusters.erase(
222+
std::remove(
223+
clusters.begin(),
224+
clusters.end(),
225+
correspondingSegment),
226+
clusters.end());
206227
}
207228
}
208-
return std::make_tuple(unifiedPointCloud, segments);
229+
return unifiedPointCloud;
209230
}
210231

211232
} // namespace diffCheck::segmentation

src/diffCheck/segmentation/DFSegmentation.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,16 @@ namespace diffCheck::segmentation
2424
int knnNeighborhoodSize = 10,
2525
float radiusNeighborhoodSize = 10.f,
2626
bool colorClusters = false);
27+
28+
/** @brief Associates point cloud segments to mesh faces. It uses the center of mass of the segments and the mesh faces to find correspondances. For each mesh face it then iteratively associate the points of the segment that are actually on the mesh face.
29+
* @param referenceMesh the vector of mesh faces to associate with the segments
30+
* @param clusters the vector of clusters from cilantro to associate with the mesh faces of the reference mesh
31+
* @param associationThreshold the threshold to consider the points of a segment and a mesh face as associable. The lower the number, the more strict the association will be and some poinnts on the mesh face might be wrongfully excluded.
32+
* @return std::shared_ptr<geometry::DFPointCloud> The unified segments
33+
*/
34+
static std::shared_ptr<geometry::DFPointCloud> DFSegmentation::AssociateClusters(
35+
std::vector<std::shared_ptr<geometry::DFMesh>> referenceMesh,
36+
std::vector<std::shared_ptr<geometry::DFPointCloud>> &clusters,
37+
double associationThreshold);
2738
};
2839
} // namespace diffCheck::segmentation

src/diffCheckApp.cc

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -33,62 +33,43 @@ int main()
3333
pcdSrc->EstimateNormals();
3434
segments = diffCheck::segmentation::DFSegmentation::NormalBasedSegmentation(
3535
pcdSrc,
36-
20.f,
37-
10,
36+
2.0f,
37+
100,
3838
true,
39-
50,
39+
30,
4040
0.5f,
41-
true);
41+
false);
4242
std::cout << "number of segments:" << segments.size()<< std::endl;
4343

44-
std::tuple<std::shared_ptr<diffCheck::geometry::DFPointCloud>, std::vector<std::shared_ptr<diffCheck::geometry::DFPointCloud>>> unifiedSegments =
45-
diffCheck::segmentation::DFSegmentation::AssociateSegments(meshSrc, segments, 0.15);
44+
std::shared_ptr<diffCheck::geometry::DFPointCloud> unifiedSegments =
45+
diffCheck::segmentation::DFSegmentation::AssociateSegments(meshSrc, segments, .1);
4646

4747
diffCheck::visualizer::Visualizer vis;
48-
for (auto segment : std::get<1>(unifiedSegments))
48+
for (auto segment : segments)
4949
{
5050
// colorize the segments with random colors
5151
double r = static_cast<double>(rand()) / RAND_MAX;
5252
double g = static_cast<double>(rand()) / RAND_MAX;
5353
double b = static_cast<double>(rand()) / RAND_MAX;
5454

55+
segment->Colors.clear();
5556
for (int i = 0; i < segment->Points.size(); i++)
5657
{
5758
segment->Colors.push_back(Eigen::Vector3d(r, g, b));
5859
}
59-
vis.AddPointCloud(segment);
60-
61-
// // colorize the segments with random colors
62-
// double r = static_cast<double>(rand()) / RAND_MAX;
63-
// double g = static_cast<double>(rand()) / RAND_MAX;
64-
// double b = static_cast<double>(rand()) / RAND_MAX;
65-
// for (int i = 0; i < std::get<0>(unifiedSegments)->Points.size(); i++)
66-
// {
67-
// std::get<0>(unifiedSegments)->Colors.push_back(Eigen::Vector3d(r, g, b));
68-
// }
69-
// vis.AddPointCloud(std::get<0>(unifiedSegments));
70-
71-
// for (auto segemt : std::get<1>(unifiedSegments))
72-
// {
73-
// for (int i = 0; i < segemt->Points.size(); i++)
74-
// {
75-
// segemt->Colors.push_back(Eigen::Vector3d(0, 0, 1));
76-
// }
77-
// vis.AddPointCloud(segemt);
78-
// }
60+
// vis.AddPointCloud(segment);
7961

8062
}
8163
for(auto mesh : meshSrc)
8264
{
8365
vis.AddMesh(mesh);
8466
}
8567

86-
auto unified = std::get<0>(unifiedSegments);
87-
for (int i = 0; i < unified->Points.size(); i++)
68+
for (int i = 0; i < unifiedSegments->Points.size(); i++)
8869
{
89-
unified->Colors.push_back(Eigen::Vector3d(0, 0, 0));
70+
unifiedSegments->Colors.push_back(Eigen::Vector3d(0, 0, 0));
9071
}
91-
vis.AddPointCloud(unified);
72+
vis.AddPointCloud(unifiedSegments);
9273

9374
auto endTime = std::chrono::high_resolution_clock::now();
9475
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(endTime - initTime);

0 commit comments

Comments
 (0)