Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend segmentation components #23

Merged
merged 58 commits into from
Jul 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
ac0211d
WIP-ADD DFSegmentation.cc and hh
DamienGilliard May 29, 2024
ff4a3a4
FIX: target include directories for boost
DamienGilliard Jun 11, 2024
a1ce0f3
ADD: cilantro submodule
DamienGilliard Jun 11, 2024
b75aa99
WIP-ADD: GetCenterPoint() to point cloud objects
DamienGilliard Jun 12, 2024
5ae1b17
WIP-ADD: SegmentationPointCloud static method using cilantro
DamienGilliard Jun 12, 2024
c021636
WIP-FIX: numpy array for colors in rh to df point cloud conversion
DamienGilliard Jun 12, 2024
b1a74b7
WIP-ADD: scan_segmentation component
DamienGilliard Jun 12, 2024
6da8b98
WIP: extent bindings for segmentation and GetCenterPoint method
DamienGilliard Jun 12, 2024
a1e36fa
WIP-FIX: OG cilantro submodule deleted
DamienGilliard Jun 22, 2024
279a437
WIP-FIX: added diffCheck fork of cilantro as submodule
DamienGilliard Jun 22, 2024
651eea6
FIX: update CMakeLists.txt for new submodule
DamienGilliard Jun 23, 2024
0804de2
FIX: submodule with https link instead of ssh
DamienGilliard Jun 23, 2024
970e13d
FIX: update the submodule for config.hpp fix
DamienGilliard Jun 23, 2024
0f3009d
CAP: segmentation function well implemented and documented
DamienGilliard Jun 23, 2024
1861891
CAP-fix:typo in segmentation parameter order
DamienGilliard Jun 23, 2024
b6427b8
FIX: update component code in code.py
DamienGilliard Jun 23, 2024
6c95c01
FIX: parameters passed to segmentation function in code.py
DamienGilliard Jun 23, 2024
1902f16
FIX: code.py
DamienGilliard Jun 23, 2024
47448fa
FIX: mismatch in parameters for plugin code + conversion DFPointCloud…
DamienGilliard Jun 23, 2024
d1de3e8
FIX: naming of the cilantro wrap function changed to SmoothSegmentation
DamienGilliard Jun 24, 2024
f6fd4e9
WIP-ADD: AssociateSegments function created
DamienGilliard Jun 24, 2024
1adc9de
FIX: renaming of cilantro segmentation wrap following review
DamienGilliard Jun 24, 2024
e320d64
Merge branch 'semantic_segmentation' of github.com:diffCheckOrg/diffC…
DamienGilliard Jun 24, 2024
8bff20f
WIP: creation of the aggregatino function that associates point cloud…
DamienGilliard Jun 25, 2024
58daa2a
FIX-MERGE: bringing the assembly/beam structure to the segmentation m…
9and3 Jun 29, 2024
e0b531d
ADD: small cmake utilitiy for dev convinience
9and3 Jun 29, 2024
3940e23
ADD: normal estimation to dfcloud
9and3 Jun 29, 2024
acc643c
TEMP: working on colored cluster + visualizer
9and3 Jun 29, 2024
08b09db
WIP: adding coloring for cloud and clustering
9and3 Jun 30, 2024
3eb0fc5
CAP: refactored backend for segmeentations and normal estimations
9and3 Jun 30, 2024
c9277c7
WIP: segmentation now using triangle faces + small fixes
DamienGilliard Jun 30, 2024
2010cb0
ADD: egg link to gitignore
9and3 Jun 30, 2024
73888c9
ADD-MILESTONE: wraps for normal estimation + segmentation
9and3 Jun 30, 2024
af0c8b8
commit before rebase
DamienGilliard Jul 1, 2024
b24e67f
WIP: commit before pull
DamienGilliard Jul 1, 2024
50cdc17
WIP: rebased onto 'segmentation' branch
DamienGilliard Jul 1, 2024
2503cfb
Merge branch 'semantic_segmentation' of github.com:diffCheckOrg/diffC…
DamienGilliard Jul 1, 2024
c8e9ad5
CAP: AssociateClusters function implemented in the back-end
DamienGilliard Jul 2, 2024
032f428
UPDATE: CleanUnassociatedClusters method added, and PR remarks included
DamienGilliard Jul 6, 2024
b688ec9
UPDATE-WIP: add IsPointOnFace function, and angle threshold parameter…
DamienGilliard Jul 10, 2024
111c484
UPDATE: adding some preventive checks to the methods in DFSegmentation
DamienGilliard Jul 10, 2024
38c12c5
CAP: Association functions implemented, defensive checks added, and g…
DamienGilliard Jul 10, 2024
060464a
Merge pull request #33 from diffCheckOrg/semantic_segmentation
9and3 Jul 11, 2024
701f47d
FIX: correcting names in bindings + values default
9and3 Jul 11, 2024
d2905ff
mERGE-FIX: Merge branch 'test_suite' into segmentation for fixing cma…
9and3 Jul 11, 2024
94bdf5a
FIX: frix from main for colors convertion
9and3 Jul 11, 2024
304d2ba
WIP: working on example
9and3 Jul 13, 2024
6701304
Merge branch 'main' into segmentation
9and3 Jul 13, 2024
b7cd47d
FIX: DFFace to mesh method added
9and3 Jul 14, 2024
1dba340
WIP: working on wrap cad segmentator integration
9and3 Jul 14, 2024
673b159
FIX-TYPO
9and3 Jul 14, 2024
6c3dda2
ADD: temp icon
9and3 Jul 14, 2024
2385589
ADD: metadata for cad segmentator added
9and3 Jul 15, 2024
a22ecf4
UPDATE: association criterion now with projection, and no unwanted de…
DamienGilliard Jul 16, 2024
e8f7f0c
UPDATE: new meshing parameters for brepface to mesh conversion
DamienGilliard Jul 16, 2024
8cca66a
UPDATE-FIX: segmentation methods more robust, and IsPointOnFace metho…
DamienGilliard Jul 18, 2024
e3d2f97
FIX: removed commented-out IsPointOnFace method in DFSegmentation cla…
DamienGilliard Jul 18, 2024
0805cb4
UPDATE: CAD_segmentator code.py updated following changes to c++ side
DamienGilliard Jul 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/

