DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
AngleLinearMinimizer.h
1 
17 #pragma once
18 
35 #if defined(AngleLinearMinimizer_RECURSES)
36 #error Recursive header files inclusion detected in AngleLinearMinimizer.h
37 #else // defined(AngleLinearMinimizer_RECURSES)
38 
39 #define AngleLinearMinimizer_RECURSES
40 
41 #if !defined AngleLinearMinimizer_h
42 
43 #define AngleLinearMinimizer_h
44 
46 // Inclusions
47 #include <iostream>
48 #include <vector>
49 #include "DGtal/base/Common.h"
50 #include "DGtal/math/AngleComputer.h"
51 #include "DGtal/arithmetic/ModuloComputer.h"
52 //#include "DGtal/io/boards/Board2D.h"
54 
55 namespace DGtal
56 {
57 
59 // class AngleLinearMinimizer
69 {
70 
71 public:
75  struct ValueInfo
76  {
80  double value;
81 
85  double oldValue;
86 
90  double min;
91 
95  double max;
96 
100  double distToNext;
101 
102  };
103 
104 
105 
106  // ----------------------- Standard services ------------------------------
107 public:
108 
112  virtual ~AngleLinearMinimizer();
113 
118 
122  void reset();
123 
129  void init( unsigned int nbMax );
130 
131 
135  ValueInfo & rw( unsigned int i );
136 
137 
141  const ValueInfo & ro( unsigned int i ) const;
142 
146  unsigned int maxSize() const;
147 
151  unsigned int size() const;
152 
157  void setSize( unsigned int nb );
158 
165  void setIsCurveOpen( bool is_curve_open = false );
166 
167 
168 
169 
170  // ------------------------- Optimization services --------------------------
171 
172 public:
173 
179  double getEnergy( unsigned int i1, unsigned int i2 ) const;
180 
186  double getFormerEnergy( unsigned int i1, unsigned int i2 ) const;
187 
188 
192  std::vector<double> getGradient() const;
193 
194 
198  std::vector<double> getFormerGradient() const;
199 
209  double optimize();
210 
211 
224  double optimize( unsigned int i1, unsigned int i2 );
225 
226 
230  double sum() const;
231 
232 
233 
237  double max() const;
238 
239 
240 protected:
241 
251  virtual void oneStep( unsigned int i1, unsigned int i2 );
252 
253 
254 public:
263  virtual double lastDelta() const;
264 
265 
266 
267 
268 
269  // --------------- CDrawableWithBoard2D realization -------------------
270  public:
271 
276  //DrawableWithBoard2D* defaultStyle( std::string mode = "" ) const;
277 
281  std::string className() const;
282 
283  // ----------------------- Interface --------------------------------------
284 public:
285 
286 
291  void selfDisplay ( std::ostream & out ) const;
292 
297  bool isValid() const;
298 
299  // ------------------------- Protected Datas ------------------------------
300 
301 protected:
306 
311 
316  unsigned int mySize;
317 
318 private:
319 
323  unsigned int myMaxSize;
324 
325 
326 
327 
328  // ------------------------- Private Datas --------------------------------
329 private:
333  double mySum;
334 
338  double myMax;
339 
340  // ------------------------- Hidden services ------------------------------
341 
342 
343 
344 private:
358 
359 
360 
361  // ------------------------- Internals ------------------------------------
362 private:
363 
364 }; // end of class AngleLinearMinimizer
365 
366 
367 
368 
373  {
374  public:
379 
384 
385  protected:
386 
395  virtual void oneStep( unsigned int i1, unsigned int i2 );
396 
397 public:
406  virtual double lastDelta() const;
407 
408  // ----------------------- Interface --------------------------------------
409  public:
414  virtual void selfDisplay( std::ostream & aStream ) const;
415 
416  };
417 
418 
419 
424  {
425  private:
426 
430  double myStep;
431 
432  public:
436  AngleLinearMinimizerByGradientDescent( double step = 0.1 );
437 
442 
443  protected:
444 
453  virtual void oneStep( unsigned int i1, unsigned int i2 );
454 
455 public:
464  virtual double lastDelta() const;
465 
466  // ----------------------- Interface --------------------------------------
467  public:
472  virtual void selfDisplay( std::ostream & aStream ) const;
473 
474  };
475 
476 
482  {
483  private:
484 
488  double myStep;
489 
490  public:
495 
500 
501  protected:
502 
511  virtual void oneStep( unsigned int i1, unsigned int i2 );
512 
513 public:
522  virtual double lastDelta() const;
523 
524  // ----------------------- Interface --------------------------------------
525  public:
530  virtual void selfDisplay( std::ostream & aStream ) const;
531 
532  };
533 
534 
535 
536 
543 std::ostream&
544 operator<< ( std::ostream & out, const AngleLinearMinimizer & object );
545 
546 
547 } // namespace DGtal
548 
549 
551 // Includes inline functions.
552 #include "DGtal/math/AngleLinearMinimizer.ih"
553 
554 // //
556 
557 #endif // !defined AngleLinearMinimizer_h
558 
559 #undef AngleLinearMinimizer_RECURSES
560 #endif // else defined(AngleLinearMinimizer_RECURSES)