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,
96 const double &angleAppears,
const double &angleDisappears,
97 bool &changed,
bool useOgre,
bool testRoi,
102 #ifdef VISP_HAVE_OGRE
113 #ifdef VISP_HAVE_OGRE
124 #ifdef VISP_HAVE_OGRE
133 bool isAppearing(
const unsigned int i){
return Lpol[i]->isAppearing(); }
136 #ifdef VISP_HAVE_OGRE
152 bool isVisible(
const unsigned int i){
return Lpol[i]->isVisible(); }
154 #ifdef VISP_HAVE_OGRE
159 inline PolygonType*
operator[](
const unsigned int i) {
return Lpol[i];}
161 inline const PolygonType*
operator[](
const unsigned int i)
const {
return Lpol[i];}
165 #ifdef VISP_HAVE_OGRE
182 #ifdef VISP_HAVE_OGRE
191 inline unsigned int size()
const {
return (
unsigned int)Lpol.size(); }
193 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
223 template<
class PolygonType>
225 : Lpol(), nbVisiblePolygon(0)
226 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
231 #ifdef VISP_HAVE_OGRE
232 ogreInitialised =
false;
242 template<
class PolygonType>
245 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
253 #ifdef VISP_HAVE_OGRE
267 lOgrePolygons.resize(0);
276 template<
class PolygonType>
280 PolygonType *p_new =
new PolygonType;
281 p_new->index = p->index;
282 p_new->setNbPoint(p->nbpt);
283 p_new->isvisible = p->isvisible;
284 p_new->useLod = p->useLod;
285 p_new->minLineLengthThresh = p->minLineLengthThresh;
286 p_new->minPolygonAreaThresh = p->minPolygonAreaThresh;
287 p_new->setName(p->name);
289 for(
unsigned int i = 0; i < p->nbpt; i++)
290 p_new->p[i]= p->p[i];
291 Lpol.push_back(p_new);
297 template<
class PolygonType>
301 nbVisiblePolygon = 0;
302 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
310 #ifdef VISP_HAVE_OGRE
324 lOgrePolygons.resize(0);
326 ogreInitialised =
false;
347 template<
class PolygonType>
350 const double &angleAppears,
const double &angleDisappears,
351 bool &changed,
bool useOgre,
bool testRoi,
355 nbVisiblePolygon = 0;
361 #ifdef VISP_HAVE_OGRE
365 vpTRACE(
"ViSP doesn't have Ogre3D, simple visibility test used");
369 for (
unsigned int i = 0; i < Lpol.size(); i++){
370 if (computeVisibility(cMo, angleAppears, angleDisappears, changed, useOgre, testRoi, I, cam, cameraPos, i))
373 return nbVisiblePolygon;
392 template<
class PolygonType>
395 const double &angleAppears,
const double &angleDisappears,
396 bool &changed,
bool useOgre,
bool ,
400 #ifdef VISP_HAVE_OGRE
406 unsigned int i = index;
407 Lpol[i]->changeFrame(cMo);
408 Lpol[i]->isappearing =
false;
417 if(Lpol[i]->isVisible())
419 bool testDisappear =
false;
420 unsigned int nbCornerInsidePrev = 0;
430 #ifdef VISP_HAVE_OGRE
431 testDisappear = ((!Lpol[i]->isVisible(cMo, angleDisappears,
true, cam, I)) || !isVisibleOgre(cameraPos,i));
433 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears,
false, cam, I));
436 testDisappear = (!Lpol[i]->isVisible(cMo, angleDisappears,
false, cam, I));
443 Lpol[i]->isvisible =
false;
447 Lpol[i]->isvisible =
true;
449 if(nbCornerInsidePrev > Lpol[i]->getNbCornerInsidePrevImage())
455 bool testAppear =
true;
462 #ifdef VISP_HAVE_OGRE
463 testAppear = ((Lpol[i]->isVisible(cMo, angleAppears,
true, cam, I)) && isVisibleOgre(cameraPos,i));
465 testAppear = (Lpol[i]->isVisible(cMo, angleAppears,
false, cam, I));
468 testAppear = (Lpol[i]->isVisible(cMo, angleAppears,
false, cam, I));
473 Lpol[i]->isvisible =
true;
479 Lpol[i]->isvisible =
false;
484 return Lpol[i]->isvisible;
498 template<
class PolygonType>
502 return setVisible(I, cam, cMo, angle, angle, changed);
517 template<
class PolygonType>
521 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
false,
true,I,cam);
534 template<
class PolygonType>
538 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
false);
541 #ifdef VISP_HAVE_OGRE
547 template<
class PolygonType>
551 ogreInitialised =
true;
553 ogre->
init(ogreBackground,
false,
true);
555 for(
unsigned int n = 0 ; n < Lpol.size(); n++){
556 Ogre::ManualObject* manual = ogre->
getSceneManager()->createManualObject(Ogre::StringConverter::toString(n));
558 manual->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
559 for(
unsigned int i = 0; i < Lpol[n]->nbpt; i++){
560 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());
561 manual->colour(1.0, 1.0, 1.0);
568 ogre->
getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
570 lOgrePolygons.push_back(manual);
579 template<
class PolygonType>
584 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
585 if(Lpol[i]->isVisible()){
586 lOgrePolygons[i]->setVisible(
true);
589 lOgrePolygons[i]->setVisible(
false);
591 ogre->
display(ogreBackground, cMo);
607 template<
class PolygonType>
611 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
true,
true,I,cam);
624 template<
class PolygonType>
628 return setVisiblePrivate(cMo,angleAppears,angleDisappears,changed,
true);
639 template<
class PolygonType>
645 if(Lpol[index]->getNbPoint() <= 2){
646 lOgrePolygons[index]->setVisible(
true);
647 Lpol[index]->isvisible =
true;
651 Ogre::Vector3 camera((Ogre::Real)cameraPos[0],(Ogre::Real)cameraPos[1],(Ogre::Real)cameraPos[2]);
652 if(!ogre->
getCamera()->isVisible(lOgrePolygons[index]->getBoundingBox())){
653 lOgrePolygons[index]->setVisible(
false);
654 Lpol[index]->isvisible =
false;
659 Ogre::Vector3 origin(0,0,0);
660 for(
unsigned int j = 0 ; j < Lpol[index]->getNbPoint() ; j++){
661 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());
664 origin /= (Ogre::Real)Lpol[index]->getNbPoint();
665 Ogre::Vector3 direction = origin - camera;
667 Ogre::RaySceneQuery *mRaySceneQuery = ogre->
getSceneManager()->createRayQuery(Ogre::Ray(camera, direction));
668 mRaySceneQuery->setSortByDistance(
true);
670 Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
671 Ogre::RaySceneQueryResult::iterator it = result.begin();
673 bool visible =
false;
674 double distance, distancePrev;
675 if(it != result.end()){
676 if(it->movable->getName().find(
"SimpleRenderable") != Ogre::String::npos)
679 if(it != result.end()){
680 distance = it->distance;
681 distancePrev = distance;
682 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
687 while(!visible && it != result.end()){
688 distance = it->distance;
690 if(std::fabs(distance - distancePrev) < distance * std::numeric_limits<double>::epsilon()){
691 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
696 distancePrev = distance;
706 lOgrePolygons[index]->setVisible(
true);
707 Lpol[index]->isvisible =
true;
710 lOgrePolygons[index]->setVisible(
false);
711 Lpol[index]->isvisible =
false;
716 return Lpol[index]->isvisible;
718 #endif //VISP_HAVE_OGRE
720 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
730 template<
class PolygonType>
734 nbVisiblePolygon = 0 ;
736 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
737 if (Lpol[i]->isVisible(cMo, depthTest)){
741 return nbVisiblePolygon ;
743 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
745 #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.
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
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()