Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureDepth.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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 * 2D point visual feature.
32 */
33
38
39#include <visp3/visual_features/vpBasicFeature.h>
40#include <visp3/visual_features/vpFeatureDepth.h>
41
42// Exception
43#include <visp3/core/vpException.h>
44#include <visp3/visual_features/vpFeatureException.h>
45
46// Debug trace
47#include <visp3/core/vpDebug.h>
48
49// math
50#include <visp3/core/vpMath.h>
51
52#include <visp3/core/vpFeatureDisplay.h>
53
54/*
55attributes and members directly related to the vpBasicFeature needs
56other functionalities ar useful but not mandatory
57*/
58
64{
65 // feature dimension
66 dim_s = 1;
67 nbParameters = 3;
68
69 // memory allocation
70 s.resize(dim_s);
71 if (flags == nullptr)
72 flags = new bool[nbParameters];
73 for (unsigned int i = 0; i < nbParameters; i++)
74 flags[i] = false;
75 x = y = 0.;
76 Z = 1.;
77}
78
82vpFeatureDepth::vpFeatureDepth() : x(0), y(0), Z(1.) { init(); }
83
90void vpFeatureDepth::set_LogZoverZstar(double LogZoverZstar) { s[0] = LogZoverZstar; }
91
98double vpFeatureDepth::get_LogZoverZstar() const { return s[0]; }
99
107{
108 this->x = x_;
109 flags[0] = true;
110}
111
118double vpFeatureDepth::get_x() const { return x; }
119
127{
128 this->y = y_;
129 flags[1] = true;
130}
131
138double vpFeatureDepth::get_y() const { return y; }
139
147{
148 this->Z = Z_;
149 flags[2] = true;
150}
151
158double vpFeatureDepth::get_Z() const { return Z; }
159
172void vpFeatureDepth::set_xyZLogZoverZstar(double x_, double y_, double Z_, double LogZoverZstar)
173{
174 set_x(x_);
175 set_y(y_);
176 set_Z(Z_);
177 set_LogZoverZstar(LogZoverZstar);
178 for (unsigned int i = 0; i < nbParameters; i++)
179 flags[i] = true;
180}
181
208{
209 vpMatrix L;
210
212 for (unsigned int i = 0; i < nbParameters; i++) {
213 if (flags[i] == false) {
214 switch (i) {
215 case 0:
216 vpTRACE("Warning !!! The interaction matrix is computed but x was "
217 "not set yet");
218 break;
219 case 1:
220 vpTRACE("Warning !!! The interaction matrix is computed but y was "
221 "not set yet");
222 break;
223 case 2:
224 vpTRACE("Warning !!! The interaction matrix is computed but z was "
225 "not set yet");
226 break;
227 default:
228 vpTRACE("Problem during the reading of the variable flags");
229 }
230 }
231 }
232 resetFlags();
233 }
234
235 L.resize(1, 6);
236
237 double x_ = get_x();
238 double y_ = get_y();
239 double Z_ = get_Z();
240
241 if (Z_ < 0) {
242 vpERROR_TRACE("Point is behind the camera ");
243 std::cout << "Z = " << Z_ << std::endl;
244
245 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point is behind the camera "));
246 }
247
248 if (fabs(Z_) < 1e-6) {
249 vpERROR_TRACE("Point Z coordinates is null ");
250 std::cout << "Z = " << Z_ << std::endl;
251
252 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z coordinates is null"));
253 }
254
255 if (FEATURE_ALL & select) {
256 L = 0;
257 L[0][0] = 0;
258 L[0][1] = 0;
259 L[0][2] = -1 / Z_;
260 L[0][3] = -y_;
261 L[0][4] = x_;
262 L[0][5] = 0;
263 }
264
265 return L;
266}
267
304vpColVector vpFeatureDepth::error(const vpBasicFeature &s_star, unsigned int select)
305{
306
307 if (fabs(s_star.get_s().sumSquare()) > 1e-6) {
308 vpERROR_TRACE("s* should be zero ! ");
310 }
311
312 vpColVector e(1);
313 if (FEATURE_ALL & select) {
314 e[0] = s[0];
315 }
316
317 return e;
318}
319
335void vpFeatureDepth::print(unsigned int select) const
336{
337 if (FEATURE_ALL & select) {
338 std::cout << "Point: x=" << get_x();
339 std::cout << " Point: y=" << get_y();
340 std::cout << " Point: Z=" << get_Z();
341
342 std::cout << " log(Z/Z*)=" << get_LogZoverZstar();
343
344 std::cout << std::endl;
345 }
346}
347
359vpFeatureDepth &vpFeatureDepth::buildFrom(const double &x_, const double &y_, const double &Z_, const double &LogZoverZstar)
360{
361
362 s[0] = LogZoverZstar;
363
364 this->x = x_;
365 this->y = y_;
366 this->Z = Z_;
367
368 if (Z < 0) {
369 vpERROR_TRACE("Point is behind the camera ");
370 std::cout << "Z = " << Z << std::endl;
371
372 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point is behind the camera "));
373 }
374
375 if (fabs(Z) < 1e-6) {
376 vpERROR_TRACE("Point Z coordinates is null ");
377 std::cout << "Z = " << Z << std::endl;
378
379 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z coordinates is null"));
380 }
381
382 for (unsigned int i = 0; i < nbParameters; ++i) {
383 flags[i] = true;
384 }
385 return *this;
386}
387
399{
400 vpFeatureDepth *feature = new vpFeatureDepth;
401 return feature;
402}
403
410 const vpColor & /* color */, unsigned int /* thickness */) const
411{
412 static int firsttime = 0;
413
414 if (firsttime == 0) {
415 firsttime = 1;
416 vpERROR_TRACE("not implemented");
417 // Do not throw and error since it is not subject
418 // to produce a failure
419 }
420}
421
426void vpFeatureDepth::display(const vpCameraParameters & /* cam */, const vpImage<vpRGBa> & /* I */,
427 const vpColor & /* color */, unsigned int /* thickness */) const
428{
429 static int firsttime = 0;
430
431 if (firsttime == 0) {
432 firsttime = 1;
433 vpERROR_TRACE("not implemented");
434 // Do not throw and error since it is not subject
435 // to produce a failure
436 }
437}
438END_VISP_NAMESPACE
439/*
440 * Local variables:
441 * c-basic-offset: 2
442 * End:
443 */
void resize(unsigned int nrows, unsigned int ncols, bool flagNullify=true, bool recopy_=true)
Definition vpArray2D.h:448
vpColVector s
State of the visual feature.
unsigned int nbParameters
Number of parameters needed to compute the interaction matrix.
vpColVector get_s(unsigned int select=FEATURE_ALL) const
Get the feature vector .
unsigned int dim_s
Dimension of the visual feature.
vpBasicFeatureDeallocatorType deallocate
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
double sumSquare() const
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
void set_x(double x)
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
double get_y() const
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpFeatureDepth & buildFrom(const double &x, const double &y, const double &Z, const double &LogZoverZstar)
void set_y(double y)
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
void init() VP_OVERRIDE
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
double get_LogZoverZstar() const
void set_LogZoverZstar(double LogZoverZstar)
void set_xyZLogZoverZstar(double x, double y, double Z, double logZZs)
vpFeatureDepth * duplicate() const VP_OVERRIDE
double get_Z() const
void set_Z(double Z)
double get_x() const
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
#define vpTRACE
Definition vpDebug.h:450
#define vpERROR_TRACE
Definition vpDebug.h:423