Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpPolygon.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  * Defines a generic 2D polygon.
33  *
34  * Author:
35  * Amaury Dame
36  * Nicolas Melchior
37  * Romain Tallonneau
38  *
39  *****************************************************************************/
40 
41 #ifndef vpPolygon_h
42 #define vpPolygon_h
43 
44 #include <list>
45 #include <vector>
46 
47 #include <visp3/core/vpCameraParameters.h>
48 #include <visp3/core/vpColor.h>
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpImagePoint.h>
51 #include <visp3/core/vpPoint.h>
52 #include <visp3/core/vpRect.h>
53 
103 class VISP_EXPORT vpPolygon
104 {
105 protected:
107  std::vector<vpImagePoint> _corners;
112  double _area;
115  bool _goodPoly;
118 
119 public:
122  PnPolyRayCasting
124  };
125 
126  vpPolygon();
127  explicit vpPolygon(const std::vector<vpImagePoint> &corners);
128  explicit vpPolygon(const std::list<vpImagePoint> &corners);
129  vpPolygon(const vpPolygon &poly);
130  virtual ~vpPolygon();
131 
132  vpPolygon &operator=(const vpPolygon &poly);
133 
134  void buildFrom(const std::vector<vpImagePoint> &corners);
135  void buildFrom(const std::list<vpImagePoint> &corners);
136  void buildFrom(const std::vector<vpPoint> &corners, const vpCameraParameters &cam);
137 
138  unsigned int getSize() const;
139  void initClick(const vpImage<unsigned char> &I, unsigned int size = 5, const vpColor &color = vpColor::red,
140  unsigned int thickness = 1);
141  void initClick(const vpImage<vpRGBa> &I, unsigned int size = 5, const vpColor &color = vpColor::red,
142  unsigned int thickness = 1);
143 
144  bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method = PnPolyRayCasting) const;
145 
146  void display(const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness = 1) const;
147 
153  const std::vector<vpImagePoint> &getCorners() const { return _corners; }
154 
161  inline double getArea() const { return this->_area; }
162 
169  inline vpImagePoint getCenter() const { return this->_center; }
170 
177  inline vpRect getBoundingBox() const { return _bbox; }
178 
179 protected:
180  void init(const std::vector<vpImagePoint> &corners);
181  void init(const std::list<vpImagePoint> &corners);
182  void updateArea();
183  void updateCenter();
184  void updateBoundingBox();
185 
186 private:
187  bool testIntersectionSegments(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpImagePoint &ip3,
188  const vpImagePoint &ip4) const;
189  void precalcValuesPnPoly();
190 
191  std::vector<double> m_PnPolyConstants;
192  std::vector<double> m_PnPolyMultiples;
193 
194  //###################
195  // Static Functions
196  //###################
197 
198 public:
199  static bool isInside(const std::vector<vpImagePoint> &roi, const double &i, const double &j,
200  const PointInPolygonMethod &method = PnPolyRayCasting);
201 };
202 
203 #endif
Class to define RGB colors available for display functionnalities.
Definition: vpColor.h:157
double getArea() const
Definition: vpPolygon.h:161
vpRect _bbox
Bounding box containing the polygon.
Definition: vpPolygon.h:117
vpImagePoint _center
Definition: vpPolygon.h:110
vpRect getBoundingBox() const
Definition: vpPolygon.h:177
static const vpColor red
Definition: vpColor.h:217
Defines a generic 2D polygon.
Definition: vpPolygon.h:103
PointInPolygonMethod
Definition: vpPolygon.h:120
Generic class defining intrinsic camera parameters.
const std::vector< vpImagePoint > & getCorners() const
Definition: vpPolygon.h:153
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
Definition: vpPolygon.h:107
bool _goodPoly
Definition: vpPolygon.h:115
Defines a rectangle in the plane.
Definition: vpRect.h:79
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:87
double _area
Area of the polygon.
Definition: vpPolygon.h:112
vpImagePoint getCenter() const
Definition: vpPolygon.h:169