From 2a65c0607e8193f94d879f6cc89b392b89b610fa Mon Sep 17 00:00:00 2001 From: Jacques-Olivier Lachaud Date: Mon, 4 Nov 2019 21:52:45 +0100 Subject: [PATCH 1/5] Fix conflict with module AT name --- src/DGtal/dec/doc/moduleAT.dox | 2 +- src/DGtal/dec/doc/packageDEC.dox | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DGtal/dec/doc/moduleAT.dox b/src/DGtal/dec/doc/moduleAT.dox index 0f97dd421a..f3649b6ab4 100644 --- a/src/DGtal/dec/doc/moduleAT.dox +++ b/src/DGtal/dec/doc/moduleAT.dox @@ -12,7 +12,7 @@ namespace DGtal { /*! -@page moduleAT Piecewise-smooth approximation using a discrete calculus model of Ambrosio-Tortorelli functional +@page moduleGenericAT Piecewise-smooth approximation using a discrete calculus model of Ambrosio-Tortorelli functional @writers Jacques-Olivier Lachaud, Marion Foare, David Coeurjolly, Pierre Gueth diff --git a/src/DGtal/dec/doc/packageDEC.dox b/src/DGtal/dec/doc/packageDEC.dox index 8b2e69ccae..db46bc1764 100644 --- a/src/DGtal/dec/doc/packageDEC.dox +++ b/src/DGtal/dec/doc/packageDEC.dox @@ -56,7 +56,7 @@ Basic operators, such as Hodge duality operator or exterior derivative, can be c - \ref moduleDECHelmoltz (Pierre Gueth) - \ref moduleDECPropagation (Pierre Gueth) - \ref moduleHeatLaplaceOperator (Thomas Caissard) -- \ref moduleAT (Jacques-Olivier Lachaud, Marion Foare, David Coeurjolly, Pierre Gueth) +- \ref moduleGenericAT (Jacques-Olivier Lachaud, Marion Foare, David Coeurjolly, Pierre Gueth) @b Package @b Concepts @b Overview - \ref packageDECConcepts From 073326d22e74f70ce32b476e55b83308a1ab67f8 Mon Sep 17 00:00:00 2001 From: Jacques-Olivier Lachaud Date: Mon, 4 Nov 2019 22:32:09 +0100 Subject: [PATCH 2/5] Add missing file --- examples/dec/CMakeLists.txt | 3 +- examples/dec/exampleSurfaceATNormals.cpp | 143 +++++++++++++++++++++++ 2 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 examples/dec/exampleSurfaceATNormals.cpp diff --git a/examples/dec/CMakeLists.txt b/examples/dec/CMakeLists.txt index ed9490f3ac..f8f1a29430 100644 --- a/examples/dec/CMakeLists.txt +++ b/examples/dec/CMakeLists.txt @@ -18,10 +18,11 @@ endif(WITH_CAIRO AND WITH_EIGEN AND WITH_QGLVIEWER) if (WITH_EIGEN) set(DGTAL_EXAMPLES_SRC2_DEC examplePropagation + exampleSurfaceATNormals ) foreach(FILE ${DGTAL_EXAMPLES_SRC2_DEC}) add_executable(${FILE} ${FILE}) target_link_libraries (${FILE} DGtal ${DGtalLibDependencies}) endforeach(FILE) -endif() \ No newline at end of file +endif() diff --git a/examples/dec/exampleSurfaceATNormals.cpp b/examples/dec/exampleSurfaceATNormals.cpp new file mode 100644 index 0000000000..a4e9309626 --- /dev/null +++ b/examples/dec/exampleSurfaceATNormals.cpp @@ -0,0 +1,143 @@ +/** + * 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 surface-AT-normals + * @ingroup Examples + * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr ) + * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France + * + * @date 2019/06/09 + * + * An example file named surface-AT-normals. + * + * This file is part of the DGtal library. + */ + +///////////////////////////////////////////////////////////////////// +//! [AT-surface-includes] +#include +#include "ConfigExamples.h" +#include "DGtal/base/Common.h" +#include "DGtal/helpers/StdDefs.h" +#include "DGtal/helpers/Shortcuts.h" +#include "DGtal/helpers/ShortcutsGeometry.h" +#include "DGtal/dec/ATSolver2D.h" +#include "DGtal/dec/DiscreteExteriorCalculusFactory.h" +//! [AT-surface-includes] +/////////////////////////////////////////////////////////////////////////////// + +using namespace std; +using namespace DGtal; + +/////////////////////////////////////////////////////////////////////////////// + +int main( int argc, char** argv ) +{ + typedef Z3i::KSpace KSpace; + typedef Shortcuts< KSpace > SH3; + typedef ShortcutsGeometry< KSpace > SHG3; + typedef SH3::Surfel Surfel; + typedef SH3::Cell Cell; + typedef SHG3::RealVector RealVector; + + const double alpha_at = 0.1; + const double lambda_at = 0.025; + const double e1 = 2.0; + const double e2 = 0.25; + const double er = 2.0; + + const string volfile = argc > 1 ? argv[ 1 ] : examplesPath + "samples/Al.100.vol"; + const double threshold = argc > 2 ? atof( argv[ 2 ] ) : 0.5; + auto params = SH3::defaultParameters() | SHG3::defaultParameters(); + params( "colormap", "Tics" ); + trace.beginBlock ( "Load vol file -> build digital surface -> estimate II normals." ); + //! [AT-surface-init] + auto bimage = SH3::makeBinaryImage( volfile, params ); + auto K = SH3::getKSpace( bimage, params ); + auto surface = SH3::makeDigitalSurface( bimage, K, params ); + auto surfels = SH3::getSurfelRange( surface, params ); + auto linels = SH3::getCellRange( surface, 1 ); + auto ii_normals= SHG3::getIINormalVectors( bimage, surfels, params ); + auto uembedder = SH3::getCellEmbedder( K ); + auto embedder = SH3::getSCellEmbedder( K ); + //! [AT-surface-init] + trace.endBlock(); + + trace.beginBlock ( "Creating AT solver for digital surface" ); + //! [AT-surface-calculus] + typedef DiscreteExteriorCalculusFactory CalculusFactory; + const auto calculus = CalculusFactory::createFromNSCells<2>( surfels.begin(), surfels.end() ); + //! [AT-surface-calculus] + //! [AT-surface-solve] + ATSolver2D< KSpace > at_solver(calculus, 1); + at_solver.initInputVectorFieldU2( ii_normals, surfels.cbegin(), surfels.cend() ); + at_solver.setUp( alpha_at, lambda_at ); + at_solver.solveGammaConvergence( e1, e2, er ); + //! [AT-surface-solve] + trace.endBlock(); + + trace.beginBlock ( "Save AT normals as OBJ file" ); + //! [AT-surface-getU2] + auto at_normals = ii_normals; + at_solver.getOutputVectorFieldU2( at_normals, surfels.cbegin(), surfels.cend() ); + //! [AT-surface-getU2] + SH3::RealPoints positions( surfels.size() ); + std::transform( surfels.cbegin(), surfels.cend(), positions.begin(), + [&] (const SH3::SCell& c) { return embedder( c ); } ); + SH3::Colors colors( surfels.size() ); + for ( size_t i = 0; i < surfels.size(); i++ ) + colors[ i ] = SH3::Color( (unsigned char) 255.0*fabs( at_normals[ i ][ 0 ] ), + (unsigned char) 255.0*fabs( at_normals[ i ][ 1 ] ), + (unsigned char) 255.0*fabs( at_normals[ i ][ 2 ] ) ); + std::transform( surfels.cbegin(), surfels.cend(), positions.begin(), + [&] (const SH3::SCell& c) { return embedder( c ); } ); + + bool ok1 = SH3::saveOBJ( surface, at_normals, SH3::Colors(), + "output-surface.obj" ); + bool ok2 = SH3::saveOBJ( surface, at_normals, colors, + "output-surface-at-normals.obj" ); + bool ok3 = SH3::saveVectorFieldOBJ( positions, at_normals, 0.05, SH3::Colors(), + "output-vf-at-normals.obj", + SH3::Color( 0, 0, 0 ), SH3::Color::Red ); + //! [AT-surface-getV0] + SH3::Scalars features( linels.size() ); + at_solver.getOutputScalarFieldV0( features, linels.cbegin(), linels.cend(), + at_solver.Maximum ); + //! [AT-surface-getV0] + SH3::RealPoints f0; + SH3::RealVectors f1; + for ( size_t i = 0; i < linels.size(); i++ ) + { + if ( features[ i ] < threshold ) + { + const Cell linel = linels[ i ]; + const Dimension d = * K.uDirs( linel ); + const Cell p0 = K.uIncident( linel, d, false ); + const Cell p1 = K.uIncident( linel, d, true ); + f0.push_back( uembedder( p0 ) ); + f1.push_back( uembedder( p1 ) - uembedder( p0 ) ); + } + } + bool ok4 = SH3::saveVectorFieldOBJ( f0, f1, 0.1, SH3::Colors(), + "output-features.obj", + SH3::Color( 0, 0, 0 ), SH3::Color::Red ); + + trace.endBlock(); + return 0; +} +// // +/////////////////////////////////////////////////////////////////////////////// From e37d77a99a60f2a9fdfbd2c82789e32e313b380f Mon Sep 17 00:00:00 2001 From: Jacques-Olivier Lachaud Date: Mon, 4 Nov 2019 22:48:52 +0100 Subject: [PATCH 3/5] Fix example --- examples/dec/exampleSurfaceATNormals.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/examples/dec/exampleSurfaceATNormals.cpp b/examples/dec/exampleSurfaceATNormals.cpp index a4e9309626..1caee34aec 100644 --- a/examples/dec/exampleSurfaceATNormals.cpp +++ b/examples/dec/exampleSurfaceATNormals.cpp @@ -62,10 +62,9 @@ int main( int argc, char** argv ) const string volfile = argc > 1 ? argv[ 1 ] : examplesPath + "samples/Al.100.vol"; const double threshold = argc > 2 ? atof( argv[ 2 ] ) : 0.5; - auto params = SH3::defaultParameters() | SHG3::defaultParameters(); - params( "colormap", "Tics" ); trace.beginBlock ( "Load vol file -> build digital surface -> estimate II normals." ); //! [AT-surface-init] + auto params = SH3::defaultParameters() | SHG3::defaultParameters(); auto bimage = SH3::makeBinaryImage( volfile, params ); auto K = SH3::getKSpace( bimage, params ); auto surface = SH3::makeDigitalSurface( bimage, K, params ); From e11abafa1cc990826e39ed1fa9a6fb2e9bab2eb9 Mon Sep 17 00:00:00 2001 From: Jacques-Olivier Lachaud Date: Tue, 5 Nov 2019 11:38:13 +0100 Subject: [PATCH 4/5] Fix doc --- examples/dec/exampleSurfaceATNormals.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/dec/exampleSurfaceATNormals.cpp b/examples/dec/exampleSurfaceATNormals.cpp index 1caee34aec..f9cf78943e 100644 --- a/examples/dec/exampleSurfaceATNormals.cpp +++ b/examples/dec/exampleSurfaceATNormals.cpp @@ -15,14 +15,14 @@ **/ /** - * @file surface-AT-normals + * @file exampleSurfaceATNormals.cpp * @ingroup Examples * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr ) * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France * * @date 2019/06/09 * - * An example file named surface-AT-normals. + * An example file named exampleSurfaceATNormals. * * This file is part of the DGtal library. */ @@ -55,7 +55,7 @@ int main( int argc, char** argv ) typedef SHG3::RealVector RealVector; const double alpha_at = 0.1; - const double lambda_at = 0.025; + const double lambda_at = 0.01; const double e1 = 2.0; const double e2 = 0.25; const double er = 2.0; From 8d958d65c395bf389b55fe096e34e67f9c6565f6 Mon Sep 17 00:00:00 2001 From: Jacques-Olivier Lachaud Date: Tue, 5 Nov 2019 13:16:00 +0100 Subject: [PATCH 5/5] Update ChangeLog --- ChangeLog.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 9d1d3b0048..414b39094f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -82,6 +82,12 @@ (Adrien Krähenbühl, [#1325](https://github.com/DGtal-team/DGtal/pull/1426)) +- *DEC* + - Fix issue (https://github.com/DGtal-team/DGtal/issues/1441)) + related to bad link in DEC/moduleAT documentation and missing + associated example exampleSurfaceATnormals.cpp (Jacques-Olivier + Lachaud,[#1442](https://github.com/DGtal-team/DGtal/pull/1442)) + - *doc* - Promoting the `Shortcuts` documentation page on the main page. (David Coeurjolly [#1417](https://github.com/DGtal-team/DGtal/pull/1417))