Visual Servoing Platform  version 3.0.0
vpTranslationVector.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Translation vector.
32  *
33  * Authors:
34  * Eric Marchand
35  * Fabien Spindler
36  *
37  *****************************************************************************/
38 
39 
40 #include <stdio.h>
41 #include <string.h>
42 
43 #include <visp3/core/vpTranslationVector.h>
44 
56 vpTranslationVector::vpTranslationVector(const double tx, const double ty, const double tz)
57  : vpArray2D<double>(3, 1)
58 {
59  (*this)[0] = tx;
60  (*this)[1] = ty;
61  (*this)[2] = tz;
62 }
63 
72  : vpArray2D<double>(3, 1)
73 {
74  M.extract( *this );
75 }
76 
85  : vpArray2D<double>(3, 1)
86 {
87  (*this)[0] = p[0];
88  (*this)[1] = p[1];
89  (*this)[2] = p[2];
90 }
91 
105  : vpArray2D<double>(tv)
106 {
107 }
108 
122 {
123  M.extract( *this );
124  return *this ;
125 }
126 
138 {
139  (*this)[0] = p[0];
140  (*this)[1] = p[1];
141  (*this)[2] = p[2];
142  return *this ;
143 }
144 
154 vpTranslationVector::buildFrom(const double tx, const double ty, const double tz)
155 {
156  set(tx, ty, tz);
157  return *this ;
158 }
159 
166 void
167 vpTranslationVector::set(const double tx, const double ty, const double tz)
168 {
169  (*this)[0] = tx ;
170  (*this)[1] = ty ;
171  (*this)[2] = tz ;
172 }
173 
193 {
195 
196  for (unsigned int i=0;i<3;i++) s[i] = (*this)[i]+tv[i] ;
197 
198  return s;
199 }
200 
220 {
221  vpTranslationVector sub ;
222 
223  for (unsigned int i=0;i<3;i++) sub[i] = (*this)[i]-tv[i] ;
224 
225  return sub;
226 }
227 
228 
244 {
246  for (unsigned int i=0;i<dsize;i++)
247  {
248  *(tv.data + i) = -*(data + i) ;
249  }
250 
251  return tv;
252 }
253 
270 {
272  for (unsigned int i=0;i<dsize;i++) {
273  *(tv.data + i) = (*(data + i)) * x ;
274  }
275 
276  return tv;
277 }
278 
289 {
290  vpMatrix M(rowNum, v.getCols());
291  for (unsigned int i=0; i<rowNum; i++) {
292  for (unsigned int j=0; j<v.getCols(); j++) {
293  M[i][j] = (*this)[i] * v[j];
294  }
295  }
296  return M;
297 }
298 
307 {
308  for (unsigned int i=0;i<rowNum;i++)
309  (*this)[i] *= x;
310  return (*this);
311 }
320 {
321  for (unsigned int i=0;i<rowNum;i++)
322  (*this)[i] /= x;
323  return (*this);
324 }
325 
342 {
344  for (unsigned int i=0;i<dsize;i++) {
345  *(tv.data + i) = (*(data + i)) / x ;
346  }
347 
348  return tv;
349 }
350 
365 {
366  unsigned int k = tv.rowNum ;
367  if (rowNum != k){
368  try {
369  resize(k, 1);
370  }
371  catch(...)
372  {
373  throw ;
374  }
375  }
376 
377  memcpy(data, tv.data, rowNum*sizeof(double)) ;
378 
379  return *this;
380 }
381 
394 {
395  double *d = data ;
396 
397  for (int i=0;i<3;i++)
398  *(d++)= x ;
399 
400  return *this;
401 }
402 
420 void
422 {
423  M.resize(3,3) ;
424  M[0][0] = 0 ; M[0][1] = -tv[2] ; M[0][2] = tv[1] ;
425  M[1][0] = tv[2] ; M[1][1] = 0 ; M[1][2] = -tv[0] ;
426  M[2][0] = -tv[1]; M[2][1] = tv[0] ; M[2][2] = 0 ;
427 }
428 
447 vpMatrix
449 {
450  vpMatrix M(3, 3);
451  skew(tv,M);
452  return M;
453 }
454 
473 vpMatrix
475 {
476  vpMatrix M(3, 3);
477  skew(*this,M);
478  return M;
479 }
480 
481 
493  const vpTranslationVector &b)
494 {
495  vpMatrix skew_a = vpTranslationVector::skew(a) ;
496  return (vpTranslationVector)(skew_a * b);
497 }
498 
503 {
504  vpRowVector v(rowNum);
505  memcpy(v.data, data, rowNum*sizeof(double)) ;
506  return v;
507 }
508 
517 {
518  double norm=0.0;
519  double x ;
520  for (unsigned int i=0;i<dsize;i++) {
521  x = *(data +i); norm += x*x;
522  }
523 
524  return sqrt(norm);
525 }
526 
533 {
534  double sum_square=0.0;
535  double x ;
536 
537  for (unsigned int i=0;i<rowNum;i++) {
538  x=rowPtrs[i][0];
539  sum_square += x*x;
540  }
541 
542  return sum_square;
543 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:92
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
Definition: vpArray2D.h:167
vpTranslationVector & operator*=(double x)
static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of row vector and the associated operations.
Definition: vpRowVector.h:70
vpTranslationVector operator-() const
Type * data
Address of the first element of the data array.
Definition: vpArray2D.h:84
Implementation of a generic 2D array used as vase class of matrices and vectors.
Definition: vpArray2D.h:70
unsigned int getCols() const
Return the number of columns of the 2D array.
Definition: vpArray2D.h:154
unsigned int rowNum
Number of rows in the array.
Definition: vpArray2D.h:74
vpTranslationVector operator/(const double x) const
double euclideanNorm() const
void resize(const unsigned int nrows, const unsigned int ncols, const bool flagNullify=true)
void extract(vpRotationMatrix &R) const
vpRowVector t() const
vpTranslationVector & operator/=(double x)
Implementation of a pose vector and operations on poses.
Definition: vpPoseVector.h:93
vpMatrix operator*(const vpRowVector &v) const
vpTranslationVector & operator=(const vpTranslationVector &tv)
unsigned int dsize
Current array size (rowNum * colNum)
Definition: vpArray2D.h:80
void set(const double tx, const double ty, const double tz)
Class that consider the case of a translation vector.
double ** rowPtrs
Address of the first element of each rows.
Definition: vpArray2D.h:78
vpTranslationVector buildFrom(const double tx, const double ty, const double tz)
vpTranslationVector operator+(const vpTranslationVector &tv) const