Image Component Library (ICL)
Scene.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/Scene.h **
10 ** Module : ICLGeom **
11 ** Authors: Christof Elbrechter, Erik Weitnauer, Daniel Dornbusch, **
12 ** Matthias Esau **
13 ** **
14 ** **
15 ** GNU LESSER GENERAL PUBLIC LICENSE **
16 ** This file may be used under the terms of the GNU Lesser General **
17 ** Public License version 3.0 as published by the **
18 ** **
19 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
20 ** included in the packaging of this file. Please review the **
21 ** following information to ensure the license requirements will **
22 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
23 ** **
24 ** The development of this software was supported by the **
25 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
26 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
27 ** Forschungsgemeinschaft (DFG) in the context of the German **
28 ** Excellence Initiative. **
29 ** **
30 ********************************************************************/
31 
32 #pragma once
33 
34 #ifndef ICL_HAVE_OPENGL
35  #ifdef WIN32
36  #pragma WARNING("this header must not be included if ICL_HAVE_OPENGL is not defined")
37  #else
38  #warning "this header must not be included if ICL_HAVE_OPENGL is not defined"
39  #endif
40 #else
41 
42 #include <ICLUtils/CompatMacros.h>
43 #include <ICLGeom/SceneObject.h>
44 #include <ICLGeom/Camera.h>
45 #include <ICLGeom/SceneLight.h>
46 #include <ICLGeom/Primitive.h>
48 #include <ICLCore/Img.h>
49 #include <ICLUtils/FPSEstimator.h>
50 
51 #ifdef ICL_HAVE_QT
52 #include <ICLQt/MouseHandler.h>
53 #include <ICLQt/DrawWidget3D.h>
55 #endif
56 
57 #include <ICLUtils/Lockable.h>
58 #include <ICLUtils/Configurable.h>
59 #include <ICLUtils/SmartArray.h>
60 #include <map>
61 #include <ICLGeom/ShaderUtil.h>
62 
63 namespace icl{
65  namespace qt {class ICLDrawWidget;}
68  namespace geom{
69 
71 
123 
130 
139 
141  public:
142 
144  friend class SceneObject;
145 
146  struct GLCallback;
147 
149  Scene();
150 
152  ~Scene();
153 
155  Scene(const Scene &scene);
156 
158  Scene &operator=(const Scene &scene);
159 
161 
172  void addCamera(const Camera &cam, float visSize=1.0);
173 
175  void removeCamera(int index);
176 
178 
187  Camera &getCamera(int camIndex = 0);
188 
190  const Camera &getCamera(int camIndex =0) const;
191 
193  inline int getCameraCount() const { return (int)m_cameras.size(); }
194 
196 
199  std::vector<Camera*> getAllCameras(int firstIndex=0, int num=-1);
200 
202 
206  void addObject(SceneObject *object, bool passOwnerShip=false);
207 
209 
210  void removeObject(int idx);
211 
213 
214  void removeObject(const SceneObject *obj);
215 
217 
218  void removeObjects(int startIndex, int endIndex=-1);
219 
221  inline int getObjectCount() const { return m_objects.size(); }
222 
224 
225  SceneObject *getObject(int index) ;
226 
228 
229  const SceneObject *getObject(int index) const ;
230 
232 
237  SceneObject *getObject(const std::vector<int> recursiveIndices) ;
238 
240 
245  SceneObject *getObject(const std::vector<int> recursiveIndices) const ;
246 
248 
250  std::vector<int> findPath(const SceneObject *o) const ;
251 
253 
254  void clear(bool camerasToo=false);
255 
256 #ifdef ICL_HAVE_QT
257  qt::MouseHandler *getMouseHandler(int camIndex=0);
259 
261  void setMouseHandler(SceneMouseHandler* sceneMouseHandler, int camIndex=0);
262 
264 
265  qt::ICLDrawWidget3D::GLCallback *getGLCallback(int camIndex);
266 
270  DistToCamCenter
271  };
272  const core::Img8u &render(int camIndx, const core::ImgBase *background = 0, core::Img32f *depthBuffer = 0,
273  DepthBufferMode mode = DistToCamCenter, bool fastRendering=false);
274 
276 
309  mutable icl::qt::GLFragmentShader* m_shaders[ShaderUtil::COUNT];
311 
313  struct RenderSettings;
314  mutable RenderSettings *m_renderSettings;
315  struct FBOData;
316  mutable FBOData *m_fboData;
317 #endif
318 
320 
321  void setDrawCamerasEnabled(bool enabled);
322 
324  bool getDrawCamerasEnabled() const;
325 
327  void setDrawLightsEnabled(bool enabled, float lightSize=1);
328 
330  bool getDrawLightsEnabled() const;
331 
333  void setDrawCoordinateFrameEnabled(bool enabled, float size=120);
334 
336  bool getDrawCoordinateFrameEnabled() const;
337 
339  void setDrawObjectFramesEnabled(bool enabled, float size);
340 
342  bool getDrawObjectFramesEnabled() const;
343 
345  void setCursor(Vec newPosition);
346 
348  Vec getCursor();
349 
351  void activateCursor(bool activate = true);
352 
354 
357  SceneLight &getLight(int index) ;
358 
360 
362  const SceneLight &getLight(int index) const ;
363 
364 
366 
367  void setLightingEnabled(bool flag);
368 
370 
372  void setGlobalAmbientLight(const GeomColor &color);
373 
375 
377  inline Hit findObject(int camIndex, int xScreen, int yScreen){
378  return findObject(getCamera(camIndex).getViewRay(utils::Point(xScreen,yScreen)));
379  }
380 
382 
384  Hit findObject(const ViewRay &v);
385 
386 
388  std::vector<Hit> findObjects(const ViewRay &v);
389 
391  inline std::vector<Hit> findObjects(int camIndex, int xScreen, int ySceen){
392  return findObjects(getCamera(camIndex).getViewRay(utils::Point(xScreen,ySceen)));
393  }
394 
396 
403  void setBounds(float minX, float maxX=0, float minY=0, float mayY=0, float minZ=0, float maxZ=0);
404 
406 
408  void setBackgroundColor(const GeomColor &color);
409 
411  GeomColor getBackgroundColor() const;
412 
413  protected:
414 
416  void createDisplayList(SceneObject *o) const;
417 
419  void freeDisplayList(SceneObject *o) const;
420 
421 
422  public:
424 
429  virtual void grab(PointCloudObjectBase &dst);
430 
431  protected:
432 #ifdef ICL_HAVE_QT
433  void renderScene(int camIndex, qt::ICLDrawWidget3D *widget=0) const;
435 
437  void renderShadow(const unsigned int light, const unsigned int shadow, unsigned int size,
438  int camID) const;
439 
441  void renderSceneObjectRecursiveShadow(ShaderUtil* util, SceneObject *o, int camID) const;
442 #endif
443 
445  void renderSceneObjectRecursive(SceneObject *o, int camID) const{
446  ShaderUtil util;
447  renderSceneObjectRecursive(&util, o, camID);
448  };
449 
451  void renderSceneObjectRecursive(ShaderUtil* util, SceneObject *o, int camID) const;
452 
454  void renderObjectFramesRecursive(SceneObject *o, SceneObject *cs, int camID) const;
455 
457 
459  float getMaxSceneDim() const;
460 
462  void extendMaxSceneDimRecursive(float &minX, float &maxX,
463  float &minY, float &maxY,
464  float &minZ, float &maxZ,
465  SceneObject *o) const;
466 
468  std::vector<Camera> m_cameras;
469 
471  std::vector<utils::SmartPtr<SceneObject> > m_objects;
472 
474  std::vector<utils::SmartPtr<SceneObject> > m_cameraObjects;
475 
476 #ifdef ICL_HAVE_QT
477  std::vector<utils::SmartPtr<SceneMouseHandler> > m_mouseHandlers;
479 
481  std::vector<utils::SmartPtr<GLCallback> > m_glCallbacks;
482 
483  struct PBuffer;
484 
486  void freeAllPBuffers();
487 
489  void freePBuffer(const utils::Size &size);
490 
491  struct PBufferIndex : public utils::Size{
492  pthread_t threadID;
493  PBufferIndex(const utils::Size &size);
494  bool operator<(const PBufferIndex &other) const;
495  };
496  mutable std::map<PBufferIndex, PBuffer*> m_pbuffers;
497 #endif
498 
501 
504 
507 
509  utils::SmartPtr<SceneObject> m_shadowCameraObjects[8];
510 
512  mutable bool m_previousLightState[8][4];
513 
516 
519 
522 
524 
525  private:
527  static void freeDisplayList(void *handle);
528  };
529  } // namespace geom
530 
531 }
532 
533 #endif
Simple wrapper class for OpenGL 2.0 Fragment Shader Programs.
Definition: GLFragmentShader.h:45
Class providing a mouse handler for class scene.
Definition: SceneMouseHandler.h:136
FBOData * m_fboData
Definition: Scene.h:315
undocument this line if you encounter any issues!
Definition: Any.h:37
Definition: ShaderUtil.h:56
Base class for point cloud data types.
Definition: PointCloudObjectBase.h:98
utils::FPSEstimator m_fps
Definition: Scene.h:523
#define ICLGeom_API
Definition: CompatMacros.h:179
utils::SmartPtr< SceneObject > m_coordinateFrameObject
internally used scene object
Definition: Scene.h:500
utils::SmartPtr< SceneObject > m_objectFrameObject
also internally used object frame object
Definition: Scene.h:503
RenderSettings * m_renderSettings
Definition: Scene.h:313
Hit findObject(int camIndex, int xScreen, int yScreen)
picks the closest contained scene-object clicked at given ScreenPosition
Definition: Scene.h:377
std::vector< utils::SmartPtr< GLCallback > > m_glCallbacks
internally used list of callbacks
Definition: Scene.h:481
int getObjectCount() const
returns the number of top-level objects
Definition: Scene.h:221
std::vector< Hit > findObjects(int camIndex, int xScreen, int ySceen)
retunrs all objects on that are intersected by the defined cameras viewray through given x and y
Definition: Scene.h:391
std::vector< utils::SmartPtr< SceneObject > > m_cameraObjects
internal list of top-level camera objects used for camera visualization
Definition: Scene.h:474
std::map< PBufferIndex, PBuffer * > m_pbuffers
Definition: Scene.h:496
Camera class.
Definition: Camera.h:132
internally used callback class type
Definition: DrawWidget3D.h:55
core::depth buffer values define distance to the camera's z=0 plane
Definition: Scene.h:269
void renderSceneObjectRecursive(SceneObject *o, int camID) const
internally used rendering method for recursive rendering of the scene graph
Definition: Scene.h:445
raw core::depth buffer in range [0,1]
Definition: Scene.h:268
GeomColor m_backgroundColor
current scene background color
Definition: Scene.h:521
utility structure that defines a hit between a ViewRay and SceneObjects
Definition: Hit.h:45
Definition: Scene.h:491
Size class of the ICL.
Definition: Size.h:61
Definition: ShaderUtil.h:47
pthread_t threadID
Definition: Scene.h:492
Scene Implementation that is used to handle a list of objects and cameras.
Definition: Scene.h:138
DepthBufferMode
Definition: Scene.h:267
MouseEvent Handler.
Definition: MouseHandler.h:92
This is a view-ray's line equation in parameter form.
Definition: ViewRay.h:49
Extended ICLDrawWidget, able to draw 2D and 3D primitives using OpenGL.
Definition: DrawWidget3D.h:51
int getCameraCount() const
returns the count of contained cameras
Definition: Scene.h:193
Point class of the ICL used e.g. for the Images ROI offset.
Definition: Point.h:58
ICLQt_API void color(float r, float g=-1, float b=-1, float alpha=255)
sets the current color to given r,g,b,alpha value
ICLQt_API core::Img< T > grab(const std::string &dev, const std::string &devSpec, const utils::Size &size=utils::Size::null, core::format fmt=core::formatRGB, bool releaseGrabber=false)
grabs a new image from given device (affinity for floats)
math::FixedColVector< int, 4 > m_globalAmbientLight
global ambient light
Definition: Scene.h:518
std::vector< Camera > m_cameras
internal list of cameras
Definition: Scene.h:468
Interface for objects, that can be locked using an internal mutex.
Definition: Lockable.h:41
Wrapper class for OpenGL lights.
Definition: SceneLight.h:72
SceneObject * m_cursor
Definition: Scene.h:140
Generic interface for PointCloud sources.
Definition: PointCloudGrabber.h:45
utils::SmartArray< utils::Range32f > m_bounds
optionally given bounds of the scene
Definition: Scene.h:515
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
Specialization of the SmartPtrBase class for Pointers.
Definition: SmartPtr.h:75
The SceneObject class defines visible objects in scenes or scene graph nodes.
Definition: SceneObject.h:140
Utility clas for online FPS estimation.
Definition: FPSEstimator.h:41
std::vector< utils::SmartPtr< SceneObject > > m_objects
internal list of top-level objects
Definition: Scene.h:471