DGtalTools  1.2.0
ATu0v1.h
1 
17 #pragma once
18 
33 #if defined(ATu0v1_RECURSES)
34 #error Recursive header files inclusion detected in ATu0v1.h
35 #else // defined(ATu0v1_RECURSES)
37 #define ATu0v1_RECURSES
38 
39 #if !defined ATu0v1_h
41 #define ATu0v1_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 ATu0v1
72  template < typename TKSpace,
73  typename TLinearAlgebra = EigenLinearAlgebraBackend >
74  struct ATu0v1 : 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::PrimalHodge0;
98  using typename Base::PrimalHodge1;
99  using typename Base::PrimalHodge2;
100  using typename Base::DualHodge0;
101  using typename Base::DualHodge1;
102  using typename Base::DualHodge2;
103  using Base::calculus;
104  using Base::verbose;
105  using Base::D0;
106  using Base::D1;
107  using Base::dual_D0;
108  using Base::dual_D1;
109  using Base::primal_h0;
110  using Base::primal_h1;
111  using Base::primal_h2;
112  using Base::dual_h0;
113  using Base::dual_h1;
114  using Base::dual_h2;
115 
116  typedef typename LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver;
117  typedef DiscreteExteriorCalculusSolver<Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL>
119  typedef DiscreteExteriorCalculusSolver<Calculus, LinearAlgebraSolver, 1, PRIMAL, 1, PRIMAL>
121 
122  BOOST_STATIC_ASSERT(( KSpace::dimension == 2 ));
123 
124  // ----------------------- Standard services ------------------------------
125  public:
126 
130  ~ATu0v1() = default;
131 
136  ATu0v1( int _verbose = 1 );
137 
141  void init( Clone<KSpace> K );
142 
147  ATu0v1 ( const ATu0v1 & other ) = delete;
148 
153  ATu0v1 ( ATu0v1 && other ) = delete;
154 
160  ATu0v1 & operator= ( const ATu0v1 & other ) = delete;
161 
167  ATu0v1 & operator= ( ATu0v1 && other ) = delete;
168 
197  template <typename Image, typename Function >
198  void addInput( const Image& image,
199  const Function& f,
200  bool perfect_data = false );
201 
206 
215  void setAlpha( Scalar _alpha );
216 
232  void setAlpha( Scalar _alpha, const PrimalForm0& m );
233 
244  void setLambda( Scalar _lambda );
245 
256  void setEpsilon( Scalar _epsilon );
257 
260 
262  Scalar getAlpha() const { return alpha; }
263 
265  Scalar getLambda() const { return lambda; }
266 
268  Scalar getEpsilon() const { return epsilon; }
269 
272  const PrimalForm0& getG( int i ) const { return g0.at( i ); }
273 
276  const PrimalForm0& getU( int i ) const { return u0.at( i ); }
277 
279  const PrimalForm1& getV() const { return v1; }
280 
282  unsigned int size0() const { return alpha_Id0.myContainer.columns(); }
283 
285  unsigned int size1() const { return v1.myContainer.rows(); }
286 
287  // ----------------------- Solver --------------------------------------
288  public:
289 
292  bool solveU();
293 
296  bool solveV();
297 
303 
307 
308  // ----------------------- Interface --------------------------------------
309  public:
310 
315  void selfDisplay ( std::ostream & out ) const;
316 
321  bool isValid() const;
322 
323 
324  // ------------------------- Public Datas ------------------------------
325  public:
326 
333 
336 
337  // ------------------------- Protected Datas ------------------------------
338  protected:
339 
341  std::vector< PrimalForm0 > g0;
343  std::vector< PrimalForm0 > i0;
345  std::vector< PrimalForm0 > u0;
351  double alpha;
353  double lambda;
355  double epsilon;
356 
361 
365  std::vector< PrimalForm0 > alpha_g0;
374 
375  // ------------------------- Private Datas --------------------------------
376  private:
377 
378  // ------------------------- Hidden services ------------------------------
379  protected:
380 
381  // ------------------------- Internals ------------------------------------
382  private:
383 
384  }; // end of class ATu0v1
385 
386 
393  template <typename TKSpace, typename TLinearAlgebra>
394  std::ostream&
395  operator<< ( std::ostream & out, const ATu0v1<TKSpace, TLinearAlgebra> & object );
396 
397 } // namespace DGtal
398 
399 
401 // Includes inline functions.
402 //#include "DGtal/dec/ATu0v1.ih"
403 #include "ATu0v1.ih"
404 
405 // //
407 
408 #endif // !defined ATu0v1_h
409 
410 #undef ATu0v1_RECURSES
411 #endif // else defined(ATu0v1_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) 0-form(s) and v ...
Definition: ATu0v1.h:75
Scalar getAlpha() const
Definition: ATu0v1.h:262
PrimalIdentity1 left_V1
epsilon * lambda * edge laplacien + (lambda / (4*epsilon)) * Id1
Definition: ATu0v1.h:371
PrimalForm1 l_1_over_4e
lambda 1/(4*epsilon) 1
Definition: ATu0v1.h:373
SolverU solver_u
The solver for every 0-form u[i].
Definition: ATu0v1.h:358
void setUFromInput()
std::vector< PrimalForm0 > g0
The g 0-forms.
Definition: ATu0v1.h:341
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL > SolverU
Definition: ATu0v1.h:118
void setAlpha(Scalar _alpha, const PrimalForm0 &m)
unsigned int size0() const
Definition: ATu0v1.h:282
ATu0v1(ATu0v1 &&other)=delete
Calculus::PrimalForm1 PrimalForm1
Scalar computeSNR() const
Computes the SNR of u wrt ideal input (should have been given.
unsigned int size1() const
Definition: ATu0v1.h:285
PrimalIdentity0 alpha_Id0
alpha Id0
Definition: ATu0v1.h:363
void setAlpha(Scalar _alpha)
std::vector< PrimalForm0 > i0
The ideal input 0-forms (for snr computation).
Definition: ATu0v1.h:343
Scalar computeVariation()
Calculus::PrimalForm0 PrimalForm0
SolverV solver_v
The solver for 1-form v.
Definition: ATu0v1.h:360
RealVector::Component Scalar
TLinearAlgebra LinearAlgebra
Definition: ATu0v1.h:77
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 1, PRIMAL, 1, PRIMAL > SolverV
Definition: ATu0v1.h:120
std::vector< PrimalForm0 > u0
The u 0-forms.
Definition: ATu0v1.h:345
double epsilon
Thickness of discontinuity set (in length unit).
Definition: ATu0v1.h:355
const PrimalForm1 & getV() const
Definition: ATu0v1.h:279
Scalar getEpsilon() const
Definition: ATu0v1.h:268
void setLambda(Scalar _lambda)
PrimalIdentity1 L1
edge laplacien
Definition: ATu0v1.h:335
PrimalForm1 former_v1
The v 1-form at the previous iteration.
Definition: ATu0v1.h:349
Scalar delta_v_loo
The Linfinity-norm of variation of v.
Definition: ATu0v1.h:332
const PrimalForm0 & getG(int i) const
Definition: ATu0v1.h:272
Calculus::PrimalIdentity0 PrimalIdentity0
~ATu0v1()=default
ATu0v1(int _verbose=1)
BOOST_STATIC_ASSERT((KSpace::dimension==2))
Scalar checkV()
void init(Clone< KSpace > K)
Scalar getLambda() const
Definition: ATu0v1.h:265
void addInput(const Image &image, const Function &f, bool perfect_data=false)
void setEpsilon(Scalar _epsilon)
ATu0v1(const ATu0v1 &other)=delete
void selfDisplay(std::ostream &out) const
PrimalForm1 v1
The v 1-form.
Definition: ATu0v1.h:347
Scalar delta_v_l1
The L1-norm of variation of v.
Definition: ATu0v1.h:328
DECImage2D< TKSpace, TLinearAlgebra > Base
Definition: ATu0v1.h:78
Scalar delta_v_l2
The L2-norm of variation of v.
Definition: ATu0v1.h:330
std::vector< PrimalForm0 > alpha_g0
alpha g0
Definition: ATu0v1.h:365
double lambda
Amount of discontinuity parameter lambda (in 1/length unit).
Definition: ATu0v1.h:353
PrimalIdentity1 l_L1
lambda * edge laplacien
Definition: ATu0v1.h:367
bool isValid() const
const PrimalForm0 & getU(int i) const
Definition: ATu0v1.h:276
double alpha
Smoothness parameter alpha of AT (in 1/area unit)
Definition: ATu0v1.h:351
Calculus::PrimalIdentity1 PrimalIdentity1
TKSpace KSpace
Definition: ATu0v1.h:76
PrimalForm1 l_1_over_4
lambda 1/4 1
Definition: ATu0v1.h:369
LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver
Definition: ATu0v1.h:116
ATu0v1 & operator=(const ATu0v1 &other)=delete
Aim: This class simplifies the development of 2D image processing tools using discrete exterior calcu...
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
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::DualHodge1 DualHodge1
DiscreteExteriorCalculus< 2, 2, LinearAlgebra > Calculus
Calculus::PrimalHodge1 PrimalHodge1
Calculus::PrimalIdentity2 PrimalIdentity2
Calculus::PrimalIdentity1 PrimalIdentity1
Calculus::PrimalHodge0 PrimalHodge0
Calculus::DualHodge0 DualHodge0
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