ViSP  2.8.0
vpAdaptativeGain.cpp
1 /****************************************************************************
2  *
3  * $Id: vpAdaptativeGain.cpp 4317 2013-07-17 09:40:17Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Adaptative gain.
36  *
37  * Authors:
38  * Nicolas Mansard
39  *
40  *****************************************************************************/
49 #include <visp/vpConfig.h>
50 
51 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
52 
53 /* --- VISP --- */
54 #include <visp/vpAdaptativeGain.h>
55 #include <visp/vpColVector.h>
56 #include <visp/vpDebug.h>
57 
58 #include <iostream>
59 #include <cmath> // std::fabs
60 #include <limits> // numeric_limits
61 
62 const double vpAdaptativeGain::DEFAULT_LAMBDA_ZERO = 1.666;
63 const double vpAdaptativeGain::DEFAULT_LAMBDA_INFINI = 0.1666;
64 const double vpAdaptativeGain::DEFAULT_LAMBDA_PENTE = 1.666;
65 
66 /* -------------------------------------------------------------------------- */
67 /* --- CONSTRUCTION --------------------------------------------------------- */
68 /* -------------------------------------------------------------------------- */
69 
77  :
78  coeff_a (),
79  coeff_b (),
80  coeff_c ()
81 {
82  vpDEBUG_TRACE (10, "# Entree constructeur par default.");
83  this ->initFromVoid ();
84 
85  vpDEBUG_TRACE (10, "# Sortie constructeur par default.");
86  return;
87 }
88 
89 /* -------------------------------------------------------------------------- */
90 /* --- INIT ----------------------------------------------------------------- */
91 /* -------------------------------------------------------------------------- */
92 
100 initFromConstant (const double lambda)
101 {
102  vpDEBUG_TRACE (10, "# Entree.");
103 
104  this ->coeff_a = 0;
105  this ->coeff_b = 1;
106  this ->coeff_c = lambda;
107 
108  vpDEBUG_TRACE (10, "# Sortie.");
109  return;
110 }
111 
112 
121 {
122  vpDEBUG_TRACE (10, "# Entree.");
123 
124  this ->initStandard (vpAdaptativeGain::DEFAULT_LAMBDA_ZERO,
127 
128  vpDEBUG_TRACE (10, "# Sortie.");
129  return;
130 }
131 
132 
143 initStandard (const double en_zero,
144  const double en_infini,
145  const double pente_en_zero)
146 {
147  vpDEBUG_TRACE (10, "# Entree.");
148 
149  this ->coeff_a = en_zero - en_infini;
150  //if (0 == this ->coeff_a)
151  if (std::fabs(this ->coeff_a) <= std::numeric_limits<double>::epsilon())
152  {
153  this ->coeff_b = 0;
154  }
155  else
156  {
157  this ->coeff_b = pente_en_zero / ( this ->coeff_a);
158  }
159  this ->coeff_c = en_infini;
160 
161  vpDEBUG_TRACE (10, "# Sortie :a,b,c= %.3f,%.3f,%.3f.",
162  this ->coeff_a, this ->coeff_b, this ->coeff_c);
163  return;
164 }
165 
166 
167 
168 /* -------------------------------------------------------------------------- */
169 /* --- MODIFICATOR ---------------------------------------------------------- */
170 /* -------------------------------------------------------------------------- */
171 
177 double vpAdaptativeGain::
179 {
180  vpDEBUG_TRACE (10, "# Entree.");
181 
182  double res = this ->coeff_a + this ->coeff_c;
183 
184  this ->coeff_a = 0;
185  this ->coeff_b = 1;
186  this ->coeff_c = res;
187 
188  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
189  return res;
190 }
191 
192 /* -------------------------------------------------------------------------- */
193 /* --- VALEUR --------------------------------------------------------------- */
194 /* -------------------------------------------------------------------------- */
195 
206 double vpAdaptativeGain::
207 value_const (const double val_e) const
208 {
209  vpDEBUG_TRACE (10, "# Entree.");
210 
211  double res = this ->coeff_a * exp (- this ->coeff_b * val_e)
212  + this ->coeff_c;
213 
214  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
215  return res;
216 }
217 
223 double vpAdaptativeGain::
224 limitValue_const (void) const
225 {
226  vpDEBUG_TRACE (10, "# Entree.");
227 
228  double res = this ->coeff_c;
229 
230  vpDEBUG_TRACE (10, "# Sortie: %.3f.", res);
231  return res;
232 }
233 
234 
235 
247 double vpAdaptativeGain::
248 value (const double val_e) const
249 {
250  vpDEBUG_TRACE (10, "# Entree.");
251 
252  this ->lambda = this ->value_const (val_e);
253 
254  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
255  return lambda;
256 }
257 
258 
265 double vpAdaptativeGain::
266 limitValue (void) const
267 {
268  vpDEBUG_TRACE (10, "# Entree.");
269 
270  this ->lambda = this ->limitValue_const ();
271 
272  vpDEBUG_TRACE (10, "# Sortie: %.3f.", this ->lambda);
273  return lambda;
274 }
275 
276 /* -------------------------------------------------------------------------- */
277 /* --- ACCESSORS ------------------------------------------------------------ */
278 /* -------------------------------------------------------------------------- */
279 
280 
281 
282 // double vpAdaptativeGain::
283 // getLastValue (void) const
284 // {
285 // return this ->lambda;
286 // }
287 
296 double vpAdaptativeGain::
297 operator() (const double val_e) const
298 {
299  return this ->value (val_e);
300 }
301 
307 double vpAdaptativeGain::
308 operator() (void) const
309 {
310  return this ->limitValue ();
311 }
312 
321 double vpAdaptativeGain::
322 operator() (const vpColVector & e) const
323 {
324  return this ->value (e .infinityNorm());
325 }
326 
327 
328 // double operator() (double val_e) const;
329 // double operator() (const CColVector & e) const;
330 
331 /* -------------------------------------------------------------------------- */
332 /* --- OUTPUT --------------------------------------------------------------- */
333 /* -------------------------------------------------------------------------- */
334 
335 
336 
344 std::ostream&
345 operator<< (std::ostream &os, const vpAdaptativeGain& lambda)
346 {
347  os << "Zero= " << lambda .coeff_a + lambda .coeff_c
348  << "\tInf= " << lambda .coeff_c
349  << "\tDeriv= " << lambda .coeff_a * lambda .coeff_b;
350 
351  return os;
352 }
353 
354 #endif
355 
356 /*
357  * Local variables:
358  * c-basic-offset: 4
359  * End:
360  */
#define vpDEBUG_TRACE
Definition: vpDebug.h:454
static const double DEFAULT_LAMBDA_INFINI
double setConstant(void)
static const double DEFAULT_LAMBDA_PENTE
void initFromConstant(double lambda)
double limitValue_const(void) const
Adaptative gain computation.
double operator()(void) const
vp_deprecated vpAdaptativeGain(void)
void initStandard(double en_zero, double en_infini, double pente_en_zero)
VISP_EXPORT std::ostream & operator<<(std::ostream &os, const vpImagePoint &ip)
Definition: vpImagePoint.h:529
double limitValue(void) const
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double value_const(double val_e) const
static const double DEFAULT_LAMBDA_ZERO
double value(double val_e) const