Visual Servoing Platform  version 3.0.1
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vpPolygon.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2017 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Defines a generic 2D polygon.
32  *
33  * Author:
34  * Amaury Dame
35  * Nicolas Melchior
36  * Romain Tallonneau
37  *
38  *****************************************************************************/
39 
40 #ifndef vpPolygon_h
41 #define vpPolygon_h
42 
43 #include <vector>
44 #include <list>
45 
46 #include <visp3/core/vpImagePoint.h>
47 #include <visp3/core/vpRect.h>
48 #include <visp3/core/vpColor.h>
49 #include <visp3/core/vpImage.h>
50 #include <visp3/core/vpPoint.h>
51 #include <visp3/core/vpCameraParameters.h>
52 
99 class VISP_EXPORT vpPolygon
100 {
101  protected:
103  std::vector<vpImagePoint> _corners;
107  double _area;
109  bool _goodPoly;
112 
113  public:
116  PnPolyRayCasting
117  };
118 
119  vpPolygon();
120  vpPolygon(const std::vector<vpImagePoint>& corners);
121  vpPolygon(const std::list<vpImagePoint>& corners);
122  vpPolygon(const vpPolygon &poly);
123  virtual ~vpPolygon();
124 
125  vpPolygon &operator=(const vpPolygon& poly);
126 
127  void buildFrom(const std::vector<vpImagePoint>& corners);
128  void buildFrom(const std::list<vpImagePoint>& corners);
129  void buildFrom(const std::vector<vpPoint>& corners, const vpCameraParameters& cam);
130 
131  unsigned int getSize() const;
132  void initClick(const vpImage<unsigned char>& I);
133 
134  bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method=PnPolyRayCasting) const;
135 
136  void display(const vpImage<unsigned char>& I, const vpColor& color, unsigned int thickness=1) const;
137 
143  const std::vector<vpImagePoint>& getCorners() const {
144  return _corners;
145  }
146 
147 
154  inline double getArea() const{
155  return this->_area;
156  }
157 
164  inline vpImagePoint getCenter() const{
165  return this->_center;
166  }
167 
174  inline vpRect getBoundingBox() const {
175  return _bbox;
176  }
177 
178  protected:
179  void init(const std::vector<vpImagePoint>& corners);
180  void init(const std::list<vpImagePoint>& corners);
181  void updateArea();
182  void updateCenter();
183  void updateBoundingBox();
184 
185  private:
186  bool testIntersectionSegments(const vpImagePoint& ip1, const vpImagePoint& ip2, const vpImagePoint& ip3, const vpImagePoint& ip4) const;
187  void precalcValuesPnPoly();
188 
189  std::vector<double> m_PnPolyConstants;
190  std::vector<double> m_PnPolyMultiples;
191 
192  //###################
193  // Static Functions
194  //###################
195 
196  public:
197  static bool isInside(const std::vector<vpImagePoint>& roi, const double &i, const double &j, const PointInPolygonMethod &method=PnPolyRayCasting);
198  private:
199  static bool intersect(const vpImagePoint& p1, const vpImagePoint& p2, const double &i, const double &j, const double &i_test, const double &j_test);
200 };
201 
202 #endif
203 
const std::vector< vpImagePoint > & getCorners() const
Definition: vpPolygon.h:143
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
vpRect _bbox
Bounding box containing the polygon.
Definition: vpPolygon.h:111
vpImagePoint _center
Center of the polygon. It is automatically computed when the corners are set.
Definition: vpPolygon.h:105
Defines a generic 2D polygon.
Definition: vpPolygon.h:99
vpRect getBoundingBox() const
Definition: vpPolygon.h:174
PointInPolygonMethod
Definition: vpPolygon.h:114
Generic class defining intrinsic camera parameters.
double getArea() const
Definition: vpPolygon.h:154
vpImagePoint getCenter() const
Definition: vpPolygon.h:164
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
Definition: vpPolygon.h:103
bool _goodPoly
Flag set to true when the polygon is a good polygon (ie. it has more than two corners) or false other...
Definition: vpPolygon.h:109
Defines a rectangle in the plane.
Definition: vpRect.h:82
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:88
double _area
Area of the polygon.
Definition: vpPolygon.h:107