ViSP  2.9.0
testDisplacement.cpp
1 /****************************************************************************
2  *
3  * $Id: testDisplacement.cpp 4658 2014-02-09 09:50:14Z 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  * Tests transformation within various representations of rotation.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
54 #include <visp/vpMath.h>
55 #include <visp/vpRotationMatrix.h>
56 #include <visp/vpHomography.h>
57 #include <visp/vpDebug.h>
58 #include <visp/vpThetaUVector.h>
59 #include <visp/vpParseArgv.h>
60 #include <stdlib.h>
61 #include <stdio.h>
62 
63 // List of allowed command line options
64 #define GETOPTARGS "h"
65 
66 void usage(const char *name, const char *badparam);
67 bool getOptions(int argc, const char **argv);
68 
74 void usage(const char *name, const char *badparam)
75 {
76  fprintf(stdout, "\n\
77 Tests transformation within various representations of rotation.\n\
78 \n\
79 SYNOPSIS\n\
80  %s [-h]\n", name);
81 
82  fprintf(stdout, "\n\
83 OPTIONS: Default\n\
84  -h\n\
85  Print the help.\n");
86 
87  if (badparam)
88  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
89 }
97 bool getOptions(int argc, const char **argv)
98 {
99  const char *optarg_;
100  int c;
101  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
102 
103  switch (c) {
104  case 'h': usage(argv[0], NULL); return false; break;
105 
106  default:
107  usage(argv[0], optarg_);
108  return false; break;
109  }
110  }
111 
112  if ((c == 1) || (c == -1)) {
113  // standalone param or error
114  usage(argv[0], NULL);
115  std::cerr << "ERROR: " << std::endl;
116  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
117  return false;
118  }
119 
120  return true;
121 }
122 
123 
124 int
125 main(int argc, const char ** argv)
126 {
127  try {
128  // Read the command line options
129  if (getOptions(argc, argv) == false) {
130  exit (-1);
131  }
132 
133  {
135 
136  std::cout << "Initialization " <<std::endl ;
137  // std::cout << tu << std::endl ;
138 
139  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
140  vpRotationMatrix R(tu) ;
141 
142  // pure rotation
144  M.insert(R) ;
145 
146  std::cout << "M" <<std::endl <<M << std::endl ;
147  vpPlane p(0,0,1,1) ;
148 
149  vpHomography H(M,p) ;
150 
151  std::cout << "H" <<std::endl <<H << std::endl ;
152 
153  vpColVector n ;
155 
156  H.computeDisplacement(R,T,n) ;
157 
158  std::cout << "R" <<std::endl << R ;
159  std::cout << "T" <<std::endl << T.t() << std::endl;
160  std::cout << "n" <<std::endl << n.t() << std::endl;
161  }
162  std::cout <<"------------------------------------------------------" << std::endl ;
163 
164  {
166 
167  std::cout << "Initialization " << std::endl ;
168  // std::cout << tu << std::endl ;
169 
170  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
171  vpRotationMatrix R(tu) ;
172 
173  // pure rotation
175  M.insert(R) ;
176 
177  M[0][3] = 0.21 ;
178  M[1][3] = 0.31 ;
179  M[2][3] = 0.5 ;
180 
181  std::cout << "M" << std::endl << M << std::endl ;
182  vpPlane p(0,0,1,1) ;
183 
184  vpHomography H(M,p) ;
185 
186  std::cout << "H" << std::endl << H << std::endl ;
187 
188  vpColVector n ;
190 
191  H.computeDisplacement(R,T,n) ;
192 
193  std::cout << "R" <<std::endl << R ;
194  std::cout << "T" <<std::endl << T.t() << std::endl;
195  std::cout << "n" <<std::endl << n.t() << std::endl;
196  }
197 
198  std::cout <<"------------------------------------------------------" << std::endl ;
199  {
200  vpThetaUVector tu(vpMath::rad(-190), vpMath::rad(12), vpMath::rad(-45)) ;
201 
202  vpRotationMatrix R(tu) ;
203 
204  // pure rotation
206  M.insert(R) ;
207 
208  M[0][3] = 0.21 ;
209  M[1][3] =- 0.31 ;
210  M[2][3] = 0.5 ;
211 
212  std::cout << "M" << std::endl << M << std::endl ;
213  vpPlane p(0.4,-0.5,0.5,1) ;
214 
215  vpHomography H(M,p) ;
216 
217  std::cout << "H" << std::endl << H << std::endl ;
218 
219  vpColVector n ;
221  H.computeDisplacement(R,T,n) ;
222 
223  std::cout << "R" <<std::endl << R ;
224  std::cout << "T" <<std::endl << T.t() << std::endl;
225  std::cout << "n" <<std::endl << n.t() << std::endl;
226 
227  vpPlane p1(n[0],n[1],n[2],1.0) ;
228  H.buildFrom(R,T,p1) ;
229  std::cout << "H" << std::endl << H << std::endl ;
230  }
231  return 0;
232  }
233  catch(vpException e) {
234  std::cout << "Catch an exception: " << e << std::endl;
235  return 1;
236  }
237 }
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
error that can be emited by ViSP classes.
Definition: vpException.h:76
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
The vpRotationMatrix considers the particular case of a rotation matrix.
void insert(const vpRotationMatrix &R)
This class aims to compute the homography wrt.two images.
Definition: vpHomography.h:178
vpRowVector t() const
transpose of Vector
static double rad(double deg)
Definition: vpMath.h:100
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
This class defines the container for a plane geometrical structure.
Definition: vpPlane.h:67
Class that consider the case of a translation vector.
Class that consider the case of the parameterization for the rotation.