DGtalTools  1.2.0
ATu2v0.h
1 
17 #pragma once
18 
33 #if defined(ATu2v0_RECURSES)
34 #error Recursive header files inclusion detected in ATu2v0.h
35 #else // defined(ATu2v0_RECURSES)
37 #define ATu2v0_RECURSES
38 
39 #if !defined ATu2v0_h
41 #define ATu2v0_h
42 
44 // Inclusions
45 #include <iostream>
46 // always include EigenSupport.h before any other Eigen headers
47 #include "DGtal/math/linalg/EigenSupport.h"
48 #include "DGtal/base/Common.h"
49 #include "DGtal/dec/DiscreteExteriorCalculus.h"
50 #include "DGtal/dec/DiscreteExteriorCalculusSolver.h"
51 #include "DGtal/dec/DiscreteExteriorCalculusFactory.h"
52 #include "DECImageHelpers.h"
53 
55 
56 namespace DGtal
57 {
58 
60  // template class ATu2v0
72  template < typename TKSpace,
73  typename TLinearAlgebra = EigenLinearAlgebraBackend >
74  struct ATu2v0 : public DECImage2D<TKSpace, TLinearAlgebra>
75  {
76  typedef TKSpace KSpace;
77  typedef TLinearAlgebra LinearAlgebra;
79  using typename Base::Space;
80  using typename Base::Point;
81  using typename Base::RealVector;
82  using typename Base::Scalar;
83  using typename Base::SCell;
84  using typename Base::Domain;
85  using typename Base::Calculus;
86  using typename Base::Index;
87  using typename Base::PrimalForm0;
88  using typename Base::PrimalForm1;
89  using typename Base::PrimalForm2;
90  using typename Base::PrimalIdentity0;
91  using typename Base::PrimalIdentity1;
92  using typename Base::PrimalIdentity2;
93  using typename Base::PrimalDerivative0;
94  using typename Base::PrimalDerivative1;
95  using typename Base::DualDerivative0;
96  using typename Base::DualDerivative1;
97  using typename Base::PrimalAntiderivative1;
98  using typename Base::PrimalAntiderivative2;
99  using typename Base::DualAntiderivative1;
100  using typename Base::DualAntiderivative2;
101  using typename Base::PrimalHodge0;
102  using typename Base::PrimalHodge1;
103  using typename Base::PrimalHodge2;
104  using typename Base::DualHodge0;
105  using typename Base::DualHodge1;
106  using typename Base::DualHodge2;
107  using Base::calculus;
108  using Base::verbose;
109  using Base::D0;
110  using Base::D1;
111  using Base::dual_D0;
112  using Base::dual_D1;
113  using Base::primal_h0;
114  using Base::primal_h1;
115  using Base::primal_h2;
116  using Base::dual_h0;
117  using Base::dual_h1;
118  using Base::dual_h2;
119 
120  typedef typename LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver;
121  typedef DiscreteExteriorCalculusSolver<Calculus, LinearAlgebraSolver, 2, PRIMAL, 2, PRIMAL>
123  typedef DiscreteExteriorCalculusSolver<Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL>
125 
126  BOOST_STATIC_ASSERT(( KSpace::dimension == 2 ));
127 
128  // ----------------------- Standard services ------------------------------
129  public:
130 
134  ~ATu2v0() = default;
135 
140  ATu2v0( int _verbose = 1 );
141 
145  void init( Clone<KSpace> K );
146 
151  ATu2v0 ( const ATu2v0 & other ) = delete;
152 
157  ATu2v0 ( ATu2v0 && other ) = delete;
158 
164  ATu2v0 & operator= ( const ATu2v0 & other ) = delete;
165 
171  ATu2v0 & operator= ( ATu2v0 && other ) = delete;
172 
201  template <typename Image, typename Function>
202  void addInput( const Image& image,
203  const Function& f,
204  bool perfect_data = false );
205 
207  void setMetricAverage( bool average );
208 
213 
220 
229  void setAlpha( Scalar _alpha );
230 
246  void setAlpha( Scalar _alpha, const PrimalForm2& m );
247 
258  void setLambda( Scalar _lambda );
259 
270  void setEpsilon( Scalar _epsilon );
271 
274 
276  Scalar getAlpha() const { return alpha; }
277 
279  Scalar getLambda() const { return lambda; }
280 
282  Scalar getEpsilon() const { return epsilon; }
283 
286  const PrimalForm2& getG( int i ) const { return g2.at( i ); }
287 
290  const PrimalForm2& getU( int i ) const { return u2.at( i ); }
291 
293  const PrimalForm0& getV() const { return v0; }
294 
296  unsigned int size0() const { return v0.myContainer.rows(); }
297 
298  // /// @return the size of a 1-form vector
299  // unsigned int size1() const { return v1.myContainer.rows(); }
300 
301  // ----------------------- Solver --------------------------------------
302  public:
303 
306  bool solveU();
307 
310  bool solveV();
311 
317 
321 
322  // ----------------------- Interface --------------------------------------
323  public:
324 
329  void selfDisplay ( std::ostream & out ) const;
330 
335  bool isValid() const;
336 
337 
338  // ------------------------- Public Datas ------------------------------
339  public:
340 
347 
354 
355  // ------------------------- Protected Datas ------------------------------
356  protected:
357 
359  std::vector< PrimalForm2 > g2;
361  std::vector< PrimalForm2 > i2;
363  std::vector< PrimalForm2 > u2;
369  double alpha;
371  double lambda;
373  double epsilon;
374 
379 
383  std::vector< PrimalForm2 > alpha_g2;
392 
395 
396  // ------------------------- Private Datas --------------------------------
397  private:
398 
399  // ------------------------- Hidden services ------------------------------
400  protected:
401 
402  // ------------------------- Internals ------------------------------------
403  private:
404 
405  }; // end of class ATu2v0
406 
407 
414  template <typename TKSpace, typename TLinearAlgebra>
415  std::ostream&
416  operator<< ( std::ostream & out, const ATu2v0<TKSpace, TLinearAlgebra> & object );
417 
418 } // namespace DGtal
419 
420 
422 // Includes inline functions.
423 //#include "DGtal/dec/ATu2v0.ih"
424 #include "ATu2v0.ih"
425 
426 // //
428 
429 #endif // !defined ATu2v0_h
430 
431 #undef ATu2v0_RECURSES
432 #endif // else defined(ATu2v0_RECURSES)
Definition: ATu0v1.h:57
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
Aim: This class solves Ambrosio-Tortorelli functional in a plane for u a (vector of) 2-form(s) and v ...
Definition: ATu2v0.h:75
std::vector< PrimalForm2 > i2
The ideal input 2-forms (for snr computation).
Definition: ATu2v0.h:361
PrimalForm0 l_1_over_4e
lambda 1/(4*epsilon) 1
Definition: ATu2v0.h:389
Scalar checkV()
SolverV solver_v
The solver for 0-form v.
Definition: ATu2v0.h:378
double epsilon
Thickness of discontinuity set (in length unit).
Definition: ATu2v0.h:373
Scalar computeSNR() const
Computes the SNR of u wrt ideal input (should have been given.
void setUFromInput()
bool metric_average
When 'true', use metric average, otherwise use identity.
Definition: ATu2v0.h:394
Scalar computeVariation()
ATu2v0(const ATu2v0 &other)=delete
void setEpsilon(Scalar _epsilon)
void addInput(const Image &image, const Function &f, bool perfect_data=false)
Scalar delta_v_l2
The L2-norm of variation of v.
Definition: ATu2v0.h:344
double lambda
Amount of discontinuity parameter lambda (in 1/length unit).
Definition: ATu2v0.h:371
PrimalIdentity0 l_1_over_4e_Id0
lambda 1/(4_epsilon) Id0
Definition: ATu2v0.h:391
void selfDisplay(std::ostream &out) const
PrimalAntiderivative2 primal_AD2
Antiderivative 2-form -> to 1-form.
Definition: ATu2v0.h:353
Scalar getLambda() const
Definition: ATu2v0.h:279
Scalar delta_v_loo
The Linfinity-norm of variation of v.
Definition: ATu2v0.h:346
void init(Clone< KSpace > K)
BOOST_STATIC_ASSERT((KSpace::dimension==2))
Scalar getAlpha() const
Definition: ATu2v0.h:276
TLinearAlgebra LinearAlgebra
Definition: ATu2v0.h:77
Calculus::PrimalDerivative0 PrimalDerivative0
Calculus::PrimalForm0 PrimalForm0
RealVector::Component Scalar
ATu2v0(ATu2v0 &&other)=delete
~ATu2v0()=default
std::vector< PrimalForm2 > u2
The u 2-forms.
Definition: ATu2v0.h:363
SolverU solver_u
The solver for every 2-form u[i].
Definition: ATu2v0.h:376
PrimalForm0 v0
The v 0-form.
Definition: ATu2v0.h:365
PrimalForm0 former_v0
The v 0-form at the previous iteration.
Definition: ATu2v0.h:367
Calculus::PrimalForm2 PrimalForm2
LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver
Definition: ATu2v0.h:120
Calculus::PrimalDerivative1 PrimalDerivative1
void setUFromInputAndMask()
PrimalIdentity0 left_V0
(lambda / (4*epsilon)) * Id0 + lambda epsilon D0^t D0
Definition: ATu2v0.h:385
PrimalForm0 l_1_over_4
lambda 1/4 1
Definition: ATu2v0.h:387
Scalar getEpsilon() const
Definition: ATu2v0.h:282
Scalar delta_v_l1
The L1-norm of variation of v.
Definition: ATu2v0.h:342
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 2, PRIMAL, 2, PRIMAL > SolverU
Definition: ATu2v0.h:122
ATu2v0(int _verbose=1)
Calculus::PrimalIdentity0 PrimalIdentity0
void setAlpha(Scalar _alpha, const PrimalForm2 &m)
PrimalDerivative1 M12
edge_to_face average operator
Definition: ATu2v0.h:351
std::vector< PrimalForm2 > g2
The g 2-forms.
Definition: ATu2v0.h:359
const PrimalForm2 & getU(int i) const
Definition: ATu2v0.h:290
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL > SolverV
Definition: ATu2v0.h:124
double alpha
Smoothness parameter alpha of AT (in 1/area unit)
Definition: ATu2v0.h:369
PrimalDerivative0 M01
point_to_edge average operator
Definition: ATu2v0.h:349
TKSpace KSpace
Definition: ATu2v0.h:76
std::vector< PrimalForm2 > alpha_g2
alpha g2
Definition: ATu2v0.h:383
void setMetricAverage(bool average)
Use metric average to smooth L1-metric effects.
Calculus::PrimalIdentity2 PrimalIdentity2
const PrimalForm2 & getG(int i) const
Definition: ATu2v0.h:286
void setAlpha(Scalar _alpha)
unsigned int size0() const
Definition: ATu2v0.h:296
ATu2v0 & operator=(const ATu2v0 &other)=delete
PrimalIdentity2 alpha_Id2
alpha Id2
Definition: ATu2v0.h:381
bool isValid() const
void setLambda(Scalar _lambda)
Calculus::PrimalAntiderivative2 PrimalAntiderivative2
DECImage2D< TKSpace, TLinearAlgebra > Base
Definition: ATu2v0.h:78
const PrimalForm0 & getV() const
Definition: ATu2v0.h:293
Aim: This class simplifies the development of 2D image processing tools using discrete exterior calcu...
Calculus::DualAntiderivative1 DualAntiderivative1
int verbose
The verbose level (0: silent).
DualDerivative0 dual_D0
dual derivative dual 0-form -> dual 1-form
Calculus::DualDerivative0 DualDerivative0
Calculus::PrimalHodge2 PrimalHodge2
PrimalHodge2 primal_h2
hodge star: 2-form -> dual 2-form
PrimalDerivative0 D0
primal derivative: 0-form -> 1-form
Calculus calculus
The discrete exterior calculus instance.
DualHodge0 dual_h0
hodge star: dual 0-form -> 0-form
Calculus::PrimalForm1 PrimalForm1
Calculus::DualHodge2 DualHodge2
Calculus::PrimalAntiderivative1 PrimalAntiderivative1
DualHodge1 dual_h1
hodge star: dual 1-form -> 1-form
KSpace::Space Space
HyperRectDomain< Space > Domain
Calculus::PrimalDerivative0 PrimalDerivative0
Calculus::PrimalForm0 PrimalForm0
RealVector::Component Scalar
Calculus::PrimalForm2 PrimalForm2
Calculus::PrimalDerivative1 PrimalDerivative1
DualHodge2 dual_h2
hodge star: dual 2-form -> 2-form
PrimalHodge0 primal_h0
hodge star: 0-form -> dual 0-form
Calculus::PrimalIdentity0 PrimalIdentity0
PrimalHodge1 primal_h1
hodge star: 1-form -> dual 1-form
Space::Point Point
Calculus::Index Index
Space::RealVector RealVector
Calculus::DualAntiderivative2 DualAntiderivative2
Calculus::DualHodge1 DualHodge1
DiscreteExteriorCalculus< 2, 2, LinearAlgebra > Calculus
Calculus::PrimalHodge1 PrimalHodge1
Calculus::PrimalIdentity2 PrimalIdentity2
Calculus::PrimalIdentity1 PrimalIdentity1
Calculus::PrimalHodge0 PrimalHodge0
Calculus::DualHodge0 DualHodge0
Calculus::PrimalAntiderivative2 PrimalAntiderivative2
KSpace::SCell SCell
PrimalDerivative1 D1
primal derivative: 1-form -> 2-form
Calculus::DualDerivative1 DualDerivative1
DualDerivative1 dual_D1
dual derivative dual 1-form -> dual 2-form