DGtal  1.3.beta
Functions
testDigitalSurfaceRegularization.cpp File Reference
#include <iostream>
#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/geometry/surfaces/DigitalSurfaceRegularization.h"
Include dependency graph for testDigitalSurfaceRegularization.cpp:

Go to the source code of this file.

Functions

 TEST_CASE ("Testing DigitalSurfaceRegularization")
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systemes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2019/10/25

Functions for testing class DigitalSurfaceRegularization.

This file is part of the DGtal library.

Definition in file testDigitalSurfaceRegularization.cpp.

Function Documentation

◆ TEST_CASE()

TEST_CASE ( "Testing DigitalSurfaceRegularization )

[DigitalRegInit]

[DigitalRegInit]

[DigitalRegUsage]

[DigitalRegUsage]

[DigitalRegCompute]

[DigitalRegCompute]

[DigitalRegOutput]

[DigitalRegOutput]

[DigitalRegII]

[DigitalRegII]

[DigitalRegLocal]

[DigitalRegLocal]

Definition at line 47 of file testDigitalSurfaceRegularization.cpp.

48 {
52  auto params = SH3::defaultParameters()
53  | SHG3::defaultParameters();
54 
55  params( "polynomial", "goursat" )( "gridstep", 1.0)("verbose", 0);
56  auto implicit_shape = SH3::makeImplicitShape3D ( params );
57  auto digitized_shape = SH3::makeDigitizedImplicitShape3D( implicit_shape, params );
58  auto K = SH3::getKSpace( params );
60 
61  SECTION("Basic Construction using Trivial Normals and regular/clamped advection")
62  {
64  auto surface = SH3::makeDigitalSurface( digitized_shape, K, params );
65  auto surfels = SH3::getSurfelRange( surface, params );
67  regul.init();
68  regul.attachConvolvedTrivialNormalVectors(params);
70  double energy = regul.computeGradient();
71  CAPTURE( regul );
72  REQUIRE( energy == Approx(1684.340));
74  auto finalenergy = regul.regularize();
76  REQUIRE( finalenergy == Approx( 4.7763 ) );
77  REQUIRE( regul.isValid() );
78 
80  auto regularizedPosition = regul.getRegularizedPositions();
81  auto original = regul.getOriginalPositions();
83  auto normals = regul.getNormalVectors();
84 
85  auto cellIndex = regul.getCellIndex();
86  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return original[ cellIndex[c]];},
87  normals, SH3::Colors(), "originalSurf.obj");
88  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return regularizedPosition[ cellIndex[c]];},
89  normals, SH3::Colors(), "regularizedSurf.obj");
90 
91  //Testing reset() at few points
92  regul.reset();
93  regularizedPosition = regul.getRegularizedPositions();
94  REQUIRE( original[0] == regularizedPosition[0] );
95  REQUIRE( original[123] == regularizedPosition[123] );
96 
97  //Testing Clamped version
98  auto finalenergyClamped = regul.regularize(200,1.0,0.001, DigitalSurfaceRegularization<SH3::DigitalSurface>::clampedAdvection);
99  regularizedPosition = regul.getRegularizedPositions();
100  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return regularizedPosition[ cellIndex[c]];},
101  normals, SH3::Colors(), "regularizedSurfClamped.obj");
102  REQUIRE( finalenergyClamped == Approx(12.1914) );
103  REQUIRE( finalenergy < finalenergyClamped );
104 
105  //Testing accessor
106  auto aPointelIndex = cellIndex.begin();
107  REQUIRE( regularizedPosition[ aPointelIndex->second ] == regul.getRegularizedPosition( aPointelIndex->first) );
108  }
109 
110  SECTION("Basic Construction with II Normal Vectors")
111  {
112  auto surface = SH3::makeDigitalSurface( digitized_shape, K, params );
113  auto surfels = SH3::getSurfelRange( surface, params );
115  auto ii_normals = SHG3::getIINormalVectors(digitized_shape, surfels, params);
117  regul.init();
118  auto surfelIndex = regul.getSurfelIndex();
119  regul.attachNormalVectors([&](SH3::SCell &c){ return ii_normals[ surfelIndex[c] ];} );
121 
122  double energy = regul.computeGradient();
123  CAPTURE( regul );
124  REQUIRE( energy == Approx(1588.649));
125  regul.regularize();
126  REQUIRE( regul.isValid() );
127 
128  auto regularizedPosition = regul.getRegularizedPositions();
129  auto normals = regul.getNormalVectors();
130  auto cellIndex = regul.getCellIndex();
131  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return regularizedPosition[ cellIndex[c]];},
132  normals, SH3::Colors(), "regularizedSurf-II.obj");
133  }
134 
135  SECTION("Warm restart")
136  {
137  auto surface = SH3::makeDigitalSurface( digitized_shape, K, params );
138  auto surfels = SH3::getSurfelRange( surface, params );
140  regul.init();
141  regul.attachConvolvedTrivialNormalVectors(params);
142  CAPTURE( regul );
143  auto energy = regul.regularize(10,1.0,0.1);
144  auto secondenergy = regul.regularize(10,1.0,0.1);
145  auto thirdenergy = regul.regularize(10,1.0,0.1);
146  CAPTURE(energy);
147  CAPTURE(secondenergy);
148  CAPTURE(thirdenergy);
149 
150  REQUIRE( energy > secondenergy );
151  REQUIRE( secondenergy > thirdenergy );
152  }
153 
154  SECTION("Local weights")
155  {
156  auto surface = SH3::makeDigitalSurface( digitized_shape, K, params );
157  auto surfels = SH3::getSurfelRange( surface, params );
159  regul.init();
160  regul.attachConvolvedTrivialNormalVectors(params);
161  CAPTURE( regul );
162  auto energy = regul.regularize(10,1.0,0.1);
163 
164  auto original = regul.getOriginalPositions();
165  std::vector<double> alphas(original.size(),0.001);
166  std::vector<double> betas(original.size(),1.0);
167  std::vector<double> gammas(original.size(), 0.05);
168 
169  //Init again with variable (but constant) weights
171  regul2.init(alphas,betas,gammas);
172  regul2.attachConvolvedTrivialNormalVectors(params);
173  auto energybis = regul2.regularize(10,1.0,0.1);
174  REQUIRE( energy == energybis );
175 
176  energybis = regul2.regularize();
177  auto regularizedPosition = regul.getRegularizedPositions();
178  auto normals = regul.getNormalVectors();
179  auto cellIndex = regul.getCellIndex();
180  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return regularizedPosition[ cellIndex[c]];},
181  normals, SH3::Colors(), "regularizedSurf-local.obj");
182 
183  //Same with higher data attachment for x < 0.0
186  for(auto i = 0 ; i < original.size(); ++i)
187  if (original[i][0]<0.0)
188  {
189  alphas[i] = 4.0;
190  betas[i] = 0.0000001;
191  gammas[i] = 0.0;
192  }
193  regul3.init(alphas,betas,gammas);
194  regul3.attachConvolvedTrivialNormalVectors(params);
195  energybis = regul3.regularize();
197 
198  regularizedPosition = regul3.getRegularizedPositions();
199  SH3::saveOBJ(surface, [&] (const SH3::Cell &c){ return regularizedPosition[ cellIndex[c]];},
200  normals, SH3::Colors(), "regularizedSurf-localsplit.obj");
201  }
202 }

