Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
testPoint.cpp
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4  *
5  * This software is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
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 https://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 
40 #include <visp3/core/vpDebug.h>
41 #include <visp3/core/vpHomogeneousMatrix.h>
42 #include <visp3/core/vpMath.h>
43 #include <visp3/core/vpPoint.h>
44 #include <visp3/visual_features/vpFeatureBuilder.h>
45 #include <visp3/visual_features/vpFeatureException.h>
46 #include <visp3/visual_features/vpFeaturePoint.h>
47 
48 #include <stdio.h>
49 #include <stdlib.h>
50 
51 int main()
52 {
53 #ifdef ENABLE_VISP_NAMESPACE
54  using namespace VISP_NAMESPACE_NAME;
55 #endif
56  try {
58  cMo[0][3] = 0.1;
59  cMo[1][3] = 0.2;
60  cMo[2][3] = 2;
61 
62  vpPoint point;
63  vpTRACE("set point coordinates in the world frame ");
64  point.setWorldCoordinates(0, 0, 0);
65 
66  std::cout << "------------------------------------------------------" << std::endl;
67  vpTRACE("test the projection ");
68  point.track(cMo);
69 
70  vpTRACE("coordinates in the world frame ");
71  std::cout << point.oP.t() << std::endl;
72  vpTRACE("coordinates in the camera frame ");
73  std::cout << point.cP.t() << std::endl;
74 
75  vpTRACE("2D coordinates ");
76  std::cout << point.get_x() << " " << point.get_y() << std::endl;
77 
78  std::cout << "------------------------------------------------------" << std::endl;
79  vpTRACE("test the interaction matrix ");
80 
82  vpFeatureBuilder::create(p, point);
83 
84  vpMatrix L;
85  L = p.interaction();
86  std::cout << L << std::endl;
87 
88  vpTRACE("test the interaction matrix select");
89  vpTRACE("\t only X");
91  std::cout << L << std::endl;
92 
93  vpTRACE("\t only Y");
95  std::cout << L << std::endl;
96 
97  vpTRACE("\t X & Y");
99  std::cout << L << std::endl;
100 
101  vpTRACE("\t selectAll");
103  std::cout << L << std::endl;
104 
105  std::cout << "------------------------------------------------------" << std::endl;
106  vpTRACE("test the error ");
107 
108  try {
109  vpFeaturePoint pd;
110  pd.set_x(0);
111  pd.set_y(0);
112 
113  pd.print();
114  std::cout << std::endl;
115  vpColVector e;
116  e = p.error(pd);
117  std::cout << e << std::endl;
118 
119  vpTRACE("test the interaction matrix select");
120  vpTRACE("\t only X");
121  e = p.error(pd, vpFeaturePoint::selectX());
122  std::cout << e << std::endl;
123 
124  vpTRACE("\t only Y");
125  e = p.error(pd, vpFeaturePoint::selectY());
126  std::cout << e << std::endl;
127 
128  vpTRACE("\t X & Y");
130  std::cout << e << std::endl;
131 
132  vpTRACE("\t selectAll");
133  e = p.error(pd, vpFeaturePoint::selectAll());
134  std::cout << e << std::endl;
135  }
136  catch (vpFeatureException &me) {
137  std::cout << me << std::endl;
138  }
139  catch (const vpException &me) {
140  std::cout << me << std::endl;
141  }
142  std::cout << "------------------------------------------------------" << std::endl;
143  vpTRACE("test the dimension");
144  unsigned int dim;
145  dim = p.getDimension();
146  std::cout << "Dimension = " << dim << std::endl;
147 
148  vpTRACE("test the dimension with select");
149  vpTRACE("\t only X");
151  std::cout << "Dimension = " << dim << std::endl;
152 
153  vpTRACE("\t only Y");
155  std::cout << "Dimension = " << dim << std::endl;
156 
157  vpTRACE("\t X & Y");
159  std::cout << "Dimension = " << dim << std::endl;
160 
161  vpTRACE("\t selectAll");
163  std::cout << "Dimension = " << dim << std::endl;
164  return EXIT_SUCCESS;
165  }
166  catch (const vpException &e) {
167  std::cout << "Catch an exception: " << e << std::endl;
168  return EXIT_FAILURE;
169  }
170 }
static unsigned int selectAll()
Select all the features.
unsigned int getDimension(unsigned int select=FEATURE_ALL) const
Get the feature vector dimension.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
vpRowVector t() const
error that can be emitted by ViSP classes.
Definition: vpException.h:60
static void create(vpFeaturePoint &s, const vpCameraParameters &cam, const vpImagePoint &t)
Error that can be emitted by the vpBasicFeature class and its derivates.
Class that defines a 2D point visual feature which is composed by two parameters that are the cartes...
static unsigned int selectX()
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
static unsigned int selectY()
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
void set_y(double y)
void set_x(double x)
void track(const vpHomogeneousMatrix &cMo)
Implementation of an homogeneous matrix and operations on such kind of matrices.
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:79
double get_y() const
Get the point y coordinate in the image plane.
Definition: vpPoint.cpp:422
double get_x() const
Get the point x coordinate in the image plane.
Definition: vpPoint.cpp:420
void setWorldCoordinates(double oX, double oY, double oZ)
Definition: vpPoint.cpp:111
vpColVector cP
Definition: vpTracker.h:73