Visual Servoing Platform  version 3.0.0
vpPolygon.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 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 
45 #include <visp3/core/vpImagePoint.h>
46 #include <visp3/core/vpRect.h>
47 #include <visp3/core/vpColor.h>
48 #include <visp3/core/vpImage.h>
49 #include <visp3/core/vpPoint.h>
50 #include <visp3/core/vpCameraParameters.h>
51 
98 class VISP_EXPORT vpPolygon
99 {
100  protected:
102  std::vector<vpImagePoint> _corners;
106  double _area;
108  bool _goodPoly;
111 
112  public:
113  vpPolygon();
114  vpPolygon(const std::vector<vpImagePoint>& corners);
115  vpPolygon(const vpPolygon &poly);
116  virtual ~vpPolygon();
117 
118  vpPolygon &operator=(const vpPolygon& poly);
119 
120  void buildFrom(const std::vector<vpImagePoint>& corners);
121  void buildFrom(const std::vector<vpPoint>& corners, const vpCameraParameters& cam);
122  void initClick(const vpImage<unsigned char>& I);
123 
124  bool isInside(const vpImagePoint &iP);
125 
126  void display(const vpImage<unsigned char>& I, const vpColor& color, unsigned int thickness=1) const;
127 
133  const std::vector<vpImagePoint>& getCorners() const {
134  return _corners;
135  }
136 
137 
144  inline double getArea() const{
145  return this->_area;
146  }
147 
154  inline vpImagePoint getCenter() const{
155  return this->_center;
156  }
157 
164  inline vpRect getBoundingBox() const {
165  return _bbox;
166  }
167 
168  protected:
169  void init(const std::vector<vpImagePoint>& corners);
170  void updateArea();
171  void updateCenter();
172  void updateBoundingBox();
173 
174  private:
175  bool testIntersectionSegments(const vpImagePoint& ip1, const vpImagePoint& ip2, const vpImagePoint& ip3, const vpImagePoint& ip4);
176 
177  //###################
178  // Static Functions
179  //###################
180 
181  public:
182  static bool isInside(const std::vector<vpImagePoint>& roi, const double &i, const double &j);
183  private:
184  static bool intersect(const vpImagePoint& p1, const vpImagePoint& p2, const double &i, const double &j, const double &i_test, const double &j_test);
185 };
186 
187 #endif
188 
const std::vector< vpImagePoint > & getCorners() const
Definition: vpPolygon.h:133
Class to define colors available for display functionnalities.
Definition: vpColor.h:121
vpRect _bbox
Boumding box containing the polygon.
Definition: vpPolygon.h:110
vpImagePoint _center
Center of the polygon. It is automatically computed when the corners are set.
Definition: vpPolygon.h:104
Defines a generic 2D polygon.
Definition: vpPolygon.h:98
vpRect getBoundingBox() const
Definition: vpPolygon.h:164
Generic class defining intrinsic camera parameters.
double getArea() const
Definition: vpPolygon.h:144
vpImagePoint getCenter() const
Definition: vpPolygon.h:154
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
Definition: vpPolygon.h:102
bool _goodPoly
Flag to indicate whether the polygon is a good polygon (ie. it has more than two corners, ...)
Definition: vpPolygon.h:108
Defines a rectangle in the plane.
Definition: vpRect.h:81
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:106