ViSP  2.9.0
testPoint.cpp
1 /****************************************************************************
2  *
3  * $Id: testPoint.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  * 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 
64 
65 void usage(const char *name, const char *badparam);
66 bool getOptions(int argc, const char **argv);
67 
73 void usage(const char *name, const char *badparam)
74 {
75  fprintf(stdout, "\n\
76 Performs various tests on the point class.\n\
77 \n\
78 SYNOPSIS\n\
79  %s [-h]\n", name);
80 
81  fprintf(stdout, "\n\
82 OPTIONS: Default\n\
83  -h\n\
84  Print the help.\n");
85 
86  if (badparam)
87  fprintf(stdout, "\nERROR: Bad parameter [%s]\n", badparam);
88 }
96 bool getOptions(int argc, const char **argv)
97 {
98  const char *optarg_;
99  int c;
100  while ((c = vpParseArgv::parse(argc, argv, GETOPTARGS, &optarg_)) > 1) {
101 
102  switch (c) {
103  case 'h': usage(argv[0], NULL); return false; break;
104 
105  default:
106  usage(argv[0], optarg_);
107  return false; break;
108  }
109  }
110 
111  if ((c == 1) || (c == -1)) {
112  // standalone param or error
113  usage(argv[0], NULL);
114  std::cerr << "ERROR: " << std::endl;
115  std::cerr << " Bad argument " << optarg_ << std::endl << std::endl;
116  return false;
117  }
118 
119  return true;
120 }
121 
122 
123 int
124 main(int argc, const char ** argv)
125 {
126  try {
127  // Read the command line options
128  if (getOptions(argc, argv) == false) {
129  exit (-1);
130  }
131 
132  vpHomogeneousMatrix cMo ;
133  cMo[0][3] = 0.1 ;
134  cMo[1][3] = 0.2 ;
135  cMo[2][3] = 2 ;
136 
137  vpPoint point ;
138  vpTRACE("set point coordinates in the world frame ") ;
139  point.setWorldCoordinates(0,0,0) ;
140 
141  std::cout <<"------------------------------------------------------"<<std::endl ;
142  vpTRACE("test the projection ") ;
143  point.track(cMo) ;
144 
145  vpTRACE("coordinates in the world frame ") ;
146  std::cout << point.oP.t() << std::endl ;
147  vpTRACE("coordinates in the camera frame ") ;
148  std::cout << point.cP.t() << std::endl ;
149 
150  vpTRACE("2D coordinates ") ;
151  std::cout<< point.get_x() << " " << point.get_y() << std::endl ;
152 
153  std::cout <<"------------------------------------------------------"<<std::endl ;
154  vpTRACE("test the interaction matrix ") ;
155 
156  vpFeaturePoint p ;
157  vpFeatureBuilder::create(p,point) ;
158 
159  vpMatrix L ;
160  L = p.interaction() ;
161  std::cout << L << std::endl ;
162 
163  vpTRACE("test the interaction matrix select") ;
164  vpTRACE("\t only X") ;
166  std::cout << L << std::endl ;
167 
168  vpTRACE("\t only Y") ;
170  std::cout << L << std::endl ;
171 
172  vpTRACE("\t X & Y") ;
175  std::cout << L << std::endl ;
176 
177  vpTRACE("\t selectAll") ;
179  std::cout << L << std::endl ;
180 
181  std::cout <<"------------------------------------------------------"<<std::endl ;
182  vpTRACE("test the error ") ;
183 
184  try{
185  vpFeaturePoint pd ;
186  pd.set_x(0) ;
187  pd.set_y(0) ;
188 
189  pd.print() ; std::cout << std::endl ;
190  vpColVector e ;
191  e = p.error(pd) ;
192  std::cout << e << std::endl ;
193 
194  vpTRACE("test the interaction matrix select") ;
195  vpTRACE("\t only X") ;
196  e = p.error(pd,vpFeaturePoint::selectX()) ;
197  std::cout << e << std::endl ;
198 
199  vpTRACE("\t only Y") ;
200  e = p.error(pd,vpFeaturePoint::selectY()) ;
201  std::cout << e << std::endl ;
202 
203  vpTRACE("\t X & Y") ;
205  std::cout << e << std::endl ;
206 
207  vpTRACE("\t selectAll") ;
208  e = p.error(pd,vpFeaturePoint::selectAll() ) ;
209  std::cout << e << std::endl ;
210  }
211  catch(vpFeatureException me){ std::cout << me << std::endl ; }
212  catch(vpException me){ std::cout << me << std::endl ; }
213  std::cout <<"------------------------------------------------------"<<std::endl ;
214  vpTRACE("test the dimension") ;
215  unsigned int dim ;
216  dim = p.getDimension() ;
217  std::cout << "Dimension = " << dim << std::endl ;
218 
219  vpTRACE("test the dimension with select") ;
220  vpTRACE("\t only X") ;
222  std::cout << "Dimension = " << dim << std::endl ;
223 
224  vpTRACE("\t only Y") ;
226  std::cout << "Dimension = " << dim << std::endl ;
227 
228  vpTRACE("\t X & Y") ;
230  std::cout << "Dimension = " << dim << std::endl ;
231 
232  vpTRACE("\t selectAll") ;
234  std::cout << "Dimension = " << dim << std::endl ;
235  return 0;
236  }
237  catch(vpException e) {
238  std::cout << "Catch an exception: " << e << std::endl;
239  return 1;
240  }
241 }
Definition of the vpMatrix class.
Definition: vpMatrix.h:98
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
unsigned int getDimension(const unsigned int select=FEATURE_ALL) const
Get the feature vector dimension.
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
#define vpTRACE
Definition: vpDebug.h:418
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
error that can be emited by ViSP classes.
Definition: vpException.h:76
static unsigned int selectAll()
Select all the features.
void track(const vpHomogeneousMatrix &cMo)
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.h:138
void set_y(const double y)
static bool parse(int *argcPtr, const char **argv, vpArgvInfo *argTable, int flags)
Definition: vpParseArgv.cpp:79
Class that defines what is a point.
Definition: vpPoint.h:65
void set_x(const double x)
vpColVector cP
Definition: vpTracker.h:82
Error that can be emited by the vpBasicFeature class and its derivates.
vpRowVector t() const
transpose of Vector
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.h:136
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
static unsigned int selectX()
static unsigned int selectY()
void setWorldCoordinates(const double ox, const double oy, const double oz)
Set the point world coordinates. We mean here the coordinates of the point in the object frame...
Definition: vpPoint.cpp:74
void print(const unsigned int select=FEATURE_ALL) const