DGtalTools  1.5.beta
ATVu2v0.h
1 
17 #pragma once
18 
33 #if defined(ATVu2v0_RECURSES)
34 #error Recursive header files inclusion detected in ATVu2v0.h
35 #else // defined(ATVu2v0_RECURSES)
37 #define ATVu2v0_RECURSES
38 
39 #if !defined ATVu2v0_h
41 #define ATVu2v0_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 ATVu2v0
75  template < typename TKSpace,
76  typename TLinearAlgebra = EigenLinearAlgebraBackend >
77  struct ATVu2v0 : public DECImage2D<TKSpace, TLinearAlgebra>
78  {
79  typedef TKSpace KSpace;
80  typedef TLinearAlgebra LinearAlgebra;
82  using typename Base::Space;
83  using typename Base::Point;
84  using typename Base::RealVector;
85  using typename Base::Scalar;
86  using typename Base::SCell;
87  using typename Base::Domain;
88  using typename Base::Calculus;
89  using typename Base::Index;
90  using typename Base::PrimalForm0;
91  using typename Base::PrimalForm1;
92  using typename Base::PrimalForm2;
93  using typename Base::PrimalIdentity0;
94  using typename Base::PrimalIdentity1;
95  using typename Base::PrimalIdentity2;
96  using typename Base::PrimalDerivative0;
97  using typename Base::PrimalDerivative1;
98  using typename Base::DualDerivative0;
99  using typename Base::DualDerivative1;
100  using typename Base::PrimalAntiderivative1;
101  using typename Base::PrimalAntiderivative2;
102  using typename Base::DualAntiderivative1;
103  using typename Base::DualAntiderivative2;
104  using typename Base::PrimalHodge0;
105  using typename Base::PrimalHodge1;
106  using typename Base::PrimalHodge2;
107  using typename Base::DualHodge0;
108  using typename Base::DualHodge1;
109  using typename Base::DualHodge2;
110  using Base::calculus;
111  using Base::verbose;
112  using Base::D0;
113  using Base::D1;
114  using Base::dual_D0;
115  using Base::dual_D1;
116  using Base::primal_h0;
117  using Base::primal_h1;
118  using Base::primal_h2;
119  using Base::dual_h0;
120  using Base::dual_h1;
121  using Base::dual_h2;
122 
123  typedef typename LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver;
128 
130 
131  // ----------------------- Standard services ------------------------------
132  public:
133 
137  ~ATVu2v0() = default;
138 
143  ATVu2v0( int _verbose = 1 );
144 
148  void init( Clone<KSpace> K );
149 
154  ATVu2v0 ( const ATVu2v0 & other ) = delete;
155 
160  ATVu2v0 ( ATVu2v0 && other ) = delete;
161 
167  ATVu2v0 & operator= ( const ATVu2v0 & other ) = delete;
168 
174  ATVu2v0 & operator= ( ATVu2v0 && other ) = delete;
175 
204  template <typename Image, typename Function>
205  void addInput( const Image& image,
206  const Function& f,
207  bool perfect_data = false );
208 
210  void setMetricAverage( bool average );
211 
216 
223 
232  void setAlpha( Scalar _alpha );
233 
249  void setAlpha( Scalar _alpha, const PrimalForm2& m );
250 
261  void setLambda( Scalar _lambda );
262 
273  void setEpsilon( Scalar _epsilon );
274 
277 
279  Scalar getAlpha() const { return alpha; }
280 
282  Scalar getLambda() const { return lambda; }
283 
285  Scalar getEpsilon() const { return epsilon; }
286 
289  const PrimalForm2& getG( int i ) const { return g2.at( i ); }
290 
293  const PrimalForm2& getU( int i ) const { return u2.at( i ); }
294 
296  const PrimalForm0& getV() const { return v0; }
297 
299  unsigned int size0() const { return v0.myContainer.rows(); }
300 
301  // /// @return the size of a 1-form vector
302  // unsigned int size1() const { return v1.myContainer.rows(); }
303 
304  // ----------------------- Solver --------------------------------------
305  public:
306 
309  bool solveU();
310 
313  bool solveV();
314 
320 
324 
325  // ----------------------- Interface --------------------------------------
326  public:
327 
332  void selfDisplay ( std::ostream & out ) const;
333 
338  bool isValid() const;
339 
340 
341  // ------------------------- Public Datas ------------------------------
342  public:
343 
350 
359 
360  // ------------------------- Protected Datas ------------------------------
361  protected:
362 
364  std::vector< PrimalForm2 > g2;
366  std::vector< PrimalForm2 > i2;
368  std::vector< PrimalForm2 > u2;
374  double alpha;
376  double lambda;
378  double epsilon;
379 
384 
388  std::vector< PrimalForm2 > alpha_g2;
397 
400 
401  // ------------------------- Private Datas --------------------------------
402  private:
403 
404  // ------------------------- Hidden services ------------------------------
405  protected:
406 
407  // ------------------------- Internals ------------------------------------
408  private:
409 
410  }; // end of class ATVu2v0
411 
412 
419  template <typename TKSpace, typename TLinearAlgebra>
420  std::ostream&
421  operator<< ( std::ostream & out, const ATVu2v0<TKSpace, TLinearAlgebra> & object );
422 
423 } // namespace DGtal
424 
425 
427 // Includes inline functions.
428 //#include "DGtal/dec/ATVu2v0.ih"
429 #include "ATVu2v0.ih"
430 
431 // //
433 
434 #endif // !defined ATVu2v0_h
435 
436 #undef ATVu2v0_RECURSES
437 #endif // else defined(ATVu2v0_RECURSES)
Container myContainer
static const constexpr Dimension dimension
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
Aim: This class solves a variant of Ambrosio-Tortorelli functional in a plane for u a (vector of) 2-f...
Definition: ATVu2v0.h:78
const PrimalForm2 & getG(int i) const
Definition: ATVu2v0.h:289
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 0, PRIMAL, 0, PRIMAL > SolverV
Definition: ATVu2v0.h:127
PrimalDerivative0 M01
point_to_edge average operator
Definition: ATVu2v0.h:352
Scalar getEpsilon() const
Definition: ATVu2v0.h:285
LinearAlgebra::SolverSimplicialLLT LinearAlgebraSolver
Definition: ATVu2v0.h:123
Scalar computeSNR() const
Computes the SNR of u wrt ideal input (should have been given.
~ATVu2v0()=default
PrimalForm0 v0
The v 0-form.
Definition: ATVu2v0.h:370
void selfDisplay(std::ostream &out) const
void setUFromInputAndMask()
PrimalIdentity2 alpha_Id2
alpha Id2
Definition: ATVu2v0.h:386
PrimalForm0 former_v0
The v 0-form at the previous iteration.
Definition: ATVu2v0.h:372
PrimalIdentity0 primal_L0
primal laplace operator on 0-forms
Definition: ATVu2v0.h:358
Scalar delta_v_loo
The Linfinity-norm of variation of v.
Definition: ATVu2v0.h:349
PrimalAntiderivative2 primal_AD2
Antiderivative 2-form -> to 1-form.
Definition: ATVu2v0.h:356
TLinearAlgebra LinearAlgebra
Definition: ATVu2v0.h:80
void setMetricAverage(bool average)
Use metric average to smooth L1-metric effects.
std::vector< PrimalForm2 > alpha_g2
alpha g2
Definition: ATVu2v0.h:388
ATVu2v0(const ATVu2v0 &other)=delete
SolverV solver_v
The solver for 0-form v.
Definition: ATVu2v0.h:383
ATVu2v0(int _verbose=1)
RealVector::Component Scalar
TKSpace KSpace
Definition: ATVu2v0.h:79
PrimalForm0 l_1
lambda 1
Definition: ATVu2v0.h:392
double alpha
Smoothness parameter alpha of AT (in 1/area unit)
Definition: ATVu2v0.h:374
PrimalDerivative1 M12
edge_to_face average operator
Definition: ATVu2v0.h:354
void setAlpha(Scalar _alpha, const PrimalForm2 &m)
DECImage2D< TKSpace, TLinearAlgebra > Base
Definition: ATVu2v0.h:81
Scalar checkV()
ATVu2v0(ATVu2v0 &&other)=delete
const PrimalForm2 & getU(int i) const
Definition: ATVu2v0.h:293
double epsilon
Thickness of discontinuity set (in length unit).
Definition: ATVu2v0.h:378
std::vector< PrimalForm2 > u2
The u 2-forms.
Definition: ATVu2v0.h:368
PrimalForm0 l_over_e_1
lambda/epsilon 1
Definition: ATVu2v0.h:394
Scalar getAlpha() const
Definition: ATVu2v0.h:279
void setLambda(Scalar _lambda)
DiscreteExteriorCalculusSolver< Calculus, LinearAlgebraSolver, 2, PRIMAL, 2, PRIMAL > SolverU
Definition: ATVu2v0.h:125
std::vector< PrimalForm2 > g2
The g 2-forms.
Definition: ATVu2v0.h:364
Scalar getLambda() const
Definition: ATVu2v0.h:282
void init(Clone< KSpace > K)
unsigned int size0() const
Definition: ATVu2v0.h:299
PrimalIdentity0 l_over_e_Id0
lambda/epsilon Id0
Definition: ATVu2v0.h:396
double lambda
Amount of discontinuity parameter lambda (in 1/length unit).
Definition: ATVu2v0.h:376
ATVu2v0 & operator=(const ATVu2v0 &other)=delete
Scalar delta_v_l1
The L1-norm of variation of v.
Definition: ATVu2v0.h:345
PrimalIdentity0 left_V0
(lambda / (4*epsilon)) * Id0 + lambda epsilon D0^t D0
Definition: ATVu2v0.h:390
const PrimalForm0 & getV() const
Definition: ATVu2v0.h:296
void addInput(const Image &image, const Function &f, bool perfect_data=false)
void setAlpha(Scalar _alpha)
Scalar delta_v_l2
The L2-norm of variation of v.
Definition: ATVu2v0.h:347
Scalar computeVariation()
SolverU solver_u
The solver for every 2-form u[i].
Definition: ATVu2v0.h:381
BOOST_STATIC_ASSERT((KSpace::dimension==2))
bool isValid() const
void setUFromInput()
void setEpsilon(Scalar _epsilon)
std::vector< PrimalForm2 > i2
The ideal input 2-forms (for snr computation).
Definition: ATVu2v0.h:366
bool metric_average
When 'true', use metric average, otherwise use identity.
Definition: ATVu2v0.h:399
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