ViSP  2.9.0
vpFeatureTranslation.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureTranslation.cpp 4649 2014-02-07 14:57:11Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 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  * 3D translation visual feature.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
44 #include <visp/vpBasicFeature.h>
45 #include <visp/vpFeatureTranslation.h>
46 
47 #include <visp/vpMath.h>
48 
49 // Exception
50 #include <visp/vpException.h>
51 #include <visp/vpMatrixException.h>
52 #include <visp/vpFeatureException.h>
53 
54 // Debug trace
55 #include <visp/vpDebug.h>
56 
57 
62 /*
63 
64 attributes and members directly related to the vpBasicFeature needs
65 other functionalities are useful but not mandatory
66 
67 */
68 
74 void
76 {
77  //feature dimension
78  dim_s = 3 ;
79  nbParameters = 1;
80 
81  // memory allocation
82  s.resize(dim_s) ;
83  if (flags == NULL)
84  flags = new bool[nbParameters];
85  for (unsigned int i = 0; i < nbParameters; i++) flags[i] = false;
86 
87 }
88 
96  : f2Mf1(), translation(r)
97 {
98  init() ;
99 }
100 
101 
113  : f2Mf1(), translation(r)
114 {
115  init() ;
116 
117  buildFrom(f2Mf1_) ;
118 }
119 
127 void
129 {
130  this->f2Mf1 = f2Mf1_ ;
131  s[0] = f2Mf1[0][3] ;
132  s[1] = f2Mf1[1][3] ;
133  s[2] = f2Mf1[2][3] ;
134 
135  flags[0] = true;
136 }
137 
147 void vpFeatureTranslation::set_Tx(const double t_x)
148 {
149  s[0] = t_x ;
150 }
160 void vpFeatureTranslation::set_Ty(const double t_y)
161 {
162  s[1] = t_y ;
163 }
173 void
175 {
176  s[2] = t_z ;
177 }
178 
185 {
186  return s[0] ;
187 }
188 
189 
196 {
197  return s[1] ;
198 }
199 
200 
206 double
208 {
209  return s[2] ;
210 }
211 
212 
294 vpMatrix
295 vpFeatureTranslation::interaction(const unsigned int select)
296 {
297 
298  vpMatrix L ;
299  L.resize(0,6) ;
300 
302  for (unsigned int i = 0; i < nbParameters; i++) {
303  if (flags[i] == false) {
304  switch(i){
305  case 0:
306  vpTRACE("Warning !!! The interaction matrix is computed but f2Mf1 was not set yet");
307  break;
308  default:
309  vpTRACE("Problem during the reading of the variable flags");
310  }
311  }
312  }
313  resetFlags();
314  }
315 
316  if (translation == cdMc) {
317  //This version is a simplification
318  if (vpFeatureTranslation::selectTx() & select ) {
319  vpMatrix Lx(1,6) ;
320 
321  for (int i=0 ; i < 3 ; i++)
322  Lx[0][i] = f2Mf1[0][i] ;
323  Lx[0][3] = 0 ; Lx[0][4] = 0 ; Lx[0][5] = 0 ;
324 
325  L = vpMatrix::stackMatrices(L,Lx) ;
326  }
327 
328  if (vpFeatureTranslation::selectTy() & select ) {
329  vpMatrix Ly(1,6) ;
330 
331  for (int i=0 ; i < 3 ; i++)
332  Ly[0][i] = f2Mf1[1][i] ;
333  Ly[0][3] = 0 ; Ly[0][4] = 0 ; Ly[0][5] = 0 ;
334 
335  L = vpMatrix::stackMatrices(L,Ly) ;
336  }
337 
338  if (vpFeatureTranslation::selectTz() & select ) {
339  vpMatrix Lz(1,6) ;
340 
341  for (int i=0 ; i < 3 ; i++)
342  Lz[0][i] = f2Mf1[2][i] ;
343  Lz[0][3] = 0 ; Lz[0][4] = 0 ; Lz[0][5] = 0 ;
344 
345  L = vpMatrix::stackMatrices(L,Lz) ;
346  }
347  }
348  if (translation == cMcd) {
349  //This version is a simplification
350  if (vpFeatureTranslation::selectTx() & select ) {
351  vpMatrix Lx(1,6) ;
352  Lx[0][0] = -1 ; Lx[0][1] = 0 ; Lx[0][2] = 0 ;
353  Lx[0][3] = 0 ; Lx[0][4] = -s[2] ; Lx[0][5] = s[1] ;
354 
355  L = vpMatrix::stackMatrices(L,Lx) ;
356  }
357 
358  if (vpFeatureTranslation::selectTy() & select ) {
359  vpMatrix Ly(1,6) ;
360  Ly[0][0] = 0 ; Ly[0][1] = -1 ; Ly[0][2] = 0 ;
361  Ly[0][3] = s[2] ; Ly[0][4] = 0 ; Ly[0][5] = -s[0] ;
362 
363  L = vpMatrix::stackMatrices(L,Ly) ;
364  }
365 
366  if (vpFeatureTranslation::selectTz() & select ) {
367  vpMatrix Lz(1,6) ;
368  Lz[0][0] = 0 ; Lz[0][1] = 0 ; Lz[0][2] = -1 ;
369  Lz[0][3] = -s[1] ; Lz[0][4] = s[0] ; Lz[0][5] = 0 ;
370 
371  L = vpMatrix::stackMatrices(L,Lz) ;
372  }
373  }
374 
375  if (translation == cMo) {
376  //This version is a simplification
377  if (vpFeatureTranslation::selectTx() & select ) {
378  vpMatrix Lx(1,6) ;
379  Lx[0][0] = -1 ; Lx[0][1] = 0 ; Lx[0][2] = 0 ;
380  Lx[0][3] = 0 ; Lx[0][4] = -s[2] ; Lx[0][5] = s[1] ;
381 
382  L = vpMatrix::stackMatrices(L,Lx) ;
383  }
384 
385  if (vpFeatureTranslation::selectTy() & select ) {
386  vpMatrix Ly(1,6) ;
387  Ly[0][0] = 0 ; Ly[0][1] = -1 ; Ly[0][2] = 0 ;
388  Ly[0][3] = s[2] ; Ly[0][4] = 0 ; Ly[0][5] = -s[0] ;
389 
390  L = vpMatrix::stackMatrices(L,Ly) ;
391  }
392 
393  if (vpFeatureTranslation::selectTz() & select ) {
394  vpMatrix Lz(1,6) ;
395  Lz[0][0] = 0 ; Lz[0][1] = 0 ; Lz[0][2] = -1 ;
396  Lz[0][3] = -s[1] ; Lz[0][4] = s[0] ; Lz[0][5] = 0 ;
397 
398  L = vpMatrix::stackMatrices(L,Lz) ;
399  }
400  }
401 
402  return L ;
403 }
404 
468  const unsigned int select)
469 {
470  vpColVector e(0) ;
471 
472  if(translation == cdMc || translation == cMcd)
473  {
474  if (s_star.get_s().sumSquare() > 1e-6)
475  {
476  vpERROR_TRACE("s* should be zero ! ") ;
478  "s* should be zero !")) ;
479  }
480  }
481 
482 
483  if (vpFeatureTranslation::selectTx() & select )
484  {
485  vpColVector ex(1) ;
486  ex[0] = s[0]-s_star[0] ;
487  e = vpMatrix::stackMatrices(e,ex) ;
488  }
489 
490  if (vpFeatureTranslation::selectTy() & select )
491  {
492  vpColVector ey(1) ;
493  ey[0] = s[1]-s_star[1] ;
494  e = vpMatrix::stackMatrices(e,ey) ;
495  }
496 
497  if (vpFeatureTranslation::selectTz() & select )
498  {
499  vpColVector ez(1) ;
500  ez[0] = s[2]-s_star[2] ;
501  e = vpMatrix::stackMatrices(e,ez) ;
502  }
503 
504  return e ;
505 }
506 
529 void
530 vpFeatureTranslation::print(const unsigned int select) const
531 {
532  std::cout <<"Translation 3D: ";
533  if (vpFeatureTranslation::selectTx() & select ) {
534  std::cout << s[0] << " ";
535  }
536  if (vpFeatureTranslation::selectTy() & select ) {
537  std::cout << s[1] << " ";
538  }
539  if (vpFeatureTranslation::selectTz() & select ) {
540  std::cout << s[2] << " ";
541  }
542  std::cout << std::endl;
543 }
544 
545 
558 {
559  vpFeatureTranslation *feature = NULL;
560  if (translation == cdMc)
561  feature = new vpFeatureTranslation(cdMc) ;
562  if (translation == cMo)
563  feature = new vpFeatureTranslation(cMo) ;
564  if (translation == cMcd)
565  feature = new vpFeatureTranslation(cMcd) ;
566  return feature ;
567 }
568 
569 
575 void
577  const vpImage<unsigned char> &/* I */,
578  const vpColor &/* color */,
579  unsigned int /* thickness */) const
580 {
581  static int firsttime =0 ;
582 
583  if (firsttime==0)
584  {
585  firsttime=1 ;
586  vpERROR_TRACE("not implemented") ;
587  // Do not throw and error since it is not subject
588  // to produce a failure
589  }
590 }
596 void
598  const vpImage<vpRGBa> &/* I */,
599  const vpColor &/* color */,
600  unsigned int /* thickness */) const
601 {
602  static int firsttime =0 ;
603 
604  if (firsttime==0)
605  {
606  firsttime=1 ;
607  vpERROR_TRACE("not implemented") ;
608  // Do not throw and error since it is not subject
609  // to produce a failure
610  }
611 }
612 
613 /*
614  * Local variables:
615  * c-basic-offset: 2
616  * End:
617  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
Class that defines the translation visual feature .
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:183
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpERROR_TRACE
Definition: vpDebug.h:395
#define vpTRACE
Definition: vpDebug.h:418
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
unsigned int dim_s
Dimension of the visual feature.
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const
static unsigned int selectTy()
double sumSquare() const
return sum of the Aij^2 (for all i, for all j)
Definition: vpMatrix.cpp:809
void set_Ty(const double t_y)
void set_Tx(const double t_x)
vpFeatureTranslation(vpFeatureTranslationRepresentationType r)
vpFeatureTranslation * duplicate() const
Feature duplication.
class that defines what is a visual feature
static unsigned int selectTz()
Error that can be emited by the vpBasicFeature class and its derivates.
Generic class defining intrinsic camera parameters.
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
void stackMatrices(const vpMatrix &A)
Definition: vpMatrix.cpp:3003
vpBasicFeatureDeallocatorType deallocate
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
void set_Tz(const double t_z)
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
static unsigned int selectTx()
void buildFrom(const vpHomogeneousMatrix &f2Mf1)
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector s
State of the visual feature.
void print(const unsigned int select=FEATURE_ALL) const
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94