Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpMbHiddenFaces.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
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 https://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
32 * in order to have a model based tracker.
33 */
34
35#ifndef VP_MB_HIDDEN_FACES_H
36#define VP_MB_HIDDEN_FACES_H
37
38#include <visp3/core/vpConfig.h>
39#include <visp3/core/vpDebug.h>
40#include <visp3/core/vpHomogeneousMatrix.h>
41#include <visp3/core/vpMeterPixelConversion.h>
42#include <visp3/core/vpPixelMeterConversion.h>
43#include <visp3/mbt/vpMbScanLine.h>
44#include <visp3/mbt/vpMbtPolygon.h>
45
46#ifdef VISP_HAVE_OGRE
47#include <visp3/ar/vpAROgre.h>
48#endif
49
50#include <limits>
51#include <vector>
52
54template <class PolygonType> class vpMbHiddenFaces;
55
56// Forward declaration to have the operator in the global namespace
57template <class PolygonType> void swap(vpMbHiddenFaces<PolygonType> &first, vpMbHiddenFaces<PolygonType> &second);
58END_VISP_NAMESPACE
59
81template <class PolygonType = vpMbtPolygon> class vpMbHiddenFaces
82{
83private:
85 std::vector<PolygonType *> Lpol;
87 unsigned int nbVisiblePolygon;
88 vpMbScanLine scanlineRender;
89
90#ifdef VISP_HAVE_OGRE
91 vpImage<unsigned char> ogreBackground;
92 bool ogreInitialised;
93 unsigned int nbRayAttempts;
94 double ratioVisibleRay;
95 vpAROgre *ogre;
96 std::vector<Ogre::ManualObject *> lOgrePolygons;
97 bool ogreShowConfigDialog;
98#endif
99
100 unsigned int setVisiblePrivate(const vpHomogeneousMatrix &cMo, const double &angleAppears,
101 const double &angleDisappears, bool &changed, bool useOgre = false,
102 bool not_used = false, unsigned int width = 0, unsigned int height = 0,
104
105public:
108 vpMbHiddenFaces(const vpMbHiddenFaces &copy);
111
112 void addPolygon(PolygonType *p);
113
114 bool computeVisibility(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
115 bool &changed, bool useOgre, bool not_used, unsigned int width, unsigned int height,
116 const vpCameraParameters &cam, const vpTranslationVector &cameraPos, unsigned int index);
117
119
120 void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h);
121
122 void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector<std::pair<vpPoint, vpPoint> > &lines,
123 const bool &displayResults = false);
124
125 vpMbScanLine &getMbScanLineRenderer() { return scanlineRender; }
126
127#ifdef VISP_HAVE_OGRE
129#endif
130
136 std::vector<PolygonType *> &getPolygon() { return Lpol; }
137
138#ifdef VISP_HAVE_OGRE
140#endif
141
147 unsigned int getNbVisiblePolygon() const { return nbVisiblePolygon; }
148
149#ifdef VISP_HAVE_OGRE
159 unsigned int getNbRayCastingAttemptsForVisibility() { return nbRayAttempts; }
160
166 vpAROgre *getOgreContext() { return ogre; }
167
177 double getGoodNbRayCastingAttemptsRatio() { return ratioVisibleRay; }
178#endif
179
180 bool isAppearing(unsigned int i) { return Lpol[i]->isAppearing(); }
181
182#ifdef VISP_HAVE_OGRE
188 bool isOgreInitialised() { return ogreInitialised; }
189#endif
190
198 bool isVisible(unsigned int i) { return Lpol[i]->isVisible(); }
199
200#ifdef VISP_HAVE_OGRE
201 bool isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index);
202#endif
203
205 inline PolygonType *operator[](unsigned int i) { return Lpol[i]; }
207 inline const PolygonType *operator[](unsigned int i) const { return Lpol[i]; }
208
209 void reset();
210
211#ifdef VISP_HAVE_OGRE
222 void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
223 {
224 ogreBackground = vpImage<unsigned char>(h, w, 0);
225 }
226
236 void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts) { nbRayAttempts = attempts; }
237
247 void setGoodNbRayCastingAttemptsRatio(const double &ratio)
248 {
249 ratioVisibleRay = ratio;
250 if (ratioVisibleRay > 1.0)
251 ratioVisibleRay = 1.0;
252 if (ratioVisibleRay < 0.0)
253 ratioVisibleRay = 0.0;
254 }
255
265 inline void setOgreShowConfigDialog(bool showConfigDialog) { ogreShowConfigDialog = showConfigDialog; }
266#endif
267
268 unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam,
269 const vpHomogeneousMatrix &cMo, const double &angle, bool &changed);
270 unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam,
271 const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
272 bool &changed);
273 unsigned int setVisible(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
274 bool &changed);
275
276#ifdef VISP_HAVE_OGRE
277 unsigned int setVisibleOgre(unsigned int width, unsigned int height, const vpCameraParameters &cam,
278 const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
279 bool &changed);
280 unsigned int setVisibleOgre(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears,
281 bool &changed);
282#endif
288 inline unsigned int size() const { return static_cast<unsigned int>(Lpol.size()); }
289};
290
294template <class PolygonType>
295vpMbHiddenFaces<PolygonType>::vpMbHiddenFaces() : Lpol(), nbVisiblePolygon(0), scanlineRender()
296{
297#ifdef VISP_HAVE_OGRE
298 ogreInitialised = false;
299 nbRayAttempts = 1;
300 ratioVisibleRay = 1.0;
301 ogreShowConfigDialog = false;
302 ogre = new vpAROgre();
303 ogreBackground = vpImage<unsigned char>(480, 640, 0);
304#endif
305}
306
311{
312 for (unsigned int i = 0; i < Lpol.size(); i++) {
313 if (Lpol[i] != nullptr) {
314 delete Lpol[i];
315 }
316 Lpol[i] = nullptr;
317 }
318 Lpol.resize(0);
319
320#ifdef VISP_HAVE_OGRE
321 if (ogre != nullptr) {
322 delete ogre;
323 ogre = nullptr;
324 }
325
326 // This is already done by calling "delete ogre"
327 // for(unsigned int i = 0 ; i < lOgrePolygons.size() ; i++){
328 // if (lOgrePolygons[i]!=nullptr){
329 // delete lOgrePolygons[i];
330 // }
331 // lOgrePolygons[i] = nullptr;
332 // }
333
334 lOgrePolygons.resize(0);
335#endif
336}
337
341template <class PolygonType>
343 : Lpol(), nbVisiblePolygon(copy.nbVisiblePolygon), scanlineRender(copy.scanlineRender)
344#ifdef VISP_HAVE_OGRE
345 ,
346 ogreBackground(copy.ogreBackground), ogreInitialised(copy.ogreInitialised), nbRayAttempts(copy.nbRayAttempts),
347 ratioVisibleRay(copy.ratioVisibleRay), ogre(nullptr), lOgrePolygons(), ogreShowConfigDialog(copy.ogreShowConfigDialog)
348#endif
349{
350 // Copy the list of polygons
351 for (unsigned int i = 0; i < copy.Lpol.size(); i++) {
352 PolygonType *poly = new PolygonType(*copy.Lpol[i]);
353 Lpol.push_back(poly);
354 }
355}
356
357template <class PolygonType> void swap(vpMbHiddenFaces<PolygonType> &first, vpMbHiddenFaces<PolygonType> &second)
358{
359 using std::swap;
360 swap(first.Lpol, second.Lpol);
361 swap(first.nbVisiblePolygon, second.nbVisiblePolygon);
362 swap(first.scanlineRender, second.scanlineRender);
363#ifdef VISP_HAVE_OGRE
364 swap(first.ogreInitialised, second.ogreInitialised);
365 swap(first.nbRayAttempts, second.nbRayAttempts);
366 swap(first.ratioVisibleRay, second.ratioVisibleRay);
367 swap(first.ogreShowConfigDialog, second.ogreShowConfigDialog);
368 swap(first.ogre, second.ogre);
369 swap(first.ogreBackground, second.ogreBackground);
370#endif
371}
372
376template <class PolygonType>
383
389template <class PolygonType> void vpMbHiddenFaces<PolygonType>::addPolygon(PolygonType *p)
390{
391 PolygonType *p_new = new PolygonType;
392 p_new->index = p->index;
393 p_new->setNbPoint(p->nbpt);
394 p_new->isvisible = p->isvisible;
395 p_new->useLod = p->useLod;
396 p_new->minLineLengthThresh = p->minLineLengthThresh;
397 p_new->minPolygonAreaThresh = p->minPolygonAreaThresh;
398 p_new->setName(p->name);
399 p_new->hasOrientation = p->hasOrientation;
400
401 for (unsigned int i = 0; i < p->nbpt; i++)
402 p_new->p[i] = p->p[i];
403 Lpol.push_back(p_new);
404}
405
409template <class PolygonType> void vpMbHiddenFaces<PolygonType>::reset()
410{
411 nbVisiblePolygon = 0;
412 for (unsigned int i = 0; i < Lpol.size(); i++) {
413 if (Lpol[i] != nullptr) {
414 delete Lpol[i];
415 }
416 Lpol[i] = nullptr;
417 }
418 Lpol.resize(0);
419
420#ifdef VISP_HAVE_OGRE
421 if (ogre != nullptr) {
422 delete ogre;
423 ogre = nullptr;
424 }
425
426 // This is already done by calling "delete ogre"
427 // for(unsigned int i = 0 ; i < lOgrePolygons.size() ; i++){
428 // if (lOgrePolygons[i]!=nullptr){
429 // delete lOgrePolygons[i];
430 // }
431 // lOgrePolygons[i] = nullptr;
432 // }
433
434 lOgrePolygons.resize(0);
435
436 ogreInitialised = false;
437 nbRayAttempts = 1;
438 ratioVisibleRay = 1.0;
439 ogre = new vpAROgre();
440 ogreBackground = vpImage<unsigned char>(480, 640);
441#endif
442}
443
451template <class PolygonType>
453{
454 for (unsigned int i = 0; i < Lpol.size(); i++) {
455 // For fast result we could just clip visible polygons.
456 // However clipping all of them gives us the possibility to return more
457 // information in the scanline visibility results
458 // if(Lpol[i]->isVisible())
459 {
460 Lpol[i]->changeFrame(cMo);
461 Lpol[i]->computePolygonClipped(cam);
462 }
463 }
464}
465
474template <class PolygonType>
476 const unsigned int &h)
477{
478 std::vector<std::vector<std::pair<vpPoint, unsigned int> > > polyClipped(Lpol.size());
479 std::vector<std::vector<std::pair<vpPoint, unsigned int> > *> listPolyClipped;
480 std::vector<int> listPolyIndices;
481
482 for (unsigned int i = 0; i < Lpol.size(); i++) {
483 // For fast result we could just use visible polygons.
484 // However using all of them gives us the possibility to return more
485 // information in the scanline visibility results
486 // if(Lpol[i]->isVisible())
487 {
488 polyClipped[i].clear();
489 Lpol[i]->getPolygonClipped(polyClipped[i]);
490 if (polyClipped[i].size() != 0) {
491 listPolyClipped.push_back(&polyClipped[i]);
492 listPolyIndices.push_back(Lpol[i]->getIndex());
493 }
494 }
495 }
496
497 scanlineRender.drawScene(listPolyClipped, listPolyIndices, cam, w, h);
498}
499
510template <class PolygonType>
512 std::vector<std::pair<vpPoint, vpPoint> > &lines,
513 const bool &displayResults)
514{
515 scanlineRender.queryLineVisibility(a, b, lines, displayResults);
516}
517
533template <class PolygonType>
534unsigned int vpMbHiddenFaces<PolygonType>::setVisiblePrivate(const vpHomogeneousMatrix &cMo, const double &angleAppears,
535 const double &angleDisappears, bool &changed, bool useOgre,
536 bool not_used, unsigned int width, unsigned int height,
537 const vpCameraParameters &cam)
538{
539 nbVisiblePolygon = 0;
540 changed = false;
541
542 vpTranslationVector cameraPos;
543
544 if (useOgre) {
545#ifdef VISP_HAVE_OGRE
546 cMo.inverse().extract(cameraPos);
547 ogre->renderOneFrame(ogreBackground, cMo);
548#else
549 vpTRACE("ViSP doesn't have Ogre3D, simple visibility test used");
550#endif
551 }
552
553 for (unsigned int i = 0; i < Lpol.size(); i++) {
554 // std::cout << "Calling poly: " << i << std::endl;
555 if (computeVisibility(cMo, angleAppears, angleDisappears, changed, useOgre, not_used, width, height, cam, cameraPos,
556 i))
557 nbVisiblePolygon++;
558 }
559 return nbVisiblePolygon;
560}
561
579template <class PolygonType>
581 const double &angleDisappears, bool &changed, bool useOgre,
582 bool not_used, unsigned int width, unsigned int height,
583 const vpCameraParameters &cam,
584 const vpTranslationVector &cameraPos, unsigned int index)
585{
586 (void)not_used;
587 unsigned int i = index;
588 Lpol[i]->changeFrame(cMo);
589 Lpol[i]->isappearing = false;
590
591 // Commented because we need to compute visibility
592 // even when dealing with line in level of detail case
593 /*if(Lpol[i]->getNbPoint() <= 2)
594 {
595 Lpol[i]->isvisible = true;
596 }
597 else*/
598 {
599 if (Lpol[i]->isVisible()) {
600 bool testDisappear = false;
601 // unsigned int nbCornerInsidePrev = 0;
602
603 if (!testDisappear) {
604 if (useOgre)
605#ifdef VISP_HAVE_OGRE
606 testDisappear =
607 ((!Lpol[i]->isVisible(cMo, angleDisappears, true, cam, width, height)) || !isVisibleOgre(cameraPos, i));
608#else
609 {
610 (void)cameraPos; // Avoid warning
611 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears, false, cam, width, height));
612 }
613#endif
614 else
615 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears, false, cam, width, height));
616 }
617
618 // test if the face is still visible
619 if (testDisappear) {
620 // std::cout << "Face " << i << " disappears" <<
621 // std::endl;
622 changed = true;
623 Lpol[i]->isvisible = false;
624 }
625 else {
626 // nbVisiblePolygon++;
627 Lpol[i]->isvisible = true;
628
629 // if(nbCornerInsidePrev > Lpol[i]->getNbCornerInsidePrevImage())
630 // changed = true;
631 }
632 }
633 else {
634 bool testAppear = true;
635
636 if (testAppear) {
637 if (useOgre)
638#ifdef VISP_HAVE_OGRE
639 testAppear =
640 ((Lpol[i]->isVisible(cMo, angleAppears, true, cam, width, height)) && isVisibleOgre(cameraPos, i));
641#else
642 testAppear = (Lpol[i]->isVisible(cMo, angleAppears, false, cam, width, height));
643#endif
644 else
645 testAppear = (Lpol[i]->isVisible(cMo, angleAppears, false, cam, width, height));
646 }
647
648 if (testAppear) {
649 // std::cout << "Face " << i << " appears" << std::endl;
650 Lpol[i]->isvisible = true;
651 changed = true;
652 // nbVisiblePolygon++;
653 }
654 else {
655 // std::cout << "Problem" << std::endl;
656 Lpol[i]->isvisible = false;
657 }
658 }
659 }
660 // std::cout << "Nombre de polygones visibles: " << nbVisiblePolygon <<
661 // std::endl;
662 return Lpol[i]->isvisible;
663}
664
677template <class PolygonType>
678unsigned int vpMbHiddenFaces<PolygonType>::setVisible(unsigned int width, unsigned int height,
679 const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo,
680 const double &angle, bool &changed)
681{
682 return setVisible(width, height, cam, cMo, angle, angle, changed);
683}
684
698template <class PolygonType>
699unsigned int vpMbHiddenFaces<PolygonType>::setVisible(unsigned int width, unsigned int height,
700 const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo,
701 const double &angleAppears, const double &angleDisappears,
702 bool &changed)
703{
704 return setVisiblePrivate(cMo, angleAppears, angleDisappears, changed, false, true, width, height, cam);
705}
706
717template <class PolygonType>
718unsigned int vpMbHiddenFaces<PolygonType>::setVisible(const vpHomogeneousMatrix &cMo, const double &angleAppears,
719 const double &angleDisappears, bool &changed)
720{
721 return setVisiblePrivate(cMo, angleAppears, angleDisappears, changed, false);
722}
723
724#ifdef VISP_HAVE_OGRE
730template <class PolygonType> void vpMbHiddenFaces<PolygonType>::initOgre(const vpCameraParameters &cam)
731{
732 ogreInitialised = true;
733 ogre->setCameraParameters(cam);
734 ogre->setShowConfigDialog(ogreShowConfigDialog);
735 ogre->init(ogreBackground, false, true);
736
737 for (unsigned int n = 0; n < Lpol.size(); n++) {
738 Ogre::ManualObject *manual = ogre->getSceneManager()->createManualObject(Ogre::StringConverter::toString(n));
739
740 manual->begin("BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
741 for (unsigned int i = 0; i < Lpol[n]->nbpt; i++) {
742 manual->position((Ogre::Real)Lpol[n]->p[i].get_oX(), (Ogre::Real)Lpol[n]->p[i].get_oY(),
743 (Ogre::Real)Lpol[n]->p[i].get_oZ());
744 manual->colour(1.0, 1.0, 1.0);
745 manual->index(i);
746 }
747
748 manual->index(0);
749 manual->end();
750
751 ogre->getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
752
753 lOgrePolygons.push_back(manual);
754 }
755}
756
762template <class PolygonType> void vpMbHiddenFaces<PolygonType>::displayOgre(const vpHomogeneousMatrix &cMo)
763{
764 if (ogreInitialised && !ogre->isWindowHidden()) {
765 for (unsigned int i = 0; i < Lpol.size(); i++) {
766 if (Lpol[i]->isVisible()) {
767 lOgrePolygons[i]->setVisible(true);
768 }
769 else
770 lOgrePolygons[i]->setVisible(false);
771 }
772 ogre->display(ogreBackground, cMo);
773 }
774}
775
789template <class PolygonType>
790unsigned int vpMbHiddenFaces<PolygonType>::setVisibleOgre(unsigned int width, unsigned int height,
791 const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo,
792 const double &angleAppears, const double &angleDisappears,
793 bool &changed)
794{
795 return setVisiblePrivate(cMo, angleAppears, angleDisappears, changed, true, true, width, height, cam);
796}
797
808template <class PolygonType>
809unsigned int vpMbHiddenFaces<PolygonType>::setVisibleOgre(const vpHomogeneousMatrix &cMo, const double &angleAppears,
810 const double &angleDisappears, bool &changed)
811{
812 return setVisiblePrivate(cMo, angleAppears, angleDisappears, changed, true);
813}
814
823template <class PolygonType>
824bool vpMbHiddenFaces<PolygonType>::isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index)
825{
826 Ogre::Vector3 camera((Ogre::Real)cameraPos[0], (Ogre::Real)cameraPos[1], (Ogre::Real)cameraPos[2]);
827 if (!ogre->getCamera()->isVisible(lOgrePolygons[index]->getBoundingBox())) {
828 lOgrePolygons[index]->setVisible(false);
829 Lpol[index]->isvisible = false;
830 return false;
831 }
832
833 // Get the center of gravity
834 bool visible = false;
835 unsigned int nbVisible = 0;
836
837 for (unsigned int i = 0; i < nbRayAttempts; i++) {
838 Ogre::Vector3 origin(0, 0, 0);
839 Ogre::Real totalFactor = 0.0f;
840
841 for (unsigned int j = 0; j < Lpol[index]->getNbPoint(); j++) {
842 Ogre::Real factor = 1.0f;
843
844 if (nbRayAttempts > 1) {
845 int r = rand() % 101;
846
847 if (r != 0)
848 factor = ((Ogre::Real)r) / 100.0f;
849 }
850
851 Ogre::Vector3 tmp((Ogre::Real)Lpol[index]->getPoint(j).get_oX(), (Ogre::Real)Lpol[index]->getPoint(j).get_oY(),
852 (Ogre::Real)Lpol[index]->getPoint(j).get_oZ());
853 tmp *= factor;
854 origin += tmp;
855 totalFactor += factor;
856 }
857
858 origin /= totalFactor;
859
860 Ogre::Vector3 direction = origin - camera;
861 Ogre::Real distanceCollision = direction.length();
862
863 direction.normalise();
864 Ogre::RaySceneQuery *mRaySceneQuery = ogre->getSceneManager()->createRayQuery(Ogre::Ray(camera, direction));
865 mRaySceneQuery->setSortByDistance(true);
866
867 Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
868 Ogre::RaySceneQueryResult::iterator it = result.begin();
869
870 // while(it != result.end()){
871 // std::cout << it->movable->getName() << "(" << it->distance<< ") :
872 // " << std::flush; it++;
873 // }
874 // std::cout << std::endl;
875 // it = result.begin();
876
877 if (it != result.end())
878 if (it->movable->getName().find("SimpleRenderable") != Ogre::String::npos) // Test if the ogreBackground is
879 // intersect in first
880 ++it;
881
882 double distance;
883 // In a case of a two-axis aligned segment, ray collision is not always
884 // working.
885 if (Lpol[index]->getNbPoint() == 2 &&
886 (((std::fabs(Lpol[index]->getPoint(0).get_oX() - Lpol[index]->getPoint(1).get_oX()) <
887 std::numeric_limits<double>::epsilon()) +
888 (std::fabs(Lpol[index]->getPoint(0).get_oY() - Lpol[index]->getPoint(1).get_oY()) <
889 std::numeric_limits<double>::epsilon()) +
890 (std::fabs(Lpol[index]->getPoint(0).get_oZ() - Lpol[index]->getPoint(1).get_oZ()) <
891 std::numeric_limits<double>::epsilon())) >= 2)) {
892 if (it != result.end()) {
893 if (it->movable->getName() == Ogre::StringConverter::toString(index)) {
894 nbVisible++;
895 }
896 else {
897 distance = it->distance;
898 // Cannot use epsilon for comparison as ray length is slightly
899 // different from the collision distance returned by
900 // Ogre::RaySceneQueryResult.
901 if (distance > distanceCollision || std::fabs(distance - distanceCollision) <
902 1e-6 /*std::fabs(distance) * std::numeric_limits<double>::epsilon()*/)
903 nbVisible++;
904 }
905 }
906 else
907 nbVisible++; // Collision not detected but present.
908 }
909 else {
910 if (it != result.end()) {
911 distance = it->distance;
912 double distancePrev = distance;
913
914 // std::cout << "For " << Ogre::StringConverter::toString(index) << ":
915 // " << it->movable->getName() << " / " << std::flush;
916
917 if (it->movable->getName() == Ogre::StringConverter::toString(index)) {
918 nbVisible++;
919 }
920 else {
921 ++it;
922 while (it != result.end()) {
923 distance = it->distance;
924
925 if (std::fabs(distance - distancePrev) <
926 1e-6 /*std::fabs(distance) * std::numeric_limits<double>::epsilon()*/) {
927 // std::cout << it->movable->getName() << " / " << std::flush;
928 if (it->movable->getName() == Ogre::StringConverter::toString(index)) {
929 nbVisible++;
930 break;
931 }
932 ++it;
933 distancePrev = distance;
934 }
935 else
936 break;
937 }
938 }
939 }
940 }
941
942 ogre->getSceneManager()->destroyQuery(mRaySceneQuery);
943 }
944
945 if ((static_cast<double>(nbVisible)) / (static_cast<double>(nbRayAttempts)) > ratioVisibleRay ||
946 std::fabs((static_cast<double>(nbVisible)) / (static_cast<double>(nbRayAttempts)) - ratioVisibleRay) <
947 ratioVisibleRay * std::numeric_limits<double>::epsilon())
948 visible = true;
949 else
950 visible = false;
951
952 if (visible) {
953 lOgrePolygons[index]->setVisible(true);
954 Lpol[index]->isvisible = true;
955 }
956 else {
957 lOgrePolygons[index]->setVisible(false);
958 Lpol[index]->isvisible = false;
959 }
960
961 return Lpol[index]->isvisible;
962}
963
964#endif // VISP_HAVE_OGRE
965END_VISP_NAMESPACE
966#endif // vpMbHiddenFaces
Implementation of an augmented reality viewer using Ogre3D 3rd party.
Definition vpAROgre.h:121
bool renderOneFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
Definition vpAROgre.cpp:780
Generic class defining intrinsic camera parameters.
Implementation of an homogeneous matrix and operations on such kind of matrices.
Definition of the vpImage class member functions.
Definition vpImage.h:131
Implementation of the polygons management for the model-based trackers.
bool isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index)
void setNbRayCastingAttemptsForVisibility(const unsigned int &attempts)
PolygonType * operator[](unsigned int i)
Operator[] as modifier.
virtual ~vpMbHiddenFaces()
void computeClippedPolygons(const vpHomogeneousMatrix &cMo, const vpCameraParameters &cam)
void setGoodNbRayCastingAttemptsRatio(const double &ratio)
bool isAppearing(unsigned int i)
vpMbHiddenFaces & operator=(vpMbHiddenFaces other)
unsigned int size() const
std::vector< PolygonType * > & getPolygon()
unsigned int setVisibleOgre(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
bool isVisible(unsigned int i)
void addPolygon(PolygonType *p)
void computeScanLineQuery(const vpPoint &a, const vpPoint &b, std::vector< std::pair< vpPoint, vpPoint > > &lines, const bool &displayResults=false)
unsigned int getNbVisiblePolygon() const
void initOgre(const vpCameraParameters &cam=vpCameraParameters())
unsigned int setVisible(unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angle, bool &changed)
double getGoodNbRayCastingAttemptsRatio()
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
friend void swap(vpMbHiddenFaces &first, vpMbHiddenFaces &second)
void computeScanLineRender(const vpCameraParameters &cam, const unsigned int &w, const unsigned int &h)
vpAROgre * getOgreContext()
const PolygonType * operator[](unsigned int i) const
Operator[] as reader.
unsigned int getNbRayCastingAttemptsForVisibility()
void displayOgre(const vpHomogeneousMatrix &cMo)
vpMbScanLine & getMbScanLineRenderer()
void setOgreShowConfigDialog(bool showConfigDialog)
bool computeVisibility(const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed, bool useOgre, bool not_used, unsigned int width, unsigned int height, const vpCameraParameters &cam, const vpTranslationVector &cameraPos, unsigned int index)
Class that defines a 3D point in the object frame and allows forward projection of a 3D point in the ...
Definition vpPoint.h:79
Class that consider the case of a translation vector.
#define vpTRACE
Definition vpDebug.h:450