ViSP  2.9.0
vpTranslationVector.cpp
1 /****************************************************************************
2  *
3  * $Id: vpTranslationVector.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  * Translation vector.
36  *
37  * Authors:
38  * Eric Marchand
39  * Fabien Spindler
40  *
41  *****************************************************************************/
42 
43 
44 #include <visp/vpTranslationVector.h>
45 #include <stdio.h>
46 #include <string.h>
47 
48 // Exception
49 #include <visp/vpException.h>
50 #include <visp/vpMatrixException.h>
51 
52 // Debug trace
53 #include <visp/vpDebug.h>
54 
60 void vpTranslationVector::init()
62 {
63  resize(3) ;
64 }
65 
73  const double ty,
74  const double tz)
75 {
76  init() ;
77  (*this)[0] = tx ;
78  (*this)[1] = ty ;
79  (*this)[2] = tz ;
80 }
81 
95 {
96 }
97 
104 void
105 vpTranslationVector::set(const double tx,
106  const double ty,
107  const double tz)
108 {
109  (*this)[0] = tx ;
110  (*this)[1] = ty ;
111  (*this)[2] = tz ;
112 }
113 
133 {
134  vpTranslationVector sum ;
135 
136  for (unsigned int i=0;i<3;i++) sum[i] = (*this)[i]+tv[i] ;
137 
138  return sum;
139 }
140 
160 {
161  vpTranslationVector sub ;
162 
163  for (unsigned int i=0;i<3;i++) sub[i] = (*this)[i]-tv[i] ;
164 
165  return sub;
166 }
167 
168 
184 {
186  for (unsigned int i=0;i<dsize;i++)
187  {
188  *(tv.data + i) = -*(data + i) ;
189  }
190 
191  return tv;
192 }
193 
210 {
212  for (unsigned int i=0;i<dsize;i++)
213  {
214  *(tv.data + i) = (*(data + i)) * x ;
215  }
216 
217  return tv;
218 }
219 
234 {
235 
236  unsigned int k = tv.rowNum ;
237  if (rowNum != k){
238  try {
239  resize(k);
240  }
241  catch(vpException me)
242  {
243  vpERROR_TRACE("Error caught") ;
244  throw ;
245  }
246  }
247 
248  memcpy(data, tv.data, rowNum*sizeof(double)) ;
249 
250  return *this;
251 }
252 
265 {
266 
267  double *d = data ;
268 
269  for (int i=0;i<3;i++)
270  *(d++)= x ;
271 
272  return *this;
273 }
274 
295 void
297 {
298  M.resize(3,3) ;
299  M[0][0] = 0 ; M[0][1] = -t[2] ; M[0][2] = t[1] ;
300  M[1][0] = t[2] ; M[1][1] = 0 ; M[1][2] = -t[0] ;
301  M[2][0] = -t[1] ; M[2][1] = t[0] ; M[2][2] = 0 ;
302 }
303 
324 vpMatrix
326 {
327  vpMatrix M(3, 3);
328  skew(t,M);
329  return M;
330 }
331 
350 vpMatrix
352 {
353  vpMatrix M(3, 3);
354  skew(*this,M);
355  return M;
356 }
357 
358 
370  const vpTranslationVector &b)
371 {
372  vpMatrix skew_a = vpTranslationVector::skew(a) ;
373  return (vpTranslationVector)(skew_a * b);
374 }
375 
376 /*
377  * Local variables:
378  * c-basic-offset: 4
379  * End:
380  */
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
void resize(const unsigned int nrows, const unsigned int ncols, const bool nullify=true)
Definition: vpMatrix.cpp:183
static vpTranslationVector cross(const vpTranslationVector &a, const vpTranslationVector &b)
#define vpERROR_TRACE
Definition: vpDebug.h:395
error that can be emited by ViSP classes.
Definition: vpException.h:76
vpTranslationVector operator-() const
double * data
address of the first element of the data array
Definition: vpMatrix.h:118
vpTranslationVector operator+(const vpTranslationVector &t) const
vpTranslationVector operator*(const double x) const
vpTranslationVector & operator=(const vpTranslationVector &t)
unsigned int rowNum
number of rows
Definition: vpMatrix.h:112
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
unsigned int dsize
Current size (rowNum * colNum)
Definition: vpMatrix.h:124
void set(const double tx, const double ty, const double tz)
Class that consider the case of a translation vector.
void resize(const unsigned int i, const bool flagNullify=true)
Definition: vpColVector.h:94