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>
66 template<
class PolygonType = vpMbtPolygon>
71 std::vector<PolygonType *> Lpol ;
73 unsigned int nbVisiblePolygon;
79 std::vector< Ogre::ManualObject* > lOgrePolygons;
82 unsigned int setVisiblePrivate(
const vpHomogeneousMatrix &_cMo,
const double &angleAppears,
const double &angleDisappears,
84 bool useOgre =
false,
bool testRoi =
false,
107 #ifdef VISP_HAVE_OGRE
118 #ifdef VISP_HAVE_OGRE
127 bool isAppearing(
const unsigned int i){
return Lpol[i]->isAppearing(); }
130 #ifdef VISP_HAVE_OGRE
146 bool isVisible(
const unsigned int i){
return Lpol[i]->isVisible(); }
148 #ifdef VISP_HAVE_OGRE
153 inline PolygonType*
operator[](
const unsigned int i) {
return Lpol[i];}
155 inline const PolygonType*
operator[](
const unsigned int i)
const {
return Lpol[i];}
159 #ifdef VISP_HAVE_OGRE
176 #ifdef VISP_HAVE_OGRE
185 inline unsigned int size()
const {
return (
unsigned int)Lpol.size(); }
187 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
217 template<
class PolygonType>
220 #ifdef VISP_HAVE_OGRE
221 ogreInitialised =
false;
226 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
235 template<
class PolygonType>
238 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
246 #ifdef VISP_HAVE_OGRE
256 template<
class PolygonType>
260 PolygonType *p_new =
new PolygonType;
261 p_new->index = p->index;
262 p_new->setNbPoint(p->nbpt);
263 p_new->isvisible = p->isvisible;
264 for(
unsigned int i = 0; i < p->nbpt; i++)
265 p_new->p[i]= p->p[i];
266 Lpol.push_back(p_new);
272 template<
class PolygonType>
276 nbVisiblePolygon = 0;
277 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
300 template<
class PolygonType>
303 bool &changed,
bool useOgre,
bool testRoi,
308 nbVisiblePolygon = 0;
314 #ifdef VISP_HAVE_OGRE
318 vpTRACE(
"ViSP doesn't have Ogre3D, simple visibility test used");
322 for (
unsigned int i = 0; i < Lpol.size(); i += 1){
323 Lpol[i]->changeFrame(_cMo);
324 Lpol[i]->isappearing =
false;
326 if(Lpol[i]->isVisible())
328 bool testDisappear =
false;
329 unsigned int nbCornerInsidePrev = 0;
332 nbCornerInsidePrev = Lpol[i]->getNbCornerInsidePrevImage();
333 if(Lpol[i]->getNbCornerInsideImage(_I, _cam) == 0)
334 testDisappear =
true;
339 #ifdef VISP_HAVE_OGRE
340 testDisappear = ((!Lpol[i]->isVisible(_cMo, angleDisappears,
true)) || !isVisibleOgre(cameraPos,i));
342 testDisappear = (!Lpol[i]->isVisible(_cMo, angleDisappears));
345 testDisappear = (!Lpol[i]->isVisible(_cMo, angleDisappears));
352 Lpol[i]->isvisible =
false;
356 Lpol[i]->isvisible =
true;
358 if(nbCornerInsidePrev > Lpol[i]->getNbCornerInsidePrevImage())
364 bool testAppear =
true;
366 if(testRoi && Lpol[i]->getNbCornerInsideImage(_I, _cam) == 0)
371 #ifdef VISP_HAVE_OGRE
372 testAppear = ((Lpol[i]->isVisible(_cMo, angleAppears,
true)) && isVisibleOgre(cameraPos,i));
374 testAppear = (Lpol[i]->isVisible(_cMo, angleAppears));
377 testAppear = (Lpol[i]->isVisible(_cMo, angleAppears));
382 Lpol[i]->isvisible =
true;
387 Lpol[i]->isvisible =
false;
392 return nbVisiblePolygon;
406 template<
class PolygonType>
410 return setVisible(_I, _cam, _cMo, angle, angle, changed);
425 template<
class PolygonType>
429 return setVisiblePrivate(_cMo,angleAppears,angleDisappears,changed,
false,
true,_I,_cam);
442 template<
class PolygonType>
446 return setVisiblePrivate(_cMo,angleAppears,angleDisappears,changed,
false);
449 #ifdef VISP_HAVE_OGRE
455 template<
class PolygonType>
459 ogreInitialised =
true;
461 ogre->
init(ogreBackground,
false,
true);
463 for(
unsigned int n = 0 ; n < Lpol.size(); n++){
464 Ogre::ManualObject* manual = ogre->
getSceneManager()->createManualObject(Ogre::StringConverter::toString(n));
466 manual->begin(
"BaseWhiteNoLighting", Ogre::RenderOperation::OT_LINE_STRIP);
467 for(
unsigned int i = 0; i < Lpol[n]->nbpt; i++){
468 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());
469 manual->colour(1.0, 1.0, 1.0);
476 ogre->
getSceneManager()->getRootSceneNode()->createChildSceneNode()->attachObject(manual);
478 lOgrePolygons.push_back(manual);
487 template<
class PolygonType>
492 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
493 if(Lpol[i]->isVisible()){
494 lOgrePolygons[i]->setVisible(
true);
497 lOgrePolygons[i]->setVisible(
false);
499 ogre->
display(ogreBackground, _cMo);
515 template<
class PolygonType>
519 return setVisiblePrivate(_cMo,angleAppears,angleDisappears,changed,
true,
true,_I,_cam);
532 template<
class PolygonType>
536 return setVisiblePrivate(_cMo,angleAppears,angleDisappears,changed,
true);
547 template<
class PolygonType>
553 if(Lpol[index]->getNbPoint() <= 2){
554 lOgrePolygons[index]->setVisible(
true);
555 Lpol[index]->isvisible =
true;
559 Ogre::Vector3 camera((Ogre::Real)cameraPos[0],(Ogre::Real)cameraPos[1],(Ogre::Real)cameraPos[2]);
560 if(!ogre->
getCamera()->isVisible(lOgrePolygons[index]->getBoundingBox())){
561 lOgrePolygons[index]->setVisible(
false);
562 Lpol[index]->isvisible =
false;
567 Ogre::Vector3 origin(0,0,0);
568 for(
unsigned int j = 0 ; j < Lpol[index]->getNbPoint() ; j++){
569 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());
572 origin /= (Ogre::Real)Lpol[index]->getNbPoint();
573 Ogre::Vector3 direction = origin - camera;
575 Ogre::RaySceneQuery *mRaySceneQuery = ogre->
getSceneManager()->createRayQuery(Ogre::Ray(camera, direction));
576 mRaySceneQuery->setSortByDistance(
true);
578 Ogre::RaySceneQueryResult &result = mRaySceneQuery->execute();
579 Ogre::RaySceneQueryResult::iterator it = result.begin();
581 bool visible =
false;
582 double distance, distancePrev;
583 if(it != result.end()){
584 if(it->movable->getName().find(
"SimpleRenderable") != Ogre::String::npos)
587 if(it != result.end()){
588 distance = it->distance;
589 distancePrev = distance;
590 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
595 while(!visible && it != result.end()){
596 distance = it->distance;
597 if(distance == distancePrev){
598 if(it->movable->getName() == Ogre::StringConverter::toString(index)){
603 distancePrev = distance;
613 lOgrePolygons[index]->setVisible(
true);
614 Lpol[index]->isvisible =
true;
617 lOgrePolygons[index]->setVisible(
false);
618 Lpol[index]->isvisible =
false;
623 return Lpol[index]->isvisible;
625 #endif //VISP_HAVE_OGRE
627 #ifdef VISP_BUILD_DEPRECATED_FUNCTIONS
637 template<
class PolygonType>
641 nbVisiblePolygon = 0 ;
643 for(
unsigned int i = 0 ; i < Lpol.size() ; i++){
644 if (Lpol[i]->isVisible(_cMo, depthTest)){
648 return nbVisiblePolygon ;
650 #endif //VISP_BUILD_DEPRECATED_FUNCTIONS
652 #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.
void resize(const unsigned int height, const unsigned int width)
set the size of the image
void initOgre(vpCameraParameters _cam=vpCameraParameters())
Implementation of an augmented reality viewer.
bool renderOneFrame(const vpImage< unsigned char > &I, const vpHomogeneousMatrix &cMw)
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 setVisibleOgre(const vpImage< unsigned char > &_I, const vpCameraParameters &_cam, const vpHomogeneousMatrix &_cMo, const double &angleAppears, const double &angleDisappears, bool &changed)
bool isVisibleOgre(const vpTranslationVector &cameraPos, const unsigned int &index)
vpAROgre * getOgreContext()
unsigned int setVisible(const vpImage< unsigned char > &_I, const vpCameraParameters &_cam, const vpHomogeneousMatrix &_cMo, const double &angle, bool &changed)
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 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()