ViSP  2.10.0
vpMbtPolygon.cpp
1 /****************************************************************************
2  *
3  * $Id: vpMbtPolygon.cpp 4952 2014-11-12 14:04: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  * Make the complete tracking of an object by using its CAD model
36  *
37  * Authors:
38  * Nicolas Melchior
39  * Romain Tallonneau
40  * Eric Marchand
41  * Aurelien Yol
42  *
43  *****************************************************************************/
44 
45 #include <limits.h>
46 
47 #include <visp/vpConfig.h>
53 #include <visp/vpMbtPolygon.h>
54 #include <visp/vpPolygon.h>
55 
60  : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
61  p(NULL), roiPointsClip(), clippingFlag(vpMbtPolygon::NO_CLIPPING),
62  distNearClip(0.001), distFarClip(100.),
63  useLod(false), minLineLengthThresh(50.0), minPolygonAreaThresh(2500.0), name("")
64 {
65 }
66 
68  : index(-1), nbpt(0), nbCornersInsidePrev(0), isvisible(false), isappearing(false),
69  p(NULL), roiPointsClip(), clippingFlag(vpMbtPolygon::NO_CLIPPING),
70  distNearClip(0.001), distFarClip(100.),
71  useLod(false), minLineLengthThresh(50.0), minPolygonAreaThresh(2500.0), name("")
72 {
73  *this = mbtp;
74 }
75 
77 {
78  index = mbtp.index;
79  nbpt = mbtp.nbpt;
81  isvisible = mbtp.isvisible;
82  isappearing = mbtp.isappearing;
86  distFarClip = mbtp.distFarClip;
87  useLod = mbtp.useLod;
90  name = mbtp.name;
91 
92  if (p) delete [] p;
93  p = new vpPoint [nbpt];
94  for(unsigned int i = 0; i < nbpt; i++)
95  p[i] = mbtp.p[i];
96 
97  return (*this);
98 }
99 
104 {
105  if (p !=NULL)
106  {
107  delete[] p;
108  p = NULL;
109  }
110 }
111 
119 vpPoint &
120 vpMbtPolygon::getPoint(const unsigned int _index)
121 {
122  if(_index >= nbpt){
123  throw vpException(vpException::dimensionError, "index out of range");
124  }
125  return p[_index];
126 }
127 
133 void
134 vpMbtPolygon::setNbPoint(const unsigned int nb)
135 {
136  nbpt = nb ;
137  if (p != NULL)
138  delete[] p;
139  p = new vpPoint[nb] ;
140 }
141 
148 void
149 vpMbtPolygon::addPoint(const unsigned int n, const vpPoint &P)
150 {
151  //if( p!NULL && n < nbpt )
152  p[n] = P ;
153 }
154 
160 void
162 {
163  for (unsigned int i = 0 ; i < nbpt ; i++)
164  {
165  p[i].changeFrame(cMo) ;
166  p[i].projection() ;
167  }
168 }
169 
185 bool
186 vpMbtPolygon::isVisible(const vpHomogeneousMatrix &cMo, const double alpha, const bool &modulo,
187  const vpCameraParameters &cam, const vpImage<unsigned char> &I)
188 {
189  // std::cout << "Computing angle from MBT Face (cMo, alpha)" << std::endl;
190 
191  changeFrame(cMo);
192 
193  if(nbpt <= 2) {
194  //Level of detail (LOD)
195  if(useLod) {
196  vpCameraParameters c = cam;
197  if(clippingFlag > 3) { // Contains at least one FOV constraint
198  c.computeFov(I.getWidth(), I.getHeight());
199  }
201  std::vector<vpImagePoint> roiImagePoints;
202  getRoiClipped(c, roiImagePoints);
203 
204  if (roiImagePoints.size() == 2) {
205  double x1 = roiImagePoints[0].get_u();
206  double y1 = roiImagePoints[0].get_v();
207  double x2 = roiImagePoints[1].get_u();
208  double y2 = roiImagePoints[1].get_v();
209  double length = std::sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
210 // std::cout << "Index=" << index << " ; Line length=" << length << " ; clippingFlag=" << clippingFlag << std::endl;
211 // vpTRACE("index=%d lenght=%f minLineLengthThresh=%f", index, length, minLineLengthThresh);
212 
213  if (length < minLineLengthThresh) {
214  isvisible = false;
215  isappearing = false;
216  return false;
217  }
218  }
219  }
220 
221  /* a line is always visible when LOD is not used */
222  isvisible = true;
223  isappearing = false;
224  return true ;
225  }
226 
227  //Check visibility from normal
228  //Newell's Method for calculating the normal of an arbitrary 3D polygon
229  //https://www.opengl.org/wiki/Calculating_a_Surface_Normal
230  vpColVector faceNormal(3);
231  vpColVector currentVertex, nextVertex;
232  for(unsigned int i = 0; i<nbpt; i++) {
233  currentVertex = p[i].cP;
234  nextVertex = p[(i+1) % nbpt].cP;
235 
236  faceNormal[0] += (currentVertex[1] - nextVertex[1]) * (currentVertex[2] + nextVertex[2]);
237  faceNormal[1] += (currentVertex[2] - nextVertex[2]) * (currentVertex[0] + nextVertex[0]);
238  faceNormal[2] += (currentVertex[0] - nextVertex[0]) * (currentVertex[1] + nextVertex[1]);
239  }
240  faceNormal.normalize();
241 
242  vpColVector e4(3) ;
243  vpPoint pt;
244  for (unsigned int i = 0; i < nbpt; i += 1){
245  pt.set_X(pt.get_X() + p[i].get_X());
246  pt.set_Y(pt.get_Y() + p[i].get_Y());
247  pt.set_Z(pt.get_Z() + p[i].get_Z());
248  }
249  e4[0] = -pt.get_X() / (double)nbpt;
250  e4[1] = -pt.get_Y() / (double)nbpt;
251  e4[2] = -pt.get_Z() / (double)nbpt;
252  e4.normalize();
253 
254  double angle = acos(vpColVector::dotProd(e4, faceNormal));
255 
256 // vpCTRACE << angle << "/" << vpMath::deg(angle) << "/" << vpMath::deg(alpha) << std::endl;
257 
258  if( angle < alpha || (modulo && (M_PI - angle) < alpha)) {
259  isvisible = true;
260  isappearing = false;
261 
262  if (useLod) {
263  vpCameraParameters c = cam;
264  if(clippingFlag > 3) { // Contains at least one FOV constraint
265  c.computeFov(I.getWidth(), I.getHeight());
266  }
268  std::vector<vpImagePoint> roiImagePoints;
269  getRoiClipped(c, roiImagePoints);
270 
271  vpPolygon roiPolygon(roiImagePoints);
272  double area = roiPolygon.getArea();
273 // std::cout << "After normal test ; Index=" << index << " ; area=" << area << " ; clippingFlag="
274 // << clippingFlag << std::endl;
275  if (area < minPolygonAreaThresh) {
276  isappearing = false;
277  isvisible = false;
278  return false;
279  }
280  }
281 
282  return true;
283  }
284 
285  if (angle < alpha+vpMath::rad(1) ){
286  isappearing = true;
287  }
288  else if (modulo && (M_PI - angle) < alpha+vpMath::rad(1) ){
289  isappearing = true;
290  }
291  else {
292  isappearing = false;
293  }
294 
295  isvisible = false ;
296  return false ;
297 }
298 
306 void
308 {
309  roiPointsClip.clear();
310  std::vector<vpColVector> fovNormals;
311  std::vector<std::pair<vpPoint,unsigned int> > roiPointsClipTemp;
312  std::vector<std::pair<vpPoint,unsigned int> > roiPointsClipTemp2;
313 
314  if(cam.isFovComputed() && clippingFlag > 3)
315  fovNormals = cam.getFovNormals();
316 
317  for(unsigned int i = 0 ; i < nbpt ; i++){
318  p[i%nbpt].projection();
319  roiPointsClipTemp.push_back(std::make_pair(p[i%nbpt],vpMbtPolygon::NO_CLIPPING));
320  }
321 
323  for(unsigned int i = 1 ; i < 64 ; i=i*2)
324  {
325  if(((clippingFlag & i) == i) || ((clippingFlag > vpMbtPolygon::FAR_CLIPPING) && (i==1)))
326  {
327  for(unsigned int j = 0 ; j < roiPointsClipTemp.size() ; j++)
328  {
329  vpPoint p1Clipped = roiPointsClipTemp[j].first;
330  vpPoint p2Clipped = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].first;
331 
332  unsigned int p2ClippedInfoBefore = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].second;
333  unsigned int p1ClippedInfo = roiPointsClipTemp[j].second;
334  unsigned int p2ClippedInfo = roiPointsClipTemp[(j+1)%roiPointsClipTemp.size()].second;
335 
336  bool problem = true;
337 
338  switch(i){
339  case 1:
340  problem = !(vpMbtPolygon::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
341  i, distNearClip));
342  break;
343  case 2:
344  problem = !(vpMbtPolygon::getClippedPointsDistance(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
345  i, distFarClip));
346  break;
347  case 4:
348  problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
349  fovNormals[0], vpMbtPolygon::LEFT_CLIPPING));
350  break;
351  case 8:
352  problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
353  fovNormals[1], vpMbtPolygon::RIGHT_CLIPPING));
354  break;
355  case 16:
356  problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
357  fovNormals[2], vpMbtPolygon::UP_CLIPPING));
358  break;
359  case 32:
360  problem = !(vpMbtPolygon::getClippedPointsFovGeneric(p1Clipped, p2Clipped, p1Clipped, p2Clipped, p1ClippedInfo, p2ClippedInfo,
361  fovNormals[3], vpMbtPolygon::DOWN_CLIPPING));
362  break;
363  }
364 
365  if(!problem)
366  {
367  p1Clipped.projection();
368  roiPointsClipTemp2.push_back(std::make_pair(p1Clipped, p1ClippedInfo));
369 
370  if(p2ClippedInfo != p2ClippedInfoBefore)
371  {
372  p2Clipped.projection();
373  roiPointsClipTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
374  }
375 
376  if(nbpt == 2){
377  if(p2ClippedInfo == p2ClippedInfoBefore)
378  {
379  p2Clipped.projection();
380  roiPointsClipTemp2.push_back(std::make_pair(p2Clipped, p2ClippedInfo));
381  }
382  break;
383  }
384  }
385  }
386 
387  roiPointsClipTemp = roiPointsClipTemp2;
388  roiPointsClipTemp2.clear();
389  }
390  }
391 
392  roiPointsClip = roiPointsClipTemp;
393 }
394 
413 bool
414 vpMbtPolygon::getClippedPointsFovGeneric(const vpPoint &p1, const vpPoint &p2,
415  vpPoint &p1Clipped, vpPoint &p2Clipped,
416  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
417  const vpColVector &normal, const unsigned int &flag)
418 {
419  vpRowVector p1Vec(3);
420  p1Vec[0] = p1.get_X(); p1Vec[1] = p1.get_Y(); p1Vec[2] = p1.get_Z();
421  p1Vec = p1Vec.normalize();
422 
423  vpRowVector p2Vec(3);
424  p2Vec[0] = p2.get_X(); p2Vec[1] = p2.get_Y(); p2Vec[2] = p2.get_Z();
425  p2Vec = p2Vec.normalize();
426 
427  if((clippingFlag & flag) == flag){
428  double beta1 = acos( p1Vec * normal );
429  double beta2 = acos( p2Vec * normal );
430 
431 // std::cout << beta1 << " && " << beta2 << std::endl;
432 
433  // if(!(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0))
434  if(beta1 < M_PI / 2.0 && beta2 < M_PI / 2.0)
435  return false;
436  else if (beta1 < M_PI / 2.0 || beta2 < M_PI / 2.0){
437  vpPoint pClipped;
438  double t = -(normal[0] * p1.get_X() + normal[1] * p1.get_Y() + normal[2] * p1.get_Z());
439  t = t / ( normal[0] * (p2.get_X() - p1.get_X()) + normal[1] * (p2.get_Y() - p1.get_Y()) + normal[2] * (p2.get_Z() - p1.get_Z()) );
440 
441  pClipped.set_X((p2.get_X() - p1.get_X())*t + p1.get_X());
442  pClipped.set_Y((p2.get_Y() - p1.get_Y())*t + p1.get_Y());
443  pClipped.set_Z((p2.get_Z() - p1.get_Z())*t + p1.get_Z());
444 
445  if(beta1 < M_PI / 2.0){
446  p1ClippedInfo = p1ClippedInfo | flag;
447  p1Clipped = pClipped;
448  }
449  else{
450  p2ClippedInfo = p2ClippedInfo | flag;
451  p2Clipped = pClipped;
452  }
453  }
454  }
455 
456  return true;
457 }
458 
459 bool
460 vpMbtPolygon::getClippedPointsDistance(const vpPoint &p1, const vpPoint &p2,
461  vpPoint &p1Clipped, vpPoint &p2Clipped,
462  unsigned int &p1ClippedInfo, unsigned int &p2ClippedInfo,
463  const unsigned int &flag, const double &distance)
464 {
465  // Since p1 and p1Clipped can be the same object as well as p2 and p2Clipped
466  // to avoid a valgrind "Source and destination overlap in memcpy" error,
467  // we introduce a two temporary points.
468  vpPoint p1Clipped_, p2Clipped_;
469  p1Clipped_ = p1;
470  p2Clipped_ = p2;
471 
472  p1Clipped = p1Clipped_;
473  p2Clipped = p2Clipped_;
474 
475 
476  bool test1 = (p1Clipped.get_Z() < distance && p2Clipped.get_Z() < distance);
477  if(flag == vpMbtPolygon::FAR_CLIPPING)
478  test1 = (p1Clipped.get_Z() > distance && p2Clipped.get_Z() > distance);
479 
480  bool test2 = (p1Clipped.get_Z() < distance || p2Clipped.get_Z() < distance);
481  if(flag == vpMbtPolygon::FAR_CLIPPING)
482  test2 = (p1Clipped.get_Z() > distance || p2Clipped.get_Z() > distance);
483 
484  bool test3 = (p1Clipped.get_Z() < distance);
485  if(flag == vpMbtPolygon::FAR_CLIPPING)
486  test3 = (p1Clipped.get_Z() > distance);
487 
488  if(test1)
489  return false;
490 
491  else if(test2){
492  vpPoint pClippedNear;
493  double t;
494  t = (p2Clipped.get_Z() - p1Clipped.get_Z());
495  t = (distance - p1Clipped.get_Z()) / t;
496 
497  pClippedNear.set_X((p2Clipped.get_X() - p1Clipped.get_X())*t + p1Clipped.get_X());
498  pClippedNear.set_Y((p2Clipped.get_Y() - p1Clipped.get_Y())*t + p1Clipped.get_Y());
499  pClippedNear.set_Z(distance);
500 
501  if(test3){
502  p1Clipped = pClippedNear;
503  if(flag == vpMbtPolygon::FAR_CLIPPING)
504  p1ClippedInfo = p1ClippedInfo | vpMbtPolygon::FAR_CLIPPING;
505  else
506  p1ClippedInfo = p1ClippedInfo | vpMbtPolygon::NEAR_CLIPPING;
507  }
508  else{
509  p2Clipped = pClippedNear;
510  if(flag == vpMbtPolygon::FAR_CLIPPING)
511  p2ClippedInfo = p2ClippedInfo | vpMbtPolygon::FAR_CLIPPING;
512  else
513  p2ClippedInfo = p2ClippedInfo | vpMbtPolygon::NEAR_CLIPPING;
514  }
515  }
516 
517  return true;
518 }
519 
529 std::vector<vpImagePoint>
531 {
532  std::vector<vpImagePoint> roi;
533  for (unsigned int i = 0; i < nbpt; i ++){
534  vpImagePoint ip;
535  vpMeterPixelConversion::convertPoint(cam, p[i].get_x(), p[i].get_y(), ip);
536  roi.push_back(ip);
537  }
538 
539  return roi;
540 }
541 
550 std::vector<vpImagePoint>
552 {
553  changeFrame(cMo);
554  return getRoi(cam);
555 }
556 
564 void
565 vpMbtPolygon::getRoiClipped(std::vector<vpPoint> &points)
566 {
567  for(unsigned int i = 0 ; i < roiPointsClip.size() ; i++){
568  points.push_back(roiPointsClip[i].first);
569  }
570 }
571 
580 void
581 vpMbtPolygon::getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi)
582 {
583  for(unsigned int i = 0 ; i < roiPointsClip.size() ; i++){
584  vpImagePoint ip;
585  vpMeterPixelConversion::convertPoint(cam,roiPointsClip[i].first.get_x(),roiPointsClip[i].first.get_y(),ip);
586 // std::cout << "## " << ip.get_j() << " - " << ip.get_i() << std::endl;
587  roi.push_back(ip);
588  }
589 }
590 
598 void
599 vpMbtPolygon::getRoiClipped(const vpCameraParameters &cam, std::vector<vpImagePoint> &roi, const vpHomogeneousMatrix &cMo)
600 {
601  changeFrame(cMo);
602  computeRoiClipped(cam);
603  getRoiClipped(cam, roi);
604 }
605 
614 void
615 vpMbtPolygon::getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi)
616 {
617  for(unsigned int i = 0 ; i < roiPointsClip.size() ; i++){
618  vpImagePoint ip;
619  roiPointsClip[i].first.projection();
620  vpMeterPixelConversion::convertPoint(cam,roiPointsClip[i].first.get_x(),roiPointsClip[i].first.get_y(),ip);
621  roi.push_back(std::make_pair(ip, roiPointsClip[i].second));
622  }
623 }
624 
632 void
633 vpMbtPolygon::getRoiClipped(const vpCameraParameters &cam, std::vector<std::pair<vpImagePoint,unsigned int> > &roi, const vpHomogeneousMatrix &cMo)
634 {
635  changeFrame(cMo);
636  computeRoiClipped(cam);
637  getRoiClipped(cam, roi);
638 }
639 
640 
641 
648 unsigned int
650 {
651  unsigned int nbPolyIn = 0;
652  for (unsigned int i = 0; i < nbpt; i ++){
653  if(p[i].get_Z() > 0){
654  vpImagePoint ip;
655  vpMeterPixelConversion::convertPoint(cam, p[i].get_x(), p[i].get_y(), ip);
656  if((ip.get_i() >= 0) && (ip.get_j() >= 0) && (ip.get_i() < I.getHeight()) && (ip.get_j() < I.getWidth()))
657  nbPolyIn++;
658  }
659  }
660 
661  nbCornersInsidePrev = nbPolyIn;
662 
663  return nbPolyIn;
664 }
665 
666 //###################################
667 // Static functions
668 //###################################
669 
683 void
684 vpMbtPolygon::getClippedPolygon(const std::vector<vpPoint> &ptIn, std::vector<vpPoint> &ptOut, const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags,
685  const vpCameraParameters &cam, const double &znear, const double &zfar)
686 {
687  ptOut.clear();
688  vpMbtPolygon poly;
689  poly.setNbPoint((unsigned int)ptIn.size());
690  poly.setClipping(clippingFlags);
691 
692  if((clippingFlags & vpMbtPolygon::NEAR_CLIPPING) == vpMbtPolygon::NEAR_CLIPPING)
693  poly.setNearClippingDistance(znear);
694 
695  if((clippingFlags & vpMbtPolygon::FAR_CLIPPING) == vpMbtPolygon::FAR_CLIPPING)
696  poly.setFarClippingDistance(zfar);
697 
698  for(unsigned int i = 0; i < ptIn.size(); i++)
699  poly.addPoint(i,ptIn[i]);
700 
701  poly.changeFrame(cMo);
702  poly.computeRoiClipped(cam);
703  poly.getRoiClipped(ptOut);
704 }
705 
706 void
707 vpMbtPolygon::getMinMaxRoi(const std::vector<vpImagePoint> &iroi, int & i_min, int &i_max, int &j_min, int &j_max)
708 {
709  // i_min_d = std::numeric_limits<double>::max(); // create an error under Windows. To fix it we have to add #undef max
710  double i_min_d = (double) INT_MAX;
711  double i_max_d = 0;
712  double j_min_d = (double) INT_MAX;
713  double j_max_d = 0;
714 
715  for (unsigned int i = 0; i < iroi.size(); i += 1){
716  if(i_min_d > iroi[i].get_i())
717  i_min_d = iroi[i].get_i();
718 
719  if(iroi[i].get_i() < 0)
720  i_min_d = 1;
721 
722  if((iroi[i].get_i() > 0) && (i_max_d < iroi[i].get_i()))
723  i_max_d = iroi[i].get_i();
724 
725  if(j_min_d > iroi[i].get_j())
726  j_min_d = iroi[i].get_j();
727 
728  if(iroi[i].get_j() < 0)
729  j_min_d = 1;//border
730 
731  if((iroi[i].get_j() > 0) && j_max_d < iroi[i].get_j())
732  j_max_d = iroi[i].get_j();
733  }
734  i_min = static_cast<int> (i_min_d);
735  i_max = static_cast<int> (i_max_d);
736  j_min = static_cast<int> (j_min_d);
737  j_max = static_cast<int> (j_max_d);
738 }
739 
747 bool
748 vpMbtPolygon::roiInsideImage(const vpImage<unsigned char>& I, const std::vector<vpImagePoint>& corners)
749 {
750  double nbPolyIn = 0;
751  for(unsigned int i=0; i<corners.size(); ++i){
752  if((corners[i].get_i() >= 0) && (corners[i].get_j() >= 0) &&
753  (corners[i].get_i() < I.getHeight()) && (corners[i].get_j() < I.getWidth())){
754  nbPolyIn++;
755  }
756  }
757 
758  if(nbPolyIn < 3 && nbPolyIn < 0.7 * corners.size())
759  return false;
760 
761  return true;
762 }
763 
809 void
810 vpMbtPolygon::setLod(const bool use_lod)
811 {
812  this->useLod = use_lod;
813 }
814 
815 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
816 
826 bool
827 vpMbtPolygon::isVisible(const vpHomogeneousMatrix &cMo, const bool &depthTest)
828 {
829  changeFrame(cMo) ;
830 
831  if(depthTest)
832  for (unsigned int i = 0 ; i < nbpt ; i++){
833  if(p[i].get_Z() < 0){
834  isappearing = false;
835  isvisible = false ;
836  return false ;
837  }
838  }
839 
840  return isVisible(cMo, vpMath::rad(89));
841 }
842 #endif
843 
844 
void setFarClippingDistance(const double &dist)
Definition: vpMbtPolygon.h:226
void setClipping(const unsigned int &flags)
Definition: vpMbtPolygon.h:219
void projection(const vpColVector &_cP, vpColVector &_p)
Projection onto the image plane of a point. Input: the 3D coordinates in the camera frame _cP...
Definition: vpPoint.cpp:132
void changeFrame(const vpHomogeneousMatrix &cMo)
bool isVisible() const
Definition: vpMbtPolygon.h:208
unsigned int getNbCornerInsideImage(const vpImage< unsigned char > &I, const vpCameraParameters &cam)
std::string name
Name of the polygon.
Definition: vpMbtPolygon.h:111
double get_i() const
Definition: vpImagePoint.h:195
unsigned int getWidth() const
Definition: vpImage.h:161
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
virtual ~vpMbtPolygon()
Definition of the row vector class.
Definition: vpRowVector.h:73
bool isFovComputed() const
static void convertPoint(const vpCameraParameters &cam, const double &x, const double &y, double &u, double &v)
Point coordinates conversion from normalized coordinates in meter to pixel coordinates ...
static void getClippedPolygon(const std::vector< vpPoint > &ptIn, std::vector< vpPoint > &ptOut, const vpHomogeneousMatrix &cMo, const unsigned int &clippingFlags, const vpCameraParameters &cam=vpCameraParameters(), const double &znear=0.001, const double &zfar=100)
void getRoiClipped(std::vector< vpPoint > &points)
vpPoint & getPoint(const unsigned int _index)
int index
Index of the polygon. Cannot be unsigned int because default value is -1.
Definition: vpMbtPolygon.h:85
error that can be emited by ViSP classes.
Definition: vpException.h:76
unsigned int nbpt
Number of points used to define the polygon.
Definition: vpMbtPolygon.h:87
vpMbtPolygon & operator=(const vpMbtPolygon &mbtp)
void set_X(const double X)
Set the point X coordinate in the camera frame.
Definition: vpPoint.h:176
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
double get_j() const
Definition: vpImagePoint.h:206
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
vpColVector cP
Definition: vpTracker.h:82
double distFarClip
Distance for near clipping.
Definition: vpMbtPolygon.h:103
void addPoint(const unsigned int n, const vpPoint &P)
Defines a generic 2D polygon.
Definition: vpPolygon.h:102
void set_Z(const double Z)
Set the point Z coordinate in the camera frame.
Definition: vpPoint.h:180
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
Implementation of a polygon of the model used by the model-based tracker.
Definition: vpMbtPolygon.h:67
Generic class defining intrinsic camera parameters.
void set_Y(const double Y)
Set the point Y coordinate in the camera frame.
Definition: vpPoint.h:178
double getArea() const
Definition: vpPolygon.h:148
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
void computeRoiClipped(const vpCameraParameters &cam=vpCameraParameters())
double get_Y() const
Get the point Y coordinate in the camera frame.
Definition: vpPoint.h:120
static double rad(double deg)
Definition: vpMath.h:100
double get_Z() const
Get the point Z coordinate in the camera frame.
Definition: vpPoint.h:122
std::vector< vpImagePoint > getRoi(const vpCameraParameters &cam)
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
void setLod(const bool use_lod)
std::vector< vpColVector > getFovNormals() const
static double dotProd(const vpColVector &a, const vpColVector &b)
Dot Product.
static void getMinMaxRoi(const std::vector< vpImagePoint > &roi, int &i_min, int &i_max, int &j_min, int &j_max)
unsigned int getHeight() const
Definition: vpImage.h:152
Class that defines a 2D point in an image. This class is useful for image processing and stores only ...
Definition: vpImagePoint.h:93
static bool roiInsideImage(const vpImage< unsigned char > &I, const std::vector< vpImagePoint > &corners)
void changeFrame(const vpHomogeneousMatrix &cMo, vpColVector &_cP)
Definition: vpPoint.cpp:150
virtual void setNbPoint(const unsigned int nb)
bool isvisible
flag to specify whether the face is visible or not
Definition: vpMbtPolygon.h:91
vpColVector & normalize()
Normalise the vector.
double get_X() const
Get the point X coordinate in the camera frame.
Definition: vpPoint.h:118
double distNearClip
Distance for near clipping.
Definition: vpMbtPolygon.h:101
void computeFov(const unsigned int &w, const unsigned int &h)
vpPoint * p
corners in the object frame
Definition: vpMbtPolygon.h:95