Visual Servoing Platform  version 3.6.1 under development (2024-03-29)
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 
34 #ifndef vpFeatureSegment_H
35 #define vpFeatureSegment_H
36 
42 #include <visp3/core/vpMatrix.h>
43 #include <visp3/core/vpPoint.h>
44 #include <visp3/core/vpRGBa.h>
45 #include <visp3/visual_features/vpBasicFeature.h>
46 #include <visp3/visual_features/vpFeatureException.h>
47 
64 class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
65 {
66 public:
67  // empty constructor
68  explicit vpFeatureSegment(bool normalized = false);
69 
70  // change values of the segment
71  void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2);
72 
73  void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpColor &color = vpColor::green,
74  unsigned int thickness = 1) const vp_override;
75  void display(const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color = vpColor::green,
76  unsigned int thickness = 1) const vp_override;
78  vpFeatureSegment *duplicate() const vp_override;
79  // compute the error between two visual features from a subset
80  // a the possible features
81  vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) vp_override;
82 
89  inline double getXc() const { return s[0]; }
90 
97  inline double getYc() const { return s[1]; }
98 
105  inline double getL() const { return s[2]; }
106 
113  inline double getAlpha() const { return s[3]; }
114 
121  inline double getZ1() const { return Z1_; }
122 
130  inline double getZ2() const { return Z2_; }
131 
132  // Basic construction.
133  void init() vp_override;
134 
135  // compute the interaction matrix from a subset a the possible features
136  vpMatrix interaction(unsigned int select = FEATURE_ALL) vp_override;
137 
138  void print(unsigned int select = FEATURE_ALL) const vp_override;
139 
143  bool isNormalized() { return normalized_; };
144 
145  static unsigned int selectXc();
146  static unsigned int selectYc();
147  static unsigned int selectL();
148  static unsigned int selectAlpha();
149 
156  void setNormalized(bool normalized) { normalized_ = normalized; };
157 
166  inline void setXc(double val)
167  {
168  s[0] = xc_ = val;
169  flags[0] = true;
170  }
171 
180  inline void setYc(double val)
181  {
182  s[1] = yc_ = val;
183  flags[1] = true;
184  }
185 
193  inline void setL(double val)
194  {
195  s[2] = l_ = val;
196  flags[2] = true;
197  }
198 
206  inline void setAlpha(double val)
207  {
208  s[3] = alpha_ = val;
209  cos_a_ = cos(val);
210  sin_a_ = sin(val);
211  flags[3] = true;
212  }
213 
225  inline void setZ1(double val)
226  {
227  Z1_ = val;
228 
229  if (Z1_ < 0) {
230  vpERROR_TRACE("Point is behind the camera ");
231  std::cout << "Z1 = " << Z1_ << std::endl;
232 
233  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 is behind the camera "));
234  }
235 
236  if (fabs(Z1_) < 1e-6) {
237  vpERROR_TRACE("Point Z1 coordinates is null ");
238  std::cout << "Z1 = " << Z1_ << std::endl;
239 
240  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 coordinates is null"));
241  }
242 
243  flags[4] = true;
244  }
245 
257  inline void setZ2(double val)
258  {
259  Z2_ = val;
260 
261  if (Z2_ < 0) {
262  vpERROR_TRACE("Point Z2 is behind the camera ");
263  std::cout << "Z2 = " << Z2_ << std::endl;
264 
265  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 is behind the camera "));
266  }
267 
268  if (fabs(Z2_) < 1e-6) {
269  vpERROR_TRACE("Point Z2 coordinates is null ");
270  std::cout << "Z2 = " << Z2_ << std::endl;
271 
272  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 coordinates is null"));
273  }
274 
275  flags[5] = true;
276  }
277 
278 private:
279  double xc_;
280  double yc_;
281  double l_;
282  double alpha_;
283  double Z1_;
284  double Z2_;
285  double cos_a_;
286  double sin_a_;
287  bool normalized_;
288 };
289 
290 #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:163
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:152
static const vpColor green
Definition: vpColor.h:214
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:146
#define vpERROR_TRACE
Definition: vpDebug.h:382