Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpPolygon3D.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 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
38
39#ifndef vpPolygon3D_HH
40#define vpPolygon3D_HH
41
42#include <vector>
43
44#include <visp3/core/vpConfig.h>
45#include <visp3/core/vpMeterPixelConversion.h>
46#include <visp3/core/vpPixelMeterConversion.h>
47#include <visp3/core/vpPoint.h>
48
56class VISP_EXPORT vpPolygon3D
57{
58public:
59 typedef enum
60 {
70 } vpPolygon3DClippingType;
71
72public:
74 unsigned int nbpt;
77 unsigned int nbCornersInsidePrev;
81 std::vector<std::pair<vpPoint, unsigned int> > polyClipped;
83 unsigned int clippingFlag;
88
89private:
90 bool getClippedPointsFovGeneric(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
91 unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const vpColVector &normal,
92 const unsigned int &flag);
93
94 bool getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
95 unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const unsigned int &flag,
96 const double &distance);
97
98public:
100 vpPolygon3D(const vpPolygon3D &mbtp);
101 virtual ~vpPolygon3D();
102
103 void addPoint(unsigned int n, const vpPoint &P);
104
105 void changeFrame(const vpHomogeneousMatrix &cMo);
106
108
116 inline unsigned int getClipping() const { return clippingFlag; }
117
123 inline double getFarClippingDistance() const { return distFarClip; }
124
130 inline unsigned int getNbPoint() const { return nbpt; }
131
137 inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
138
139 unsigned int getNbCornerInsideImage(const vpImage<unsigned char> &I, const vpCameraParameters &cam);
140
146 inline double getNearClippingDistance() const { return distNearClip; }
147
148 vpPoint &getPoint(const unsigned int _index);
149
150 std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
151
152 std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
153
154 void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi);
155
156 void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi, const vpHomogeneousMatrix &cMo);
157
158 void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi);
159
160 void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi,
161 const vpHomogeneousMatrix &cMo);
162
163#ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
168 VP_DEPRECATED void getRoiClipped(std::vector<vpPoint> &points);
170#endif
171
172 void getPolygonClipped(std::vector<std::pair<vpPoint, unsigned int> > &poly);
173
174 void getPolygonClipped(std::vector<vpPoint> &poly);
175
176 vpPolygon3D &operator=(const vpPolygon3D &mbtp);
177
185 inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
186
192 inline void setFarClippingDistance(const double &dist)
193 {
194 distFarClip = dist;
196 }
197
198 virtual void setNbPoint(unsigned int nb);
199
205 inline void setNearClippingDistance(const double &dist)
206 {
207 distNearClip = dist;
209 }
210
211public:
212 static void getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut,
213 const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags,
214 const vpCameraParameters &cam = vpCameraParameters(), const double &znear = 0.001,
215 const double &zfar = 100);
216 static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int &i_min, int &i_max, int &j_min, int &j_max);
217 static bool roiInsideImage(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &corners);
218};
219END_VISP_NAMESPACE
220
221#ifdef VISP_HAVE_NLOHMANN_JSON
222#include VISP_NLOHMANN_JSON(json.hpp)
223#include <visp3/core/vpJsonParsing.h>
224
225#if defined(__clang__)
226// Mute warning : declaration requires an exit-time destructor [-Wexit-time-destructors]
227// message : expanded from macro 'NLOHMANN_JSON_SERIALIZE_ENUM'
228# pragma clang diagnostic push
229# pragma clang diagnostic ignored "-Wexit-time-destructors"
230#endif
231
232NLOHMANN_JSON_SERIALIZE_ENUM(VISP_NAMESPACE_ADDRESSING vpPolygon3D::vpPolygon3DClippingType, {
233 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::NO_CLIPPING, "none"},
234 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::NEAR_CLIPPING, "near"},
235 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::FAR_CLIPPING, "far"},
236 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::LEFT_CLIPPING, "left"},
237 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::RIGHT_CLIPPING, "right"},
238 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::UP_CLIPPING, "up"},
239 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::DOWN_CLIPPING, "down"},
240 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::FOV_CLIPPING, "fov"},
241 {VISP_NAMESPACE_ADDRESSING vpPolygon3D::ALL_CLIPPING, "all"}
242});
243
244#if defined(__clang__)
245# pragma clang diagnostic pop
246#endif
247
248inline nlohmann::json clippingFlagsToJSON(const unsigned int flags)
249{
250#ifdef ENABLE_VISP_NAMESPACE
251 using namespace VISP_NAMESPACE_NAME;
252#endif
253 constexpr std::array<vpPolygon3D::vpPolygon3DClippingType, 3> specificFlags = {
257 };
258 for (const auto f: specificFlags) {
259 if (flags == f) {
260 return nlohmann::json::array({ f });
261 }
262 }
263 return flagsToJSON<vpPolygon3D::vpPolygon3DClippingType>(flags, {
270 });
271}
272
273#endif
274#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:131
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
Implements a 3D polygon with render functionalities like clipping.
Definition vpPolygon3D.h:57
void changeFrame(const vpHomogeneousMatrix &cMo)
void setFarClippingDistance(const double &dist)
unsigned int nbpt
Number of points used to define the polygon.
Definition vpPolygon3D.h:74
unsigned int getNbPoint() const
void setNearClippingDistance(const double &dist)
double distNearClip
Distance for near clipping.
Definition vpPolygon3D.h:85
vpPoint * p
corners in the object frame
Definition vpPolygon3D.h:79
void computePolygonClipped(const vpCameraParameters &cam=vpCameraParameters())
double getNearClippingDistance() const
unsigned int getClipping() const
unsigned int getNbCornerInsidePrevImage() const
double getFarClippingDistance() const
unsigned int clippingFlag
Clipping flag.
Definition vpPolygon3D.h:83
void setClipping(const unsigned int &flags)
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition vpPolygon3D.h:81
void addPoint(unsigned int n, const vpPoint &P)
double distFarClip
Distance for near clipping.
Definition vpPolygon3D.h:87
unsigned int nbCornersInsidePrev
Definition vpPolygon3D.h:77