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