Visual Servoing Platform  version 3.6.1 under development (2024-04-22)
vpMeSite.h
1 /*
2  * ViSP, open source Visual Servoing Platform software.
3  * Copyright (C) 2005 - 2023 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 _vpMeSite_h_
40 #define _vpMeSite_h_
41 
42 #include <visp3/core/vpDisplay.h>
43 #include <visp3/core/vpImage.h>
44 #include <visp3/core/vpMatrix.h>
45 #include <visp3/me/vpMe.h>
46 
64 class VISP_EXPORT vpMeSite
65 {
66 public:
70  typedef enum
71  {
72  NONE,
75  RANGE_RESULT
76  } vpMeSiteDisplayType;
77 
81  typedef enum
82  {
83  NO_SUPPRESSION = 0,
84  CONTRAST = 1,
85 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
86  CONSTRAST = CONTRAST,
87 #endif
88  THRESHOLD = 2,
89  M_ESTIMATOR = 3,
90  TOO_NEAR = 4,
91  UNKNOW = 5,
92  OUTSIDE_ROI_MASK = 6
93  } vpMeSiteState;
94 
96  int m_i;
98  int m_j;
100  double m_ifloat;
102  double m_jfloat;
106  double m_alpha;
108  double m_convlt;
112  double m_weight;
115 
116 public:
120  vpMeSite();
121 
125  vpMeSite(const double &ip, const double &jp);
126 
130  vpMeSite(const vpMeSite &mesite);
131 
135  virtual ~vpMeSite() { };
136 
140  double convolution(const vpImage<unsigned char> &ima, const vpMe *me);
141 
146  void display(const vpImage<unsigned char> &I);
147 
152  void display(const vpImage<vpRGBa> &I);
153 
159  inline double getAlpha() const { return m_alpha; }
160 
164  inline double getWeight() const { return m_weight; }
165 
174  vpMeSite *getQueryList(const vpImage<unsigned char> &I, const int &range) const;
175 
180  inline int get_i() const { return m_i; }
181 
186  inline int get_j() const { return m_j; }
187 
192  inline double get_ifloat() const { return m_ifloat; }
193 
198  inline double get_jfloat() const { return m_jfloat; }
199 
203  void init();
204 
208  void init(const double &ip, const double &jp, const double &alphap);
209 
213  void init(const double &ip, const double &jp, const double &alphap, const double &convltp);
214 
218  void init(const double &ip, const double &jp, const double &alphap, const double &convltp, const int &sign);
219 
223  void init(const double &ip, const double &jp, const double &alphap, const double &convltp, const int &sign, const double &contrastThreshold);
224 
235  void track(const vpImage<unsigned char> &I, const vpMe *me, const bool &test_contrast = true);
236 
242  void setAlpha(const double &a) { m_alpha = a; }
243 
247  void setDisplay(vpMeSiteDisplayType select) { m_selectDisplay = select; }
248 
256  void setState(const vpMeSiteState &flag)
257  {
258  m_state = flag;
259  }
260 
266  inline vpMeSiteState getState() const { return m_state; }
267 
273  void setWeight(const double &weight) { m_weight = weight; }
274 
286  void setContrastThreshold(const double &thresh, const vpMe &me)
287  {
288  double threshold;
289  if (me.getUseAutomaticThreshold()) {
290  threshold = std::max(thresh, me.getMinThreshold());
291  }
292  else {
293  threshold = me.getThreshold();
294  }
295 
296  m_contrastThreshold = threshold;
297  }
298 
304  inline double getContrastThreshold() const { return m_contrastThreshold; }
305 
309  vpMeSite &operator=(const vpMeSite &m);
310 
314  int operator!=(const vpMeSite &m);
315 
319  friend VISP_EXPORT std::ostream &operator<<(std::ostream &os, vpMeSite &vpMeS);
320 
321  // Static functions
333  static double distance(const vpMeSite &S1, const vpMeSite &S2)
334  {
335  return (sqrt(sqrDistance(S1, S2)));
336  }
337 
349  static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2)
350  {
351  return (vpMath::sqr(S1.m_ifloat - S2.m_ifloat) + vpMath::sqr(S1.m_jfloat - S2.m_jfloat));
352  }
353 
369  static void display(const vpImage<unsigned char> &I, const double &i, const double &j,
370  const vpMeSiteState &state = NO_SUPPRESSION);
371 
387  static void display(const vpImage<vpRGBa> &I, const double &i, const double &j,
388  const vpMeSiteState &state = NO_SUPPRESSION);
389 
390 private:
391  vpMeSiteDisplayType m_selectDisplay;
392  vpMeSiteState m_state;
393 };
394 
395 #endif
static double sqr(double x)
Definition: vpMath.h:201
Performs search in a given direction(normal) for a given distance(pixels) for a given 'site'....
Definition: vpMeSite.h:65
int m_mask_sign
Mask sign.
Definition: vpMeSite.h:104
vpMeSiteState
Definition: vpMeSite.h:82
void setDisplay(vpMeSiteDisplayType select)
Definition: vpMeSite.h:247
double m_ifloat
Subpixel coordinates along i of a site.
Definition: vpMeSite.h:100
double m_normGradient
Convolution of Site in previous image.
Definition: vpMeSite.h:110
void setAlpha(const double &a)
Definition: vpMeSite.h:242
double getAlpha() const
Definition: vpMeSite.h:159
double getContrastThreshold() const
Definition: vpMeSite.h:304
double m_convlt
Convolution of Site in previous image.
Definition: vpMeSite.h:108
void setWeight(const double &weight)
Definition: vpMeSite.h:273
double m_alpha
Angle of tangent at site.
Definition: vpMeSite.h:106
vpMeSiteDisplayType
Definition: vpMeSite.h:71
@ NONE
Not displayed.
Definition: vpMeSite.h:72
@ RESULT
Definition: vpMeSite.h:74
@ RANGE
Definition: vpMeSite.h:73
static double distance(const vpMeSite &S1, const vpMeSite &S2)
Definition: vpMeSite.h:333
double m_contrastThreshold
Old likelihood ratio threshold (to be avoided) or easy-to-use normalized threshold: minimal contrast.
Definition: vpMeSite.h:114
double getWeight() const
Definition: vpMeSite.h:164
vpMeSiteState getState() const
Definition: vpMeSite.h:266
int m_j
Integer coordinates along j of a site.
Definition: vpMeSite.h:98
int get_j() const
Definition: vpMeSite.h:186
int m_i
Integer coordinate along i of a site.
Definition: vpMeSite.h:96
double get_ifloat() const
Definition: vpMeSite.h:192
double m_jfloat
Subpixel coordinates along j of a site.
Definition: vpMeSite.h:102
virtual ~vpMeSite()
Definition: vpMeSite.h:135
int get_i() const
Definition: vpMeSite.h:180
static double sqrDistance(const vpMeSite &S1, const vpMeSite &S2)
Definition: vpMeSite.h:349
double m_weight
Uncertainty of point given as a probability between 0 and 1.
Definition: vpMeSite.h:112
double get_jfloat() const
Definition: vpMeSite.h:198
void setContrastThreshold(const double &thresh, const vpMe &me)
Definition: vpMeSite.h:286
void setState(const vpMeSiteState &flag)
Definition: vpMeSite.h:256
Definition: vpMe.h:124
bool getUseAutomaticThreshold() const
Indicates if the contrast threshold of the vpMeSite is automatically computed.
Definition: vpMe.h:332
double getThreshold() const
Definition: vpMe.h:305
double getMinThreshold() const
Definition: vpMe.h:324