References DGtal::DigitalSurfaceRegularization< TDigitalSurface >::attachConvolvedTrivialNormalVectors(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::attachNormalVectors(), CAPTURE(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::computeGradient(), DGtal::Shortcuts< TKSpace >::defaultParameters(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getCellIndex(), DGtal::Shortcuts< TKSpace >::getKSpace(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getNormalVectors(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getOriginalPositions(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getRegularizedPosition(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getRegularizedPositions(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::getSurfelIndex(), DGtal::Shortcuts< TKSpace >::getSurfelRange(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::init(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::isValid(), K, DGtal::Shortcuts< TKSpace >::makeDigitalSurface(), DGtal::Shortcuts< TKSpace >::makeDigitizedImplicitShape3D(), DGtal::Shortcuts< TKSpace >::makeImplicitShape3D(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::regularize(), REQUIRE(), DGtal::DigitalSurfaceRegularization< TDigitalSurface >::reset(), DGtal::Shortcuts< TKSpace >::saveOBJ(), and SECTION().

SH3
Shortcuts< KSpace > SH3
Definition: testArithmeticalDSSComputerOnSurfels.cpp:49
DGtal::Shortcuts::Cell
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
DGtal::Shortcuts::Colors
std::vector< Color > Colors
Definition: Shortcuts.h:192
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::Shortcuts::makeDigitalSurface
static CountedPtr< DigitalSurface > makeDigitalSurface(CountedPtr< TPointPredicate > bimage, const KSpace &K, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1209
REQUIRE
REQUIRE(domain.isInside(aPoint))
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:104
CAPTURE
CAPTURE(thicknessHV)
SHG3
ShortcutsGeometry< Z3i::KSpace > SHG3
Definition: testIntegralInvariantShortcuts.cpp:47
DGtal::Shortcuts::defaultParameters
static Parameters defaultParameters()
Definition: Shortcuts.h:203
DGtal::DigitalSurfaceRegularization
Aim: Implements Digital Surface Regularization as described in .
Definition: DigitalSurfaceRegularization.h:88
DGtal::Shortcuts::makeImplicitShape3D
static CountedPtr< ImplicitShape3D > makeImplicitShape3D(const Parameters &params=parametersImplicitShape3D())
Definition: Shortcuts.h:282
DGtal::ShortcutsGeometry
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: ShortcutsGeometry.h:76
DGtal::Shortcuts::SCell
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
DGtal::Shortcuts::makeDigitizedImplicitShape3D
static CountedPtr< DigitizedImplicitShape3D > makeDigitizedImplicitShape3D(CountedPtr< ImplicitShape3D > shape, Parameters params=parametersDigitizedImplicitShape3D())
Definition: Shortcuts.h:523
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
SECTION
SECTION("Testing constant forward iterators")
Definition: testSimpleRandomAccessRangeFromPoint.cpp:66
DGtal::Shortcuts::saveOBJ
static bool saveOBJ(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > digsurf, const TCellEmbedder &embedder, const RealVectors &normals, const Colors &diffuse_colors, std::string objfile, const Color &ambient_color=Color(32, 32, 32), const Color &diffuse_color=Color(200, 200, 255), const Color &specular_color=Color::White)
Definition: Shortcuts.h:1739
DGtal::Shortcuts::getSurfelRange
static SurfelRange getSurfelRange(CountedPtr< ::DGtal::DigitalSurface< TDigitalSurfaceContainer > > surface, const Parameters &params=parametersDigitalSurface())
Definition: Shortcuts.h:1547