Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
vpPolygon3D.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 * Implements a polygon of the model used by the model-based tracker.
32 */
33
39#ifndef vpPolygon3D_HH
40#define vpPolygon3D_HH
41
42#include <vector>
43
44#include <visp3/core/vpMeterPixelConversion.h>
45#include <visp3/core/vpPixelMeterConversion.h>
46#include <visp3/core/vpPoint.h>
47
54class VISP_EXPORT vpPolygon3D
55{
56public:
57 typedef enum {
58 NO_CLIPPING = 0,
59 NEAR_CLIPPING = 1,
60 FAR_CLIPPING = 2,
61 LEFT_CLIPPING = 4,
62 RIGHT_CLIPPING = 8,
63 UP_CLIPPING = 16,
64 DOWN_CLIPPING = 32,
65 FOV_CLIPPING = 60,
66 ALL_CLIPPING = 63
67 } vpPolygon3DClippingType;
68
69public:
71 unsigned int nbpt;
74 unsigned int nbCornersInsidePrev;
78 std::vector<std::pair<vpPoint, unsigned int> > polyClipped;
80 unsigned int clippingFlag;
85
86private:
87 bool getClippedPointsFovGeneric(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
88 unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const vpColVector &normal,
89 const unsigned int &flag);
90
91 bool getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
92 unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const unsigned int &flag,
93 const double &distance);
94
95public:
97 vpPolygon3D(const vpPolygon3D &mbtp);
98 virtual ~vpPolygon3D();
99
100 void addPoint(unsigned int n, const vpPoint &P);
101
102 void changeFrame(const vpHomogeneousMatrix &cMo);
103
104 void computePolygonClipped(const vpCameraParameters &cam = vpCameraParameters());
105
113 inline unsigned int getClipping() const { return clippingFlag; }
114
120 inline double getFarClippingDistance() const { return distFarClip; }
121
127 inline unsigned int getNbPoint() const { return nbpt; }
128
134 inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
135
136 unsigned int getNbCornerInsideImage(const vpImage<unsigned char> &I, const vpCameraParameters &cam);
137
143 inline double getNearClippingDistance() const { return distNearClip; }
144
145 vpPoint &getPoint(const unsigned int _index);
146
147 std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
148
149 std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
150
151 void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi);
152
153 void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi, const vpHomogeneousMatrix &cMo);
154
155 void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi);
156
157 void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi,
158 const vpHomogeneousMatrix &cMo);
159
160#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
165 vp_deprecated void getRoiClipped(std::vector<vpPoint> &points);
167#endif
168
169 void getPolygonClipped(std::vector<std::pair<vpPoint, unsigned int> > &poly);
170
171 void getPolygonClipped(std::vector<vpPoint> &poly);
172
173 vpPolygon3D &operator=(const vpPolygon3D &mbtp);
174
182 inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
183
189 inline void setFarClippingDistance(const double &dist)
190 {
191 distFarClip = dist;
192 clippingFlag = (clippingFlag | vpPolygon3D::FAR_CLIPPING);
193 }
194
195 virtual void setNbPoint(unsigned int nb);
196
202 inline void setNearClippingDistance(const double &dist)
203 {
204 distNearClip = dist;
205 clippingFlag = (clippingFlag | vpPolygon3D::NEAR_CLIPPING);
206 }
207
208public:
209 static void getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut,
210 const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags,
211 const vpCameraParameters &cam = vpCameraParameters(), const double &znear = 0.001,
212 const double &zfar = 100);
213 static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int &i_min, int &i_max, int &j_min, int &j_max);
214 static bool roiInsideImage(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &corners);
215};
216
217
218#ifdef VISP_HAVE_NLOHMANN_JSON
219#include <nlohmann/json.hpp>
220#include <visp3/core/vpJsonParsing.h>
221NLOHMANN_JSON_SERIALIZE_ENUM( vpPolygon3D::vpPolygon3DClippingType, {
222 {vpPolygon3D::NO_CLIPPING, "none"},
231});
232
233inline nlohmann::json clippingFlagsToJSON(const int flags) {
234 constexpr std::array<vpPolygon3D::vpPolygon3DClippingType, 3> specificFlags = {
238 };
239 for(const auto f: specificFlags) {
240 if(flags == f) {
241 return nlohmann::json::array({ f });
242 }
243 }
244 return flagsToJSON<vpPolygon3D::vpPolygon3DClippingType>(flags, {
251 });
252}
253
254#endif
255
256#endif
Generic class defining intrinsic camera parameters.
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:135
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:77
Implements a 3D polygon with render functionalities like clipping.
Definition vpPolygon3D.h:55
void setFarClippingDistance(const double &dist)
unsigned int nbpt
Number of points used to define the polygon.
Definition vpPolygon3D.h:71
unsigned int getNbPoint() const
void setNearClippingDistance(const double &dist)
double distNearClip
Distance for near clipping.
Definition vpPolygon3D.h:82
vpPoint * p
corners in the object frame
Definition vpPolygon3D.h:76
double getNearClippingDistance() const
unsigned int getClipping() const
unsigned int getNbCornerInsidePrevImage() const
double getFarClippingDistance() const
unsigned int clippingFlag
Clipping flag.
Definition vpPolygon3D.h:80
void setClipping(const unsigned int &flags)
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition vpPolygon3D.h:78
double distFarClip
Distance for near clipping.
Definition vpPolygon3D.h:84
unsigned int nbCornersInsidePrev
Definition vpPolygon3D.h:74