Skip to content

Commit 3940e23

Browse files
committed
ADD: normal estimation to dfcloud
1 parent e0b531d commit 3940e23

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/diffCheck/geometry/DFPointCloud.cc

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

34
#include "diffCheck/IOManager.hh"
45

@@ -55,6 +56,37 @@ namespace diffCheck::geometry
5556
return extremePoints;
5657
}
5758

59+
void DFPointCloud::EstimateNormals(
60+
std::optional<int> knn,
61+
std::optional<double> searchRadius
62+
)
63+
{
64+
auto O3DPointCloud = this->Cvt2O3DPointCloud();
65+
O3DPointCloud->EstimateNormals();
66+
67+
if (knn.value() != 30 && searchRadius.has_value() == false)
68+
{
69+
open3d::geometry::KDTreeSearchParamKNN knnSearchParam(knn.value());
70+
O3DPointCloud->EstimateNormals(knnSearchParam);
71+
DIFFCHECK_INFO(("Estimating normals with knn = " + std::to_string(knn.value())).c_str());
72+
}
73+
else if (searchRadius.has_value())
74+
{
75+
open3d::geometry::KDTreeSearchParamHybrid hybridSearchParam(searchRadius.value(), knn.value());
76+
O3DPointCloud->EstimateNormals(hybridSearchParam);
77+
DIFFCHECK_INFO(("Estimating normals with hybrid search radius = " + std::to_string(searchRadius.value()) + "and knn = " + std::to_string(knn.value())).c_str());
78+
}
79+
else
80+
{
81+
O3DPointCloud->EstimateNormals();
82+
DIFFCHECK_INFO("Default estimation of normals with knn = 30");
83+
}
84+
85+
this->Normals.clear();
86+
for (auto &normal : O3DPointCloud->normals_)
87+
this->Normals.push_back(normal);
88+
}
89+
5890
void DFPointCloud::VoxelDownsample(double voxelSize)
5991
{
6092
if (voxelSize <= 0)

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <optional>
34
#include <Eigen/Core>
45
#include <open3d/Open3D.h>
56

@@ -58,6 +59,18 @@ namespace diffCheck::geometry
5859
*/
5960
std::vector<Eigen::Vector3d> ComputeBoundingBox();
6061

62+
/**
63+
* @brief Estimate the normals of the point cloud by either knn or if the radius
64+
* is provided by hybrid search.
65+
*
66+
* <a href=https://www.open3d.org/html/cpp_api/classopen3d_1_1t_1_1geometry_1_1_point_cloud.html#a4937528c4b6194092631f002bccc44d0> Reference from Open3d</a>.
67+
* @param knn the number of nearest neighbors to consider (by default 30)
68+
* @param searchRadius the radius of the search, by default deactivated
69+
*/
70+
void EstimateNormals(
71+
std::optional<int> knn = 30,
72+
std::optional<double> searchRadius = std::nullopt);
73+
6174
public: ///< Downsamplers
6275
/**
6376
* @brief Downsample the point cloud with voxel grid

0 commit comments

Comments
 (0)