Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpPolygon.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
34#ifndef _vpPolygon_h_
35#define _vpPolygon_h_
36
37#include <list>
38#include <vector>
39
40#include <visp3/core/vpCameraParameters.h>
41#include <visp3/core/vpColor.h>
42#include <visp3/core/vpImage.h>
43#include <visp3/core/vpImagePoint.h>
44#include <visp3/core/vpPoint.h>
45#include <visp3/core/vpRect.h>
46
96class VISP_EXPORT vpPolygon
97{
98protected:
100 std::vector<vpImagePoint> _corners;
105 double _area;
111
112public:
118
119 vpPolygon();
120 explicit vpPolygon(const std::vector<vpImagePoint> &corners);
121 explicit 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, const bool create_convex_hull = false);
128 void buildFrom(const std::list<vpImagePoint> &corners, const bool create_convex_hull = false);
129 void buildFrom(const std::vector<vpPoint> &corners, const vpCameraParameters &cam,
130 const bool create_convex_hull = false);
131
132 unsigned int getSize() const;
133 void initClick(const vpImage<unsigned char> &I, unsigned int size = 5, const vpColor &color = vpColor::red,
134 unsigned int thickness = 1);
135 void initClick(const vpImage<vpRGBa> &I, unsigned int size = 5, const vpColor &color = vpColor::red,
136 unsigned int thickness = 1);
137
138 bool isInside(const vpImagePoint &iP, const PointInPolygonMethod &method = PnPolyRayCasting) const;
139
140 void display(const vpImage<unsigned char> &I, const vpColor &color, unsigned int thickness = 1) const;
141
147 const std::vector<vpImagePoint> &getCorners() const { return _corners; }
148
155 inline double getArea() const { return this->_area; }
156
163 inline vpImagePoint getCenter() const { return this->_center; }
164
171 inline vpRect getBoundingBox() const { return _bbox; }
172
173protected:
174 void init(const std::vector<vpImagePoint> &corners);
175 void init(const std::list<vpImagePoint> &corners);
176 void updateArea();
177 void updateCenter();
178 void updateBoundingBox();
179
180private:
181 bool testIntersectionSegments(const vpImagePoint &ip1, const vpImagePoint &ip2, const vpImagePoint &ip3,
182 const vpImagePoint &ip4) const;
183 void precalcValuesPnPoly();
184
185 std::vector<double> m_PnPolyConstants;
186 std::vector<double> m_PnPolyMultiples;
187
188 //###################
189 // Static Functions
190 //###################
191
192public:
193 static bool isInside(const std::vector<vpImagePoint> &roi, const double &i, const double &j,
194 const PointInPolygonMethod &method = PnPolyRayCasting);
195};
196
197#endif
Generic class defining intrinsic camera parameters.
Class to define RGB colors available for display functionalities.
Definition vpColor.h:152
static const vpColor red
Definition vpColor.h:211
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition of the vpImage class member functions.
Definition vpImage.h:135
Defines a generic 2D polygon.
Definition vpPolygon.h:97
bool _goodPoly
Definition vpPolygon.h:108
vpRect getBoundingBox() const
Definition vpPolygon.h:171
vpImagePoint getCenter() const
Definition vpPolygon.h:163
const std::vector< vpImagePoint > & getCorners() const
Definition vpPolygon.h:147
vpImagePoint _center
Definition vpPolygon.h:103
double getArea() const
Definition vpPolygon.h:155
vpRect _bbox
Bounding box containing the polygon.
Definition vpPolygon.h:110
PointInPolygonMethod
Definition vpPolygon.h:113
@ PnPolySegmentIntersection
Definition vpPolygon.h:114
std::vector< vpImagePoint > _corners
Collection of image points containing the corners.
Definition vpPolygon.h:100
double _area
Area of the polygon.
Definition vpPolygon.h:105
Defines a rectangle in the plane.
Definition vpRect.h:76