DGtal  1.5.beta
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)
35 #define DigitalSurfaceRegularization_RECURSES
36 
37 #if !defined DigitalSurfaceRegularization_h
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){ (void)o; 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)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: Implements Digital Surface Regularization as described in .
Positions myOriginalPositions
Copy of the input pointels positions.
Positions myRegularizedPositions
Regularized vertices.
const std::vector< double > * myBetas
Alignment attachment term local coefficients.
static void clampedAdvection(SHG3::RealPoint &p, const SHG3::RealPoint &orig, const SHG3::RealVector &v)
std::vector< SH3::Idx > myAlignPointelsIdx
Indices of adjacent pointels for the Alignement energy term.
void init(const double alpha=0.001, const double beta=1.0, const double gamma=0.05)
Initialize the parameters of the energy function.
bool myConstantCoeffs
Flag if the gradient has constant weights for the init method and gradient.
void attachConvolvedTrivialNormalVectors(const Parameters someParams=SH3::defaultParameters()|SHG3::defaultParameters())
std::vector< SH3::Cell > myAlignPointels
Adjacent pointels for the Alignement energy term.
SH3::KSpace myK
Instance of the KSpace.
SH3::SurfelRange mySurfels
Indexed surface elements.
Positions myGradientAlign
Internal members to store precomputed topological informations.
std::vector< SH3::Idx > myFairnessPointelsIdx
Indices of cells foor the Fairness term.
BOOST_CONCEPT_ASSERT((concepts::CDigitalSurfaceContainer< DigitalSurfaceContainer >))
ShortcutsGeometry< Z3i::KSpace > SHG3
We rely on the ShortcutsGeometry 3D types.
double myAlpha
Data attachment term coefficient.
CountedPtr< DigSurface > myDigitalSurface
Input DigitalSurface to regularize.
bool myInit
Flag if the object has been set up properly.
std::vector< Z3i::RealPoint > Positions
Pointels position container.
double myGamma
Fairness term coefficient.
Shortcuts< Z3i::KSpace > SH3
We rely on the Shortcuts 3D types.
std::vector< Z3i::RealVector > Normals
Pointels position container.
void attachNormalVectors(const std::function< SHG3::RealVector(SH3::SCell &)> &normalFunc)
std::vector< unsigned char > myNumberAdjEdgesToPointel
Number of adjacent edges to pointels.
DigitalSurfaceRegularization(DigitalSurfaceRegularization &&other)=delete
DigitalSurfaceRegularization & operator=(const DigitalSurfaceRegularization &other)=delete
const SH3::Surfel2Index & getSurfelIndex() const
SH3::Cell2Index myPointelIndex
Indices for pointels.
Positions myGradient
Gradient of the energy w.r.t. vertex positons.
SHG3::RealPoint getRegularizedPosition(const SH3::Cell &aPointel)
void selfDisplay(std::ostream &out) const
double regularize(const unsigned int nbIters=200, const double dt=1.0, const double epsilon=0.0001)
Main regularization loop.
void init(ConstAlias< std::vector< double > > alphas, ConstAlias< std::vector< double > > betas, ConstAlias< std::vector< double > > gammas)
Initialize the parameters of the energy function.
const std::vector< double > * myAlphas
Data attachment term local coefficients.
double myBeta
Alignment term coefficient.
double regularize(const unsigned int nbIters, const double dt, const double epsilon, const AdvectionFunction &advectionFunc)
Main regularization loop.
SH3::PolygonalSurface::FaceRange myFaces
All faces of the dual digital surfacce.
DigitalSurfaceRegularization(CountedPtr< DigSurface > aDigSurf)
const std::vector< double > * myGammas
Fairness attachment term local coefficients.
std::vector< unsigned char > myNbAdjacent
Number of adjacent faces to given vertex.
DigitalSurfaceRegularization(const DigitalSurfaceRegularization &other)=delete
const SH3::Cell2Index & getCellIndex() const
SH3::Surfel2Index mySurfelIndex
Surfel Index.
TDigitalSurface DigSurface
DigitalSurface type.
TDigitalSurface::DigitalSurfaceContainer DigitalSurfaceContainer
Digital Surface Container type.
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
std::vector< Face > FaceRange
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
static Parameters defaultParameters()
Aim: This class is used to simplify shape and surface creation. With it, you can create new shapes an...
Definition: Shortcuts.h:105
static KSpace getKSpace(const Point &low, const Point &up, Parameters params=parametersKSpace())
Definition: Shortcuts.h:332
std::map< Surfel, IdxSurfel > Surfel2Index
Definition: Shortcuts.h:188
std::map< Cell, IdxVertex > Cell2Index
Definition: Shortcuts.h:189
SCellRange SurfelRange
Definition: Shortcuts.h:176
static Parameters defaultParameters()
Definition: Shortcuts.h:203
TKSpace KSpace
Digital cellular space.
Definition: Shortcuts.h:111
LightDigitalSurface::SCell SCell
Definition: Shortcuts.h:163
LightDigitalSurface::Cell Cell
Definition: Shortcuts.h:162
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: The digital surface container concept describes a minimal set of inner types and methods so as t...