From 5e41ba48c41b1d1cd7c5204b82ccf153c50f1e5e Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 27 Jan 2026 09:59:14 +0100 Subject: [PATCH 1/7] WIP traversal --- tests/geometry/surfaces/CMakeLists.txt | 1 + .../testIntegralInvariantTraversal.cpp | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 tests/geometry/surfaces/testIntegralInvariantTraversal.cpp diff --git a/tests/geometry/surfaces/CMakeLists.txt b/tests/geometry/surfaces/CMakeLists.txt index 50d555053f..18c6d64027 100644 --- a/tests/geometry/surfaces/CMakeLists.txt +++ b/tests/geometry/surfaces/CMakeLists.txt @@ -40,6 +40,7 @@ endif() if ( DGTAL_WITH_POLYSCOPE_VIEWER ) set(POLYSCOPE_VIEWER_TESTS_SRC + testIntegralInvariantTraversal testLocalConvolutionNormalVectorEstimator testTensorVotingViewer) diff --git a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp new file mode 100644 index 0000000000..fa70feed78 --- /dev/null +++ b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp @@ -0,0 +1,116 @@ +/** + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **/ + +/** + * @file + * @ingroup Tests + * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr ) + * Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France + * + * @date 2020/03/14 + * + * Functions for testing class IntegralInvariantShortcuts. + * + * This file is part of the DGtal library. + */ + +/////////////////////////////////////////////////////////////////////////////// +#include +#include + +#include "DGtal/base/Common.h" +#include "ConfigTest.h" +#include "DGtalCatch.h" +#include "DGtal/helpers/StdDefs.h" +#include "DGtal/helpers/Shortcuts.h" +#include "DGtal/helpers/ShortcutsGeometry.h" +#include "DGtal/io/viewers/PolyscopeViewer.h" +#include "polyscope/curve_network.h" + +/////////////////////////////////////////////////////////////////////////////// +using namespace std; +using namespace DGtal; +typedef Shortcuts SH3; +typedef ShortcutsGeometry SHG3; + +/////////////////////////////////////////////////////////////////////////////// +// Functions for testing class IntegralInvariantShortcuts. +/////////////////////////////////////////////////////////////////////////////// + +int main() +{ + auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation(); + params( "polynomial", "goursat" )( "gridstep", 2. )( "surfaceTraversal", "BreadthFirst" ); + auto implicit_shape = SH3::makeImplicitShape3D ( params ); + auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params ); + auto binary_image = SH3::makeBinaryImage( digitized_shape, params ); + auto K = SH3::getKSpace( params ); + auto embedder = SH3::getSCellEmbedder(K); + + trace.info()<<"Binary image "<< *binary_image<< std::endl; + + auto surface = SH3::makeLightDigitalSurface( binary_image, K, params ); + auto surfels = SH3::getSurfelRange( surface, params ); + trace.info() << "Nb surfels= " << surfels.size() << std::endl; + + //Computing some differential quantities + params("r-radius", 3.0); + + trace.beginBlock("II SHG3 (BreadthFirst)"); + auto normals = SHG3::getIINormalVectors(binary_image,surfels,params); + trace.endBlock(); + + //Duplicating params and surfel range + auto paramsdepth= SH3::defaultParameters() | SHG3::defaultParameters(); + paramsdepth( "surfaceTraversal", "DepthFirst" )("r-radius",3.0); + auto surfelsdepth = SH3::getSurfelRange( surface, paramsdepth ); + + trace.beginBlock("II (DepthFirst)"); + auto normalsdepth = SHG3::getIINormalVectors(binary_image,surfelsdepth,paramsdepth); + trace.endBlock(); + + std::vector id(surfels.size()); + auto cpt=0; + for(auto &v: id) + v=cpt++; + + PolyscopeViewer viewer; + std::string objectName = "Surfels BF"; + viewer.draw(surfels, objectName); + viewer.addQuantity(objectName, "Normals (BF)", normals); + viewer.addQuantity(objectName, "Id (BF)", id); + + std::string objectName2 = "Surfels DF"; + viewer.draw(surfelsdepth, objectName2); + viewer.addQuantity(objectName2, "Normals (DF)", normalsdepth); + viewer.addQuantity(objectName2, "Id (BF)", id); + + //Nodes + std::vector bfnodes; + for(auto s: surfels) + bfnodes.push_back(embedder(s)); + std::vector dfnodes; + for(auto s: surfelsdepth) + dfnodes.push_back(embedder(s)); + + polyscope::registerCurveNetworkLine("BF", bfnodes)-> addNodeScalarQuantity("id", id); + polyscope::registerCurveNetworkLine("DF", dfnodes)-> addNodeScalarQuantity("id", id); + + + viewer.show(); +} + +/** @ingroup Tests **/ From ec242aba1f7f5b0d0f038ef9bb3786b202d84bbf Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 27 Jan 2026 10:25:53 +0100 Subject: [PATCH 2/7] Cleaning the code --- tests/geometry/surfaces/testIntegralInvariantTraversal.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp index fa70feed78..758d0ca0fc 100644 --- a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp +++ b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp @@ -53,7 +53,7 @@ typedef ShortcutsGeometry SHG3; int main() { auto params = SH3::defaultParameters() | SHG3::defaultParameters() | SHG3::parametersGeometryEstimation(); - params( "polynomial", "goursat" )( "gridstep", 2. )( "surfaceTraversal", "BreadthFirst" ); + params( "polynomial", "goursat" )( "gridstep", 1. )( "surfaceTraversal", "BreadthFirst" ); auto implicit_shape = SH3::makeImplicitShape3D ( params ); auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params ); auto binary_image = SH3::makeBinaryImage( digitized_shape, params ); @@ -109,7 +109,6 @@ int main() polyscope::registerCurveNetworkLine("BF", bfnodes)-> addNodeScalarQuantity("id", id); polyscope::registerCurveNetworkLine("DF", dfnodes)-> addNodeScalarQuantity("id", id); - viewer.show(); } From cc1a2ca7d62b6144a455da408a0b82e8a094e1ec Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 27 Jan 2026 15:25:00 +0100 Subject: [PATCH 3/7] Adding distance computation along the path --- .../testIntegralInvariantTraversal.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp index 758d0ca0fc..cf01451327 100644 --- a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp +++ b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp @@ -29,6 +29,7 @@ /////////////////////////////////////////////////////////////////////////////// #include +#include #include #include "DGtal/base/Common.h" @@ -106,9 +107,28 @@ int main() for(auto s: surfelsdepth) dfnodes.push_back(embedder(s)); - polyscope::registerCurveNetworkLine("BF", bfnodes)-> addNodeScalarQuantity("id", id); - polyscope::registerCurveNetworkLine("DF", dfnodes)-> addNodeScalarQuantity("id", id); + std::vector distbf, distdf; + for(auto i = 1 ; i < surfels.size(); ++i) + { + distbf.push_back( ( embedder(surfels[i]) - embedder(surfels[i-1])).norm()); + distdf.push_back( ( embedder(surfelsdepth[i]) - embedder(surfelsdepth[i-1])).norm()); + } + auto ps= polyscope::registerCurveNetworkLine("BF", bfnodes); + ps->addNodeScalarQuantity("id", id); + ps->addEdgeScalarQuantity("dist", distbf); + auto ps2=polyscope::registerCurveNetworkLine("DF", dfnodes); + ps2->addNodeScalarQuantity("id", id); + ps2->addEdgeScalarQuantity("dist", distdf); + + trace.info()<<"Counting the number of consecutive pairs with distance <= 1.0"<< std::endl; + trace.info()<<"BF strategy = "<< std::count_if(distbf.begin(), distbf.end(), [](double a){ return a-0.000001 <= 1.0;})<< std::endl; + trace.info()<<"DF strategy = "<< std::count_if(distdf.begin(), distdf.end(), [](double a){ return a-0.000001 <= 1.0;})<< std::endl; + + trace.info()<<"Counting the number of consecutive pairs with distance <= \sqrt{2}/2"<< std::endl; + trace.info()<<"BF strategy = "<< std::count_if(distbf.begin(), distbf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; + trace.info()<<"DF strategy = "<< std::count_if(distdf.begin(), distdf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; + viewer.show(); } From 933998a4980fb4d179505435ccae2a1b187f57e7 Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Wed, 28 Jan 2026 15:01:54 +0100 Subject: [PATCH 4/7] updating .gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a6cac7f56c..86a5a62b2d 100755 --- a/.gitignore +++ b/.gitignore @@ -49,4 +49,5 @@ b2/ examples/samples/bunny-512.vol src/DGtal/dec/doc/images/poly/paf.png src/cppclean.log -.vscode/ \ No newline at end of file +.vscode/ +.cache/ \ No newline at end of file From d5e1396ea89a1fc31e07539029d496f4b77e819e Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Sat, 31 Jan 2026 14:09:53 +0100 Subject: [PATCH 5/7] Adding pre-commit hook --- .pre-commit-config.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..fd16ba2dc3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,10 @@ +# See https://pre-commit.com for more information +# See https://pre-commit.com/hooks.html for more hooks +repos: +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v3.2.0 + hooks: + - id: trailing-whitespace + - id: end-of-file-fixer + - id: check-yaml + - id: check-added-large-files From d05d46efb1142f047b2e5ee47966dd2bfc4b4316 Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 3 Feb 2026 17:20:28 +0100 Subject: [PATCH 6/7] edits --- .../testIntegralInvariantTraversal.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp index cf01451327..1e43238e22 100644 --- a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp +++ b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp @@ -60,7 +60,7 @@ int main() auto binary_image = SH3::makeBinaryImage( digitized_shape, params ); auto K = SH3::getKSpace( params ); auto embedder = SH3::getSCellEmbedder(K); - + trace.info()<<"Binary image "<< *binary_image<< std::endl; auto surface = SH3::makeLightDigitalSurface( binary_image, K, params ); @@ -69,25 +69,25 @@ int main() //Computing some differential quantities params("r-radius", 3.0); - + trace.beginBlock("II SHG3 (BreadthFirst)"); auto normals = SHG3::getIINormalVectors(binary_image,surfels,params); trace.endBlock(); - + //Duplicating params and surfel range auto paramsdepth= SH3::defaultParameters() | SHG3::defaultParameters(); paramsdepth( "surfaceTraversal", "DepthFirst" )("r-radius",3.0); auto surfelsdepth = SH3::getSurfelRange( surface, paramsdepth ); - + trace.beginBlock("II (DepthFirst)"); auto normalsdepth = SHG3::getIINormalVectors(binary_image,surfelsdepth,paramsdepth); trace.endBlock(); - + std::vector id(surfels.size()); auto cpt=0; for(auto &v: id) v=cpt++; - + PolyscopeViewer viewer; std::string objectName = "Surfels BF"; viewer.draw(surfels, objectName); @@ -106,26 +106,26 @@ int main() std::vector dfnodes; for(auto s: surfelsdepth) dfnodes.push_back(embedder(s)); - + std::vector distbf, distdf; for(auto i = 1 ; i < surfels.size(); ++i) { distbf.push_back( ( embedder(surfels[i]) - embedder(surfels[i-1])).norm()); distdf.push_back( ( embedder(surfelsdepth[i]) - embedder(surfelsdepth[i-1])).norm()); } - + auto ps= polyscope::registerCurveNetworkLine("BF", bfnodes); ps->addNodeScalarQuantity("id", id); ps->addEdgeScalarQuantity("dist", distbf); auto ps2=polyscope::registerCurveNetworkLine("DF", dfnodes); ps2->addNodeScalarQuantity("id", id); ps2->addEdgeScalarQuantity("dist", distdf); - + trace.info()<<"Counting the number of consecutive pairs with distance <= 1.0"<< std::endl; trace.info()<<"BF strategy = "<< std::count_if(distbf.begin(), distbf.end(), [](double a){ return a-0.000001 <= 1.0;})<< std::endl; trace.info()<<"DF strategy = "<< std::count_if(distdf.begin(), distdf.end(), [](double a){ return a-0.000001 <= 1.0;})<< std::endl; - trace.info()<<"Counting the number of consecutive pairs with distance <= \sqrt{2}/2"<< std::endl; + trace.info()<<"Counting the number of consecutive pairs with distance <= sqrt{2}/2"<< std::endl; trace.info()<<"BF strategy = "<< std::count_if(distbf.begin(), distbf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; trace.info()<<"DF strategy = "<< std::count_if(distdf.begin(), distdf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; From 7428f21d8a862e85fd7660befe3428a764823d8f Mon Sep 17 00:00:00 2001 From: David Coeurjolly Date: Tue, 17 Feb 2026 12:42:10 +0100 Subject: [PATCH 7/7] WIP --- tests/geometry/surfaces/testIntegralInvariantTraversal.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp index 1e43238e22..67a6979eb5 100644 --- a/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp +++ b/tests/geometry/surfaces/testIntegralInvariantTraversal.cpp @@ -129,6 +129,7 @@ int main() trace.info()<<"BF strategy = "<< std::count_if(distbf.begin(), distbf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; trace.info()<<"DF strategy = "<< std::count_if(distdf.begin(), distdf.end(), [](double a){ return a-0.000001 <= sqrt(2.0)/2.0;})<< std::endl; + viewer.show(); }