Visual Servoing Platform  version 3.0.0
vpMbHiddenFaces.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  * Generic model based tracker. This class declares the methods to implement in
32  * order to have a model based tracker.
33  *
34  * Authors:
35  * Romain Tallonneau
36  * Aurelien Yol
37  *
38  *****************************************************************************/
39 #pragma once
40 
41 #ifndef vpMbHiddenFaces_HH
42 #define vpMbHiddenFaces_HH
43 
44 #include <visp3/core/vpHomogeneousMatrix.h>
45 #include <visp3/core/vpMeterPixelConversion.h>
46 #include <visp3/core/vpPixelMeterConversion.h>
47 #include <visp3/mbt/vpMbtPolygon.h>
48 #include <visp3/mbt/vpMbScanLine.h>
49 
50 #ifdef VISP_HAVE_OGRE
51  #include <visp3/ar/vpAROgre.h>
52 #endif
53 
54 #include <vector>
55 #include <limits>
56 
65 template<class PolygonType = vpMbtPolygon>
67 {
68  private:
70  std::vector<PolygonType *> Lpol ;
72  unsigned int nbVisiblePolygon;
73  vpMbScanLine scanlineRender;
74 
75 #ifdef VISP_HAVE_OGRE
76  vpImage<unsigned char> ogreBackground;
77  bool ogreInitialised;
78  unsigned int nbRayAttempts;
79  double ratioVisibleRay;
80  vpAROgre *ogre;
81  std::vector< Ogre::ManualObject* > lOgrePolygons;
82  bool ogreShowConfigDialog;
83 #endif
84 
85  unsigned int setVisiblePrivate(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
86  bool &changed,
87  bool useOgre = false, bool testRoi = false,
89  const vpCameraParameters &cam = vpCameraParameters()) ;
90 
91  public :
92  vpMbHiddenFaces() ;
94 
95  void addPolygon(PolygonType *p) ;
96 
97  bool computeVisibility(const vpHomogeneousMatrix &cMo,
98  const double &angleAppears, const double &angleDisappears,
99  bool &changed, bool useOgre, bool testRoi,
100  const vpImage<unsigned char> &I,
101  const vpCameraParameters &cam,
102  const vpTranslationVector &cameraPos,
103  unsigned int index);
104 
106 
107  void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h);
108 
109  void computeScanLineQuery(const vpPoint &a, const vpPoint &b,
110  std::vector<std::pair<vpPoint, vpPoint> > &lines, const bool &displayResults = false);
111 
112  vpMbScanLine& getMbScanLineRenderer() { return scanlineRender; }
113 
114 #ifdef VISP_HAVE_OGRE
115  void displayOgre(const vpHomogeneousMatrix &cMo);
116 #endif
117 
123  std::vector<PolygonType*>& getPolygon() {return Lpol;}
124 
125 #ifdef VISP_HAVE_OGRE
126  void initOgre(const vpCameraParameters &cam = vpCameraParameters());
127 #endif
128 
134  unsigned int getNbVisiblePolygon() const {return nbVisiblePolygon;}
135 
136 #ifdef VISP_HAVE_OGRE
137 
145  unsigned int getNbRayCastingAttemptsForVisibility() { return nbRayAttempts; }
146 
152  vpAROgre* getOgreContext(){return ogre;}
153 
161  double getGoodNbRayCastingAttemptsRatio(){ return ratioVisibleRay; }
162 #endif
163 
164  bool isAppearing(const unsigned int i){ return Lpol[i]->isAppearing(); }
165 
166 
167 #ifdef VISP_HAVE_OGRE
168 
173  bool isOgreInitialised() { return ogreInitialised; }
174 #endif
175 
183  bool isVisible(const unsigned int i){ return Lpol[i]->isVisible(); }
184 
185 #ifdef VISP_HAVE_OGRE
186  bool isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index);
187 #endif
188 
190  inline PolygonType* operator[](const unsigned int i) { return Lpol[i];}
192  inline const PolygonType* operator[](const unsigned int i) const { return Lpol[i];}
193 
194  void reset();
195 
196 #ifdef VISP_HAVE_OGRE
197 
206  void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w) { ogreBackground = vpImage<unsigned char>(h, w, 0); }
207 
216  void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts) { nbRayAttempts = attempts; }
217 
225  void setGoodNbRayCastingAttemptsRatio(const double &ratio) {ratioVisibleRay = ratio; if(ratioVisibleRay > 1.0) ratioVisibleRay = 1.0; if(ratioVisibleRay < 0.0) ratioVisibleRay = 0.0;}
236  inline void setOgreShowConfigDialog(const bool showConfigDialog){
237  ogreShowConfigDialog = showConfigDialog;
238  }
239 #endif
240 
241  unsigned int setVisible(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed) ;
242  unsigned int setVisible(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed) ;
243  unsigned int setVisible(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed) ;
244 
245 #ifdef VISP_HAVE_OGRE
246  unsigned int setVisibleOgre(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed) ;
247  unsigned int setVisibleOgre(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed) ;
248 #endif
249 
254  inline unsigned int size() const { return (unsigned int)Lpol.size(); }
255 } ;
256 
260 template<class PolygonType>
262  : Lpol(), nbVisiblePolygon(0), scanlineRender()
263 {
264 #ifdef VISP_HAVE_OGRE
265  ogreInitialised = false;
266  nbRayAttempts = 1;
267  ratioVisibleRay = 1.0;
268  ogreShowConfigDialog = false;
269  ogre = new vpAROgre();
270  ogreBackground = vpImage<unsigned char>(480, 640, 0);
271 #endif
272 }
273 
277 template<class PolygonType>
279 {
280  for(unsigned int i = 0 ; i < Lpol.size() ; i++){
281  if (Lpol[i]!=NULL){
282  delete Lpol[i] ;
283  }
284  Lpol[i] = NULL ;
285  }
286  Lpol.resize(0);
287 
288 #ifdef VISP_HAVE_OGRE
289  if(ogre != NULL){
290  delete ogre;
291  ogre = NULL;
292  }
293 
294  // This is already done by calling "delete ogre"
295 // for(unsigned int i = 0 ; i < lOgrePolygons.size() ; i++){
296 // if (lOgrePolygons[i]!=NULL){
297 // delete lOgrePolygons[i] ;
298 // }
299 // lOgrePolygons[i] = NULL ;
300 // }
301 
302  lOgrePolygons.resize(0);
303 #endif
304 }
305 
311 template<class PolygonType>
312 void
314 {
315  PolygonType *p_new = new PolygonType;
316  p_new->index = p->index;
317  p_new->setNbPoint(p->nbpt);
318  p_new->isvisible = p->isvisible;
319  p_new->useLod = p->useLod;
320  p_new->minLineLengthThresh = p->minLineLengthThresh;
321  p_new->minPolygonAreaThresh = p->minPolygonAreaThresh;
322  p_new->setName(p->name);
323  p_new->hasOrientation = p->hasOrientation;
324 
325  for(unsigned int i = 0; i < p->nbpt; i++)
326  p_new->p[i]= p->p[i];
327  Lpol.push_back(p_new);
328 }
329 
333 template<class PolygonType>
334 void
336 {
337  nbVisiblePolygon = 0;
338  for(unsigned int i = 0 ; i < Lpol.size() ; i++){
339  if (Lpol[i]!=NULL){
340  delete Lpol[i] ;
341  }
342  Lpol[i] = NULL ;
343  }
344  Lpol.resize(0);
345 
346 #ifdef VISP_HAVE_OGRE
347  if(ogre != NULL){
348  delete ogre;
349  ogre = NULL;
350  }
351 
352  // This is already done by calling "delete ogre"
353 // for(unsigned int i = 0 ; i < lOgrePolygons.size() ; i++){
354 // if (lOgrePolygons[i]!=NULL){
355 // delete lOgrePolygons[i] ;
356 // }
357 // lOgrePolygons[i] = NULL ;
358 // }
359 
360  lOgrePolygons.resize(0);
361 
362  ogreInitialised = false;
363  nbRayAttempts = 1;
364  ratioVisibleRay = 1.0;
365  ogre = new vpAROgre();
366  ogreBackground = vpImage<unsigned char>(480, 640);
367 #endif
368 }
369 
376 template<class PolygonType>
377 void
379 {
380  for (unsigned int i = 0; i < Lpol.size(); i++){
381  // For fast result we could just clip visible polygons.
382  // However clipping all of them gives us the possibility to return more information in the scanline visibility results
383 // if(Lpol[i]->isVisible())
384  {
385  Lpol[i]->changeFrame(cMo);
386  Lpol[i]->computePolygonClipped(cam);
387  }
388  }
389 }
390 
398 template<class PolygonType>
399 void
400 vpMbHiddenFaces<PolygonType>::computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h){
401  std::vector<std::vector<std::pair<vpPoint, unsigned int> > > polyClipped(Lpol.size());
402  std::vector<std::vector<std::pair<vpPoint, unsigned int> > * > listPolyClipped;
403  std::vector<int> listPolyIndices;
404 
405  for (unsigned int i = 0; i < Lpol.size(); i++){
406  // For fast result we could just use visible polygons.
407  // However using all of them gives us the possibility to return more information in the scanline visibility results
408 // if(Lpol[i]->isVisible())
409  {
410  polyClipped[i].clear();
411  Lpol[i]->getPolygonClipped(polyClipped[i]);
412  if(polyClipped[i].size() != 0)
413  {
414  listPolyClipped.push_back(&polyClipped[i]);
415  listPolyIndices.push_back(Lpol[i]->getIndex());
416  }
417  }
418  }
419 
420  scanlineRender.drawScene(listPolyClipped, listPolyIndices, cam, w, h);
421 }
422 
433 template<class PolygonType>
434 void
436  std::vector<std::pair<vpPoint, vpPoint> > &lines,
437  const bool &displayResults)
438 {
439  scanlineRender.queryLineVisibility(a,b,lines,displayResults);
440 }
441 
456 template<class PolygonType>
457 unsigned int
459  const double &angleAppears, const double &angleDisappears,
460  bool &changed, bool useOgre, bool testRoi,
461  const vpImage<unsigned char> &I,
462  const vpCameraParameters &cam)
463 {
464  nbVisiblePolygon = 0;
465  changed = false;
466 
467  vpTranslationVector cameraPos;
468 
469  if(useOgre){
470 #ifdef VISP_HAVE_OGRE
471  cMo.inverse().extract(cameraPos);
472  ogre->renderOneFrame(ogreBackground, cMo);
473 #else
474  vpTRACE("ViSP doesn't have Ogre3D, simple visibility test used");
475 #endif
476  }
477 
478  for (unsigned int i = 0; i < Lpol.size(); i++){
479  //std::cout << "Calling poly: " << i << std::endl;
480  if (computeVisibility(cMo, angleAppears, angleDisappears, changed, useOgre, testRoi, I, cam, cameraPos, i))
481  nbVisiblePolygon ++;
482  }
483  return nbVisiblePolygon;
484 }
485 
502 template<class PolygonType>
503 bool
505  const double &angleAppears, const double &angleDisappears,
506  bool &changed, bool useOgre, bool /* testRoi */,
507  const vpImage<unsigned char> & I,
508  const vpCameraParameters & cam,
509  const vpTranslationVector &
510  #ifdef VISP_HAVE_OGRE
511  cameraPos
512  #endif
513  ,
514  unsigned int index)
515 {
516  unsigned int i = index;
517  Lpol[i]->changeFrame(cMo);
518  Lpol[i]->isappearing = false;
519 
520  //Commented because we need to compute visibility
521  // even when dealing with line in level of detail case
522  /*if(Lpol[i]->getNbPoint() <= 2)
523  {
524  Lpol[i]->isvisible = true;
525  }
526  else*/{
527  if(Lpol[i]->isVisible())
528  {
529  bool testDisappear = false;
530  unsigned int nbCornerInsidePrev = 0;
531 
532 // if(testRoi){
533 // nbCornerInsidePrev = Lpol[i]->getNbCornerInsidePrevImage();
534 // if(Lpol[i]->getNbCornerInsideImage(I, cam) == 0)
535 // testDisappear = true;
536 // }
537 
538  if(!testDisappear){
539  if(useOgre)
540 #ifdef VISP_HAVE_OGRE
541  testDisappear = ((!Lpol[i]->isVisible(cMo, angleDisappears, true, cam, I)) || !isVisibleOgre(cameraPos,i));
542 #else
543  testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears, false, cam, I));
544 #endif
545  else
546  testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears, false, cam, I));
547  }
548 
549  // test if the face is still visible
550  if(testDisappear){
551 // std::cout << "Face " << i << " disappears" << std::endl;
552  changed = true;
553  Lpol[i]->isvisible = false;
554  }
555  else {
556  //nbVisiblePolygon++;
557  Lpol[i]->isvisible = true;
558 
559  if(nbCornerInsidePrev > Lpol[i]->getNbCornerInsidePrevImage())
560  changed = true;
561  }
562  }
563  else
564  {
565  bool testAppear = true;
566 
567 // if(testRoi && Lpol[i]->getNbCornerInsideImage(I, cam) == 0)
568 // testAppear = false;
569 
570  if(testAppear){
571  if(useOgre)
572 #ifdef VISP_HAVE_OGRE
573  testAppear = ((Lpol[i]->isVisible(cMo, angleAppears, true, cam, I)) && isVisibleOgre(cameraPos,i));
574 #else
575  testAppear = (Lpol[i]->isVisible(cMo, angleAppears, false, cam, I));
576 #endif
577  else
578  testAppear = (Lpol[i]->isVisible(cMo, angleAppears, false, cam, I));
579  }
580 
581  if(testAppear){
582 // std::cout << "Face " << i << " appears" << std::endl;
583  Lpol[i]->isvisible = true;
584  changed = true;
585  //nbVisiblePolygon++;
586  }
587  else{
588 // std::cout << "Problem" << std::endl;
589  Lpol[i]->isvisible = false;
590  }
591  }
592  }
593  // std::cout << "Nombre de polygones visibles: " << nbVisiblePolygon << std::endl;
594  return Lpol[i]->isvisible;
595 }
596 
608 template<class PolygonType>
609 unsigned int
610 vpMbHiddenFaces<PolygonType>::setVisible(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
611 {
612  return setVisible(I, cam, cMo, angle, angle, changed);
613 }
614 
627 template<class PolygonType>
628 unsigned int
629 vpMbHiddenFaces<PolygonType>::setVisible(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
630 {
631  return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,false,true,I,cam);
632 }
633 
644 template<class PolygonType>
645 unsigned int
646 vpMbHiddenFaces<PolygonType>::setVisible(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
647 {
648  return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,false);
649 }
650 
651 #ifdef VISP_HAVE_OGRE
652 
657 template<class PolygonType>
658 void
660 {
661  ogreInitialised = true;
662  ogre->setCameraParameters(cam);
663  ogre->setShowConfigDialog(ogreShowConfigDialog);
664  ogre->init(ogreBackground, false, true);
665 
666  for(unsigned int n = 0 ; n < Lpol.size(); n++){
667  Ogre::ManualObject* manual = ogre->getSceneManager()->createManualObject(Ogre::StringConverter::toString(n));
668 
669  manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
670  for(unsigned int i = 0; i < Lpol[n]->nbpt; i++){
671  manual->position( (Ogre::Real)Lpol[n]->p[i].get_oX(), (Ogre::Real)Lpol[n]->p[i].get_oY(), (Ogre::Real)Lpol[n]->p[i].get_oZ());
672  manual->colour(1.0, 1.0, 1.0);
673  manual->index(i);
674  }
675 
676  manual->index(0);
677  manual->end();
678 
679  ogre->getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
680 
681  lOgrePolygons.push_back(manual);
682  }
683 }
684 
690 template<class PolygonType>
691 void
693 {
694  if(ogreInitialised && !ogre->isWindowHidden()){
695  for(unsigned int i = 0 ; i < Lpol.size() ; i++){
696  if(Lpol[i]->isVisible()){
697  lOgrePolygons[i]->setVisible(true);
698  }
699  else
700  lOgrePolygons[i]->setVisible(false);
701  }
702  ogre->display(ogreBackground, cMo);
703  }
704 }
705 
718 template<class PolygonType>
719 unsigned int
720 vpMbHiddenFaces<PolygonType>::setVisibleOgre(const vpImage<unsigned char>& I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
721 {
722  return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,true,true,I,cam);
723 }
724 
735 template<class PolygonType>
736 unsigned int
737 vpMbHiddenFaces<PolygonType>::setVisibleOgre(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
738 {
739  return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,true);
740 }
741 
750 template<class PolygonType>
751 bool
752 vpMbHiddenFaces<PolygonType>::isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index)
753 {
754  Ogre::Vector3 camera((Ogre::Real)cameraPos[0],(Ogre::Real)cameraPos[1],(Ogre::Real)cameraPos[2]);
755  if(!ogre->getCamera()->isVisible(lOgrePolygons[index]->getBoundingBox())){
756  lOgrePolygons[index]->setVisible(false);
757  Lpol[index]->isvisible = false;
758  return false;
759  }
760 
761  //Get the center of gravity
762  bool visible = false;
763  unsigned int nbVisible = 0;
764 
765  for(unsigned int i = 0; i < nbRayAttempts; i++)
766  {
767  Ogre::Vector3 origin(0,0,0);
768  Ogre::Real totalFactor = 0.0f;
769 
770  for(unsigned int j = 0 ; j < Lpol[index]->getNbPoint() ; j++)
771  {
772  Ogre::Real factor = 1.0f;
773 
774  if(nbRayAttempts > 1){
775  int r = rand() % 101;
776 
777  if(r != 0)
778  factor = ((Ogre::Real)r)/100.0f;
779  }
780 
781  Ogre::Vector3 tmp((Ogre::Real)Lpol[index]->getPoint(j).get_oX(), (Ogre::Real)Lpol[index]->getPoint(j).get_oY(), (Ogre::Real)Lpol[index]->getPoint(j).get_oZ());
782  tmp *= factor;
783  origin += tmp;
784  totalFactor += factor;
785  }
786 
787  origin /= totalFactor;
788 
789  Ogre::Vector3 direction = origin - camera;
790  Ogre::Real distanceCollision = direction.length();
791 
792  direction.normalise();
793  Ogre::RaySceneQuery *mRaySceneQuery = ogre->getSceneManager()->createRayQuery(Ogre::Ray(camera, direction));
794  mRaySceneQuery->setSortByDistance(true);
795 
796  Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
797  Ogre::RaySceneQueryResult::iterator it = result.begin();
798 
799 // while(it != result.end()){
800 // std::cout << it->movable->getName() << "(" << it->distance<< ") : " << std::flush;
801 // it++;
802 // }
803 // std::cout << std::endl;
804 // it = result.begin();
805 
806  if(it != result.end())
807  if(it->movable->getName().find("SimpleRenderable") != Ogre::String::npos) //Test if the ogreBackground is intersect in first
808  it++;
809 
810  double distance, distancePrev;
811  // In a case of a two-axis aligned segment, ray collision is not always working.
812  if(Lpol[index]->getNbPoint() == 2 &&
813  (((std::fabs(Lpol[index]->getPoint(0).get_oX() - Lpol[index]->getPoint(1).get_oX()) < std::numeric_limits<double>::epsilon()) +
814  (std::fabs(Lpol[index]->getPoint(0).get_oY() - Lpol[index]->getPoint(1).get_oY()) < std::numeric_limits<double>::epsilon()) +
815  (std::fabs(Lpol[index]->getPoint(0).get_oZ() - Lpol[index]->getPoint(1).get_oZ()) < std::numeric_limits<double>::epsilon())) >= 2 ))
816  {
817  if(it != result.end())
818  {
819  if(it->movable->getName() == Ogre::StringConverter::toString(index)){
820  nbVisible++;
821  }
822  else
823  {
824  distance = it->distance;
825  // Cannot use epsilon for comparison as ray lenght is slightly different from the collision distance returned by Ogre::RaySceneQueryResult.
826  if(distance > distanceCollision || std::fabs(distance - distanceCollision) < 1e-6 /*std::fabs(distance) * std::numeric_limits<double>::epsilon()*/)
827  nbVisible++;
828  }
829  }
830  else
831  nbVisible++; // Collision not detected but present.
832  }
833  else
834  {
835  if(it != result.end())
836  {
837  distance = it->distance;
838  distancePrev = distance;
839 
840  //std::cout << "For " << Ogre::StringConverter::toString(index) << ": " << it->movable->getName() << " / " << std::flush;
841 
842  if(it->movable->getName() == Ogre::StringConverter::toString(index)){
843  nbVisible++;
844  }
845  else
846  {
847  it++;
848  while(it != result.end())
849  {
850  distance = it->distance;
851 
852  if(std::fabs(distance - distancePrev) < 1e-6 /*std::fabs(distance) * std::numeric_limits<double>::epsilon()*/){
853  //std::cout << it->movable->getName() << " / " << std::flush;
854  if(it->movable->getName() == Ogre::StringConverter::toString(index)){
855  nbVisible++;
856  break;
857  }
858  it++;
859  distancePrev = distance;
860  }
861  else
862  break;
863  }
864  }
865  }
866  }
867 
868  ogre->getSceneManager()->destroyQuery(mRaySceneQuery);
869 
870  }
871 
872  if(((double)nbVisible)/((double)nbRayAttempts) > ratioVisibleRay ||
873  std::fabs(((double)nbVisible)/((double)nbRayAttempts) - ratioVisibleRay) < ratioVisibleRay * std::numeric_limits<double>::epsilon())
874  visible = true;
875  else
876  visible = false;
877 
878  if(visible){
879  lOgrePolygons[index]->setVisible(true);
880  Lpol[index]->isvisible = true;
881  }
882  else{
883  lOgrePolygons[index]->setVisible(false);
884  Lpol[index]->isvisible = false;
885  }
886 
887  return Lpol[index]->isvisible;
888 }
889 #endif //VISP_HAVE_OGRE
890 
891 #endif // vpMbHiddenFaces
892 
const PolygonType * operator[](const unsigned int i) const
operator[] as reader.
bool isAppearing(const unsigned int i)
Implementation of the polygons management for the model-based trackers.
Ogre::Camera * getCamera()
Definition: vpAROgre.h:138
Implementation of an homogeneous matrix and operations on such kind of matrices.
unsigned int getNbVisiblePolygon() const
void setShowConfigDialog(const bool showConfigDialog)
Definition: vpAROgre.h:250
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
PolygonType * operator[](const unsigned int i)
operator[] as modifier.
void setOgreShowConfigDialog(const bool showConfigDialog)
vpMbScanLine & getMbScanLineRenderer()
Implementation of an augmented reality viewer.
Definition: vpAROgre.h:86
bool renderOneFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
Definition: vpAROgre.cpp:578
unsigned int setVisibleOgre(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
Ogre::SceneManager * getSceneManager()
Definition: vpAROgre.h:158
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
Definition: vpAROgre.cpp:614
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
Class that defines what is a point.
Definition: vpPoint.h:59
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
unsigned int setVisible(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
bool isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index)
vpAROgre * getOgreContext()
virtual void init(vpImage< unsigned char > &I, bool bufferedKeys=false, bool hidden=false)
Definition: vpAROgre.cpp:115
double getGoodNbRayCastingAttemptsRatio()
#define vpTRACE
Definition: vpDebug.h:414
void setCameraParameters(const vpCameraParameters &cameraP)
Definition: vpAROgre.cpp:654
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
Generic class defining intrinsic camera parameters.
bool computeVisibility(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed, bool useOgre, bool testRoi, const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpTranslationVector &cameraPos, unsigned int index)
void extract(vpRotationMatrix &R) const
void addPolygon(PolygonType *p)
unsigned int size() const
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
vpHomogeneousMatrix inverse() const
bool isWindowHidden()
Definition: vpAROgre.h:168
bool isVisible(const unsigned int i)
unsigned int getNbRayCastingAttemptsForVisibility()
void displayOgre(const vpHomogeneousMatrix &cMo)
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
Class that consider the case of a translation vector.
std::vector< PolygonType * > & getPolygon()