Skip to content

Commit 08b09db

Browse files
committed
WIP: adding coloring for cloud and clustering
1 parent acc643c commit 08b09db

File tree

4 files changed

+36
-45
lines changed

4 files changed

+36
-45
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,18 @@ namespace diffCheck::geometry
201201
this->Normals.push_back(normal);
202202
}
203203

204+
void DFPointCloud::ApplyColor(const Eigen::Vector3d &color)
205+
{
206+
this->Colors.clear();
207+
for (auto &point : this->Points)
208+
this->Colors.push_back(color);
209+
}
210+
void DFPointCloud::ApplyColor(int r, int g, int b)
211+
{
212+
Eigen::Vector3d color = Eigen::Vector3d(r / 255.0, g / 255.0, b / 255.0);
213+
this->ApplyColor(color);
214+
}
215+
204216
void DFPointCloud::UniformDownsample(int everyKPoints)
205217
{
206218
auto O3DPointCloud = this->Cvt2O3DPointCloud();

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ namespace diffCheck::geometry
8484
std::optional<int> knn = 10,
8585
std::optional<double> searchRadius = std::nullopt);
8686

87+
/**
88+
* @brief Paint the point cloud with a uniform color
89+
*
90+
* @param color the color to paint the point cloud
91+
*/
92+
void ApplyColor(const Eigen::Vector3d &color);
93+
void ApplyColor(int r, int g, int b);
94+
8795
public: ///< Downsamplers
8896
/**
8997
* @brief Downsample the point cloud with voxel grid

src/diffCheck/segmentation/DFSegmentation.cc

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace diffCheck::segmentation
2222
{
2323
cilantro::KNNNeighborhoodSpecification<int> neighborhood(knnNeighborhoodSize);
2424

25+
// FIXME: not clear why this is needed all the time
2526
cilantroPointCloud->estimateNormals(neighborhood);
2627

2728
cilantro::NormalsProximityEvaluator<float, 3> similarityEvaluator(
@@ -33,38 +34,31 @@ namespace diffCheck::segmentation
3334
auto clusterToPointMap = segmenter.getClusterToPointIndicesMap();
3435
int nSegments = segmenter.getNumberOfClusters();
3536

36-
// FIXME: painting color not working (see paint_uniform?)
3737
for (int indice = 0; indice<nSegments; indice++)
3838
{
3939
std::shared_ptr<geometry::DFPointCloud> segment = std::make_shared<geometry::DFPointCloud>();
40-
41-
// random rgb color in format Eigen::Vector3d from 0 to 1
42-
Eigen::Vector3d color = Eigen::Vector3d::Random();
4340
for (auto pointIndice : clusterToPointMap[indice])
4441
{
4542
Eigen::Vector3d point = cilantroPointCloud->points.col(pointIndice).cast<double>();
4643
Eigen::Vector3d normal = cilantroPointCloud->normals.col(pointIndice).cast<double>();
4744
segment->Points.push_back(point);
4845
segment->Normals.push_back(normal);
49-
if (colorClusters)
50-
segment->Colors.push_back(color);
51-
else
46+
if (cilantroPointCloud->hasColors())
5247
{
53-
if (cilantroPointCloud->colors.cols() > 0)
54-
{
55-
Eigen::Vector3d color = cilantroPointCloud->colors.col(pointIndice).cast<double>();
56-
segment->Colors.push_back(color);
57-
}
48+
Eigen::Vector3d color = cilantroPointCloud->colors.col(pointIndice).cast<double>();
49+
segment->Colors.push_back(color);
5850
}
5951
}
52+
if (colorClusters)
53+
segment->ApplyColor(Eigen::Vector3d::Random());
6054
segments.push_back(segment);
6155
}
6256
}
6357
else
6458
{
6559
cilantro::RadiusNeighborhoodSpecification<float> neighborhood(radiusNeighborhoodSize);
6660

67-
cilantroPointCloud->estimateNormals(neighborhood);
61+
// cilantroPointCloud->estimateNormals(neighborhood);
6862

6963
cilantro::NormalsProximityEvaluator<float, 3> similarityEvaluator(
7064
cilantroPointCloud->normals,
@@ -76,27 +70,15 @@ namespace diffCheck::segmentation
7670
auto clusterToPointMap = segmenter.getClusterToPointIndicesMap();
7771
int nSegments = segmenter.getNumberOfClusters();
7872

79-
// FIXME: painting color not working (see paint_uniform?)
8073
for (int indice = 0; indice<nSegments; indice++)
8174
{
8275
std::shared_ptr<geometry::DFPointCloud> segment = std::make_shared<geometry::DFPointCloud>();
83-
Eigen::Vector3d color = Eigen::Vector3d::Random();
8476
for (auto pointIndice : clusterToPointMap[indice])
8577
{
8678
Eigen::Vector3d point = cilantroPointCloud->points.col(pointIndice).cast<double>();
8779
Eigen::Vector3d normal = cilantroPointCloud->normals.col(pointIndice).cast<double>();
8880
segment->Points.push_back(point);
8981
segment->Normals.push_back(normal);
90-
if (colorClusters)
91-
segment->Colors.push_back(color);
92-
else
93-
{
94-
if (cilantroPointCloud->colors.cols() > 0)
95-
{
96-
Eigen::Vector3d color = cilantroPointCloud->colors.col(pointIndice).cast<double>();
97-
segment->Colors.push_back(color);
98-
}
99-
}
10082
}
10183
segments.push_back(segment);
10284
}

src/diffCheckApp.cc

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,38 +15,27 @@ int main()
1515

1616
pcdSrc->LoadFromPLY(pathPcdSrc);
1717

18+
// pcdSrc->EstimateNormals(false, 50);
19+
20+
// pcdSrc->ApplyColor(255, 0 , 0);
21+
22+
1823
segments = diffCheck::segmentation::DFSegmentation::NormalBasedSegmentation(
1924
pcdSrc,
20-
10.f,
25+
20.f,
2126
10,
2227
true,
2328
50,
2429
30,
2530
true);
2631
std::cout << "number of segments:" << segments.size()<< std::endl;
27-
// print the last 5 colors
28-
for (auto segment : segments)
29-
{
30-
for (int i = 0; i < 5; i++)
31-
{
32-
std::cout << segment->Colors[i].transpose() << std::endl;
33-
}
34-
}
3532

3633
diffCheck::visualizer::Visualizer vis;
37-
// vis.AddPointCloud(pcdSrc);
34+
3835
for (auto segment : segments)
39-
{
40-
// colorize the segments with random colors
41-
double r = static_cast<double>(rand()) / RAND_MAX;
42-
double g = static_cast<double>(rand()) / RAND_MAX;
43-
double b = static_cast<double>(rand()) / RAND_MAX;
44-
for (int i = 0; i < segment->Points.size(); i++)
45-
{
46-
segment->Colors.push_back(Eigen::Vector3d(r, g, b));
47-
}
4836
vis.AddPointCloud(segment);
49-
}
37+
38+
// vis.AddPointCloud(pcdSrc);
5039
vis.Run();
5140
return 0;
5241
}

0 commit comments

Comments
 (0)