ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
testDisplacement.cpp
1 /****************************************************************************
2  *
3  * $Id: testDisplacement.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  * 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 
71 void usage(const char *name, const char *badparam)
72 {
73  fprintf(stdout, "\n\
74 Tests transformation within various representations of rotation.\n\
75 \n\
76 SYNOPSIS\n\
77  %s [-h]\n", name);
78 
79  fprintf(stdout, "\n\
80 OPTIONS: Default\n\
81  -h\n\
82  Print the help.\n");
83 
84  if (badparam)
85  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
86 }
94 bool getOptions(int argc, const char **argv)
95 {
96  const char *optarg;
97  int c;
98  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
99 
100  switch (c) {
101  case 'h': usage(argv[0], NULL); return false; break;
102 
103  default:
104  usage(argv[0], optarg);
105  return false; break;
106  }
107  }
108 
109  if ((c == 1) || (c == -1)) {
110  // standalone param or error
111  usage(argv[0], NULL);
112  std::cerr << "ERROR: " << std::endl;
113  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
114  return false;
115  }
116 
117  return true;
118 }
119 
120 
121 int
122 main(int argc, const char ** argv)
123 {
124  // Read the command line options
125  if (getOptions(argc, argv) == false) {
126  exit (-1);
127  }
128 
129  {
131 
132  std::cout << "Initialization " <<std::endl ;
133  // std::cout << tu << std::endl ;
134 
135 
136  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
137  vpRotationMatrix R(tu) ;
138 
139 
140  // pure rotation
142  M.insert(R) ;
143 
144 
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  vpTRACE(" ") ;
152  std::cout << "H" <<std::endl <<H << std::endl ;
153 
154 
155  vpTRACE(" ") ;
156 
157  vpColVector n ;
159 
160  H.computeDisplacement(R,T,n) ;
161 
162  std::cout << "R" <<std::endl << R ;
163  std::cout << "T" <<std::endl << T.t() ;
164  std::cout << "n" <<std::endl << n.t() ;
165  vpTRACE(" ") ;
166  vpTRACE(" ") ;
167  }
168  std::cout <<"------------------------------------------------------" << std::endl ;
169 
170  {
172 
173  std::cout << "Initialization " <<std::endl ;
174  // std::cout << tu << std::endl ;
175 
176 
177  std::cout << "From vpThetaUVector to vpRotationMatrix " << std::endl ;
178  vpRotationMatrix R(tu) ;
179 
180 
181  // pure rotation
183  M.insert(R) ;
184 
185 
186  M[0][3] = 0.21 ;
187  M[1][3] = 0.31 ;
188  M[2][3] = 0.5 ;
189 
190 
191  std::cout << "M" <<std::endl <<M << std::endl ;
192  vpPlane p(0,0,1,1) ;
193 
194  vpHomography H(M,p) ;
195 
196  vpTRACE(" ") ;
197  std::cout << "H" <<std::endl <<H << std::endl ;
198 
199 
200  vpTRACE(" ") ;
201 
202  vpColVector n ;
204 
205  H.computeDisplacement(R,T,n) ;
206 
207  std::cout << "R" <<std::endl << R ;
208  std::cout << "T" <<std::endl << T.t() ;
209  std::cout << "n" <<std::endl << n.t() ;
210  vpTRACE(" ") ;
211  vpTRACE(" ") ;
212  }
213 
214  std::cout <<"------------------------------------------------------" << std::endl ;
215  {
216  vpThetaUVector tu(vpMath::rad(-190), vpMath::rad(12), vpMath::rad(-45)) ;
217 
218  vpRotationMatrix R(tu) ;
219 
220 
221  // pure rotation
223  M.insert(R) ;
224 
225  M[0][3] = 0.21 ;
226  M[1][3] =- 0.31 ;
227  M[2][3] = 0.5 ;
228 
229  std::cout << "M" <<std::endl <<M << std::endl ;
230  vpPlane p(0.4,-0.5,0.5,1) ;
231 
232  vpHomography H(M,p) ;
233 
234  vpTRACE(" ") ;
235  std::cout << "H" <<std::endl <<H << std::endl ;
236 
237  vpTRACE(" ") ;
238  vpColVector n ;
240  H.computeDisplacement(R,T,n) ;
241 
242  std::cout << "R" <<std::endl << R ;
243  std::cout << "T" <<std::endl << T.t() ;
244  std::cout << "n" <<std::endl << n.t() ;
245 
246  vpPlane p1(n[0],n[1],n[2],1.0) ;
247  H.buildFrom(R,T,p1) ;
248  std::cout << "H" <<std::endl <<H << std::endl ;
249 
250  }
251 }