Visual Servoing Platform  version 3.6.1 under development (2024-06-19)
vpFeatureSegment.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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 vpFeatureSegment_H
40 #define vpFeatureSegment_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpMatrix.h>
44 #include <visp3/core/vpPoint.h>
45 #include <visp3/core/vpRGBa.h>
46 #include <visp3/visual_features/vpBasicFeature.h>
47 #include <visp3/visual_features/vpFeatureException.h>
48 
66 class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
67 {
68 public:
69  // empty constructor
70  explicit vpFeatureSegment(bool normalized = false);
71 
72 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
73  // change values of the segment
74  void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2);
75 #endif
76 // change values of the segment
77  vpFeatureSegment &build(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2);
78 
79  void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpColor &color = vpColor::green,
80  unsigned int thickness = 1) const vp_override;
81  void display(const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color = vpColor::green,
82  unsigned int thickness = 1) const vp_override;
84  vpFeatureSegment *duplicate() const vp_override;
85  // compute the error between two visual features from a subset
86  // a the possible features
87  vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override;
88 
95  inline double getXc() const { return s[0]; }
96 
103  inline double getYc() const { return s[1]; }
104 
111  inline double getL() const { return s[2]; }
112 
119  inline double getAlpha() const { return s[3]; }
120 
127  inline double getZ1() const { return Z1_; }
128 
136  inline double getZ2() const { return Z2_; }
137 
138  // Basic construction.
139  void init() vp_override;
140 
141  // compute the interaction matrix from a subset a the possible features
142  vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override;
143 
144  void print(unsigned int select = FEATURE_ALL) const vp_override;
145 
149  bool isNormalized() { return normalized_; };
150 
151  static unsigned int selectXc();
152  static unsigned int selectYc();
153  static unsigned int selectL();
154  static unsigned int selectAlpha();
155 
162  void setNormalized(bool normalized) { normalized_ = normalized; };
163 
172  inline void setXc(double val)
173  {
174  s[0] = xc_ = val;
175  flags[0] = true;
176  }
177 
186  inline void setYc(double val)
187  {
188  s[1] = yc_ = val;
189  flags[1] = true;
190  }
191 
199  inline void setL(double val)
200  {
201  s[2] = l_ = val;
202  flags[2] = true;
203  }
204 
212  inline void setAlpha(double val)
213  {
214  s[3] = alpha_ = val;
215  cos_a_ = cos(val);
216  sin_a_ = sin(val);
217  flags[3] = true;
218  }
219 
231  inline void setZ1(double val)
232  {
233  Z1_ = val;
234 
235  if (Z1_ < 0) {
236  vpERROR_TRACE("Point is behind the camera ");
237  std::cout << "Z1 = " << Z1_ << std::endl;
238 
239  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 is behind the camera "));
240  }
241 
242  if (fabs(Z1_) < 1e-6) {
243  vpERROR_TRACE("Point Z1 coordinates is null ");
244  std::cout << "Z1 = " << Z1_ << std::endl;
245 
246  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 coordinates is null"));
247  }
248 
249  flags[4] = true;
250  }
251 
263  inline void setZ2(double val)
264  {
265  Z2_ = val;
266 
267  if (Z2_ < 0) {
268  vpERROR_TRACE("Point Z2 is behind the camera ");
269  std::cout << "Z2 = " << Z2_ << std::endl;
270 
271  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 is behind the camera "));
272  }
273 
274  if (fabs(Z2_) < 1e-6) {
275  vpERROR_TRACE("Point Z2 coordinates is null ");
276  std::cout << "Z2 = " << Z2_ << std::endl;
277 
278  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 coordinates is null"));
279  }
280 
281  flags[5] = true;
282  }
283 
284 private:
285  double xc_;
286  double yc_;
287  double l_;
288  double alpha_;
289  double Z1_;
290  double Z2_;
291  double cos_a_;
292  double sin_a_;
293  bool normalized_;
294 };
296 #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:171
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:153
static const vpColor green
Definition: vpColor.h:216
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:151
#define vpERROR_TRACE
Definition: vpDebug.h:385