Visual Servoing Platform  version 3.4.0
vpPolygon3D.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * Implements a polygon of the model used by the model-based tracker.
33  *
34  * Authors:
35  * Aurelien Yol
36  *
37  *****************************************************************************/
38 
44 #ifndef vpPolygon3D_HH
45 #define vpPolygon3D_HH
46 
47 #include <vector>
48 
49 #include <visp3/core/vpMeterPixelConversion.h>
50 #include <visp3/core/vpPixelMeterConversion.h>
51 #include <visp3/core/vpPoint.h>
52 
59 class VISP_EXPORT vpPolygon3D
60 {
61 public:
62  typedef enum {
63  NO_CLIPPING = 0,
64  NEAR_CLIPPING = 1,
65  FAR_CLIPPING = 2,
66  LEFT_CLIPPING = 4,
67  RIGHT_CLIPPING = 8,
68  UP_CLIPPING = 16,
69  DOWN_CLIPPING = 32,
70  FOV_CLIPPING = 60,
71  ALL_CLIPPING = 63
73 
74 public:
76  unsigned int nbpt;
79  unsigned int nbCornersInsidePrev;
83  std::vector<std::pair<vpPoint, unsigned int> > polyClipped;
85  unsigned int clippingFlag;
87  double distNearClip;
89  double distFarClip;
90 
91 private:
92  bool getClippedPointsFovGeneric(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
93  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const vpColVector &normal,
94  const unsigned int &flag);
95 
96  bool getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2, vpPoint &p1Clipped, vpPoint &p2Clipped,
97  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo, const unsigned int &flag,
98  const double &distance);
99 
100 public:
101  vpPolygon3D();
102  vpPolygon3D(const vpPolygon3D &mbtp);
103  virtual ~vpPolygon3D();
104 
105  void addPoint(unsigned int n, const vpPoint &P);
106 
107  void changeFrame(const vpHomogeneousMatrix &cMo);
108 
109  void computePolygonClipped(const vpCameraParameters &cam = vpCameraParameters());
110 
118  inline unsigned int getClipping() const { return clippingFlag; }
119 
125  inline double getFarClippingDistance() const { return distFarClip; }
126 
132  inline unsigned int getNbPoint() const { return nbpt; }
133 
139  inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
140 
141  unsigned int getNbCornerInsideImage(const vpImage<unsigned char> &I, const vpCameraParameters &cam);
142 
148  inline double getNearClippingDistance() const { return distNearClip; }
149 
150  vpPoint &getPoint(const unsigned int _index);
151 
152  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
153 
154  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
155 
156  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi);
157 
158  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi, const vpHomogeneousMatrix &cMo);
159 
160  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi);
161 
162  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint, unsigned int> > &roi,
163  const vpHomogeneousMatrix &cMo);
164 
165 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
166 
170  vp_deprecated void getRoiClipped(std::vector<vpPoint> &points);
172 #endif
173 
174  void getPolygonClipped(std::vector<std::pair<vpPoint, unsigned int> > &poly);
175 
176  void getPolygonClipped(std::vector<vpPoint> &poly);
177 
178  vpPolygon3D &operator=(const vpPolygon3D &mbtp);
179 
187  inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
188 
194  inline void setFarClippingDistance(const double &dist)
195  {
196  distFarClip = dist;
197  clippingFlag = (clippingFlag | vpPolygon3D::FAR_CLIPPING);
198  }
199 
200  virtual void setNbPoint(unsigned int nb);
201 
207  inline void setNearClippingDistance(const double &dist)
208  {
209  distNearClip = dist;
210  clippingFlag = (clippingFlag | vpPolygon3D::NEAR_CLIPPING);
211  }
212 
213 public:
214  static void getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut,
215  const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags,
216  const vpCameraParameters &cam = vpCameraParameters(), const double &znear = 0.001,
217  const double &zfar = 100);
218  static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int &i_min, int &i_max, int &j_min, int &j_max);
219  static bool roiInsideImage(const vpImage<unsigned char> &I, const std::vector<vpImagePoint> &corners);
220 };
221 
222 #endif
Implements a 3D polygon with render functionnalities like clipping.
Definition: vpPolygon3D.h:59
unsigned int nbCornersInsidePrev
Definition: vpPolygon3D.h:79
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setFarClippingDistance(const double &dist)
Definition: vpPolygon3D.h:194
double getFarClippingDistance() const
Definition: vpPolygon3D.h:125
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition: vpPoint.h:81
vpPolygon3DClippingType
Definition: vpPolygon3D.h:62
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition: vpPolygon3D.h:83
double getNearClippingDistance() const
Definition: vpPolygon3D.h:148
double distFarClip
Distance for near clipping.
Definition: vpPolygon3D.h:89
double distNearClip
Distance for near clipping.
Definition: vpPolygon3D.h:87
Generic class defining intrinsic camera parameters.
unsigned int getClipping() const
Definition: vpPolygon3D.h:118
void setClipping(const unsigned int &flags)
Definition: vpPolygon3D.h:187
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpPolygon3D.h:76
Implementation of column vector and the associated operations.
Definition: vpColVector.h:130
void setNearClippingDistance(const double &dist)
Definition: vpPolygon3D.h:207
unsigned int getNbPoint() const
Definition: vpPolygon3D.h:132
unsigned int clippingFlag
Clipping flag.
Definition: vpPolygon3D.h:85
unsigned int getNbCornerInsidePrevImage() const
Definition: vpPolygon3D.h:139