Visual Servoing Platform  version 3.1.0
vpFeatureSegment.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 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 
81  // change values of the segment
82  void buildFrom(const double x1, const double y1, const double Z1, const double x2, const double y2, const 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, const 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(const unsigned int select = FEATURE_ALL);
149 
150  void print(const 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(const double val)
179  {
180  s[0] = xc_ = val;
181  flags[0] = true;
182  }
192  inline void setYc(const double val)
193  {
194  s[1] = yc_ = val;
195  flags[1] = true;
196  }
205  inline void setL(const double val)
206  {
207  s[2] = l_ = val;
208  flags[2] = true;
209  }
218  inline void setAlpha(const 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(const 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(const 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
double getL() const
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:104
void setAlpha(const double val)
virtual void print(const unsigned int select=FEATURE_ALL) const =0
Print the name of the feature.
~vpFeatureSegment()
Destructor. Does nothing.
#define vpERROR_TRACE
Definition: vpDebug.h:393
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
virtual vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
static const vpColor green
Definition: vpColor.h:183
void setL(const double val)
void setZ1(const double val)
class that defines what is a visual feature
double getZ1() const
void setZ2(const double val)
Class that defines a 2D segment visual features. This class allow to consider two sets of visual feat...
Error that can be emited by the vpBasicFeature class and its derivates.
virtual vpMatrix interaction(const unsigned int select=FEATURE_ALL)=0
Compute the interaction matrix from a subset of the possible features.
Generic class defining intrinsic camera parameters.
virtual void init()=0
void setYc(const double val)
double getXc() const
void setNormalized(bool normalized)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double getAlpha() const
double getZ2() const
double getYc() const
virtual vpBasicFeature * duplicate() const =0
virtual void display(const vpCameraParameters &cam, const vpImage< unsigned char > &I, const vpColor &color=vpColor::green, unsigned int thickness=1) const =0
void setXc(const double val)