DGtal  1.1.0
DigitalSurfaceRegularization.h
1 
17 #pragma once
18 
31 #if defined(DigitalSurfaceRegularization_RECURSES)
32 #error Recursive header files inclusion detected in DigitalSurfaceRegularization.h
33 #else // defined(DigitalSurfaceRegularization_RECURSES)
34 
35 #define DigitalSurfaceRegularization_RECURSES
36 
37 #if !defined DigitalSurfaceRegularization_h
38 
39 #define DigitalSurfaceRegularization_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/ConstAlias.h"
46 #include "DGtal/topology/DigitalSurface.h"
47 
48 #include "DGtal/helpers/StdDefs.h"
49 #include "DGtal/helpers/Shortcuts.h"
50 #include "DGtal/helpers/ShortcutsGeometry.h"
52 
53 namespace DGtal
54  {
55 
57  // template class DigitalSurfaceRegularization
87  template <typename TDigitalSurface>
89  {
90  // ----------------------- Standard services ------------------------------
91  public:
92 
94  typedef TDigitalSurface DigSurface;
96  typedef typename TDigitalSurface::DigitalSurfaceContainer DigitalSurfaceContainer;
98 
101 
104 
106  typedef std::vector<Z3i::RealPoint> Positions;
107 
109  typedef std::vector<Z3i::RealVector> Normals;
110 
115  : myInit(false), myVerbose(false), myDigitalSurface(aDigSurf)
116  {
118  }
119 
124 
130 
136 
143 
150 
151  // ----------------------- Interface --------------------------------------
152  public:
153 
161  void attachNormalVectors(const std::function<SHG3::RealVector(SH3::SCell&)> &normalFunc);
162 
173 
174 
184  void init(const double alpha = 0.001,
185  const double beta = 1.0,
186  const double gamma = 0.05);
187 
188 
199  void init(ConstAlias< std::vector<double> > alphas,
200  ConstAlias< std::vector<double> > betas,
201  ConstAlias< std::vector<double> > gammas);
202 
203 
212  double computeGradient();
213 
214 
226 
227 
251  template <typename AdvectionFunction>
252  double regularize(const unsigned int nbIters,
253  const double dt,
254  const double epsilon,
255  const AdvectionFunction & advectionFunc);
273  double regularize(const unsigned int nbIters = 200,
274  const double dt = 1.0,
275  const double epsilon = 0.0001)
276  {
277  return regularize(nbIters,dt,epsilon,
278  [](SHG3::RealPoint& p,SHG3::RealPoint& o,SHG3::RealVector& v){ p += v; });
279  }
280 
281 
282 
293  const SHG3::RealPoint &orig,
294  const SHG3::RealVector &v)
295  {
296  p += v;
297  for(auto i=0; i < 3; ++i)
298  if ((p[i]-orig[i])> 0.5) p[i]=orig[i]+0.5;
299  else
300  if ((p[i]-orig[i])< -0.5) p[i]=orig[i]-0.5;
301  }
302 
303 
312  {
313  ASSERT_MSG(myInit, "The init() method must be called first.");
314  ASSERT_MSG(myK.uDim(aPointel) == 0, "The cell must be a pointel (0-cell)");
315  return myRegularizedPositions[ myPointelIndex[ aPointel] ];
316  }
317 
324  {
325  ASSERT_MSG(myInit, "The init() method must be called first.");
326  return myRegularizedPositions;
327  }
334  {
335  ASSERT_MSG(myInit, "The init() method must be called first.");
336  return myOriginalPositions;
337  }
344  {
345  ASSERT_MSG(myInit, "The init() method must be called first.");
346  return myPointelIndex;
347  }
353  const Normals & getNormalVectors() const
354  {
355  ASSERT_MSG(myInit, "The init() method must be called first.");
356  return myNormals;
357  }
358 
365  {
366  ASSERT_MSG(myInit, "The init() method must be called first.");
367  return mySurfelIndex;
368  }
369 
374  void reset()
375  {
376  ASSERT_MSG(myInit, "The init() method must be called first.");
377  std::copy(myOriginalPositions.begin(), myOriginalPositions.end(), myRegularizedPositions.begin());
378  }
379 
380 
381  // ----------------------- Services --------------------------------------
382 
383 
388  void selfDisplay ( std::ostream & out ) const;
389 
394  bool isValid() const;
395 
399  void enableVerbose() {myVerbose=true;}
400 
404  void disasbleVerbose() {myVerbose=false;}
405 
406  // ------------------------- Private methods --------------------------------
407  private:
408 
412  void cacheInit();
413 
414 
415  // ------------------------- Private Datas --------------------------------
416  private:
417 
419  double myAlpha;
421  double myBeta;
423  double myGamma;
424 
426  const std::vector<double> *myAlphas;
428  const std::vector<double> *myBetas;
430  const std::vector<double> *myGammas;
431 
434 
436  bool myInit;
437 
439  bool myVerbose;
440 
443 
446 
449 
452 
455 
456 
457 
458  // ---------------------------------------------------------------
460 
463 
466 
469 
472 
475 
477  std::vector< SH3::Idx > myAlignPointelsIdx;
479  std::vector< SH3::Cell > myAlignPointels;
481  std::vector<unsigned char> myNumberAdjEdgesToPointel;
483  std::vector< SH3::Idx > myFairnessPointelsIdx;
485  std::vector< unsigned char > myNbAdjacent;
488 
489  }; // end of class DigitalSurfaceRegularization
490 
491 
498  template <typename T>
499  std::ostream&
500  operator<< ( std::ostream & out, const DigitalSurfaceRegularization<T> & object );
501 
502  } // namespace surfaces
503 
504 
506 // Includes inline functions/methods if necessary.
507 #include "DGtal/geometry/surfaces/DigitalSurfaceRegularization.ih"
508 // //
510 
511 #endif // !defined DigitalSurfaceRegularization_h
512 
513 #undef DigitalSurfaceRegularization_RECURSES
514 #endif // else defined(DigitalSurfaceRegularization_RECURSES)
DGtal::DigitalSurfaceRegularization::getRegularizedPositions
const Positions & getRegularizedPositions() const
Definition: DigitalSurfaceRegularization.h:323
DGtal::Shortcuts::Cell2Index
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:188
DGtal::DigitalSurfaceRegularization::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
DGtal::Shortcuts::Cell
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
DGtal::DigitalSurfaceRegularization::cacheInit
void cacheInit()
DGtal::DigitalSurfaceRegularization::DigitalSurfaceRegularization
DigitalSurfaceRegularization(CountedPtr< DigSurface > aDigSurf)
Definition: DigitalSurfaceRegularization.h:114
DGtal::DigitalSurfaceRegularization::reset
void reset()
Definition: DigitalSurfaceRegularization.h:374
DGtal::DigitalSurfaceRegularization::myAlpha
double myAlpha
Data attachment term coefficient.
Definition: DigitalSurfaceRegularization.h:419
DGtal::DigitalSurfaceRegularization::clampedAdvection
static void clampedAdvection(SHG3::RealPoint &p, const SHG3::RealPoint &orig, const SHG3::RealVector &v)
Definition: DigitalSurfaceRegularization.h:292
DGtal::DigitalSurfaceRegularization::myAlignPointelsIdx
std::vector< SH3::Idx > myAlignPointelsIdx
Indices of adjacent pointels for the Alignement energy term.
Definition: DigitalSurfaceRegularization.h:477
DGtal::DigitalSurfaceRegularization::SHG3
ShortcutsGeometry< Z3i::KSpace > SHG3
We rely on the ShortcutsGeometry 3D types.
Definition: DigitalSurfaceRegularization.h:103
DGtal::DigitalSurfaceRegularization::myConstantCoeffs
bool myConstantCoeffs
Flag if the gradient has constant weights for the init method and gradient.
Definition: DigitalSurfaceRegularization.h:433
DGtal::DigitalSurfaceRegularization::DigitalSurfaceRegularization
DigitalSurfaceRegularization(const DigitalSurfaceRegularization &other)=delete
DGtal::DigitalSurfaceRegularization::getSurfelIndex
const SH3::Surfel2Index & getSurfelIndex() const
Definition: DigitalSurfaceRegularization.h:364
DGtal::DigitalSurfaceRegularization::init
void init(const double alpha=0.001, const double beta=1.0, const double gamma=0.05)
Initialize the parameters of the energy function.
DGtal::Shortcuts::Surfel2Index
std::map< Surfel, IdxSurfel > Surfel2Index
Definition: Shortcuts.h:187
DGtal::DigitalSurfaceRegularization::myGammas
const std::vector< double > * myGammas
Fairness attachment term local coefficients.
Definition: DigitalSurfaceRegularization.h:430
DGtal::DigitalSurfaceRegularization::SH3
Shortcuts< Z3i::KSpace > SH3
We rely on the Shortcuts 3D types.
Definition: DigitalSurfaceRegularization.h:100
DGtal::Shortcuts
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
DGtal::DigitalSurfaceRegularization::myOriginalPositions
Positions myOriginalPositions
Copy of the input pointels positions.
Definition: DigitalSurfaceRegularization.h:445
DGtal::DigitalSurfaceRegularization::computeGradient
double computeGradient()
DGtal::DigitalSurfaceRegularization::myFaces
SH3::PolygonalSurface::FaceRange myFaces
All faces of the dual digital surfacce.
Definition: DigitalSurfaceRegularization.h:487
DGtal::DigitalSurfaceRegularization::myAlignPointels
std::vector< SH3::Cell > myAlignPointels
Adjacent pointels for the Alignement energy term.
Definition: DigitalSurfaceRegularization.h:479
DGtal::DigitalSurfaceRegularization::myPointelIndex
SH3::Cell2Index myPointelIndex
Indices for pointels.
Definition: DigitalSurfaceRegularization.h:474
DGtal::concepts::CDigitalSurfaceContainer
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...
Definition: CDigitalSurfaceContainer.h:128
DGtal::DigitalSurfaceRegularization::~DigitalSurfaceRegularization
~DigitalSurfaceRegularization()=default
DGtal::Parameters
Definition: Parameters.h:146
DGtal::DigitalSurfaceRegularization::attachNormalVectors
void attachNormalVectors(const std::function< SHG3::RealVector(SH3::SCell &)> &normalFunc)
DGtal::DigitalSurfaceRegularization::myBeta
double myBeta
Alignment term coefficient.
Definition: DigitalSurfaceRegularization.h:421
DGtal::Shortcuts::defaultParameters
static Parameters defaultParameters()
Definition: Shortcuts.h:202
DGtal::DigitalSurfaceRegularization::DigitalSurfaceRegularization
DigitalSurfaceRegularization(DigitalSurfaceRegularization &&other)=delete
DGtal::DigitalSurfaceRegularization
Aim: Implements Digital Surface Regularization as described in .
Definition: DigitalSurfaceRegularization.h:89
DGtal::Shortcuts::KSpace
TKSpace KSpace
Digital cellular space.
Definition: Shortcuts.h:111
DGtal::PolygonalSurface::FaceRange
std::vector< Face > FaceRange
Definition: PolygonalSurface.h:116
DGtal::DigitalSurfaceRegularization::getCellIndex
const SH3::Cell2Index & getCellIndex() const
Definition: DigitalSurfaceRegularization.h:343
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::DigitalSurfaceRegularization::Normals
std::vector< Z3i::RealVector > Normals
Pointels position container.
Definition: DigitalSurfaceRegularization.h:109
DGtal::DigitalSurfaceRegularization::attachConvolvedTrivialNormalVectors
void attachConvolvedTrivialNormalVectors(const Parameters someParams=SH3::defaultParameters()|SHG3::defaultParameters())
DGtal::DigitalSurfaceRegularization::myGamma
double myGamma
Fairness term coefficient.
Definition: DigitalSurfaceRegularization.h:423
DGtal::DigitalSurfaceRegularization::operator=
DigitalSurfaceRegularization & operator=(const DigitalSurfaceRegularization &other)=delete
DGtal::DigitalSurfaceRegularization::myDigitalSurface
CountedPtr< DigSurface > myDigitalSurface
Input DigitalSurface to regularize.
Definition: DigitalSurfaceRegularization.h:442
DGtal::DigitalSurfaceRegularization::computeGradientLocalWeights
double computeGradientLocalWeights()
DGtal::DigitalSurfaceRegularization::myAlphas
const std::vector< double > * myAlphas
Data attachment term local coefficients.
Definition: DigitalSurfaceRegularization.h:426
DGtal::DigitalSurfaceRegularization::isValid
bool isValid() const
DGtal::DigitalSurfaceRegularization::getNormalVectors
const Normals & getNormalVectors() const
Definition: DigitalSurfaceRegularization.h:353
DGtal::DigitalSurfaceRegularization::enableVerbose
void enableVerbose()
Definition: DigitalSurfaceRegularization.h:399
DGtal::ShortcutsGeometry
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: ShortcutsGeometry.h:77
DGtal::Shortcuts::SCell
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
DGtal::DigitalSurfaceRegularization::DigSurface
TDigitalSurface DigSurface
DigitalSurface type.
Definition: DigitalSurfaceRegularization.h:94
DGtal::CountedPtr< DigSurface >
DGtal::Shortcuts::SurfelRange
SCellRange SurfelRange
Definition: Shortcuts.h:176
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::DigitalSurfaceRegularization::DigitalSurfaceContainer
TDigitalSurface::DigitalSurfaceContainer DigitalSurfaceContainer
Digital Surface Container type.
Definition: DigitalSurfaceRegularization.h:96
DGtal::DigitalSurfaceRegularization::getOriginalPositions
const Positions & getOriginalPositions() const
Definition: DigitalSurfaceRegularization.h:333
DGtal::DigitalSurfaceRegularization::myGradient
Positions myGradient
Gradient of the energy w.r.t. vertex positons.
Definition: DigitalSurfaceRegularization.h:454
DGtal::DigitalSurfaceRegularization::myK
SH3::KSpace myK
Instance of the KSpace.
Definition: DigitalSurfaceRegularization.h:465
DGtal::DigitalSurfaceRegularization::myNbAdjacent
std::vector< unsigned char > myNbAdjacent
Number of adjacent faces to given vertex.
Definition: DigitalSurfaceRegularization.h:485
DGtal::Shortcuts::getKSpace
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:331
DGtal::DigitalSurfaceRegularization::myGradientAlign
Positions myGradientAlign
Internal members to store precomputed topological informations.
Definition: DigitalSurfaceRegularization.h:462
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
DGtal::ShortcutsGeometry::defaultParameters
static Parameters defaultParameters()
Definition: ShortcutsGeometry.h:209
DGtal::DigitalSurfaceRegularization::myVerbose
bool myVerbose
Flag for verbose messages.
Definition: DigitalSurfaceRegularization.h:439
DGtal::DigitalSurfaceRegularization::getRegularizedPosition
SHG3::RealPoint getRegularizedPosition(const SH3::Cell &aPointel)
Definition: DigitalSurfaceRegularization.h:311
DGtal::DigitalSurfaceRegularization::init
void init(ConstAlias< std::vector< double > > alphas, ConstAlias< std::vector< double > > betas, ConstAlias< std::vector< double > > gammas)
Initialize the parameters of the energy function.
DGtal::DigitalSurfaceRegularization::myBetas
const std::vector< double > * myBetas
Alignment attachment term local coefficients.
Definition: DigitalSurfaceRegularization.h:428
DGtal::DigitalSurfaceRegularization::mySurfelIndex
SH3::Surfel2Index mySurfelIndex
Surfel Index.
Definition: DigitalSurfaceRegularization.h:471
DGtal::DigitalSurfaceRegularization::mySurfels
SH3::SurfelRange mySurfels
Indexed surface elements.
Definition: DigitalSurfaceRegularization.h:468
DGtal::DigitalSurfaceRegularization::myInit
bool myInit
Flag if the object has been set up properly.
Definition: DigitalSurfaceRegularization.h:436
DGtal::DigitalSurfaceRegularization::myRegularizedPositions
Positions myRegularizedPositions
Regularized vertices.
Definition: DigitalSurfaceRegularization.h:448
DGtal::DigitalSurfaceRegularization::regularize
double regularize(const unsigned int nbIters, const double dt, const double epsilon, const AdvectionFunction &advectionFunc)
Main regularization loop.
DGtal::DigitalSurfaceRegularization::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
DGtal::DigitalSurfaceRegularization::disasbleVerbose
void disasbleVerbose()
Definition: DigitalSurfaceRegularization.h:404
DGtal::DigitalSurfaceRegularization::Positions
std::vector< Z3i::RealPoint > Positions
Pointels position container.
Definition: DigitalSurfaceRegularization.h:106
DGtal::DigitalSurfaceRegularization::regularize
double regularize(const unsigned int nbIters=200, const double dt=1.0, const double epsilon=0.0001)
Main regularization loop.
Definition: DigitalSurfaceRegularization.h:273
DGtal::DigitalSurfaceRegularization::myFairnessPointelsIdx
std::vector< SH3::Idx > myFairnessPointelsIdx
Indices of cells foor the Fairness term.
Definition: DigitalSurfaceRegularization.h:483
DGtal::DigitalSurfaceRegularization::myNormals
Normals myNormals
Normals.
Definition: DigitalSurfaceRegularization.h:451
DGtal::DigitalSurfaceRegularization::myNumberAdjEdgesToPointel
std::vector< unsigned char > myNumberAdjEdgesToPointel
Number of adjacent edges to pointels.
Definition: DigitalSurfaceRegularization.h:481