Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpFeatureSegment.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 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
38
39#ifndef VP_FEATURE_SEGMENT_H
40#define VP_FEATURE_SEGMENT_H
41
42#include <visp3/core/vpConfig.h>
43#include <visp3/core/vpDebug.h>
44#include <visp3/core/vpMatrix.h>
45#include <visp3/core/vpPoint.h>
46#include <visp3/core/vpRGBa.h>
47#include <visp3/visual_features/vpBasicFeature.h>
48#include <visp3/visual_features/vpFeatureException.h>
49
67class VISP_EXPORT vpFeatureSegment : public vpBasicFeature
68{
69public:
70 // empty constructor
71 VP_EXPLICIT vpFeatureSegment(bool normalized = false);
72
73// change values of the segment
74 vpFeatureSegment &buildFrom(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2);
75
76 void display(const vpCameraParameters &cam, const vpImage<unsigned char> &I, const vpColor &color = vpColor::green,
77 unsigned int thickness = 1) const VP_OVERRIDE;
78 void display(const vpCameraParameters &cam, const vpImage<vpRGBa> &I, const vpColor &color = vpColor::green,
79 unsigned int thickness = 1) const VP_OVERRIDE;
81 vpFeatureSegment *duplicate() const VP_OVERRIDE;
82 // compute the error between two visual features from a subset
83 // a the possible features
84 vpColVector error(const vpBasicFeature &s_star, unsigned int select = FEATURE_ALL) VP_OVERRIDE;
85
92 inline double getXc() const { return s[0]; }
93
100 inline double getYc() const { return s[1]; }
101
108 inline double getL() const { return s[2]; }
109
116 inline double getAlpha() const { return s[3]; }
117
124 inline double getZ1() const { return Z1_; }
125
133 inline double getZ2() const { return Z2_; }
134
135 // Basic construction.
136 void init() VP_OVERRIDE;
137
138 // compute the interaction matrix from a subset a the possible features
139 vpMatrix interaction(unsigned int select = FEATURE_ALL) VP_OVERRIDE;
140
141 void print(unsigned int select = FEATURE_ALL) const VP_OVERRIDE;
142
146 bool isNormalized() { return normalized_; }
147
148 static unsigned int selectXc();
149 static unsigned int selectYc();
150 static unsigned int selectL();
151 static unsigned int selectAlpha();
152
159 void setNormalized(bool normalized) { normalized_ = normalized; }
160
169 inline void setXc(double val)
170 {
171 s[0] = xc_ = val;
172 flags[0] = true;
173 }
174
183 inline void setYc(double val)
184 {
185 s[1] = yc_ = val;
186 flags[1] = true;
187 }
188
196 inline void setL(double val)
197 {
198 s[2] = l_ = val;
199 flags[2] = true;
200 }
201
209 inline void setAlpha(double val)
210 {
211 s[3] = alpha_ = val;
212 cos_a_ = cos(val);
213 sin_a_ = sin(val);
214 flags[3] = true;
215 }
216
228 inline void setZ1(double val)
229 {
230 Z1_ = val;
231
232 if (Z1_ < 0) {
233 vpERROR_TRACE("Point is behind the camera ");
234 std::cout << "Z1 = " << Z1_ << std::endl;
235
236 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 is behind the camera "));
237 }
238
239 if (fabs(Z1_) < 1e-6) {
240 vpERROR_TRACE("Point Z1 coordinates is null ");
241 std::cout << "Z1 = " << Z1_ << std::endl;
242
243 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z1 coordinates is null"));
244 }
245
246 flags[4] = true;
247 }
248
260 inline void setZ2(double val)
261 {
262 Z2_ = val;
263
264 if (Z2_ < 0) {
265 vpERROR_TRACE("Point Z2 is behind the camera ");
266 std::cout << "Z2 = " << Z2_ << std::endl;
267
268 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 is behind the camera "));
269 }
270
271 if (fabs(Z2_) < 1e-6) {
272 vpERROR_TRACE("Point Z2 coordinates is null ");
273 std::cout << "Z2 = " << Z2_ << std::endl;
274
275 throw(vpFeatureException(vpFeatureException::badInitializationError, "Point Z2 coordinates is null"));
276 }
277
278 flags[5] = true;
279 }
280
281private:
282 double xc_;
283 double yc_;
284 double l_;
285 double alpha_;
286 double Z1_;
287 double Z2_;
288 double cos_a_;
289 double sin_a_;
290 bool normalized_;
291};
292END_VISP_NAMESPACE
293#endif
virtual vpColVector error(const vpBasicFeature &s_star, unsigned int select=FEATURE_ALL)
vpColVector s
State of the visual feature.
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.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor green
Definition vpColor.h:201
Error that can be emitted by the vpBasicFeature class and its derivates.
@ badInitializationError
Wrong feature initialization.
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)
VP_EXPLICIT vpFeatureSegment(bool normalized=false)
vpFeatureSegment & buildFrom(const double &x1, const double &y1, const double &Z1, const double &x2, const double &y2, const double &Z2)
double getXc() const
void setZ1(double val)
double getYc() const
double getL() const
void setXc(double val)
void setYc(double val)
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:175
#define vpERROR_TRACE
Definition vpDebug.h:423