Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testPoint.cpp
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
9  * See the file LICENSE.txt at the root directory of this source
10  * distribution for additional information about the GNU GPL.
11  *
12  * For using ViSP with software that can not be combined with the GNU
13  * GPL, please contact Inria about acquiring a ViSP Professional
14  * Edition License.
15  *
16  * See http://visp.inria.fr for more information.
17  *
18  * This software was developed at:
19  * Inria Rennes - Bretagne Atlantique
20  * Campus Universitaire de Beaulieu
21  * 35042 Rennes Cedex
22  * France
23  *
24  * If you have questions regarding the use of this file, please contact
25  * Inria at visp@inria.fr
26  *
27  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29  *
30  * Description:
31  * Performs various tests on the point class.
32  *
33  * Authors:
34  * Eric Marchand
35  *
36  *****************************************************************************/
37 
38 
39 
45 #include <visp3/core/vpMath.h>
46 #include <visp3/core/vpHomogeneousMatrix.h>
47 #include <visp3/core/vpPoint.h>
48 #include <visp3/visual_features/vpFeaturePoint.h>
49 #include <visp3/visual_features/vpFeatureException.h>
50 #include <visp3/core/vpDebug.h>
51 #include <visp3/visual_features/vpFeatureBuilder.h>
52 
53 #include <stdlib.h>
54 #include <stdio.h>
55 
56 int main()
57 {
58  try {
60  cMo[0][3] = 0.1 ;
61  cMo[1][3] = 0.2 ;
62  cMo[2][3] = 2 ;
63 
64  vpPoint point ;
65  vpTRACE("set point coordinates in the world frame ") ;
66  point.setWorldCoordinates(0,0,0) ;
67 
68  std::cout <<"------------------------------------------------------"<<std::endl ;
69  vpTRACE("test the projection ") ;
70  point.track(cMo) ;
71 
72  vpTRACE("coordinates in the world frame ") ;
73  std::cout << point.oP.t() << std::endl ;
74  vpTRACE("coordinates in the camera frame ") ;
75  std::cout << point.cP.t() << std::endl ;
76 
77  vpTRACE("2D coordinates ") ;
78  std::cout<< point.get_x() << " " << point.get_y() << std::endl ;
79 
80  std::cout <<"------------------------------------------------------"<<std::endl ;
81  vpTRACE("test the interaction matrix ") ;
82 
83  vpFeaturePoint p ;
84  vpFeatureBuilder::create(p,point) ;
85 
86  vpMatrix L ;
87  L = p.interaction() ;
88  std::cout << L << std::endl ;
89 
90  vpTRACE("test the interaction matrix select") ;
91  vpTRACE("\t only X") ;
93  std::cout << L << std::endl ;
94 
95  vpTRACE("\t only Y") ;
97  std::cout << L << std::endl ;
98 
99  vpTRACE("\t X & Y") ;
102  std::cout << L << std::endl ;
103 
104  vpTRACE("\t selectAll") ;
106  std::cout << L << std::endl ;
107 
108  std::cout <<"------------------------------------------------------"<<std::endl ;
109  vpTRACE("test the error ") ;
110 
111  try{
112  vpFeaturePoint pd ;
113  pd.set_x(0) ;
114  pd.set_y(0) ;
115 
116  pd.print() ; std::cout << std::endl ;
117  vpColVector e ;
118  e = p.error(pd) ;
119  std::cout << e << std::endl ;
120 
121  vpTRACE("test the interaction matrix select") ;
122  vpTRACE("\t only X") ;
123  e = p.error(pd,vpFeaturePoint::selectX()) ;
124  std::cout << e << std::endl ;
125 
126  vpTRACE("\t only Y") ;
127  e = p.error(pd,vpFeaturePoint::selectY()) ;
128  std::cout << e << std::endl ;
129 
130  vpTRACE("\t X & Y") ;
132  std::cout << e << std::endl ;
133 
134  vpTRACE("\t selectAll") ;
135  e = p.error(pd,vpFeaturePoint::selectAll() ) ;
136  std::cout << e << std::endl ;
137  }
138  catch(vpFeatureException &me){ std::cout << me << std::endl ; }
139  catch(vpException &me){ std::cout << me << std::endl ; }
140  std::cout <<"------------------------------------------------------"<<std::endl ;
141  vpTRACE("test the dimension") ;
142  unsigned int dim ;
143  dim = p.getDimension() ;
144  std::cout << "Dimension = " << dim << std::endl ;
145 
146  vpTRACE("test the dimension with select") ;
147  vpTRACE("\t only X") ;
149  std::cout << "Dimension = " << dim << std::endl ;
150 
151  vpTRACE("\t only Y") ;
153  std::cout << "Dimension = " << dim << std::endl ;
154 
155  vpTRACE("\t X & Y") ;
157  std::cout << "Dimension = " << dim << std::endl ;
158 
159  vpTRACE("\t selectAll") ;
161  std::cout << "Dimension = " << dim << std::endl ;
162  return 0;
163  }
164  catch(vpException &e) {
165  std::cout << "Catch an exception: " << e << std::endl;
166  return 1;
167  }
168 }
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
vpMatrix interaction(const unsigned int select=FEATURE_ALL)
unsigned int getDimension(const unsigned int select=FEATURE_ALL) const
Get the feature vector dimension.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
error that can be emited by ViSP classes.
Definition: vpException.h:73
static unsigned int selectY()
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.cpp:458
void set_y(const double y)
Class that defines what is a point.
Definition: vpPoint.h:59
void set_x(const double x)
vpColVector cP
Definition: vpTracker.h:77
static unsigned int selectX()
#define vpTRACE
Definition: vpDebug.h:414
Error that can be emited by the vpBasicFeature class and its derivates.
vpRowVector t() const
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:456
void setWorldCoordinates(const double oX, const double oY, const double oZ)
Definition: vpPoint.cpp:111
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpDot &d)
void print(const unsigned int select=FEATURE_ALL) const