ViSP  2.8.0
vpMbtPolygon.h
1 /****************************************************************************
2  *
3  * $Id: vpMbtPolygon.h 4331 2013-07-22 12:37:11Z ayol $
4  *
5  * This file is part of the ViSP software.
6  * Copyright (C) 2005 - 2013 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  virtual ~vpMbtPolygon() ;
120 
121  void addPoint(const unsigned int n, const vpPoint &P) ;
122 
123  void changeFrame(const vpHomogeneousMatrix &cMo) ;
124 
125  void computeRoiClipped(const vpCameraParameters &cam = vpCameraParameters());
126 
134  inline unsigned int getClipping() const { return clippingFlag; }
135 
141  inline double getFarClippingDistance() const { return distFarClip; }
142 
148  inline int getIndex() const {return index ;}
149 
155  inline unsigned int getNbPoint() const {return nbpt ;}
156 
162  inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
163 
164  unsigned int getNbCornerInsideImage(const vpImage<unsigned char>& I, const vpCameraParameters &cam);
165 
171  inline double getNearClippingDistance() const { return distNearClip; }
172 
173  vpPoint & getPoint(const unsigned int _index);
174 
175  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
176 
177  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
178 
179  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi);
180 
181  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi, const vpHomogeneousMatrix &cMo);
182 
183  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi);
184 
185  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo);
186 
187  inline bool isAppearing() const {return isappearing;}
188  virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo = false) ;
189  bool isVisible() const {return isvisible;}
190 
198  inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
199 
205  inline void setFarClippingDistance(const double &dist) { distFarClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::FAR_CLIPPING);}
206 
212  virtual inline void setIndex(const int i ) { index = i ; }
213  virtual void setNbPoint(const unsigned int nb) ;
214 
220  inline void setNearClippingDistance(const double &dist) { distNearClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::NEAR_CLIPPING);}
221 
222 public:
223  static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int & i_min, int &i_max, int &j_min, int &j_max);
224  static bool roiInsideImage(const vpImage<unsigned char>& I, const std::vector<vpImagePoint>& corners);
225 
226 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
227 public:
231  bool isVisible(const vpHomogeneousMatrix &cMo, const bool &depthTest = false) ;
232 #endif
233 };
234 
235 #endif
236 
void setFarClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:205
void setClipping(const unsigned int &flags)
Definition: vpMbtPolygon.h:198
bool isVisible() const
Definition: vpMbtPolygon.h:189
unsigned int getClipping() const
Definition: vpMbtPolygon.h:134
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:171
int index
Index of the polygon. Cannot be unsigned int because deafult 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:220
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:187
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
int getIndex() const
Definition: vpMbtPolygon.h:148
unsigned int getNbCornerInsidePrevImage() const
Definition: vpMbtPolygon.h:162
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:141
unsigned int getNbPoint() const
Definition: vpMbtPolygon.h:155
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:212
vpPoint * p
corners in the object frame
Definition: vpMbtPolygon.h:95