Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Filip Novotny
35  * Fabien Spindler
36  *
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/visual_features/vpBasicFeature.h>
51 #include <visp3/core/vpRGBa.h>
52 #include <visp3/visual_features/vpFeatureException.h>
53 
72 class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
73 {
74 public:
75  //empty constructor
76  vpFeatureSegment(bool normalized=false);
77 
80  // change values of the segment
81  void buildFrom(const double x1, const double y1, const double Z1, const double x2, const double y2, const double Z2);
82 
83  void display(const vpCameraParameters &cam,
84  const vpImage<unsigned char> &I,
85  const vpColor &color=vpColor::green,
86  unsigned int thickness=1) const ;
87  void display(const vpCameraParameters &cam,
88  const vpImage<vpRGBa> &I,
89  const vpColor &color=vpColor::green,
90  unsigned int thickness=1) const ;
92  vpFeatureSegment *duplicate() const ;
93  // compute the error between two visual features from a subset
94  // a the possible features
95  vpColVector error(const vpBasicFeature &s_star,
96  const unsigned int select = FEATURE_ALL) ;
97 
103  inline double getXc() const { return s[0] ; }
104 
110  inline double getYc() const { return s[1] ; }
111 
118  inline double getL() const { return s[2] ; }
119 
125  inline double getAlpha() const { return s[3] ;}
126 
133  inline double getZ1() const { return Z1_ ;}
134 
141  inline double getZ2() const { return Z2_ ;}
142 
143  // Basic construction.
144  void init() ;
145 
146  // compute the interaction matrix from a subset a the possible features
147  vpMatrix interaction(const unsigned int select = FEATURE_ALL);
148 
149  void print(const unsigned int select= FEATURE_ALL) const ;
150 
154  bool isNormalized() { return normalized_; };
155 
156  static unsigned int selectXc();
157  static unsigned int selectYc();
158  static unsigned int selectL();
159  static unsigned int selectAlpha();
160 
166  void setNormalized(bool normalized) { normalized_ = normalized; };
175  inline void setXc(const double val){
176  s[0] = xc_ = val;
177  flags[0] = true;
178  }
187  inline void setYc(const double val){
188  s[1] = yc_ = val;
189  flags[1] = true;
190  }
198  inline void setL(const double val){
199  s[2] = l_ = val;
200  flags[2] = true;
201  }
209  inline void setAlpha(const double val){
210  s[3] = alpha_ = val;
211  cos_a_ = cos(val);
212  sin_a_ = sin(val);
213  flags[3] = true;
214  }
215 
227  inline void setZ1(const double val)
228  {
229  Z1_ = val;
230 
231  if (Z1_ < 0)
232  {
233  vpERROR_TRACE("Point is behind the camera ") ;
234  std::cout <<"Z1 = " << Z1_ << std::endl ;
235 
237  "Point Z1 is behind the camera ")) ;
238  }
239 
240  if (fabs(Z1_) < 1e-6)
241  {
242  vpERROR_TRACE("Point Z1 coordinates is null ") ;
243  std::cout <<"Z1 = " << Z1_ << std::endl ;
244 
246  "Point Z1 coordinates is null")) ;
247  }
248 
249  flags[4] = true;
250  }
251 
263  inline void setZ2(const double val)
264  {
265  Z2_ = val;
266 
267  if (Z2_ < 0)
268  {
269  vpERROR_TRACE("Point Z2 is behind the camera ") ;
270  std::cout <<"Z2 = " << Z2_ << std::endl ;
271 
273  "Point Z2 is behind the camera ")) ;
274  }
275 
276  if (fabs(Z2_) < 1e-6)
277  {
278  vpERROR_TRACE("Point Z2 coordinates is null ") ;
279  std::cout <<"Z2 = " << Z2_ << std::endl ;
280 
282  "Point Z2 coordinates is null")) ;
283  }
284 
285  flags[5] = true;
286  }
287 
288 
289 private:
290  double xc_;
291  double yc_;
292  double l_;
293  double alpha_;
294  double Z1_;
295  double Z2_;
296  double cos_a_;
297  double sin_a_;
298  bool normalized_;
299 } ;
300 
301 #endif
302 
Implementation of a matrix and operations on matrices.
Definition: vpMatrix.h:97
double getZ1() const
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:391
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
double getZ2() const
virtual vpColVector error(const vpBasicFeature &s_star, const unsigned int select=FEATURE_ALL)
Compute the error between two visual features from a subset of the possible features.
static const vpColor green
Definition: vpColor.h:166
void setL(const double val)
void setZ1(const double val)
class that defines what is a visual feature
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.
double getAlpha() const
Generic class defining intrinsic camera parameters.
virtual void init()=0
double getL() const
void setYc(const double val)
void setNormalized(bool normalized)
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
double getYc() const
virtual vpBasicFeature * duplicate() const =0
double getXc() const
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)