Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
vpTemplateTrackerZone.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Template tracker.
33  *
34  * Authors:
35  * Amaury Dame
36  * Aurelien Yol
37  *
38 *****************************************************************************/
39 #ifndef vpTemplateTrackerZone_hh
40 #define vpTemplateTrackerZone_hh
41 
42 #include <vector>
43 
44 #include <visp3/core/vpConfig.h>
45 #include <visp3/core/vpDisplay.h>
46 #include <visp3/core/vpException.h>
47 #include <visp3/core/vpImage.h>
48 #include <visp3/core/vpRect.h>
49 #include <visp3/tt/vpTemplateTrackerHeader.h>
50 #include <visp3/tt/vpTemplateTrackerTriangle.h>
51 
52 BEGIN_VISP_NAMESPACE
63 class VISP_EXPORT vpTemplateTrackerZone
64 {
65 protected:
66  std::vector<vpTemplateTrackerTriangle> Zone;
67  int min_x;
68  int min_y;
69  int max_x;
70  int max_y;
71 
72 public:
75  virtual ~vpTemplateTrackerZone();
76 
77  // add a triangle to the zone
78  void add(const vpTemplateTrackerTriangle &t);
79  void clear();
80  void copy(const vpTemplateTrackerZone &z);
81 
82  // display the area on an image
83  void display(const vpImage<unsigned char> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
84  void display(const vpImage<vpRGBa> &I, const vpColor &col = vpColor::green, unsigned int thickness = 3);
85 
86  // colorie le tieme triangle
87  void fillTriangle(vpImage<unsigned char> &I, unsigned int id, unsigned char gray_level);
88 
89  double getArea() const;
90  vpImagePoint getCenter() const;
91  vpImagePoint getCenter(int borne_x, int borne_y) const;
92  // get bounds of the area
93  int getMaxx() const;
94  int getMaxy() const;
95  int getMinx() const;
96  int getMiny() const;
97  vpRect getBoundingBox() const;
98 
101  unsigned int getNbTriangle() const { return (unsigned int)Zone.size(); }
102  vpTemplateTrackerZone getPyramidDown() const;
103  // renvoie le ieme triangle de la zone
104  void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const;
105  vpTemplateTrackerTriangle getTriangle(unsigned int i) const;
106 
107  // create an area by clicking on an image
108  void initClick(const vpImage<unsigned char> &I, bool delaunay = false);
109  // create an area with a pointer of integer that describes a series of
110  // triangles:
111  // *pt= t0.S1.x,t0.S1.y,t0.S2.x,t0.S2.y,t0.S3.x,t0.S3.y, t1.S1.x ...
112  void initFromPoints(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ip, bool delaunay = false);
113 
114  // check if a point is in the area
115  bool inZone(const int &i, const int &j) const;
116  bool inZone(const double &i, const double &j) const;
117  // check if a point is in the area and return the corresponding triangle
118  // id_triangle where the point is.
119  bool inZone(const int &i, const int &j, unsigned int &id_triangle) const;
120  bool inZone(const double &i, const double &j, unsigned int &id_triangle) const;
121 
122  vpTemplateTrackerZone &operator=(const vpTemplateTrackerZone &z);
123 };
124 END_VISP_NAMESPACE
125 #endif
Class to define RGB colors available for display functionalities.
Definition: vpColor.h:157
static const vpColor green
Definition: vpColor.h:220
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:82
Defines a rectangle in the plane.
Definition: vpRect.h:79
std::vector< vpTemplateTrackerTriangle > Zone
Vector of triangles that defines the zone.
int max_y
Bounding box parameter.
unsigned int getNbTriangle() const
int max_x
Bounding box parameter.
int min_y
Bounding box parameter.
int min_x
Bounding box parameter.