Visual Servoing Platform  version 3.3.0
vpFeatureSegment.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Segment visual feature.
33  *
34  * Authors:
35  * Filip Novotny
36  * Fabien Spindler
37  *
38  *****************************************************************************/
39 
40 #ifndef vpFeatureSegment_H
41 #define vpFeatureSegment_H
42 
48 #include <visp3/core/vpMatrix.h>
49 #include <visp3/core/vpPoint.h>
50 #include <visp3/core/vpRGBa.h>
51 #include <visp3/visual_features/vpBasicFeature.h>
52 #include <visp3/visual_features/vpFeatureException.h>
53 
73 class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
74 {
75 public:
76  // empty constructor
77  explicit vpFeatureSegment(bool normalized = false);
78 
80  virtual ~vpFeatureSegment() {}
81  // change values of the segment
82  void buildFrom(double x1, double y1, double Z1, double x2, double y2, double Z2);
83 
84  void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpColor &color = vpColor::green,
85  unsigned int thickness = 1) const;
86  void display(const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color = vpColor::green,
87  unsigned int thickness = 1) const;
89  vpFeatureSegment *duplicate() const;
90  // compute the error between two visual features from a subset
91  // a the possible features
92  vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL);
93 
100  inline double getXc() const { return s[0]; }
101 
108  inline double getYc() const { return s[1]; }
109 
117  inline double getL() const { return s[2]; }
118 
125  inline double getAlpha() const { return s[3]; }
126 
133  inline double getZ1() const { return Z1_; }
134 
142  inline double getZ2() const { return Z2_; }
143 
144  // Basic construction.
145  void init();
146 
147  // compute the interaction matrix from a subset a the possible features
148  vpMatrix interaction(unsigned int select = FEATURE_ALL);
149 
150  void print(unsigned int select = FEATURE_ALL) const;
151 
155  bool isNormalized() { return normalized_; };
156 
157  static unsigned int selectXc();
158  static unsigned int selectYc();
159  static unsigned int selectL();
160  static unsigned int selectAlpha();
161 
168  void setNormalized(bool normalized) { normalized_ = normalized; };
178  inline void setXc(double val)
179  {
180  s[0] = xc_ = val;
181  flags[0] = true;
182  }
192  inline void setYc(double val)
193  {
194  s[1] = yc_ = val;
195  flags[1] = true;
196  }
205  inline void setL(double val)
206  {
207  s[2] = l_ = val;
208  flags[2] = true;
209  }
218  inline void setAlpha(double val)
219  {
220  s[3] = alpha_ = val;
221  cos_a_ = cos(val);
222  sin_a_ = sin(val);
223  flags[3] = true;
224  }
225 
238  inline void setZ1(double val)
239  {
240  Z1_ = val;
241 
242  if (Z1_ < 0) {
243  vpERROR_TRACE("Point is behind the camera ");
244  std::cout << "Z1 = " << Z1_ << std::endl;
245 
246  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 is behind the camera "));
247  }
248 
249  if (fabs(Z1_) < 1e-6) {
250  vpERROR_TRACE("Point Z1 coordinates is null ");
251  std::cout << "Z1 = " << Z1_ << std::endl;
252 
253  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 coordinates is null"));
254  }
255 
256  flags[4] = true;
257  }
258 
271  inline void setZ2(double val)
272  {
273  Z2_ = val;
274 
275  if (Z2_ < 0) {
276  vpERROR_TRACE("Point Z2 is behind the camera ");
277  std::cout << "Z2 = " << Z2_ << std::endl;
278 
279  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 is behind the camera "));
280  }
281 
282  if (fabs(Z2_) < 1e-6) {
283  vpERROR_TRACE("Point Z2 coordinates is null ");
284  std::cout << "Z2 = " << Z2_ << std::endl;
285 
286  throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 coordinates is null"));
287  }
288 
289  flags[5] = true;
290  }
291 
292 private:
293  double xc_;
294  double yc_;
295  double l_;
296  double alpha_;
297  double Z1_;
298  double Z2_;
299  double cos_a_;
300  double sin_a_;
301  bool normalized_;
302 };
303 
304 #endif
vpFeatureSegment::getZ2
double getZ2() const
Definition: vpFeatureSegment.h:142
vpBasicFeature::interaction
virtual vpMatrix interaction(unsigned int select=FEATURE_ALL)=0
Compute the interaction matrix from a subset of the possible features.
vpFeatureSegment::getZ1
double getZ1() const
Definition: vpFeatureSegment.h:133
vpFeatureSegment::setNormalized
void setNormalized(bool normalized)
Definition: vpFeatureSegment.h:168
vpBasicFeature::display
virtual void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const =0
vpFeatureSegment::setZ1
void setZ1(double val)
Definition: vpFeatureSegment.h:238
vpBasicFeature::print
virtual void print(unsigned int select=FEATURE_ALL) const =0
Print the name of the feature.
vpCameraParameters
Generic class defining intrinsic camera parameters.
Definition: vpCameraParameters.h:233
vpBasicFeature::init
virtual void init()=0
vpFeatureSegment::setAlpha
void setAlpha(double val)
Definition: vpFeatureSegment.h:218
vpFeatureSegment
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
Definition: vpFeatureSegment.h:73
vpFeatureSegment::~vpFeatureSegment
virtual ~vpFeatureSegment()
Destructor. Does nothing.
Definition: vpFeatureSegment.h:80
vpColVector
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
vpMatrix
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:164
vpColor::green
static const vpColor green
Definition: vpColor.h:182
vpFeatureSegment::setYc
void setYc(double val)
Definition: vpFeatureSegment.h:192
vpFeatureSegment::setL
void setL(double val)
Definition: vpFeatureSegment.h:205
vpFeatureException
Error that can be emited by the vpBasicFeature class and its derivates.
Definition: vpFeatureException.h:72
vpFeatureException::badInitializationError
@ badInitializationError
Definition: vpFeatureException.h:84
vpFeatureSegment::getL
double getL() const
Definition: vpFeatureSegment.h:117
vpFeatureSegment::setXc
void setXc(double val)
Definition: vpFeatureSegment.h:178
vpFeatureSegment::setZ2
void setZ2(double val)
Definition: vpFeatureSegment.h:271
vpERROR_TRACE
#define vpERROR_TRACE
Definition: vpDebug.h:393
vpBasicFeature::error
virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
Definition: vpBasicFeature.cpp:151
vpFeatureSegment::getAlpha
double getAlpha() const
Definition: vpFeatureSegment.h:125
vpFeatureSegment::isNormalized
bool isNormalized()
Definition: vpFeatureSegment.h:155
vpImage< unsigned char >
vpFeatureSegment::getYc
double getYc() const
Definition: vpFeatureSegment.h:108
vpColor
Class to define colors available for display functionnalities.
Definition: vpColor.h:119
vpFeatureSegment::getXc
double getXc() const
Definition: vpFeatureSegment.h:100
vpBasicFeature::duplicate
virtual vpBasicFeature * duplicate() const =0
vpBasicFeature
class that defines what is a visual feature
Definition: vpBasicFeature.h:77