ViSP  2.8.0
vpPolygon.h
1 /****************************************************************************
2  *
3  * $Id: vpPolygon.h 4056 2013-01-05 13:04:42Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Defines a generic 2D polygon.
36  *
37  * Author:
38  * Amaury Dame
39  * Nicolas Melchior
40  * Romain Tallonneau
41  *
42  *****************************************************************************/
43 
44 #ifndef vpPolygon_h
45 #define vpPolygon_h
46 
93 #include <visp/vpImagePoint.h>
94 #include <visp/vpRect.h>
95 #include <visp/vpColor.h>
96 #include <visp/vpImage.h>
97 #include <visp/vpPoint.h>
98 #include <visp/vpCameraParameters.h>
99 
100 #include <vector>
101 
102 class VISP_EXPORT vpPolygon
103 {
104  protected:
106  std::vector<vpImagePoint> _corners;
110  double _area;
112  bool _goodPoly;
115 
116  public:
117  vpPolygon();
118  vpPolygon(const std::vector<vpImagePoint>& corners);
119  vpPolygon(const vpPolygon &poly);
120  virtual ~vpPolygon();
121 
122  vpPolygon &operator=(const vpPolygon& poly);
123 
124  void buildFrom(const std::vector<vpImagePoint>& corners);
125  void buildFrom(const std::vector<vpPoint>& corners, const vpCameraParameters& cam);
126  void initClick(const vpImage<unsigned char>& I);
127 
128  bool isInside(const vpImagePoint &iP);
129 
130  void display(const vpImage<unsigned char>& I, const vpColor& color, unsigned int thickness=1);
131 
137  const std::vector<vpImagePoint>& getCorners() const {
138  return _corners;
139  }
140 
141 
148  inline double getArea() const{
149  return this->_area;
150  }
151 
158  inline vpImagePoint getCenter() const{
159  return this->_center;
160  }
161 
168  inline vpRect getBoundingBox() const {
169  return _bbox;
170  }
171 
172  protected:
173  void init(const std::vector<vpImagePoint>& corners);
174  void updateArea();
175  void updateCenter();
176  void updateBoundingBox();
177 
178  private:
179  bool testIntersectionSegments(const vpImagePoint& ip1, const vpImagePoint& ip2, const vpImagePoint& ip3, const vpImagePoint& ip4);
180 
181 };
182 
183 #endif
184 
const std::vector< vpImagePoint > & getCorners() const
Definition: vpPolygon.h:137
Class to define colors available for display functionnalities.
Definition: vpColor.h:125
vpRect _bbox
Boumding box containing the polygon.
Definition: vpPolygon.h:114
vpImagePoint _center
Center of the polygon. It is automatically computed when the corners are set.
Definition: vpPolygon.h:108
Defines a generic 2D polygon.
Definition: vpPolygon.h:102
vpRect getBoundingBox() const
Definition: vpPolygon.h:168
Generic class defining intrinsic camera parameters.
double getArea() const
Definition: vpPolygon.h:148
vpImagePoint getCenter() const
Definition: vpPolygon.h:158
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
Definition: vpPolygon.h:106
bool _goodPoly
Flag to indicate whether the polygon is a good polygon (ie. it has more than two corners, ...)
Definition: vpPolygon.h:112
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:92
double _area
Area of the polygon.
Definition: vpPolygon.h:110