Visual Servoing Platform  version 3.6.1 under development (2025-02-01)
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 
48 BEGIN_VISP_NAMESPACE
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) const;
150 
155  void display(const vpImage<vpRGBa> &I) const;
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 
251  void trackMultipleHypotheses(const vpImage<unsigned char> &I, const vpMe &me, const bool &test_contrast,
252  std::vector<vpMeSite> &outputHypotheses, const unsigned numCandidates);
253 
259  void setAlpha(const double &a) { m_alpha = a; }
260 
264  void setDisplay(vpMeSiteDisplayType select) { m_selectDisplay = select; }
265 
273  void setState(const vpMeSiteState &flag)
274  {
275  m_state = flag;
276  }
277 
283  inline vpMeSiteState getState() const { return m_state; }
284 
290  void setWeight(const double &weight) { m_weight = weight; }
291 
303  void setContrastThreshold(const double &thresh, const vpMe &me)
304  {
305  double threshold;
306  if (me.getUseAutomaticThreshold()) {
307  threshold = std::max(thresh, me.getMinThreshold());
308  }
309  else {
310  threshold = me.getThreshold();
311  }
312 
313  m_contrastThreshold = threshold;
314  }
315 
321  inline double getContrastThreshold() const { return m_contrastThreshold; }
322 
323 
329  inline double computeFinalThreshold(const vpMe &me) const
330  {
331  const double threshold = getContrastThreshold();
333  return 2.0 * threshold;
334  }
335  else {
336  const double n_d = me.getMaskSize();
337  return threshold / (100.0 * n_d * trunc(n_d / 2.0));
338  }
339  }
340 
344  vpMeSite &operator=(const vpMeSite &m);
345 
349  int operator!=(const vpMeSite &m);
350 
354  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpMeSite &vpMeS);
355 
356  // Static functions
368  static double distance(const vpMeSite &S1, const vpMeSite &S2)
369  {
370  return (sqrt(sqrDistance(S1, S2)));
371  }
372 
384  static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2)
385  {
386  return (vpMath::sqr(S1.m_ifloat - S2.m_ifloat) + vpMath::sqr(S1.m_jfloat - S2.m_jfloat));
387  }
388 
404  static void display(const vpImage<unsigned char> &I, const double &i, const double &j,
405  const vpMeSiteState &state = NO_SUPPRESSION);
406 
422  static void display(const vpImage<vpRGBa> &I, const double &i, const double &j,
423  const vpMeSiteState &state = NO_SUPPRESSION);
424 
425 private:
426  vpMeSiteDisplayType m_selectDisplay;
427  vpMeSiteState m_state;
428 };
429 
430 END_VISP_NAMESPACE
431 
432 #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:264
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:259
double getAlpha() const
Definition: vpMeSite.h:162
double getContrastThreshold() const
Definition: vpMeSite.h:321
double m_convlt
Convolution of Site in previous image.
Definition: vpMeSite.h:111
void setWeight(const double &weight)
Definition: vpMeSite.h:290
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:368
double computeFinalThreshold(const vpMe &me) const
Definition: vpMeSite.h:329
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:283
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:384
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:303
void setState(const vpMeSiteState &flag)
Definition: vpMeSite.h:273
Definition: vpMe.h:134
bool getUseAutomaticThreshold() const
Indicates if the contrast threshold of the vpMeSite is automatically computed.
Definition: vpMe.h:318
vpLikelihoodThresholdType getLikelihoodThresholdType() const
Definition: vpMe.h:327
double getThreshold() const
Definition: vpMe.h:291
unsigned int getMaskSize() const
Definition: vpMe.h:225
@ NORMALIZED_THRESHOLD
Definition: vpMe.h:145
double getMinThreshold() const
Definition: vpMe.h:310