Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Scene.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLGeom/src/ICLGeom/Scene.h                            **
00010 ** Module : ICLGeom                                                **
00011 ** Authors: Christof Elbrechter, Erik Weitnauer, Daniel Dornbusch, **
00012 **          Matthias Esau                                          **
00013 **                                                                 **
00014 **                                                                 **
00015 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00016 ** This file may be used under the terms of the GNU Lesser General **
00017 ** Public License version 3.0 as published by the                  **
00018 **                                                                 **
00019 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00020 ** included in the packaging of this file.  Please review the      **
00021 ** following information to ensure the license requirements will   **
00022 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00023 **                                                                 **
00024 ** The development of this software was supported by the           **
00025 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00026 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00027 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00028 ** Excellence Initiative.                                          **
00029 **                                                                 **
00030 ********************************************************************/
00031 
00032 #pragma once
00033 
00034 #ifndef ICL_HAVE_OPENGL
00035   #ifdef WIN32
00036     #pragma WARNING("this header must not be included if ICL_HAVE_OPENGL is not defined")
00037   #else
00038     #warning "this header must not be included if ICL_HAVE_OPENGL is not defined"
00039   #endif
00040 #else
00041 
00042 #include <ICLUtils/CompatMacros.h>
00043 #include <ICLGeom/SceneObject.h>
00044 #include <ICLGeom/Camera.h>
00045 #include <ICLGeom/SceneLight.h>
00046 #include <ICLGeom/Primitive.h>
00047 #include <ICLGeom/PointCloudGrabber.h>
00048 #include <ICLCore/Img.h>
00049 #include <ICLUtils/FPSEstimator.h>
00050 
00051 #ifdef ICL_HAVE_QT
00052 #include <ICLQt/MouseHandler.h>
00053 #include <ICLQt/DrawWidget3D.h>
00054 #include <ICLGeom/SceneMouseHandler.h>
00055 #endif
00056 
00057 #include <ICLUtils/Lockable.h>
00058 #include <ICLUtils/Configurable.h>
00059 #include <ICLUtils/SmartArray.h>
00060 #include <map>
00061 #include <ICLGeom/ShaderUtil.h>
00062 
00063 namespace icl{
00065   namespace qt {class ICLDrawWidget;}
00068   namespace geom{
00069  
00071 
00123 
00130 
00138     class ICLGeom_API Scene : public utils::Lockable, public geom::PointCloudGrabber{
00139       public:
00140 
00142       friend class SceneObject;
00143     
00144       struct GLCallback;
00145     
00147       Scene();
00148     
00150       ~Scene();
00151     
00153       Scene(const Scene &scene);
00154     
00156       Scene &operator=(const Scene &scene);
00157 
00159 
00170       void addCamera(const Camera &cam, float visSize=1.0);
00171     
00173       void removeCamera(int index);
00174     
00176 
00185       Camera &getCamera(int camIndex = 0);
00186     
00188       const Camera &getCamera(int camIndex =0) const;
00189     
00191       inline int getCameraCount() const { return (int)m_cameras.size(); }
00192 
00194 
00197       std::vector<Camera*> getAllCameras(int firstIndex=0, int num=-1);
00198     
00200 
00204       void addObject(SceneObject *object, bool passOwnerShip=false);
00205     
00207 
00208       void removeObject(int idx);
00209     
00211 
00212       void removeObject(const SceneObject *obj);
00213 
00215 
00216       void removeObjects(int startIndex, int endIndex=-1);
00217     
00219       inline int getObjectCount() const { return m_objects.size(); }
00220     
00222 
00223       SceneObject *getObject(int index) throw (utils::ICLException);
00224 
00226 
00227       const SceneObject *getObject(int index) const throw (utils::ICLException);
00228     
00230 
00235       SceneObject *getObject(const std::vector<int> recursiveIndices) throw (utils::ICLException);
00236 
00238 
00243       SceneObject *getObject(const std::vector<int> recursiveIndices) const throw (utils::ICLException);
00244     
00246 
00248       std::vector<int> findPath(const SceneObject *o) const throw (utils::ICLException);
00249     
00251 
00252       void clear(bool camerasToo=false);
00253 
00254 #ifdef ICL_HAVE_QT
00255 
00256       qt::MouseHandler *getMouseHandler(int camIndex=0);
00257     
00259       void setMouseHandler(SceneMouseHandler* sceneMouseHandler, int camIndex=0);
00260     
00262 
00263       qt::ICLDrawWidget3D::GLCallback *getGLCallback(int camIndex);
00264 
00265       enum DepthBufferMode{
00266         RawDepth01,      
00267         DistToCamPlane,  
00268         DistToCamCenter  
00269       };
00270       const core::Img8u &render(int camIndx, const core::ImgBase *background = 0, core::Img32f *depthBuffer = 0,
00271         DepthBufferMode mode = DistToCamCenter);
00272     
00274 
00307 
00308       mutable icl::qt::GLFragmentShader* m_shaders[ShaderUtil::COUNT];
00309       
00311       struct RenderSettings;
00312       mutable RenderSettings *m_renderSettings;
00313       struct FBOData;
00314       mutable FBOData *m_fboData;
00315 #endif
00316 
00318 
00319       void setDrawCamerasEnabled(bool enabled);
00320     
00322       bool getDrawCamerasEnabled() const;
00323 
00325       void setDrawLightsEnabled(bool enabled, float lightSize=1);
00326     
00328       bool getDrawLightsEnabled() const;
00329     
00331       void setDrawCoordinateFrameEnabled(bool enabled, float size=120);
00332     
00334       bool getDrawCoordinateFrameEnabled() const;
00335 
00337       void setDrawObjectFramesEnabled(bool enabled, float size);
00338       
00340       bool getDrawObjectFramesEnabled() const;
00341       
00343 
00346       SceneLight &getLight(int index) throw (utils::ICLException);
00347 
00349 
00351       const SceneLight &getLight(int index) const throw (utils::ICLException);
00352 
00353     
00355 
00356       void setLightingEnabled(bool flag);
00357 
00359 
00361       void setGlobalAmbientLight(const GeomColor &color);
00362       
00364 
00366       inline Hit findObject(int camIndex, int xScreen, int yScreen){
00367         return findObject(getCamera(camIndex).getViewRay(utils::Point(xScreen,yScreen)));
00368       }
00369     
00371 
00373       Hit findObject(const ViewRay &v);
00374     
00375     
00377       std::vector<Hit> findObjects(const ViewRay &v);
00378     
00380       inline std::vector<Hit> findObjects(int camIndex, int xScreen, int ySceen){
00381         return findObjects(getCamera(camIndex).getViewRay(utils::Point(xScreen,ySceen)));
00382       }
00383     
00385 
00392       void setBounds(float minX, float maxX=0, float minY=0, float mayY=0, float minZ=0, float maxZ=0);
00393       
00395 
00397       void setBackgroundColor(const GeomColor &color);
00398 
00400       GeomColor getBackgroundColor() const;
00401       
00402       protected:
00403 
00405       void createDisplayList(SceneObject *o) const;
00406 
00408       void freeDisplayList(SceneObject *o) const;
00409       
00410       
00412 
00414       virtual void grab(PointCloudObjectBase &dst);
00415 
00416 #ifdef ICL_HAVE_QT
00417 
00418       void renderScene(int camIndex, qt::ICLDrawWidget3D *widget=0) const;
00419       
00421       void renderShadow(const unsigned int light, const unsigned int shadow, unsigned int size = 512) const;
00422       
00424       void renderSceneObjectRecursiveShadow(ShaderUtil* util, SceneObject *o) const;
00425 #endif
00426 
00428       void renderSceneObjectRecursive(SceneObject *o) const{
00429         ShaderUtil util;
00430         renderSceneObjectRecursive(&util, o);
00431       };
00432       
00434       void renderSceneObjectRecursive(ShaderUtil* util, SceneObject *o) const;
00435 
00437       void renderObjectFramesRecursive(SceneObject *o, SceneObject *cs) const;
00438 
00440 
00442       float getMaxSceneDim() const;
00443     
00445       void extendMaxSceneDimRecursive(float &minX, float &maxX, 
00446                                       float &minY, float &maxY, 
00447                                       float &minZ, float &maxZ,
00448                                       SceneObject *o) const;
00449 
00451       std::vector<Camera> m_cameras;
00452 
00454       std::vector<utils::SmartPtr<SceneObject> > m_objects;
00455 
00457       std::vector<utils::SmartPtr<SceneObject> > m_cameraObjects;
00458 
00459 #ifdef ICL_HAVE_QT
00460 
00461       std::vector<utils::SmartPtr<SceneMouseHandler> > m_mouseHandlers;
00462 
00464       std::vector<utils::SmartPtr<GLCallback> > m_glCallbacks;
00465 
00466       struct PBuffer;
00467 
00469       void freeAllPBuffers();
00470 
00472       void freePBuffer(const utils::Size &size);
00473 
00474       struct PBufferIndex : public utils::Size{
00475         pthread_t threadID;
00476         PBufferIndex(const utils::Size &size);
00477         bool operator<(const PBufferIndex &other) const;
00478       };
00479       mutable std::map<PBufferIndex, PBuffer*> m_pbuffers;
00480 #endif
00481 
00483       mutable utils::SmartPtr<SceneObject> m_coordinateFrameObject;
00484 
00486       mutable utils::SmartPtr<SceneObject> m_objectFrameObject;
00487       
00489       utils::SmartPtr<SceneLight> m_lights[8];
00490       
00492       utils::SmartPtr<SceneObject> m_shadowCameraObjects[8];
00493       
00495       mutable bool m_previousLightState[8][3];
00496     
00498       utils::SmartArray<utils::Range32f> m_bounds;
00499       
00501       math::FixedColVector<int,4> m_globalAmbientLight;
00502 
00504       GeomColor m_backgroundColor;
00505       
00506       utils::FPSEstimator m_fps;
00507 
00508       private:
00510       static void freeDisplayList(void *handle);
00511     };
00512   } // namespace geom
00513 
00514 }
00515 
00516 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines