Skip to content

Commit 6744eed

Browse files
ADD SOR method to DFPointCloud objects (#99)
* UPDATE: add SOR method to DFPointCloud objects * ADD: test for SOR of DFPointCloud objects * ADD: python test for SOR method of DFPointCloud objects * ADD: component for statistical outlier removal method * FIX: small changes + docuemtnation --------- Co-authored-by: Andrea Settimi <andreasettimi39@gmail.com>
1 parent 58e3f68 commit 6744eed

File tree

13 files changed

+161
-2
lines changed

13 files changed

+161
-2
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. image:: ../src/gh/components/DF_remove_statistical_outliers/icon.png
2+
:align: left
3+
:width: 40px
4+
5+
``DFRemoveStatisticalOutliers`` component
6+
===========================
7+
8+
.. ghcomponent_to_rst:: ../src/gh/components/DF_remove_statistical_outliers

doc/gh_components.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ DF has a Grasshopper_ plugin with a set of components that allows the user to in
7878

7979
* - .. image:: ../src/gh/components/DF_brep_to_cloud/icon.png
8080
- `gh_DFBrepToCloud <gh_DFBrepToCloud.html>`_
81-
-
82-
-
81+
- .. image:: ../src/gh/components/DF_remove_statistical_outliers/icon.png
82+
- `gh_DFRemoveStatisticalOutliers <gh_DFRemoveStatisticalOutliers.html>`_
8383

8484

8585

src/diffCheck/IOManager.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,11 @@ namespace diffCheck::io
5252
std::filesystem::path pathCloud = pathTestData / "roof_quarter.ply";
5353
return pathCloud.string();
5454
}
55+
56+
std::string GetPlanePCWithOneOutliers()
57+
{
58+
std::filesystem::path pathTestData = GetTestDataDir();
59+
std::filesystem::path pathCloud = pathTestData / "test_pc_for_SOR_101pts_with_1_outlier.ply";
60+
return pathCloud.string();
61+
}
5562
} // namespace diffCheck::io

src/diffCheck/IOManager.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,6 @@ namespace diffCheck::io
3333
std::string GetTestDataDir();
3434
/// @brief Get the path to the roof quarter ply test file
3535
std::string GetRoofQuarterPlyPath();
36+
/// @brief Get the path to the plane point cloud with one outlier
37+
std::string GetPlanePCWithOneOutliers();
3638
} // namespace diffCheck::io

src/diffCheck/geometry/DFPointCloud.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,22 @@ namespace diffCheck::geometry
200200
this->ApplyColor(color);
201201
}
202202

