Skip to content

Commit 3eb0fc5

Browse files
committed
CAP: refactored backend for segmeentations and normal estimations
1 parent 08b09db commit 3eb0fc5

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ namespace diffCheck::geometry
146146
{
147147
if (!useCilantroEvaluator)
148148
{
149+
this->Normals.clear();
149150
auto O3DPointCloud = this->Cvt2O3DPointCloud();
150151

151152
if (knn.value() != 30 && searchRadius.has_value() == false)
@@ -165,8 +166,6 @@ namespace diffCheck::geometry
165166
O3DPointCloud->EstimateNormals();
166167
DIFFCHECK_INFO("Default estimation of normals with knn = 30");
167168
}
168-
169-
this->Normals.clear();
170169
for (auto &normal : O3DPointCloud->normals_)
171170
this->Normals.push_back(normal);
172171
}

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 = 10,
84+
std::optional<int> knn = 50,
8585
std::optional<double> searchRadius = std::nullopt);
8686

8787
/**

src/diffCheck/segmentation/DFSegmentation.cc

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,19 @@ namespace diffCheck::segmentation
1515
int radiusNeighborhoodSize,
1616
bool colorClusters)
1717
{
18+
if (!pointCloud->HasNormals())
19+
{
20+
DIFFCHECK_WARN("The point cloud does not have normals. Estimating normals with 50 neighbors.");
21+
pointCloud->EstimateNormals(true, 50);
22+
}
23+
1824
std::shared_ptr<cilantro::PointCloud3f> cilantroPointCloud = pointCloud->Cvt2CilantroPointCloud();
1925

2026
std::vector<std::shared_ptr<geometry::DFPointCloud>> segments;
2127
if (useKnnNeighborhood)
2228
{
2329
cilantro::KNNNeighborhoodSpecification<int> neighborhood(knnNeighborhoodSize);
2430

25-
// FIXME: not clear why this is needed all the time
26-
cilantroPointCloud->estimateNormals(neighborhood);
27-
2831
cilantro::NormalsProximityEvaluator<float, 3> similarityEvaluator(
2932
cilantroPointCloud->normals,
3033
normalThresholdDegree*M_PI/180.0f);
@@ -58,8 +61,6 @@ namespace diffCheck::segmentation
5861
{
5962
cilantro::RadiusNeighborhoodSpecification<float> neighborhood(radiusNeighborhoodSize);
6063

61-
// cilantroPointCloud->estimateNormals(neighborhood);
62-
6364
cilantro::NormalsProximityEvaluator<float, 3> similarityEvaluator(
6465
cilantroPointCloud->normals,
6566
normalThresholdDegree*M_PI/180.0f);
@@ -79,7 +80,14 @@ namespace diffCheck::segmentation
7980
Eigen::Vector3d normal = cilantroPointCloud->normals.col(pointIndice).cast<double>();
8081
segment->Points.push_back(point);
8182
segment->Normals.push_back(normal);
83+
if (cilantroPointCloud->hasColors())
84+
{
85+
Eigen::Vector3d color = cilantroPointCloud->colors.col(pointIndice).cast<double>();
86+
segment->Colors.push_back(color);
87+
}
8288
}
89+
if (colorClusters)
90+
segment->ApplyColor(Eigen::Vector3d::Random());
8391
segments.push_back(segment);
8492
}
8593
}

src/diffCheck/visualizer.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ namespace diffCheck::visualizer
2424
{
2525
vis.AddGeometry(geometry);
2626
}
27-
vis.GetRenderOption().point_color_option_ = open3d::visualization::RenderOption::PointColorOption::Color;
27+
if (this->RenderPcdColorNormals)
28+
vis.GetRenderOption().point_color_option_ = open3d::visualization::RenderOption::PointColorOption::Normal;
29+
else
30+
vis.GetRenderOption().point_color_option_ = open3d::visualization::RenderOption::PointColorOption::Color;
2831
if (this->ShowNormals)
2932
vis.GetRenderOption().TogglePointShowNormal();
3033
vis.Run();

src/diffCheck/visualizer.hh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ namespace diffCheck::visualizer
2222
int posX = 50,
2323
int posY = 50,
2424
bool showNormals = true,
25-
bool showWireframe = true
25+
bool showWireframe = true,
26+
bool renderPcdColorNormals = false
2627
) : Title(title), Width(width), Height(height),
2728
PosX(posX), PosY(posY),
28-
ShowNormals(showNormals), ShowWireframe(showWireframe)
29+
ShowNormals(showNormals), ShowWireframe(showWireframe),
30+
RenderPcdColorNormals(renderPcdColorNormals)
2931
{}
3032
~Visualizer() = default;
3133

@@ -62,6 +64,8 @@ namespace diffCheck::visualizer
6264
bool ShowNormals;
6365
/// @brief weither to show the wireframe
6466
bool ShowWireframe;
67+
/// @brief weither to render the point cloud color normals
68+
bool RenderPcdColorNormals;
6569

6670
private:
6771
/// @brief the geometries to visualize

src/diffCheckApp.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "diffCheck.hh"
2+
#include "diffCheck/log.hh"
23

34
#include <iostream>
45
#include <fstream>
@@ -15,27 +16,23 @@ int main()
1516

1617
pcdSrc->LoadFromPLY(pathPcdSrc);
1718

18-
// pcdSrc->EstimateNormals(false, 50);
19-
20-
// pcdSrc->ApplyColor(255, 0 , 0);
21-
22-
19+
pcdSrc->EstimateNormals(100);
2320
segments = diffCheck::segmentation::DFSegmentation::NormalBasedSegmentation(
2421
pcdSrc,
2522
20.f,
2623
10,
2724
true,
2825
50,
29-
30,
26+
10,
3027
true);
3128
std::cout << "number of segments:" << segments.size()<< std::endl;
3229

33-
diffCheck::visualizer::Visualizer vis;
30+
std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
31+
vis->RenderPcdColorNormals = false;
3432

3533
for (auto segment : segments)
36-
vis.AddPointCloud(segment);
34+
vis->AddPointCloud(segment);
3735

38-
// vis.AddPointCloud(pcdSrc);
39-
vis.Run();
36+
vis->Run();
4037
return 0;
4138
}

0 commit comments

Comments
 (0)