Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpFeatureSegment.h
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  * Segment visual feature.
32  */
33 
39 #ifndef VP_FEATURE_SEGMENT_H
40 #define VP_FEATURE_SEGMENT_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDebug.h>
44 #include <visp3/core/vpMatrix.h>
45 #include <visp3/core/vpPoint.h>
46 #include <visp3/core/vpRGBa.h>
47 #include <visp3/visual_features/vpBasicFeature.h>
48 #include <visp3/visual_features/vpFeatureException.h>
49 
67 class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
68 {
69 public:
70  // empty constructor
71  VP_EXPLICIT vpFeatureSegment(bool normalized = false);
72 
73 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
74  // change values of the segment
75  void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2);
76 #endif
77 // change values of the segment
78  vpFeatureSegment &build(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2);
79 
80  void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpColor &color = vpColor::green,
81  unsigned int thickness = 1) const VP_OVERRIDE;
82  void display(const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color = vpColor::green,
83  unsigned int thickness = 1) const VP_OVERRIDE;
85  vpFeatureSegment *duplicate() const VP_OVERRIDE;
86  // compute the error between two visual features from a subset
87  // a the possible features
88  vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE;
89 
96  inline double getXc() const { return s[0]; }
97 
104  inline double getYc() const { return s[1]; }
105 
112  inline double getL() const { return s[2]; }
113 
120  inline double getAlpha() const { return s[3]; }
121 
128  inline double getZ1() const { return Z1_; }
129 
137  inline double getZ2() const { return Z2_; }
138 
139  // Basic construction.
140  void init() VP_OVERRIDE;
141 
142  // compute the interaction matrix from a subset a the possible features
143  vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE;
144 
145  void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE;
146 
150  bool isNormalized() { return normalized_; };
151 
152  static unsigned int selectXc();
153  static unsigned int selectYc();
154  static unsigned int selectL();
155  static unsigned int selectAlpha();
156 
163  void setNormalized(bool normalized) { normalized_ = normalized; };
164 
173  inline void setXc(double val)
174  {
175  s[0] = xc_ = val;
176  flags[0] = true;
177  }
178 
187  inline void setYc(double val)
188  {
189  s[1] = yc_ = val;
190  flags[1] = true;
191  }
192 
200  inline void setL(double val)
201  {
202  s[2] = l_ = val;
203  flags[2] = true;
204  }
205 
213  inline void setAlpha(double val)
214  {
215  s[3] = alpha_ = val;
216  cos_a_ = cos(val);
217  sin_a_ = sin(val);
218  flags[3] = true;
219  }
220 
232  inline void setZ1(double val)
233  {
234  Z1_ = val;
235 
236  if (Z1_ < 0) {
237  vpERROR_TRACE("Point is behind the camera ");
238  std::cout << "Z1 = " << Z1_ << std::endl;
239 
240  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 is behind the camera "));
241  }
242 
243  if (fabs(Z1_) < 1e-6) {
244  vpERROR_TRACE("Point Z1 coordinates is null ");
245  std::cout << "Z1 = " << Z1_ << std::endl;
246 
247  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 coordinates is null"));
248  }
249 
250  flags[4] = true;
251  }
252 
264  inline void setZ2(double val)
265  {
266  Z2_ = val;
267 
268  if (Z2_ < 0) {
269  vpERROR_TRACE("Point Z2 is behind the camera ");
270  std::cout << "Z2 = " << Z2_ << std::endl;
271 
272  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 is behind the camera "));
273  }
274 
275  if (fabs(Z2_) < 1e-6) {
276  vpERROR_TRACE("Point Z2 coordinates is null ");
277  std::cout << "Z2 = " << Z2_ << std::endl;
278 
279  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 coordinates is null"));
280  }
281 
282  flags[5] = true;
283  }
284 
285 private:
286  double xc_;
287  double yc_;
288  double l_;
289  double alpha_;
290  double Z1_;
291  double Z2_;
292  double cos_a_;
293  double sin_a_;
294  bool normalized_;
295 };
296 END_VISP_NAMESPACE
297 #endif
class that defines what is a visual feature
virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
virtual void init()=0
virtual void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const =0
virtual vpBasicFeature * duplicate() const =0
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor green
Definition: vpColor.h:220
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
double getZ2() const
double getZ1() const
double getAlpha() const
void setAlpha(double val)
void setNormalized(bool normalized)
void setL(double val)
void setZ2(double val)
double getXc() const
void setZ1(double val)
double getYc() const
double getL() const
void setXc(double val)
void setYc(double val)
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:169
#define vpERROR_TRACE
Definition: vpDebug.h:409