Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeaturePoint3D.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 * 3D point visual feature.
32 */
33
34#include <visp3/visual_features/vpBasicFeature.h>
35#include <visp3/visual_features/vpFeaturePoint3D.h>
36
37// Exception
38#include <visp3/core/vpException.h>
39#include <visp3/visual_features/vpFeatureException.h>
40
41// Debug trace
42#include <visp3/core/vpDebug.h>
43
44/*
45
46 attributes and members directly related to the vpBasicFeature needs
47 other functionalities are useful but not mandatory
48
49*/
50
60{
61 // feature dimension
62 dim_s = 3;
63 nbParameters = 3;
64
65 // memory allocation
66 s.resize(dim_s);
67 if (flags == nullptr)
68 flags = new bool[nbParameters];
69 for (unsigned int i = 0; i < nbParameters; i++)
70 flags[i] = false;
71
72 // default value XYZ
73 s[0] = 0;
74 s[1] = 0;
75 s[2] = 1;
76}
77
85
96{
97 s[0] = X;
98 flags[0] = true;
99}
100
111{
112 s[1] = Y;
113 flags[1] = true;
114}
115
126{
127 s[2] = Z;
128 flags[2] = true;
129}
130
140void vpFeaturePoint3D::set_XYZ(double X, double Y, double Z)
141{
142 set_X(X);
143 set_Y(Y);
144 set_Z(Z);
145
146 for (unsigned int i = 0; i < nbParameters; i++)
147 flags[i] = true;
148}
149
151double vpFeaturePoint3D::get_X() const { return s[0]; }
152
154double vpFeaturePoint3D::get_Y() const { return s[1]; }
155
157double vpFeaturePoint3D::get_Z() const { return s[2]; }
158
227{
228 vpMatrix L;
229
230 L.resize(0, 6);
231
233 for (unsigned int i = 0; i < nbParameters; i++) {
234 if (flags[i] == false) {
235 switch (i) {
236 case 0:
237 vpTRACE("Warning !!! The interaction matrix is computed but X was "
238 "not set yet");
239 break;
240 case 1:
241 vpTRACE("Warning !!! The interaction matrix is computed but Y was "
242 "not set yet");
243 break;
244 case 2:
245 vpTRACE("Warning !!! The interaction matrix is computed but Z was "
246 "not set yet");
247 break;
248 default:
249 vpTRACE("Problem during the reading of the variable flags");
250 }
251 }
252 }
253 resetFlags();
254 }
255
256 double X = get_X();
257 double Y = get_Y();
258 double Z = get_Z();
259
260 if (vpFeaturePoint3D::selectX() & select) {
261 vpMatrix Lx(1, 6);
262 Lx = 0;
263
264 Lx[0][0] = -1;
265 Lx[0][1] = 0;
266 Lx[0][2] = 0;
267 Lx[0][3] = 0;
268 Lx[0][4] = -Z;
269 Lx[0][5] = Y;
270
271 L = vpMatrix::stack(L, Lx);
272 }
273
274 if (vpFeaturePoint3D::selectY() & select) {
275 vpMatrix Ly(1, 6);
276 Ly = 0;
277
278 Ly[0][0] = 0;
279 Ly[0][1] = -1;
280 Ly[0][2] = 0;
281 Ly[0][3] = Z;
282 Ly[0][4] = 0;
283 Ly[0][5] = -X;
284
285 L = vpMatrix::stack(L, Ly);
286 }
287 if (vpFeaturePoint3D::selectZ() & select) {
288 vpMatrix Lz(1, 6);
289 Lz = 0;
290
291 Lz[0][0] = 0;
292 Lz[0][1] = 0;
293 Lz[0][2] = -1;
294 Lz[0][3] = -Y;
295 Lz[0][4] = X;
296 Lz[0][5] = 0;
297
298 L = vpMatrix::stack(L, Lz);
299 }
300 return L;
301}
302
354vpColVector vpFeaturePoint3D::error(const vpBasicFeature &s_star, unsigned int select)
355{
356 vpColVector e(0);
357
358 try {
359 if (vpFeaturePoint3D::selectX() & select) {
360 vpColVector ex(1);
361 ex[0] = s[0] - s_star[0];
362
363 e = vpColVector::stack(e, ex);
364 }
365
366 if (vpFeaturePoint3D::selectY() & select) {
367 vpColVector ey(1);
368 ey[0] = s[1] - s_star[1];
369 e = vpColVector::stack(e, ey);
370 }
371
372 if (vpFeaturePoint3D::selectZ() & select) {
373 vpColVector ez(1);
374 ez[0] = s[2] - s_star[2];
375 e = vpColVector::stack(e, ez);
376 }
377 }
378 catch (...) {
379 throw;
380 }
381
382 return e;
383}
384
402{
403 // cP is expressed in homogeneous coordinates
404 // we devide by the fourth coordinate
405 s[0] = p.cP[0] / p.cP[3];
406 s[1] = p.cP[1] / p.cP[3];
407 s[2] = p.cP[2] / p.cP[3];
408
409 double Z = s[2];
410 if (Z < 0) {
411 vpERROR_TRACE("Point is behind the camera ");
412 std::cout << "Z = " << Z << std::endl;
413
414 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point is behind the camera "));
415 }
416
417 if (fabs(Z) < 1e-6) {
418 vpERROR_TRACE("Point Z coordinates is null ");
419 std::cout << "Z = " << Z << std::endl;
420
421 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z coordinates is null"));
422 }
423
424 for (unsigned int i = 0; i < nbParameters; ++i) {
425 flags[i] = true;
426 }
427 return *this;
428}
429
448vpFeaturePoint3D &vpFeaturePoint3D::buildFrom(const double &X, const double &Y, const double &Z)
449{
450 s[0] = X;
451 s[1] = Y;
452 s[2] = Z;
453
454 if (Z < 0) {
455 vpERROR_TRACE("Point is behind the camera ");
456 std::cout << "Z = " << Z << std::endl;
457
458 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point is behind the camera "));
459 }
460
461 if (fabs(Z) < 1e-6) {
462 vpERROR_TRACE("Point Z coordinates is null ");
463 std::cout << "Z = " << Z << std::endl;
464
465 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z coordinates is null"));
466 }
467
468 for (unsigned int i = 0; i < nbParameters; ++i) {
469 flags[i] = true;
470 }
471 return *this;
472}
473
497void vpFeaturePoint3D::print(unsigned int select) const
498{
499
500 std::cout << "Point3D: ";
501 if (vpFeaturePoint3D::selectX() & select)
502 std::cout << " X=" << get_X();
503 if (vpFeaturePoint3D::selectY() & select)
504 std::cout << " Y=" << get_Y();
505 if (vpFeaturePoint3D::selectZ() & select)
506 std::cout << " Z=" << get_Z();
507 std::cout << std::endl;
508}
509
522{
523 vpFeaturePoint3D *feature = new vpFeaturePoint3D;
524 return feature;
525}
526
532 const vpColor & /* color */, unsigned int /* thickness */) const
533{
534 static int firsttime = 0;
535
536 if (firsttime == 0) {
537 firsttime = 1;
538 vpERROR_TRACE("not implemented");
539 // Do not throw and error since it is not subject
540 // to produce a failure
541 }
542}
543
549 const vpColor & /* color */, unsigned int /* thickness */) const
550{
551 static int firsttime = 0;
552
553 if (firsttime == 0) {
554 firsttime = 1;
555 vpERROR_TRACE("not implemented");
556 // Do not throw and error since it is not subject
557 // to produce a failure
558 }
559}
560
585unsigned int vpFeaturePoint3D::selectX() { return FEATURE_LINE[0]; }
586
612unsigned int vpFeaturePoint3D::selectY() { return FEATURE_LINE[1]; }
613
638unsigned int vpFeaturePoint3D::selectZ() { return FEATURE_LINE[2]; }
639END_VISP_NAMESPACE
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.
unsigned int dim_s
Dimension of the visual feature.
static const unsigned int FEATURE_LINE[32]
vpBasicFeatureDeallocatorType deallocate
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
void stack(double d)
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
static unsigned int selectX()
double get_X() const
Return the coordinate in the camera frame of the 3D point.
void set_XYZ(double X, double Y, double Z)
double get_Y() const
Return the coordinate in the camera frame of the 3D point.
vpFeaturePoint3D * duplicate() const VP_OVERRIDE
static unsigned int selectZ()
vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL) VP_OVERRIDE
vpFeaturePoint3D & buildFrom(const vpPoint &p)
void print(unsigned int select=FEATURE_ALL) const VP_OVERRIDE
static unsigned int selectY()
void init() VP_OVERRIDE
vpMatrix interaction(unsigned int select=FEATURE_ALL) VP_OVERRIDE
void set_X(double X)
double get_Z() const
Return the coordinate in the camera frame of the 3D point.
void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const VP_OVERRIDE
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
void stack(const vpMatrix &A)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
#define vpTRACE
Definition vpDebug.h:450
#define vpERROR_TRACE
Definition vpDebug.h:423