Visual Servoing Platform  version 3.2.1 under development (2019-05-20)
vpTemplateTrackerZone.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 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 http://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  * Fabien Spindler
38  *
39  *****************************************************************************/
40 #ifndef vpTemplateTrackerZone_hh
41 #define vpTemplateTrackerZone_hh
42 
43 #include <vector>
44 
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 
62 class VISP_EXPORT vpTemplateTrackerZone
63 {
64 protected:
65  std::vector<vpTemplateTrackerTriangle> Zone;
66  int min_x;
67  int min_y;
68  int max_x;
69  int max_y;
70 
71 public:
74  virtual ~vpTemplateTrackerZone();
75 
76  // add a triangle to the zone
77  void add(const vpTemplateTrackerTriangle &t);
78  void clear();
79  void copy(const vpTemplateTrackerZone &z);
80 
81  // display the area on an image
82  void display(const vpImage<unsigned char> &I, const vpColor &col = vpColor::green, const unsigned int thickness = 3);
83  void display(const vpImage<vpRGBa> &I, const vpColor &col = vpColor::green, const unsigned int thickness = 3);
84 
85  // colorie le tieme triangle
86  void fillTriangle(vpImage<unsigned char> &I, unsigned int id, unsigned char gray_level);
87 
88  double getArea() const;
89  vpImagePoint getCenter() const;
90  vpImagePoint getCenter(int borne_x, int borne_y) const;
91  // get bounds of the area
92  int getMaxx() const;
93  int getMaxy() const;
94  int getMinx() const;
95  int getMiny() const;
96  vpRect getBoundingBox() const;
97 
100  unsigned int getNbTriangle() const { return (unsigned int)Zone.size(); }
101  vpTemplateTrackerZone getPyramidDown() const;
102  // renvoie le ieme triangle de la zone
103  void getTriangle(unsigned int i, vpTemplateTrackerTriangle &T) const;
104  vpTemplateTrackerTriangle getTriangle(unsigned int i) const;
105 
106  // create an area by clicking on an image
107  void initClick(const vpImage<unsigned char> &I, bool delaunay = false);
108  // create an area with a pointer of integer that describes a series of
109  // triangles:
110  // *pt= t0.S1.x,t0.S1.y,t0.S2.x,t0.S2.y,t0.S3.x,t0.S3.y, t1.S1.x ...
111  void initFromPoints(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &ip, bool delaunay = false);
112 
113  // check if a point is in the area
114  bool inZone(const int &i, const int &j) const;
115  bool inZone(const double &i, const double &j) const;
116  // check if a point is in the area and return the corresponding triangle
117  // id_triangle where the point is.
118  bool inZone(const int &i, const int &j, unsigned int &id_triangle) const;
119  bool inZone(const double &i, const double &j, unsigned int &id_triangle) const;
120 
121  vpTemplateTrackerZone &operator=(const vpTemplateTrackerZone &z);
122 };
123 #endif
std::vector< vpTemplateTrackerTriangle > Zone
Vector of triangles that defines the zone.
int max_y
Bounding box parameter.
Class to define colors available for display functionnalities.
Definition: vpColor.h:120
int min_x
Bounding box parameter.
static const vpColor green
Definition: vpColor.h:183
unsigned int getNbTriangle() const
int min_y
Bounding box parameter.
int max_x
Bounding box parameter.
Defines a rectangle in the plane.
Definition: vpRect.h:78
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88