ViSP  2.8.0
vpFeatureDepth.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureDepth.cpp 4056 2013-01-05 13:04:42Z 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  * 2D point visual feature.
36  *
37  * Authors:
38  * Nicolas Melchior
39  *
40  *****************************************************************************/
41 
42 
49 #include <visp/vpBasicFeature.h>
50 #include <visp/vpFeatureDepth.h>
51 
52 // Exception
53 #include <visp/vpException.h>
54 #include <visp/vpMatrixException.h>
55 #include <visp/vpFeatureException.h>
56 
57 // Debug trace
58 #include <visp/vpDebug.h>
59 
60 // math
61 #include <visp/vpMath.h>
62 
63 #include <visp/vpFeatureDisplay.h>
64 
65 
66 
67 /*
68 
69 
70 
71 attributes and members directly related to the vpBasicFeature needs
72 other functionalities ar useful but not mandatory
73 
74 
75 
76 
77 
78 */
79 
83 void
85 {
86  //feature dimension
87  dim_s = 1 ;
88  nbParameters = 3;
89 
90  // memory allocation
91  s.resize(dim_s) ;
92  if (flags == NULL)
93  flags = new bool[nbParameters];
94  for (unsigned int i = 0; i < nbParameters; i++) flags[i] = false;
95 }
96 
97 
102 {
103  init() ;
104 }
105 
106 
112 void
113 vpFeatureDepth::set_LogZoverZstar(const double LogZoverZstar)
114 {
115  s[0] = LogZoverZstar ;
116 }
117 
118 
124 double
126 {
127  return s[0] ;
128 }
129 
130 
136 void
137 vpFeatureDepth::set_x(const double x)
138 {
139  this->x = x ;
140  flags[0] = true;
141 }
142 
143 
149 double
151 {
152  return x ;
153 }
154 
155 
161 void
162 vpFeatureDepth::set_y(const double y)
163 {
164  this->y = y ;
165  flags[1] = true;
166 }
167 
168 
174 double
176 {
177  return y ;
178 }
179 
185 void
186 vpFeatureDepth::set_Z(const double Z)
187 {
188  this->Z = Z ;
189  flags[2] = true;
190 }
191 
192 
198 double
200 {
201  return Z ;
202 }
203 
204 
213 void
215  const double y,
216  const double Z,
217  const double LogZoverZstar)
218 {
219  set_x(x) ;
220  set_y(y) ;
221  set_Z(Z) ;
222  set_LogZoverZstar(LogZoverZstar) ;
223  for( unsigned int i = 0; i < nbParameters; i++) flags[i] = true;
224 }
225 
226 
248 vpMatrix
249 vpFeatureDepth::interaction(const unsigned int select)
250 {
251  vpMatrix L ;
252 
254  {
255  for (unsigned int i = 0; i < nbParameters; i++)
256  {
257  if (flags[i] == false)
258  {
259  switch(i){
260  case 0:
261  vpTRACE("Warning !!! The interaction matrix is computed but x was not set yet");
262  break;
263  case 1:
264  vpTRACE("Warning !!! The interaction matrix is computed but y was not set yet");
265  break;
266  case 2:
267  vpTRACE("Warning !!! The interaction matrix is computed but z was not set yet");
268  break;
269  default:
270  vpTRACE("Problem during the reading of the variable flags");
271  }
272  }
273  }
274  resetFlags();
275  }
276 
277  L.resize(1,6) ;
278 
279  double x = get_x();
280  double y = get_y();
281  double Z = get_Z();
282 
283  if (Z < 0)
284  {
285  vpERROR_TRACE("Point is behind the camera ") ;
286  std::cout <<"Z = " << Z << std::endl ;
287 
289  "Point is behind the camera ")) ;
290  }
291 
292  if (fabs(Z) < 1e-6)
293  {
294  vpERROR_TRACE("Point Z coordinates is null ") ;
295  std::cout <<"Z = " << Z << std::endl ;
296 
298  "Point Z coordinates is null")) ;
299  }
300 
301  if (FEATURE_ALL & select)
302  {
303  L = 0;
304  L[0][0] = 0;
305  L[0][1] = 0;
306  L[0][2] = -1/Z;
307  L[0][3] = -y;
308  L[0][4] = x;
309  L[0][5] = 0;
310  }
311 
312  return L ;
313 }
314 
315 
353  const unsigned int select)
354 {
355 
356  if (fabs(s_star.get_s().sumSquare()) > 1e-6)
357  {
358  vpERROR_TRACE("s* should be zero ! ") ;
360  "s* should be zero !")) ;
361  }
362 
363  vpColVector e(1) ;
364  if(FEATURE_ALL & select)
365  {
366  e[0] = s[0];
367  }
368 
369  return e ;
370 }
371 
372 
387 void
388 vpFeatureDepth::print(const unsigned int select ) const
389 {
390  if (FEATURE_ALL & select)
391  {
392  std::cout <<"Point: x=" << get_x() ;
393  std::cout <<" Point: y=" << get_y() ;
394  std::cout <<" Point: Z=" << get_Z() ;
395 
396  std::cout << " log(Z/Z*)=" << get_LogZoverZstar() ;
397 
398  std::cout <<std::endl ;
399  }
400 }
401 
402 
411 void
412 vpFeatureDepth::buildFrom(const double x, const double y, const double Z, const double LogZoverZstar)
413 {
414 
415  s[0] = LogZoverZstar;
416 
417  this->x = x ;
418  this->y = y ;
419  this->Z = Z ;
420 
421  if (Z < 0)
422  {
423  vpERROR_TRACE("Point is behind the camera ") ;
424  std::cout <<"Z = " << Z << std::endl ;
425 
427  "Point is behind the camera ")) ;
428  }
429 
430  if (fabs(Z) < 1e-6)
431  {
432  vpERROR_TRACE("Point Z coordinates is null ") ;
433  std::cout <<"Z = " << Z << std::endl ;
434 
436  "Point Z coordinates is null")) ;
437  }
438 
439  for( unsigned int i = 0; i < nbParameters; i++) flags[i] = true;
440 
441 }
442 
443 
444 
456 {
457  vpFeatureDepth *feature = new vpFeatureDepth;
458  return feature ;
459 }
460 
466 void
468  const vpImage<unsigned char> &/* I */,
469  const vpColor &/* color */,
470  unsigned int /* thickness */) const
471 {
472  static int firsttime =0 ;
473 
474  if (firsttime==0)
475  {
476  firsttime=1 ;
477  vpERROR_TRACE("not implemented") ;
478  // Do not throw and error since it is not subject
479  // to produce a failure
480  }
481 }
487 void
489  const vpImage<vpRGBa> &/* I */,
490  const vpColor &/* color */,
491  unsigned int /* thickness */) const
492 {
493  static int firsttime =0 ;
494 
495  if (firsttime==0)
496  {
497  firsttime=1 ;
498  vpERROR_TRACE("not implemented") ;
499  // Do not throw and error since it is not subject
500  // to produce a failure
501  }
502 }
503 
504 /*
505  * Local variables:
506  * c-basic-offset: 2
507  * End:
508  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
bool * flags
Ensure that all the parameters needed to compute the iteraction matrix are set.
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:174
static const unsigned int FEATURE_ALL
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
#define vpERROR_TRACE
Definition: vpDebug.h:379
#define vpTRACE
Definition: vpDebug.h:401
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
void buildFrom(const double x, const double y, const double Z, const double LogZoverZstar)
Class that defines a 3D point visual feature which is composed by one parameters that is that defin...
unsigned int dim_s
Dimension of the visual feature.
void print(const unsigned int select=FEATURE_ALL) const
void set_y(const double y)
double get_Z() const
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
Definition: vpMatrix.cpp:760
void set_LogZoverZstar(const double LogZoverZstar)
class that defines what is a visual feature
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
void set_x(const double x)
Error that can be emited by the vpBasicFeature class and its derivates.
Generic class defining intrinsic camera parameters.
double get_y() const
vpBasicFeatureDeallocatorType deallocate
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
void set_Z(const double Z)
double get_LogZoverZstar() const
void set_xyZLogZoverZstar(const double x, const double y, const double Z, const double logZZs)
vpFeatureDepth * duplicate() const
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
double get_x() const
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector s
State of the visual feature.
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94