44 #ifndef vpMbHiddenFaces_HH
45 #define vpMbHiddenFaces_HH
47 #include <visp/vpHomogeneousMatrix.h>
48 #include <visp/vpMeterPixelConversion.h>
49 #include <visp/vpPixelMeterConversion.h>
50 #include <visp/vpMbtPolygon.h>
53 #include <visp/vpAROgre.h>
67 template<
class PolygonType = vpMbtPolygon>
72 std::vector<PolygonType *> Lpol ;
74 unsigned int nbVisiblePolygon;
80 std::vector< Ogre::ManualObject* > lOgrePolygons;
83 unsigned int setVisiblePrivate(
const vpHomogeneousMatrix &cMo,
const double &angleAppears,
const double &angleDisappears,
85 bool useOgre =
false,
bool testRoi =
false,
108 #ifdef VISP_HAVE_OGRE
119 #ifdef VISP_HAVE_OGRE
128 bool isAppearing(
const unsigned int i){
return Lpol[i]->isAppearing(); }
131 #ifdef VISP_HAVE_OGRE
147 bool isVisible(
const unsigned int i){
return Lpol[i]->isVisible(); }
149 #ifdef VISP_HAVE_OGRE
154 inline PolygonType*
operator[](
const unsigned int i) {
return Lpol[i];}
156 inline const PolygonType*
operator[](
const unsigned int i)
const {
return Lpol[i];}
160 #ifdef VISP_HAVE_OGRE
177 #ifdef VISP_HAVE_OGRE
186 inline unsigned int size()
const {
return (
unsigned int)Lpol.size(); }
188 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
218 template<
class PolygonType>
220 : Lpol(), nbVisiblePolygon(0)
221 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
226 #ifdef VISP_HAVE_OGRE
227 ogreInitialised =
false;
238 template<
class PolygonType>
241 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
249 #ifdef VISP_HAVE_OGRE
259 template<
class PolygonType>
263 PolygonType *p_new =
new PolygonType;
264 p_new->index = p->index;
265 p_new->setNbPoint(p->nbpt);
266 p_new->isvisible = p->isvisible;
267 for(
unsigned int i = 0; i < p->nbpt; i++)
268 p_new->p[i]= p->p[i];
269 Lpol.push_back(p_new);
275 template<
class PolygonType>
279 nbVisiblePolygon = 0;
280 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
303 template<
class PolygonType>
306 bool &changed,
bool useOgre,
bool testRoi,
311 nbVisiblePolygon = 0;
317 #ifdef VISP_HAVE_OGRE
321 vpTRACE(
"ViSP doesn't have Ogre3D, simple visibility test used");
325 for (
unsigned int i = 0; i < Lpol.size(); i += 1){
326 Lpol[i]->changeFrame(cMo);
327 Lpol[i]->isappearing =
false;
329 if(Lpol[i]->isVisible())
331 bool testDisappear =
false;
332 unsigned int nbCornerInsidePrev = 0;
335 nbCornerInsidePrev = Lpol[i]->getNbCornerInsidePrevImage();
336 if(Lpol[i]->getNbCornerInsideImage(I, cam) == 0)
337 testDisappear =
true;
342 #ifdef VISP_HAVE_OGRE
343 testDisappear = ((!Lpol[i]->isVisible(cMo, angleDisappears,
true)) || !isVisibleOgre(cameraPos,i));
345 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears));
348 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears));
355 Lpol[i]->isvisible =
false;
359 Lpol[i]->isvisible =
true;
361 if(nbCornerInsidePrev > Lpol[i]->getNbCornerInsidePrevImage())
367 bool testAppear =
true;
369 if(testRoi && Lpol[i]->getNbCornerInsideImage(I, cam) == 0)
374 #ifdef VISP_HAVE_OGRE
375 testAppear = ((Lpol[i]->isVisible(cMo, angleAppears,
true)) && isVisibleOgre(cameraPos,i));
377 testAppear = (Lpol[i]->isVisible(cMo, angleAppears));
380 testAppear = (Lpol[i]->isVisible(cMo, angleAppears));
385 Lpol[i]->isvisible =
true;
390 Lpol[i]->isvisible =
false;
395 return nbVisiblePolygon;
409 template<
class PolygonType>
413 return setVisible(I, cam, cMo, angle, angle, changed);
428 template<
class PolygonType>
432 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
false,
true,I,cam);
445 template<
class PolygonType>
449 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
false);
452 #ifdef VISP_HAVE_OGRE
458 template<
class PolygonType>
462 ogreInitialised =
true;
464 ogre->
init(ogreBackground,
false,
true);
466 for(
unsigned int n = 0 ; n < Lpol.size(); n++){
467 Ogre::ManualObject* manual = ogre->
getSceneManager()->createManualObject(Ogre::StringConverter::toString(n));
469 manual->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
470 for(
unsigned int i = 0; i < Lpol[n]->nbpt; i++){
471 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());
472 manual->colour(1.0, 1.0, 1.0);
479 ogre->
getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
481 lOgrePolygons.push_back(manual);
490 template<
class PolygonType>
495 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
496 if(Lpol[i]->isVisible()){
497 lOgrePolygons[i]->setVisible(
true);
500 lOgrePolygons[i]->setVisible(
false);
502 ogre->
display(ogreBackground, cMo);
518 template<
class PolygonType>
522 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
true,
true,I,cam);
535 template<
class PolygonType>
539 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
true);
550 template<
class PolygonType>
556 if(Lpol[index]->getNbPoint() <= 2){
557 lOgrePolygons[index]->setVisible(
true);
558 Lpol[index]->isvisible =
true;
562 Ogre::Vector3 camera((Ogre::Real)cameraPos[0],(Ogre::Real)cameraPos[1],(Ogre::Real)cameraPos[2]);
563 if(!ogre->
getCamera()->isVisible(lOgrePolygons[index]->getBoundingBox())){
564 lOgrePolygons[index]->setVisible(
false);
565 Lpol[index]->isvisible =
false;
570 Ogre::Vector3 origin(0,0,0);
571 for(
unsigned int j = 0 ; j < Lpol[index]->getNbPoint() ; j++){
572 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());
575 origin /= (Ogre::Real)Lpol[index]->getNbPoint();
576 Ogre::Vector3 direction = origin - camera;
578 Ogre::RaySceneQuery *mRaySceneQuery = ogre->
getSceneManager()->createRayQuery(Ogre::Ray(camera, direction));
579 mRaySceneQuery->setSortByDistance(
true);
581 Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
582 Ogre::RaySceneQueryResult::iterator it = result.begin();
584 bool visible =
false;
585 double distance, distancePrev;
586 if(it != result.end()){
587 if(it->movable->getName().find(
"SimpleRenderable") != Ogre::String::npos)
590 if(it != result.end()){
591 distance = it->distance;
592 distancePrev = distance;
593 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
598 while(!visible && it != result.end()){
599 distance = it->distance;
601 if(std::fabs(distance - distancePrev) < distance * std::numeric_limits<double>::epsilon()){
602 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
607 distancePrev = distance;
617 lOgrePolygons[index]->setVisible(
true);
618 Lpol[index]->isvisible =
true;
621 lOgrePolygons[index]->setVisible(
false);
622 Lpol[index]->isvisible =
false;
627 return Lpol[index]->isvisible;
629 #endif //VISP_HAVE_OGRE
631 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
641 template<
class PolygonType>
645 nbVisiblePolygon = 0 ;
647 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
648 if (Lpol[i]->isVisible(cMo, depthTest)){
652 return nbVisiblePolygon ;
654 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
656 #endif // vpMbHiddenFaces
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()
The class provides a data structure for the homogeneous matrices as well as a set of operations on th...
unsigned int getNbVisiblePolygon() const
void setShowConfigDialog(const bool showConfigDialog)
void setBackgroundSizeOgre(const unsigned int &h, const unsigned int &w)
PolygonType * operator[](const unsigned int i)
operator[] as modifier.
Implementation of an augmented reality viewer.
bool renderOneFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
unsigned int setVisibleOgre(const vpImage< unsigned char > &I, const vpCameraParameters &cam, const vpHomogeneousMatrix &cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
vp_deprecated void setDepthTest(const bool &d)
Ogre::SceneManager * getSceneManager()
virtual void display(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
bool depthTest
Boolean specifying if a polygon has to be entirely in front of the camera or not. ...
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)
void setCameraParameters(const vpCameraParameters &cameraP)
Generic class defining intrinsic camera parameters.
void resize(const unsigned int h, const unsigned int w)
set the size of the image
void extract(vpRotationMatrix &R) const
void addPolygon(PolygonType *p)
unsigned int size() const
vp_deprecated bool getDepthTest()
vpHomogeneousMatrix inverse() const
bool isVisible(const unsigned int i)
void displayOgre(const vpHomogeneousMatrix &cMo)
Class that consider the case of a translation vector.
std::vector< PolygonType * > & getPolygon()