ViSP  2.10.0
vpMbtPolygon.h
1 /****************************************************************************
2  *
3  * $Id: vpMbtPolygon.h 5126 2015-01-05 22:07:11Z 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;
105  bool useLod;
111  std::string name;
112 
113 private:
114  bool getClippedPointsFovGeneric(const vpPoint &p1, const vpPoint &p2,
115  vpPoint &p1Clipped, vpPoint &p2Clipped,
116  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
117  const vpColVector &normal,
118  const unsigned int &flag);
119 
120  bool getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2,
121  vpPoint &p1Clipped, vpPoint &p2Clipped,
122  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
123  const unsigned int &flag, const double &distance);
124 
125 public:
126  vpMbtPolygon() ;
127  vpMbtPolygon(const vpMbtPolygon& mbtp) ;
128  virtual ~vpMbtPolygon() ;
129 
130  void addPoint(const unsigned int n, const vpPoint &P) ;
131 
132  void changeFrame(const vpHomogeneousMatrix &cMo) ;
133 
134  void computeRoiClipped(const vpCameraParameters &cam = vpCameraParameters());
135 
143  inline unsigned int getClipping() const { return clippingFlag; }
144 
150  inline double getFarClippingDistance() const { return distFarClip; }
151 
157  inline int getIndex() const {return index ;}
158 
164  inline std::string getName() const {return name;}
165 
171  inline unsigned int getNbPoint() const {return nbpt ;}
172 
178  inline unsigned int getNbCornerInsidePrevImage() const { return nbCornersInsidePrev; }
179 
180  unsigned int getNbCornerInsideImage(const vpImage<unsigned char>& I, const vpCameraParameters &cam);
181 
187  inline double getNearClippingDistance() const { return distNearClip; }
188 
189  vpPoint & getPoint(const unsigned int _index);
190 
191  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam);
192 
193  std::vector<vpImagePoint> getRoi(const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo);
194 
195  void getRoiClipped(std::vector<vpPoint> &points);
196 
197  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi);
198 
199  void getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint>&roi, const vpHomogeneousMatrix &cMo);
200 
201  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi);
202 
203  void getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo);
204 
205  inline bool isAppearing() const {return isappearing;}
206  virtual bool isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo = false,
208  bool isVisible() const {return isvisible;}
209 
210  vpMbtPolygon& operator=(const vpMbtPolygon& mbtp) ;
211 
219  inline void setClipping(const unsigned int &flags) { clippingFlag = flags; }
220 
226  inline void setFarClippingDistance(const double &dist) { distFarClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::FAR_CLIPPING);}
227 
233  virtual inline void setIndex(const int i ) { index = i ; }
234 
235  // Due to a doxygen warning include the sample code in the doc, we remove the inline and put the doc in the *.cpp file
236  void setLod(const bool use_lod);
247  inline void setMinLineLengthThresh(const double min_line_length) {
248  this->minLineLengthThresh = min_line_length;
249  }
260  inline void setMinPolygonAreaThresh(const double min_polygon_area) {
261  this->minPolygonAreaThresh = min_polygon_area;
262  }
263 
269  inline void setName(const std::string &face_name) {
270  this->name = face_name;
271  }
272 
273  virtual void setNbPoint(const unsigned int nb) ;
274 
280  inline void setNearClippingDistance(const double &dist) { distNearClip = dist; clippingFlag = (clippingFlag | vpMbtPolygon::NEAR_CLIPPING);}
281 
282 public:
283  static void getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut, const vpHomogeneousMatrix &cMo,
284  const unsigned int &clippingFlags, const vpCameraParameters &cam = vpCameraParameters(),
285  const double &znear = 0.001, const double &zfar = 100 );
286  static void getMinMaxRoi(const std::vector<vpImagePoint> &roi, int & i_min, int &i_max, int &j_min, int &j_max);
287  static bool roiInsideImage(const vpImage<unsigned char>& I, const std::vector<vpImagePoint>& corners);
288 
289 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
290 public:
294  bool isVisible(const vpHomogeneousMatrix &cMo, const bool &depthTest = false) ;
295 #endif
296 };
297 
298 #endif
299 
void setFarClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:226
void setClipping(const unsigned int &flags)
Definition: vpMbtPolygon.h:219
bool isVisible() const
Definition: vpMbtPolygon.h:208
std::string name
Name of the polygon.
Definition: vpMbtPolygon.h:111
unsigned int getClipping() const
Definition: vpMbtPolygon.h:143
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:187
int index
Index of the polygon. Cannot be unsigned int because default value is -1.
Definition: vpMbtPolygon.h:85
void setMinPolygonAreaThresh(const double min_polygon_area)
Definition: vpMbtPolygon.h:260
void setName(const std::string &face_name)
Definition: vpMbtPolygon.h:269
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpMbtPolygon.h:87
void setNearClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:280
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
double minLineLengthThresh
Threshold for minimum line length in pixel to consider if the line is visible or not in LOD case...
Definition: vpMbtPolygon.h:107
bool isAppearing() const
Definition: vpMbtPolygon.h:205
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
std::string getName() const
Definition: vpMbtPolygon.h:164
int getIndex() const
Definition: vpMbtPolygon.h:157
unsigned int getNbCornerInsidePrevImage() const
Definition: vpMbtPolygon.h:178
Generic class defining intrinsic camera parameters.
double minPolygonAreaThresh
Threshold for minimum polygon area in pixel to consider if the polygon is visible or not in LOD case...
Definition: vpMbtPolygon.h:109
bool isappearing
flag to specify whether the face is appearing or not
Definition: vpMbtPolygon.h:93
bool useLod
Flag to specify if the visibility of the polygon depends also of the current level of detail (LOD) ...
Definition: vpMbtPolygon.h:105
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:150
unsigned int getNbPoint() const
Definition: vpMbtPolygon.h:171
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
void setMinLineLengthThresh(const double min_line_length)
Definition: vpMbtPolygon.h:247
virtual void setIndex(const int i)
Definition: vpMbtPolygon.h:233
vpPoint * p
corners in the object frame
Definition: vpMbtPolygon.h:95