# egg-info
*.egg-info/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
[submodule "deps/pybind11"]
path = deps/pybind11
url = https://github.com/pybind/pybind11.git
[submodule "deps/submodule-cilantro"]
path = deps/submodule-cilantro
url = https://github.com/diffCheckOrg/submodule-cilantro.git
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
"cwctype": "cpp",
"memory_resource": "cpp",
"scoped_allocator": "cpp",
"strstream": "cpp"
"strstream": "cpp",
"core": "cpp"
}
}
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,15 @@ endif()

# Boost (header only) -----------------------------------------------------
download_submodule_project(boost)
target_link_directories(${SHARED_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/boost/win/1_89/include/boost-1_85)
target_include_directories(${SHARED_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/boost/win/1_89/include/boost-1_85)

# CGAL (header-only) ------------------------------------------------------
target_include_directories(${SHARED_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/cgal/include)

# Cilantro (header-only) --------------------------------------------------
download_submodule_project(cilantro)
target_include_directories(${SHARED_LIB_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/deps/submodule-cilantro/include)

# loguru (header-only) ----------------------------------------------------
download_submodule_project(loguru)
add_subdirectory(deps/loguru)
Expand Down
41 changes: 41 additions & 0 deletions ScreenCamera_2024-06-30-00-00-53.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"class_name" : "PinholeCameraParameters",
"extrinsic" :
[
0.78518600604290978,
-0.4688467948733368,
0.4045560762754441,
0.0,
-0.61432912235314374,
-0.67201447960085037,
0.41351695084435719,
0.0,
0.077991444038432445,
-0.57321830234544802,
-0.81568260525341763,
0.0,
1416.8243739322577,
908.62300697364822,
1063.1264987715035,
1.0
],
"intrinsic" :
{
"height" : 800,
"intrinsic_matrix" :
[
692.82032302755101,
0.0,
0.0,
0.0,
692.82032302755101,
0.0,
499.5,
399.5,
1.0
],
"width" : 1000
},
"version_major" : 1,
"version_minor" : 0
}
41 changes: 41 additions & 0 deletions ScreenCamera_2024-06-30-11-58-46.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"class_name" : "PinholeCameraParameters",
"extrinsic" :
[
0.76239913059926834,
-0.422274821893041,
0.49033818988192268,
0.0,
-0.54132130094127906,
-0.00099240450767756894,
0.8408152378974435,
0.0,
-0.35456849099817256,
-0.90646731321570218,
-0.22934296427574399,
0.0,
1550.6223360557265,
197.24908733414611,
336.92784140962624,
1.0
],
"intrinsic" :
{
"height" : 800,
"intrinsic_matrix" :
[
692.82032302755101,
0.0,
0.0,
0.0,
692.82032302755101,
0.0,
499.5,
399.5,
1.0
],
"width" : 1000
},
"version_major" : 1,
"version_minor" : 0
}
Binary file added ScreenCapture_2024-06-30-00-00-53.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScreenCapture_2024-06-30-11-58-46.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes
Binary file added assets/icon_pool/normal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon_pool/normal_cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon_pool/normal_cloud.xcf
Binary file not shown.
Binary file added assets/icon_pool/normal_segment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon_pool/normal_segmenter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon_pool/normal_segmenter.xcf
Binary file not shown.
Binary file added assets/icon_pool/scan_segmentation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cmake/build_run.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.\cmake\build.bat ; if ($?) { .\build\bin\Release\diffCheckApp.exe }
2 changes: 1 addition & 1 deletion deps/eigen
Submodule eigen updated from 02bcf9 to d791d4
2 changes: 1 addition & 1 deletion deps/pybind11
Submodule pybind11 updated 102 files
1 change: 1 addition & 0 deletions deps/submodule-cilantro
Submodule submodule-cilantro added at 4c9fa6
3 changes: 3 additions & 0 deletions src/diffCheck.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <open3d/Open3D.h>
#include <loguru.hpp>

#include <cilantro/cilantro.hpp>

// diffCheck includes
#include "diffCheck/log.hh"
const diffCheck::Log LOG = diffCheck::Log();
Expand All @@ -14,3 +16,4 @@ const diffCheck::Log LOG = diffCheck::Log();
#include "diffCheck/transformation/DFTransformation.hh"
#include "diffCheck/registrations/DFGlobalRegistrations.hh"
#include "diffCheck/registrations/DFRefinedRegistration.hh"
#include "diffCheck/segmentation/DFSegmentation.hh"
56 changes: 56 additions & 0 deletions src/diffCheck/geometry/DFMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,62 @@ namespace diffCheck::geometry
return bboxPts;
}

Eigen::Vector3d DFMesh::GetFirstNormal()
{
if (this->NormalsFace.size() == 0)
{
std::shared_ptr<open3d::geometry::TriangleMesh> O3DTriangleMesh = this->Cvt2O3DTriangleMesh();
O3DTriangleMesh->ComputeTriangleNormals();
this->NormalsFace.resize(O3DTriangleMesh->triangle_normals_.size());
for (size_t i = 0; i < O3DTriangleMesh->triangle_normals_.size(); i++)
{
this->NormalsFace[i] = O3DTriangleMesh->triangle_normals_[i];
}

}
return this->NormalsFace[0];
}

bool DFMesh::IsPointOnFace(Eigen::Vector3d point, double associationThreshold)
{
/*
To check if the point is in the face, we take into account all the triangles forming the face.
We calculate the area of each triangle, then check if the sum of the areas of the tree triangles
formed by two of the points of the referencr triangle and our point is equal to the reference triangle area
(within a user-defined margin). If it is the case, the triangle is in the face.
*/
std::vector<Eigen::Vector3i> faceTriangles = this->Faces;
for (Eigen::Vector3i triangle : faceTriangles)
{
Eigen::Vector3d v0 = this->Vertices[triangle[0]];
Eigen::Vector3d v1 = this->Vertices[triangle[1]];
Eigen::Vector3d v2 = this->Vertices[triangle[2]];
Eigen::Vector3d n = (v1 - v0).cross(v2 - v0);
double normOfNormal = n.norm();
n.normalize();

Eigen::Vector3d projectedPoint = point - n * (n.dot(point - v0)) ;

double referenceTriangleArea = normOfNormal*0.5;
Eigen::Vector3d n1 = (v1 - v0).cross(projectedPoint - v0);
double area1 = n1.norm()*0.5;
Eigen::Vector3d n2 = (v2 - v1).cross(projectedPoint - v1);
double area2 = n2.norm()*0.5;
Eigen::Vector3d n3 = (v0 - v2).cross(projectedPoint - v2);
double area3 = n3.norm()*0.5;
double res = (area1 + area2 + area3 - referenceTriangleArea) / referenceTriangleArea;

// arbitrary value to avoid false positives (points that, when projected on the triangle, are in it, but that are actually located too far from the mesh to actually belong to it)
double maxProjectionDistance = std::min({(v1 - v0).norm(), (v2 - v1).norm(), (v0 - v2).norm()});

if (std::abs(res) < associationThreshold && (projectedPoint - point).norm() < maxProjectionDistance)
{
return true;
}
}
return false;
}
Comment on lines +98 to +136
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@9and3 It's there !


void DFMesh::LoadFromPLY(const std::string &path)
{
std::shared_ptr<diffCheck::geometry::DFMesh> tempMesh_ptr = diffCheck::io::ReadPLYMeshFromFile(path);
Expand Down
15 changes: 15 additions & 0 deletions src/diffCheck/geometry/DFMesh.hh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe here we could add the function to test if a point is on a mesh face @DamienGilliard ?

Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ namespace diffCheck::geometry
*/
std::vector<Eigen::Vector3d> GetTightBoundingBox();

/**
* @brief Get the first normal of the mesh. Meant for planar meshes
*
* @return Eigen::Vector3d the normal
*/
Eigen::Vector3d GetFirstNormal();

/**
* @brief Check if a point is on a face of the mesh
*
* @param point the point to check
* @param associationThreshold the threshold to consider the point associable to the mesh. It is the ratio between the surface of the closest mesh triangle of the mesh face, and the sum of the areas of the three triangles described by the point projected on the mesh face and two of the mesh triangle vertices. The lower the number, the more strict the association will be and some poinnts on the mesh face might be wrongfully excluded. In theory, in a perfect case, a value of 0 could be used, but in practice, values of 0.05-0.2 are more realistic, depending on the application.
*/
bool IsPointOnFace(Eigen::Vector3d point, double associationThreshold = 0.1);

public: ///< I/O loader
/**
* @brief Read a mesh from a file
Expand Down
Loading
Loading