Visual Servoing Platform  version 3.0.0
vpPolygon3D.h
1 /****************************************************************************
2  *
3  * This file is part of the ViSP software.
4  * Copyright (C) 2005 - 2015 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * ("GPL") version 2 as published by the Free Software Foundation.
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 http://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  * Authors:
34  * Aurelien Yol
35  *
36  *****************************************************************************/
37 
43 #ifndef vpPolygon3D_HH
44 #define vpPolygon3D_HH
45 
46 #include <vector>
47 
48 #include <visp3/core/vpPoint.h>
49 #include <visp3/core/vpPixelMeterConversion.h>
50 #include <visp3/core/vpMeterPixelConversion.h>
51 
52 
59 class VISP_EXPORT vpPolygon3D
60 {
61 public:
62  typedef enum
63  {
64  NO_CLIPPING = 0,
65  NEAR_CLIPPING = 1,
66  FAR_CLIPPING = 2,
67  LEFT_CLIPPING = 4,
68  RIGHT_CLIPPING = 8,
69  UP_CLIPPING = 16,
70  DOWN_CLIPPING = 32,
71  FOV_CLIPPING = 60,
72  ALL_CLIPPING = 63
73  } vpPolygon3DClippingType;
74 
75 public:
77  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,
93  vpPoint &p1Clipped, vpPoint &p2Clipped,
94  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
95  const vpColVector &normal,
96  const unsigned int &flag);
97 
98  bool getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2,
99  vpPoint &p1Clipped, vpPoint &p2Clipped,
100  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
101  const unsigned int &flag, const double &distance);
102 
103 public:
104  vpPolygon3D() ;
105  vpPolygon3D(const vpPolygon3D& mbtp) ;
106  virtual ~vpPolygon3D() ;
107 
108  void addPoint(const unsigned int n, const vpPoint &P) ;
109 
110  void changeFrame(const vpHomogeneousMatrix &cMo) ;
111 
112  void computePolygonClipped(const vpCameraParameters &cam = vpCameraParameters());
113 
121  inline unsigned int getClipping() const { return clippingFlag; }
122 
128  inline double getFarClippingDistance() const { return distFarClip; }
129 
135  inline unsigned int getNbPoint() const {return nbpt ;}
136 
142  inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
143 
144  unsigned int getNbCornerInsideImage(const vpImage<unsigned char>& I, const vpCameraParameters &cam);
145 
151  inline double getNearClippingDistance() const { return distNearClip; }
152 
153  vpPoint & getPoint(const unsigned int _index);
154 
155  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
156 
157  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
158 
159  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi);
160 
161  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi, const vpHomogeneousMatrix &cMo);
162 
163  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi);
164 
165  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo);
166 
167 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
168 
172  vp_deprecated void getRoiClipped(std::vector<vpPoint> &points);
174 #endif
175 
176  void getPolygonClipped(std::vector<std::pair<vpPoint,unsigned int> > &poly);
177 
178  void getPolygonClipped(std::vector<vpPoint> &poly);
179 
180  vpPolygon3D& operator=(const vpPolygon3D& mbtp) ;
181 
189  inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
190 
196  inline void setFarClippingDistance(const double &dist) { distFarClip = dist; clippingFlag = (clippingFlag | vpPolygon3D::FAR_CLIPPING);}
197 
198  virtual void setNbPoint(const unsigned int nb) ;
199 
205  inline void setNearClippingDistance(const double &dist) { distNearClip = dist; clippingFlag = (clippingFlag | vpPolygon3D::NEAR_CLIPPING);}
206 
207 public:
208  static void getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut, const vpHomogeneousMatrix &cMo,
209  const unsigned int &clippingFlags, const vpCameraParameters &cam = vpCameraParameters(),
210  const double &znear = 0.001, const double &zfar = 100 );
211  static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int & i_min, int &i_max, int &j_min, int &j_max);
212  static bool roiInsideImage(const vpImage<unsigned char>& I, const std::vector<vpImagePoint>& corners);
213 };
214 
215 #endif
216 
Implements a 3D polygon with render functionnalities like clipping.
Definition: vpPolygon3D.h:59
unsigned int nbCornersInsidePrev
Number of corners inside the image during the last call to getNbCornerInsideImage.
Definition: vpPolygon3D.h:79
Implementation of an homogeneous matrix and operations on such kind of matrices.
void setFarClippingDistance(const double &dist)
Definition: vpPolygon3D.h:196
double getFarClippingDistance() const
Definition: vpPolygon3D.h:128
vpPoint * p
corners in the object frame
Definition: vpPolygon3D.h:81
Class that defines what is a point.
Definition: vpPoint.h:59
double getNearClippingDistance() const
Definition: vpPolygon3D.h:151
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:121
std::vector< std::pair< vpPoint, unsigned int > > polyClipped
Region of interest clipped.
Definition: vpPolygon3D.h:83
void setClipping(const unsigned int &flags)
Definition: vpPolygon3D.h:189
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpPolygon3D.h:77
Implementation of column vector and the associated operations.
Definition: vpColVector.h:72
void setNearClippingDistance(const double &dist)
Definition: vpPolygon3D.h:205
unsigned int getNbPoint() const
Definition: vpPolygon3D.h:135
unsigned int clippingFlag
Clipping flag.
Definition: vpPolygon3D.h:85
unsigned int getNbCornerInsidePrevImage() const
Definition: vpPolygon3D.h:142