203+
void DFPointCloud::RemoveStatisticalOutliers(int nbNeighbors, double stdRatio)
204+
{
205+
std::shared_ptr<open3d::geometry::PointCloud> O3DPointCloud = this->Cvt2O3DPointCloud();
206+
std::tuple<std::shared_ptr<open3d::geometry::PointCloud>, std::vector<size_t>> returnedTuple = O3DPointCloud->RemoveStatisticalOutliers(nbNeighbors, stdRatio);
207+
std::shared_ptr<open3d::geometry::PointCloud> O3DPointCloudWithoutOutliers = std::get<0>(returnedTuple);
208+
this->Points.clear();
209+
for (auto &point : O3DPointCloudWithoutOutliers->points_)
210+
this->Points.push_back(point);
211+
this->Colors.clear();
212+
for (auto &color : O3DPointCloudWithoutOutliers->colors_)
213+
this->Colors.push_back(color);
214+
this->Normals.clear();
215+
for (auto &normal : O3DPointCloudWithoutOutliers->normals_)
216+
this->Normals.push_back(normal);
217+
}
218+
203219
void DFPointCloud::UniformDownsample(int everyKPoints)
204220
{
205221
auto O3DPointCloud = this->Cvt2O3DPointCloud();

src/diffCheck/geometry/DFPointCloud.hh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ namespace diffCheck::geometry
7979
void ApplyColor(const Eigen::Vector3d &color);
8080
void ApplyColor(int r, int g, int b);
8181

82+
/**
83+
* @brief Remove the statistical outilers from the point cloud
84+
*
85+
* @param nbNeighbors the number of neighbors to consider
86+
* @param stdRatio the standard deviation ratio
87+
*
88+
* @see https://www.open3d.org/docs/latest/cpp_api/classopen3d_1_1geometry_1_1_point_cloud.html#a9c34dee60f36ec36a7de4ae2d55623cd
89+
*/
90+
void RemoveStatisticalOutliers(int nbNeighbors, double stdRatio);
91+
8292
public: ///< Downsamplers
8393
/**
8494
* @brief Downsample the point cloud with voxel grid

src/diffCheckBindings.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ PYBIND11_MODULE(diffcheck_bindings, m) {
5252
.def("apply_color", (void (diffCheck::geometry::DFPointCloud::*)(int, int, int)) &diffCheck::geometry::DFPointCloud::ApplyColor,
5353
py::arg("r"), py::arg("g"), py::arg("b"))
5454

55+
.def("remove_statistical_outliers", &diffCheck::geometry::DFPointCloud::RemoveStatisticalOutliers,
56+
py::arg("nb_neighbors"), py::arg("std_ratio"))
57+
5558
.def("load_from_PLY", &diffCheck::geometry::DFPointCloud::LoadFromPLY)
5659
.def("add_points", &diffCheck::geometry::DFPointCloud::AddPoints)
5760

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#! python3
2+
3+
import Rhino
4+
from ghpythonlib.componentbase import executingcomponent as component
5+
6+
import diffCheck.df_cvt_bindings as cvt
7+
8+
class DFRemoveStatisticalOutliers(component):
9+
def RunScript(self, i_cloud: Rhino.Geometry.PointCloud, i_knn : int, i_ratio : float):
10+
if i_cloud is None or i_ratio is None or i_knn is None:
11+
return None
12+
13+
df_cloud = cvt.cvt_rhcloud_2_dfcloud(i_cloud)
14+
df_cloud.remove_statistical_outliers(nb_neighbors=i_knn, std_ratio=i_ratio)
15+
o_cloud = cvt.cvt_dfcloud_2_rhcloud(df_cloud)
16+
17+
return o_cloud
9.46 KB
Loading
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"name": "DFRemoveStatisticalOutliers",
3+
"nickname": "DFRemoveStatisticalOutliers",
4+
"category": "diffCheck",
5+
"subcategory": "Cloud",
6+
"description": "Remove statistical outliers from a point cloud.",
7+
"exposure": 4,
8+
"instanceGuid": "9fd3273c-c06e-4f9d-83bf-c58178cb3da7",
9+
"ghpython": {
10+
"hideOutput": true,
11+
"hideInput": true,
12+
"isAdvancedMode": true,
13+
"marshalOutGuids": true,
14+
"iconDisplay": 2,
15+
"inputParameters": [
16+
{
17+
"name": "i_cloud",
18+
"nickname": "i_cloud",
19+
"description": "The cloud from which statistical outliers should be removed.",
20+
"optional": false,
21+
"allowTreeAccess": true,
22+
"showTypeHints": true,
23+
"scriptParamAccess": "item",
24+
"wireDisplay": "default",
25+
"sourceCount": 0,
26+
"typeHintID": "pointcloud"
27+
},
28+
{
29+
"name": "i_knn",
30+
"nickname": "i_knn",
31+
"description": "The number of neighbors to consider when detecting statistical outliers.",
32+
"optional": false,
33+
"allowTreeAccess": true,
34+
"showTypeHints": true,
35+
"scriptParamAccess": "item",
36+
"wireDisplay": "default",
37+
"sourceCount": 0,
38+
"typeHintID": "int"
39+
},
40+
{
41+
"name": "i_ratio",
42+
"nickname": "i_ratio",
43+
"description": "The standard deviation threshold for the detection of statistical outliers.",
44+
"optional": false,
45+
"allowTreeAccess": true,
46+
"showTypeHints": true,
47+
"scriptParamAccess": "item",
48+
"wireDisplay": "default",
49+
"sourceCount": 0,
50+
"typeHintID": "float"
51+
}
52+
],
53+
"outputParameters": [
54+
{
55+
"name": "o_cloud",
56+
"nickname": "o_cloud",
57+
"description": "The new cloud with outliers removed.",
58+
"optional": false,
59+
"sourceCount": 0,
60+
"graft": false
61+
}
62+
]
63+
}
64+
}

0 commit comments

Comments
 (0)