Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
vpMeSite.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  * Moving edges.
32  */
33 
39 #ifndef VP_ME_SITE_H
40 #define VP_ME_SITE_H
41 
42 #include <visp3/core/vpConfig.h>
43 #include <visp3/core/vpDisplay.h>
44 #include <visp3/core/vpImage.h>
45 #include <visp3/core/vpMatrix.h>
46 #include <visp3/me/vpMe.h>
47 
49 
67 class VISP_EXPORT vpMeSite
68 {
69 public:
73  typedef enum
74  {
75  NONE,
78  RANGE_RESULT
79  } vpMeSiteDisplayType;
80 
84  typedef enum
85  {
86  NO_SUPPRESSION = 0,
87  CONTRAST = 1,
88 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
89  CONSTRAST = CONTRAST,
90 #endif
91  THRESHOLD = 2,
92  M_ESTIMATOR = 3,
93  TOO_NEAR = 4,
94  UNKNOW = 5,
95  OUTSIDE_ROI_MASK = 6
96  } vpMeSiteState;
97 
99  int m_i;
101  int m_j;
103  double m_ifloat;
105  double m_jfloat;
109  double m_alpha;
111  double m_convlt;
115  double m_weight;
118 
119 public:
123  vpMeSite();
124 
128  vpMeSite(const double &ip, const double &jp);
129 
133  vpMeSite(const vpMeSite &mesite);
134 
138  virtual ~vpMeSite() { };
139 
143  double convolution(const vpImage<unsigned char> &ima, const vpMe *me);
144 
149  void display(const vpImage<unsigned char> &I);
150 
155  void display(const vpImage<vpRGBa> &I);
156 
162  inline double getAlpha() const { return m_alpha; }
163 
167  inline double getWeight() const { return m_weight; }
168 
177  vpMeSite *getQueryList(const vpImage<unsigned char> &I, const int &range) const;
178 
183  inline int get_i() const { return m_i; }
184 
189  inline int get_j() const { return m_j; }
190 
195  inline double get_ifloat() const { return m_ifloat; }
196 
201  inline double get_jfloat() const { return m_jfloat; }
202 
206  void init();
207 
211  void init(const double &ip, const double &jp, const double &alphap);
212 
216  void init(const double &ip, const double &jp, const double &alphap, const double &convltp);
217 
221  void init(const double &ip, const double &jp, const double &alphap, const double &convltp, const int &sign);
222 
226  void init(const double &ip, const double &jp, const double &alphap, const double &convltp, const int &sign, const double &contrastThreshold);
227 
238  void track(const vpImage<unsigned char> &I, const vpMe *me, const bool &test_contrast = true);
239 
245  void setAlpha(const double &a) { m_alpha = a; }
246 
250  void setDisplay(vpMeSiteDisplayType select) { m_selectDisplay = select; }
251 
259  void setState(const vpMeSiteState &flag)
260  {
261  m_state = flag;
262  }
263 
269  inline vpMeSiteState getState() const { return m_state; }
270 
276  void setWeight(const double &weight) { m_weight = weight; }
277 
289  void setContrastThreshold(const double &thresh, const vpMe &me)
290  {
291  double threshold;
292  if (me.getUseAutomaticThreshold()) {
293  threshold = std::max(thresh, me.getMinThreshold());
294  }
295  else {
296  threshold = me.getThreshold();
297  }
298 
299  m_contrastThreshold = threshold;
300  }
301 
307  inline double getContrastThreshold() const { return m_contrastThreshold; }
308 
312  vpMeSite &operator=(const vpMeSite &m);
313 
317  int operator!=(const vpMeSite &m);
318 
322  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpMeSite &vpMeS);
323 
324  // Static functions
336  static double distance(const vpMeSite &S1, const vpMeSite &S2)
337  {
338  return (sqrt(sqrDistance(S1, S2)));
339  }
340 
352  static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2)
353  {
354  return (vpMath::sqr(S1.m_ifloat - S2.m_ifloat) + vpMath::sqr(S1.m_jfloat - S2.m_jfloat));
355  }
356 
372  static void display(const vpImage<unsigned char> &I, const double &i, const double &j,
373  const vpMeSiteState &state = NO_SUPPRESSION);
374 
390  static void display(const vpImage<vpRGBa> &I, const double &i, const double &j,
391  const vpMeSiteState &state = NO_SUPPRESSION);
392 
393 private:
394  vpMeSiteDisplayType m_selectDisplay;
395  vpMeSiteState m_state;
396 };
397 
398 END_VISP_NAMESPACE
399 
400 #endif
static double sqr(double x)
Definition: vpMath.h:203
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
Definition: vpMeSite.h:68
int m_mask_sign
Mask sign.
Definition: vpMeSite.h:107
vpMeSiteState
Definition: vpMeSite.h:85
void setDisplay(vpMeSiteDisplayType select)
Definition: vpMeSite.h:250
double m_ifloat
Subpixel coordinates along i of a site.
Definition: vpMeSite.h:103
double m_normGradient
Convolution of Site in previous image.
Definition: vpMeSite.h:113
void setAlpha(const double &a)
Definition: vpMeSite.h:245
double getAlpha() const
Definition: vpMeSite.h:162
double getContrastThreshold() const
Definition: vpMeSite.h:307
double m_convlt
Convolution of Site in previous image.
Definition: vpMeSite.h:111
void setWeight(const double &weight)
Definition: vpMeSite.h:276
double m_alpha
Angle of tangent at site.
Definition: vpMeSite.h:109
vpMeSiteDisplayType
Definition: vpMeSite.h:74
@ NONE
Not displayed.
Definition: vpMeSite.h:75
@ RESULT
Definition: vpMeSite.h:77
@ RANGE
Definition: vpMeSite.h:76
static double distance(const vpMeSite &S1, const vpMeSite &S2)
Definition: vpMeSite.h:336
double m_contrastThreshold
Old likelihood ratio threshold (to be avoided) or easy-to-use normalized threshold: minimal contrast.
Definition: vpMeSite.h:117
double getWeight() const
Definition: vpMeSite.h:167
vpMeSiteState getState() const
Definition: vpMeSite.h:269
int m_j
Integer coordinates along j of a site.
Definition: vpMeSite.h:101
int get_j() const
Definition: vpMeSite.h:189
int m_i
Integer coordinate along i of a site.
Definition: vpMeSite.h:99
double get_ifloat() const
Definition: vpMeSite.h:195
double m_jfloat
Subpixel coordinates along j of a site.
Definition: vpMeSite.h:105
virtual ~vpMeSite()
Definition: vpMeSite.h:138
int get_i() const
Definition: vpMeSite.h:183
static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2)
Definition: vpMeSite.h:352
double m_weight
Uncertainty of point given as a probability between 0 and 1.
Definition: vpMeSite.h:115
double get_jfloat() const
Definition: vpMeSite.h:201
void setContrastThreshold(const double &thresh, const vpMe &me)
Definition: vpMeSite.h:289
void setState(const vpMeSiteState &flag)
Definition: vpMeSite.h:259
Definition: vpMe.h:134
bool getUseAutomaticThreshold() const
Indicates if the contrast threshold of the vpMeSite is automatically computed.
Definition: vpMe.h:318
double getThreshold() const
Definition: vpMe.h:291
double getMinThreshold() const
Definition: vpMe.h:310