DGtal  1.4.beta
exampleSurfaceATNormals.cpp File Reference
#include <iostream>
#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"
Include dependency graph for exampleSurfaceATNormals.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

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 http://www.gnu.org/licenses/.

Author
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
Date
2019/06/09

An example file named exampleSurfaceATNormals.

This file is part of the DGtal library.

Definition in file exampleSurfaceATNormals.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

[AT-surface-init]

[AT-surface-init]

[AT-surface-calculus]

[AT-surface-calculus] [AT-surface-solve]

[AT-surface-solve]

[AT-surface-getU2]

[AT-surface-getU2]

[AT-surface-getV0]

[AT-surface-getV0]

Definition at line 48 of file exampleSurfaceATNormals.cpp.

49 {
50  typedef Z3i::KSpace KSpace;
51  typedef Shortcuts< KSpace > SH3;
53  typedef SH3::Cell Cell;
54 
55  const double alpha_at = 0.1;
56  const double lambda_at = 0.01;
57  const double e1 = 2.0;
58  const double e2 = 0.25;
59  const double er = 2.0;
60 
61  const string volfile = argc > 1 ? argv[ 1 ] : examplesPath + "samples/Al.100.vol";
62  const double threshold = argc > 2 ? atof( argv[ 2 ] ) : 0.5;
63  trace.beginBlock ( "Load vol file -> build digital surface -> estimate II normals." );
65  auto params = SH3::defaultParameters() | SHG3::defaultParameters();
66  auto bimage = SH3::makeBinaryImage( volfile, params );
67  auto K = SH3::getKSpace( bimage, params );
68  auto surface = SH3::makeDigitalSurface( bimage, K, params );
69  auto surfels = SH3::getSurfelRange( surface, params );
70  auto linels = SH3::getCellRange( surface, 1 );
71  auto ii_normals= SHG3::getIINormalVectors( bimage, surfels, params );
72  auto uembedder = SH3::getCellEmbedder( K );
73  auto embedder = SH3::getSCellEmbedder( K );
75  trace.endBlock();
76 
77  trace.beginBlock ( "Creating AT solver for digital surface" );
80  const auto calculus = CalculusFactory::createFromNSCells<2>( surfels.begin(), surfels.end() );
83  ATSolver2D< KSpace > at_solver(calculus, 1);
84  at_solver.initInputVectorFieldU2( ii_normals, surfels.cbegin(), surfels.cend() );
85  at_solver.setUp( alpha_at, lambda_at );
86  at_solver.solveGammaConvergence( e1, e2, er );
88  trace.endBlock();
89 
90  trace.beginBlock ( "Save AT normals as OBJ file" );
92  auto at_normals = ii_normals;
93  at_solver.getOutputVectorFieldU2( at_normals, surfels.cbegin(), surfels.cend() );
95  SH3::RealPoints positions( surfels.size() );
96  std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
97  [&] (const SH3::SCell& c) { return embedder( c ); } );
98  SH3::Colors colors( surfels.size() );
99  for ( size_t i = 0; i < surfels.size(); i++ )
100  colors[ i ] = SH3::Color( (unsigned char) 255.0*fabs( at_normals[ i ][ 0 ] ),
101  (unsigned char) 255.0*fabs( at_normals[ i ][ 1 ] ),
102  (unsigned char) 255.0*fabs( at_normals[ i ][ 2 ] ) );
103  std::transform( surfels.cbegin(), surfels.cend(), positions.begin(),
104  [&] (const SH3::SCell& c) { return embedder( c ); } );
105 
106  bool ok1 = SH3::saveOBJ( surface, at_normals, SH3::Colors(),
107  "output-surface.obj" );
108  bool ok2 = SH3::saveOBJ( surface, at_normals, colors,
109  "output-surface-at-normals.obj" );
110  bool ok3 = SH3::saveVectorFieldOBJ( positions, at_normals, 0.05, SH3::Colors(),
111  "output-vf-at-normals.obj",
112  SH3::Color( 0, 0, 0 ), SH3::Color::Red );
113 
114  ASSERT(ok1 && ok2 && ok3);
116  SH3::Scalars features( linels.size() );
117  at_solver.getOutputScalarFieldV0( features, linels.cbegin(), linels.cend(),
118  at_solver.Maximum );
120  SH3::RealPoints f0;
121  SH3::RealVectors f1;
122  for ( size_t i = 0; i < linels.size(); i++ )
123  {
124  if ( features[ i ] < threshold )
125  {
126  const Cell linel = linels[ i ];
127  const Dimension d = * K.uDirs( linel );
128  const Cell p0 = K.uIncident( linel, d, false );
129  const Cell p1 = K.uIncident( linel, d, true );
130  f0.push_back( uembedder( p0 ) );
131  f1.push_back( uembedder( p1 ) - uembedder( p0 ) );
132  }
133  }
134  bool ok4 = SH3::saveVectorFieldOBJ( f0, f1, 0.1, SH3::Colors(),
135  "output-features.obj",
136  SH3::Color( 0, 0, 0 ), SH3::Color::Red );
137 
138  ASSERT(ok4);
139  trace.endBlock();
140  return 0;
141 }
Aim: This class solves Ambrosio-Tortorelli functional on a two-dimensional digital space (a 2D grid o...
Definition: ATSolver2D.h:91
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Red
Definition: Color.h:416
Aim: This class provides static members to create DEC structures from various other DGtal structures.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Cell uIncident(const Cell &c, Dimension k, bool up) const
Return the forward or backward unsigned cell incident to [c] along axis [k], depending on [up].
DirIterator uDirs(const Cell &p) const
Given an unsigned cell [p], returns an iterator to iterate over each coordinate the cell spans.
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
std::vector< Color > Colors
Definition: Shortcuts.h:192
std::vector< RealPoint > RealPoints
Definition: Shortcuts.h:180
std::vector< RealVector > RealVectors
Definition: Shortcuts.h:179
std::vector< Scalar > Scalars
Definition: Shortcuts.h:178
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
void beginBlock(const std::string &keyword="")
double endBlock()
DGtal::uint32_t Dimension
Definition: Common.h:136
Trace trace
Definition: Common.h:153
Shortcuts< KSpace > SH3
KSpace K
KSpace::Cell Cell
ShortcutsGeometry< Z3i::KSpace > SHG3

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::getOutputScalarFieldV0(), DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::getOutputVectorFieldU2(), DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::initInputVectorFieldU2(), K, DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::Maximum, DGtal::Color::Red, DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::setUp(), DGtal::ATSolver2D< TKSpace, TLinearAlgebra >::solveGammaConvergence(), DGtal::trace, DGtal::KhalimskySpaceND< dim, TInteger >::uDirs(), and DGtal::KhalimskySpaceND< dim, TInteger >::uIncident().