ViSP  2.9.0
vpMbtPolygon.h
1 /****************************************************************************
2  *
3  * $Id: vpMbtPolygon.h 4632 2014-02-03 17:06:40Z fspindle $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2014 by INRIA. All rights reserved.
7  *
8  * This software is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * ("GPL") version 2 as published by the Free Software Foundation.
11  * See the file LICENSE.txt at the root directory of this source
12  * distribution for additional information about the GNU GPL.
13  *
14  * For using ViSP with software that can not be combined with the GNU
15  * GPL, please contact INRIA about acquiring a ViSP Professional
16  * Edition License.
17  *
18  * See http://www.irisa.fr/lagadic/visp/visp.html for more information.
19  *
20  * This software was developed at:
21  * INRIA Rennes - Bretagne Atlantique
22  * Campus Universitaire de Beaulieu
23  * 35042 Rennes Cedex
24  * France
25  * http://www.irisa.fr/lagadic
26  *
27  * If you have questions regarding the use of this file, please contact
28  * INRIA at visp@inria.fr
29  *
30  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
31  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
32  *
33  *
34  * Description:
35  * Implements a polygon of the model used by the model-based tracker.
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Romain Tallonneau
40  * Eric Marchand
41  * Aurelien Yol
42  *
43  *****************************************************************************/
44 
50 #ifndef vpMbtPolygon_HH
51 #define vpMbtPolygon_HH
52 
53 #include <visp/vpPoint.h>
54 #include <visp/vpMeterPixelConversion.h>
55 #include <visp/vpPixelMeterConversion.h>
56 
57 #include <vector>
58 
67 class VISP_EXPORT vpMbtPolygon
68 {
69 public:
70  typedef enum
71  {
72  NO_CLIPPING = 0,
73  NEAR_CLIPPING = 1,
74  FAR_CLIPPING = 2,
75  LEFT_CLIPPING = 4,
76  RIGHT_CLIPPING = 8,
77  UP_CLIPPING = 16,
78  DOWN_CLIPPING = 32,
79  FOV_CLIPPING = 60,
80  ALL_CLIPPING = 63
81  } vpMbtPolygonClippingType;
82 
83 public:
85  int index;
87  unsigned int nbpt;
89  unsigned int nbCornersInsidePrev;
91  bool isvisible;
97  std::vector<std::pair<vpPoint,unsigned int> > roiPointsClip;
99  unsigned int clippingFlag;
101  double distNearClip;
103  double distFarClip;
104 
105 private:
106  bool getClippedPointsFov(const vpPoint &p1, const vpPoint &p2,
107  vpPoint &p1Clipped, vpPoint &p2Clipped,
108  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
109  const vpColVector &normal,
110  const unsigned int &flag);
111 
112  bool getClippedPoints(const vpPoint &p1, const vpPoint &p2,
113  vpPoint &p1Clipped, vpPoint &p2Clipped,
114  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
115  const vpCameraParameters &cam, const std::vector<vpColVector> &fovNormals);
116 
117 public:
118  vpMbtPolygon() ;
119  vpMbtPolygon(const vpMbtPolygon& mbtp) ;
120  virtual ~vpMbtPolygon() ;
121 
122  void addPoint(const unsigned int n, const vpPoint &P) ;
123 
124  void changeFrame(const vpHomogeneousMatrix &cMo) ;
125 
126  void computeRoiClipped(const vpCameraParameters &cam = vpCameraParameters());
127 
135  inline unsigned int getClipping() const { return clippingFlag; }
136 
142  inline double getFarClippingDistance() const { return distFarClip; }
143 
149  inline int getIndex() const {return index ;}
150 
156  inline unsigned int getNbPoint() const {return nbpt ;}
157 
163  inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
164 
165  unsigned int getNbCornerInsideImage(const vpImage<unsigned char>& I, const vpCameraParameters &cam);
166 
172  inline double getNearClippingDistance() const { return distNearClip; }
173 
174  vpPoint & getPoint(const unsigned int _index);
175 
176  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
177 
178  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
179 
180  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi);
181 
182  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi, const vpHomogeneousMatrix &cMo);
183 
184  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi);
185 
186  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo);
187 
188  inline bool isAppearing() const {return isappearing;}
189  virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo = false) ;
190  bool isVisible() const {return isvisible;}
191 
192  vpMbtPolygon& operator=(const vpMbtPolygon& mbtp) ;
193 
201  inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
202 
208  inline void setFarClippingDistance(const double &dist) { distFarClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::FAR_CLIPPING);}
209 
215  virtual inline void setIndex(const int i ) { index = i ; }
216  virtual void setNbPoint(const unsigned int nb) ;
217 
223  inline void setNearClippingDistance(const double &dist) { distNearClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::NEAR_CLIPPING);}
224 
225 public:
226  static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int & i_min, int &i_max, int &j_min, int &j_max);
227  static bool roiInsideImage(const vpImage<unsigned char>& I, const std::vector<vpImagePoint>& corners);
228 
229 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
230 public:
234  bool isVisible(const vpHomogeneousMatrix &cMo, const bool &depthTest = false) ;
235 #endif
236 };
237 
238 #endif
239 
void setFarClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:208
void setClipping(const unsigned int &flags)
Definition: vpMbtPolygon.h:201
bool isVisible() const
Definition: vpMbtPolygon.h:190
unsigned int getClipping() const
Definition: vpMbtPolygon.h:135
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned int clippingFlag
Clipping flag.
Definition: vpMbtPolygon.h:99
double getNearClippingDistance() const
Definition: vpMbtPolygon.h:172
int index
Index of the polygon. Cannot be unsigned int because default value is -1.
Definition: vpMbtPolygon.h:85
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpMbtPolygon.h:87
void setNearClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:223
unsigned int nbCornersInsidePrev
Number of corners inside the image during the last call to getNbCornerInsideImage.
Definition: vpMbtPolygon.h:89
Class that defines what is a point.
Definition: vpPoint.h:65
std::vector< std::pair< vpPoint, unsigned int > > roiPointsClip
Region of interest clipped.
Definition: vpMbtPolygon.h:97
double distFarClip
Distance for near clipping.
Definition: vpMbtPolygon.h:103
bool isAppearing() const
Definition: vpMbtPolygon.h:188
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
int getIndex() const
Definition: vpMbtPolygon.h:149
unsigned int getNbCornerInsidePrevImage() const
Definition: vpMbtPolygon.h:163
Generic class defining intrinsic camera parameters.
bool isappearing
flag to specify whether the face is appearing or not
Definition: vpMbtPolygon.h:93
Class that provides a data structure for the column vectors as well as a set of operations on these v...
Definition: vpColVector.h:72
double getFarClippingDistance() const
Definition: vpMbtPolygon.h:142
unsigned int getNbPoint() const
Definition: vpMbtPolygon.h:156
bool isvisible
flag to specify whether the face is visible or not
Definition: vpMbtPolygon.h:91
double distNearClip
Distance for near clipping.
Definition: vpMbtPolygon.h:101
virtual void setIndex(const int i)
Definition: vpMbtPolygon.h:215
vpPoint * p
corners in the object frame
Definition: vpMbtPolygon.h:95