31 #include "DGtal/base/Common.h"
32 #include "ConfigTest.h"
33 #include "DGtalCatch.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/helpers/Shortcuts.h"
36 #include "DGtal/helpers/ShortcutsGeometry.h"
37 #include "DGtal/geometry/surfaces/DigitalSurfaceRegularization.h"
41 using namespace DGtal;
52 auto params = SH3::defaultParameters()
53 | SHG3::defaultParameters();
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 );
61 SECTION(
"Basic Construction using Trivial Normals and regular/clamped advection")
64 auto surface = SH3::makeDigitalSurface( digitized_shape,
K, params );
65 auto surfels = SH3::getSurfelRange(
surface, params );
72 REQUIRE( energy == Approx(1684.340));
76 REQUIRE( finalenergy == Approx( 4.7763 ) );
86 SH3::saveOBJ(
surface, [&] (
const SH3::Cell &c){
return original[ cellIndex[c]];},
88 SH3::saveOBJ(
surface, [&] (
const SH3::Cell &c){
return regularizedPosition[ cellIndex[c]];},
94 REQUIRE( original[0] == regularizedPosition[0] );
95 REQUIRE( original[123] == regularizedPosition[123] );
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 );
106 auto aPointelIndex = cellIndex.begin();
110 SECTION(
"Basic Construction with II Normal Vectors")
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);
124 REQUIRE( energy == Approx(1588.649));
131 SH3::saveOBJ(
surface, [&] (
const SH3::Cell &c){
return regularizedPosition[ cellIndex[c]];},
137 auto surface = SH3::makeDigitalSurface( digitized_shape,
K, params );
138 auto surfels = SH3::getSurfelRange(
surface, params );
144 auto secondenergy = regul.
regularize(10,1.0,0.1);
145 auto thirdenergy = regul.
regularize(10,1.0,0.1);
150 REQUIRE( energy > secondenergy );
151 REQUIRE( secondenergy > thirdenergy );
156 auto surface = SH3::makeDigitalSurface( digitized_shape,
K, params );
157 auto surfels = SH3::getSurfelRange(
surface, params );
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);
171 regul2.
init(alphas,betas,gammas);
173 auto energybis = regul2.
regularize(10,1.0,0.1);
174 REQUIRE( energy == energybis );
180 SH3::saveOBJ(
surface, [&] (
const SH3::Cell &c){
return regularizedPosition[ cellIndex[c]];},
181 normals,
SH3::Colors(),
"regularizedSurf-local.obj");
186 for(
size_t i = 0 ; i < original.size(); ++i)
187 if (original[i][0]<0.0)
190 betas[i] = 0.0000001;
193 regul3.init(alphas,betas,gammas);
194 regul3.attachConvolvedTrivialNormalVectors(params);
195 energybis = regul3.regularize();
198 regularizedPosition = regul3.getRegularizedPositions();
199 SH3::saveOBJ(
surface, [&] (
const SH3::Cell &c){
return regularizedPosition[ cellIndex[c]];},
200 normals,
SH3::Colors(),
"regularizedSurf-localsplit.obj");
Aim: Implements Digital Surface Regularization as described in .
void init(const double alpha=0.001, const double beta=1.0, const double gamma=0.05)
Initialize the parameters of the energy function.
void attachConvolvedTrivialNormalVectors(const Parameters someParams=SH3::defaultParameters()|SHG3::defaultParameters())
const Normals & getNormalVectors() const
const Positions & getOriginalPositions() const
void attachNormalVectors(const std::function< SHG3::RealVector(SH3::SCell &)> &normalFunc)
const Positions & getRegularizedPositions() const
const SH3::Surfel2Index & getSurfelIndex() const
SHG3::RealPoint getRegularizedPosition(const SH3::Cell &aPointel)
double regularize(const unsigned int nbIters, const double dt, const double epsilon, const AdvectionFunction &advectionFunc)
Main regularization loop.
const SH3::Cell2Index & getCellIndex() const
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...
std::vector< Color > Colors
LightDigitalSurface::SCell SCell
LightDigitalSurface::Cell Cell
CountedPtr< SH3::DigitalSurface > surface
DGtal is the top-level namespace which contains all DGtal functions and types.
TEST_CASE("Testing DigitalSurfaceRegularization")
ShortcutsGeometry< Z3i::KSpace > SHG3
SECTION("Testing constant forward iterators")
REQUIRE(domain.isInside(aPoint))