ViSP
 All Classes Functions Variables Enumerations Enumerator Friends Groups Pages
testPoint.cpp
1 /****************************************************************************
2  *
3  * $Id: testPoint.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  * Performs various tests on the point class.
36  *
37  * Authors:
38  * Eric Marchand
39  *
40  *****************************************************************************/
41 
42 
43 
49 // List of allowed command line options
50 #define GETOPTARGS "h"
51 
52 #include <visp/vpMath.h>
53 #include <visp/vpHomogeneousMatrix.h>
54 #include <visp/vpPoint.h>
55 #include <visp/vpFeaturePoint.h>
56 #include <visp/vpFeatureException.h>
57 #include <visp/vpDebug.h>
58 #include <visp/vpFeatureBuilder.h>
59 #include <visp/vpParseArgv.h>
60 
61 #include <stdlib.h>
62 #include <stdio.h>
63 
69 void usage(const char *name, const char *badparam)
70 {
71  fprintf(stdout, "\n\
72 Performs various tests on the point class.\n\
73 \n\
74 SYNOPSIS\n\
75  %s [-h]\n", name);
76 
77  fprintf(stdout, "\n\
78 OPTIONS: Default\n\
79  -h\n\
80  Print the help.\n");
81 
82  if (badparam)
83  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
84 }
92 bool getOptions(int argc, const char **argv)
93 {
94  const char *optarg;
95  int c;
96  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg)) > 1) {
97 
98  switch (c) {
99  case 'h': usage(argv[0], NULL); return false; break;
100 
101  default:
102  usage(argv[0], optarg);
103  return false; break;
104  }
105  }
106 
107  if ((c == 1) || (c == -1)) {
108  // standalone param or error
109  usage(argv[0], NULL);
110  std::cerr << "ERROR: " << std::endl;
111  std::cerr << " Bad argument " << optarg << std::endl << std::endl;
112  return false;
113  }
114 
115  return true;
116 }
117 
118 
119 int
120 main(int argc, const char ** argv)
121 {
122  // Read the command line options
123  if (getOptions(argc, argv) == false) {
124  exit (-1);
125  }
126 
127  vpHomogeneousMatrix cMo ;
128  cMo[0][3] = 0.1 ;
129  cMo[1][3] = 0.2 ;
130  cMo[2][3] = 2 ;
131 
132  vpPoint point ;
133  vpTRACE("set point coordinates in the world frame ") ;
134  point.setWorldCoordinates(0,0,0) ;
135 
136 
137  std::cout <<"------------------------------------------------------"<<std::endl ;
138  vpTRACE("test the projection ") ;
139  point.track(cMo) ;
140 
141  vpTRACE("coordinates in the world frame ") ;
142  std::cout << point.oP.t() << std::endl ;
143  vpTRACE("coordinates in the camera frame ") ;
144  std::cout << point.cP.t() << std::endl ;
145 
146  vpTRACE("2D coordinates ") ;
147  std::cout<< point.get_x() << " " << point.get_y() << std::endl ;
148 
149  std::cout <<"------------------------------------------------------"<<std::endl ;
150  vpTRACE("test the interaction matrix ") ;
151 
152  vpFeaturePoint p ;
153  vpFeatureBuilder::create(p,point) ;
154 
155  vpMatrix L ;
156  L = p.interaction() ;
157  std::cout << L << std::endl ;
158 
159  vpTRACE("test the interaction matrix select") ;
160  vpTRACE("\t only X") ;
162  std::cout << L << std::endl ;
163 
164  vpTRACE("\t only Y") ;
166  std::cout << L << std::endl ;
167 
168  vpTRACE("\t X & Y") ;
171  std::cout << L << std::endl ;
172 
173  vpTRACE("\t selectAll") ;
175  std::cout << L << std::endl ;
176 
177  std::cout <<"------------------------------------------------------"<<std::endl ;
178  vpTRACE("test the error ") ;
179 
180  try{
181  vpFeaturePoint pd ;
182  pd.set_x(0) ;
183  pd.set_y(0) ;
184 
185  pd.print() ; std::cout << std::endl ;
186  vpColVector e ;
187  e = p.error(pd) ;
188  std::cout << e << std::endl ;
189 
190  vpTRACE("test the interaction matrix select") ;
191  vpTRACE("\t only X") ;
192  e = p.error(pd,vpFeaturePoint::selectX()) ;
193  std::cout << e << std::endl ;
194 
195  vpTRACE("\t only Y") ;
196  e = p.error(pd,vpFeaturePoint::selectY()) ;
197  std::cout << e << std::endl ;
198 
199  vpTRACE("\t X & Y") ;
201  std::cout << e << std::endl ;
202 
203  vpTRACE("\t selectAll") ;
204  e = p.error(pd,vpFeaturePoint::selectAll() ) ;
205  std::cout << e << std::endl ;
206  }
207  catch(vpFeatureException me){ std::cout << me << std::endl ; }
208  catch(vpException me){ std::cout << me << std::endl ; }
209  std::cout <<"------------------------------------------------------"<<std::endl ;
210  vpTRACE("test the dimension") ;
211  unsigned int dim ;
212  dim = p.getDimension() ;
213  std::cout << "Dimension = " << dim << std::endl ;
214 
215  vpTRACE("test the dimension with select") ;
216  vpTRACE("\t only X") ;
218  std::cout << "Dimension = " << dim << std::endl ;
219 
220  vpTRACE("\t only Y") ;
222  std::cout << "Dimension = " << dim << std::endl ;
223 
224  vpTRACE("\t X & Y") ;
226  std::cout << "Dimension = " << dim << std::endl ;
227 
228  vpTRACE("\t selectAll") ;
230  std::cout << "Dimension = " << dim << std::endl ;
231 
232 }