ViSP  2.8.0
vpFeatureTranslation.cpp
1 /****************************************************************************
2  *
3  * $Id: vpFeatureTranslation.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  * 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 {
97  init() ;
98 
99  translation = r;
100 }
101 
102 
114 {
115  init() ;
116 
117  translation = r;
118 
119  buildFrom(f2Mf1) ;
120 }
121 
129 void
131 {
132  this->f2Mf1 = f2Mf1 ;
133  s[0] = f2Mf1[0][3] ;
134  s[1] = f2Mf1[1][3] ;
135  s[2] = f2Mf1[2][3] ;
136 
137  flags[0] = true;
138 }
139 
149 void vpFeatureTranslation::set_Tx(const double t_x)
150 {
151  s[0] = t_x ;
152 }
162 void vpFeatureTranslation::set_Ty(const double t_y)
163 {
164  s[1] = t_y ;
165 }
175 void
177 {
178  s[2] = t_z ;
179 }
180 
187 {
188  return s[0] ;
189 }
190 
191 
198 {
199  return s[1] ;
200 }
201 
202 
208 double
210 {
211  return s[2] ;
212 }
213 
214 
296 vpMatrix
297 vpFeatureTranslation::interaction(const unsigned int select)
298 {
299 
300  vpMatrix L ;
301  L.resize(0,6) ;
302 
304  for (unsigned int i = 0; i < nbParameters; i++) {
305  if (flags[i] == false) {
306  switch(i){
307  case 0:
308  vpTRACE("Warning !!! The interaction matrix is computed but f2Mf1 was not set yet");
309  break;
310  default:
311  vpTRACE("Problem during the reading of the variable flags");
312  }
313  }
314  }
315  resetFlags();
316  }
317 
318  if (translation == cdMc) {
319  //This version is a simplification
320  if (vpFeatureTranslation::selectTx() & select ) {
321  vpMatrix Lx(1,6) ;
322 
323  for (int i=0 ; i < 3 ; i++)
324  Lx[0][i] = f2Mf1[0][i] ;
325  Lx[0][3] = 0 ; Lx[0][4] = 0 ; Lx[0][5] = 0 ;
326 
327  L = vpMatrix::stackMatrices(L,Lx) ;
328  }
329 
330  if (vpFeatureTranslation::selectTy() & select ) {
331  vpMatrix Ly(1,6) ;
332 
333  for (int i=0 ; i < 3 ; i++)
334  Ly[0][i] = f2Mf1[1][i] ;
335  Ly[0][3] = 0 ; Ly[0][4] = 0 ; Ly[0][5] = 0 ;
336 
337  L = vpMatrix::stackMatrices(L,Ly) ;
338  }
339 
340  if (vpFeatureTranslation::selectTz() & select ) {
341  vpMatrix Lz(1,6) ;
342 
343  for (int i=0 ; i < 3 ; i++)
344  Lz[0][i] = f2Mf1[2][i] ;
345  Lz[0][3] = 0 ; Lz[0][4] = 0 ; Lz[0][5] = 0 ;
346 
347  L = vpMatrix::stackMatrices(L,Lz) ;
348  }
349  }
350  if (translation == cMcd) {
351  //This version is a simplification
352  if (vpFeatureTranslation::selectTx() & select ) {
353  vpMatrix Lx(1,6) ;
354  Lx[0][0] = -1 ; Lx[0][1] = 0 ; Lx[0][2] = 0 ;
355  Lx[0][3] = 0 ; Lx[0][4] = -s[2] ; Lx[0][5] = s[1] ;
356 
357  L = vpMatrix::stackMatrices(L,Lx) ;
358  }
359 
360  if (vpFeatureTranslation::selectTy() & select ) {
361  vpMatrix Ly(1,6) ;
362  Ly[0][0] = 0 ; Ly[0][1] = -1 ; Ly[0][2] = 0 ;
363  Ly[0][3] = s[2] ; Ly[0][4] = 0 ; Ly[0][5] = -s[0] ;
364 
365  L = vpMatrix::stackMatrices(L,Ly) ;
366  }
367 
368  if (vpFeatureTranslation::selectTz() & select ) {
369  vpMatrix Lz(1,6) ;
370  Lz[0][0] = 0 ; Lz[0][1] = 0 ; Lz[0][2] = -1 ;
371  Lz[0][3] = -s[1] ; Lz[0][4] = s[0] ; Lz[0][5] = 0 ;
372 
373  L = vpMatrix::stackMatrices(L,Lz) ;
374  }
375  }
376 
377  if (translation == cMo) {
378  //This version is a simplification
379  if (vpFeatureTranslation::selectTx() & select ) {
380  vpMatrix Lx(1,6) ;
381  Lx[0][0] = -1 ; Lx[0][1] = 0 ; Lx[0][2] = 0 ;
382  Lx[0][3] = 0 ; Lx[0][4] = -s[2] ; Lx[0][5] = s[1] ;
383 
384  L = vpMatrix::stackMatrices(L,Lx) ;
385  }
386 
387  if (vpFeatureTranslation::selectTy() & select ) {
388  vpMatrix Ly(1,6) ;
389  Ly[0][0] = 0 ; Ly[0][1] = -1 ; Ly[0][2] = 0 ;
390  Ly[0][3] = s[2] ; Ly[0][4] = 0 ; Ly[0][5] = -s[0] ;
391 
392  L = vpMatrix::stackMatrices(L,Ly) ;
393  }
394 
395  if (vpFeatureTranslation::selectTz() & select ) {
396  vpMatrix Lz(1,6) ;
397  Lz[0][0] = 0 ; Lz[0][1] = 0 ; Lz[0][2] = -1 ;
398  Lz[0][3] = -s[1] ; Lz[0][4] = s[0] ; Lz[0][5] = 0 ;
399 
400  L = vpMatrix::stackMatrices(L,Lz) ;
401  }
402  }
403 
404  return L ;
405 }
406 
470  const unsigned int select)
471 {
472  vpColVector e(0) ;
473 
474  if(translation == cdMc || translation == cMcd)
475  {
476  if (s_star.get_s().sumSquare() > 1e-6)
477  {
478  vpERROR_TRACE("s* should be zero ! ") ;
480  "s* should be zero !")) ;
481  }
482  }
483 
484 
485  if (vpFeatureTranslation::selectTx() & select )
486  {
487  vpColVector ex(1) ;
488  ex[0] = s[0]-s_star[0] ;
489  e = vpMatrix::stackMatrices(e,ex) ;
490  }
491 
492  if (vpFeatureTranslation::selectTy() & select )
493  {
494  vpColVector ey(1) ;
495  ey[0] = s[1]-s_star[1] ;
496  e = vpMatrix::stackMatrices(e,ey) ;
497  }
498 
499  if (vpFeatureTranslation::selectTz() & select )
500  {
501  vpColVector ez(1) ;
502  ez[0] = s[2]-s_star[2] ;
503  e = vpMatrix::stackMatrices(e,ez) ;
504  }
505 
506  return e ;
507 }
508 
531 void
532 vpFeatureTranslation::print(const unsigned int select) const
533 {
534  std::cout <<"Translation 3D: ";
535  if (vpFeatureTranslation::selectTx() & select ) {
536  std::cout << s[0] << " ";
537  }
538  if (vpFeatureTranslation::selectTy() & select ) {
539  std::cout << s[1] << " ";
540  }
541  if (vpFeatureTranslation::selectTz() & select ) {
542  std::cout << s[2] << " ";
543  }
544  std::cout << std::endl;
545 }
546 
547 
560 {
561  vpFeatureTranslation *feature = NULL;
562  if (translation == cdMc)
563  feature = new vpFeatureTranslation(cdMc) ;
564  if (translation == cMo)
565  feature = new vpFeatureTranslation(cMo) ;
566  if (translation == cMcd)
567  feature = new vpFeatureTranslation(cMcd) ;
568  return feature ;
569 }
570 
571 
577 void
579  const vpImage<unsigned char> &/* I */,
580  const vpColor &/* color */,
581  unsigned int /* thickness */) const
582 {
583  static int firsttime =0 ;
584 
585  if (firsttime==0)
586  {
587  firsttime=1 ;
588  vpERROR_TRACE("not implemented") ;
589  // Do not throw and error since it is not subject
590  // to produce a failure
591  }
592 }
598 void
600  const vpImage<vpRGBa> &/* I */,
601  const vpColor &/* color */,
602  unsigned int /* thickness */) const
603 {
604  static int firsttime =0 ;
605 
606  if (firsttime==0)
607  {
608  firsttime=1 ;
609  vpERROR_TRACE("not implemented") ;
610  // Do not throw and error since it is not subject
611  // to produce a failure
612  }
613 }
614 
615 /*
616  * Local variables:
617  * c-basic-offset: 2
618  * End:
619  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:96
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:174
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:379
#define vpTRACE
Definition: vpDebug.h:401
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:760
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)
static vpMatrix stackMatrices(const vpMatrix &A, const vpMatrix &B)
Stack two Matrices C = [ A B ]^T.
Definition: vpMatrix.cpp:2263
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