V-ART
scene.h
Go to the documentation of this file.
1 
5 #ifndef VART_SCENE_H
6 #define VART_SCENE_H
7 
8 #ifdef WIN32
9  #define WINGDI
10  #include <windows.h>
11 #endif
12 #ifdef VART_OGL
13  #include <GL/gl.h>
14 #endif
15 
16 #include "vart/light.h"
17 #include "vart/camera.h"
18 #include "vart/color.h" // for background color
19 #include "vart/boundingbox.h"
20 #include <string> //STL include
21 #include <list> //STL include
22 #include <iostream> // for XmlPrintOn
23 
24 namespace VART {
25  class GraphicObj;
35  class Scene {
36  public:
37  Scene();
46  virtual ~Scene();
47 
48  std::list<const Light*> GetLights();
49 
52  std::list<Camera*> GetCameras();
53 
59  void AddLight(Light* newLight);
60 
65  void AddLight(const Light& newLight);
66 
73  void AddCamera(Camera* newCamera);
74 
81  void AddObject(SceneNode* newObjectPtr);
82 
87  void Unreference(const SceneNode* sceneNodePtr);
88 
90  const Light* GetLight(const std::string& lightName);
91 
93  const Camera* GetCamera(const std::string& cameraName);
94 
96  void SetCamera(const std::string& cameraName);
97 
98  std::list<SceneNode*> GetObjects();
99 
103  SceneNode* GetObject(const std::string& objectName) const;
104 
107  SceneNode* GetObjectRec(const std::string& objectName) const;
108 
112  const Color& GetBackgroundColor();
113 
118  void SetBackgroundColor(Color color);
119 
126  virtual bool DrawOGL(Camera* cameraPtr = NULL) const;
127 
133  bool DrawLightsOGL() const;
134 
136  Camera* GetCurrentCamera() const;
137 
140  const Camera* UseNextCamera();
141 
144  const Camera* UsePreviousCamera();
145 
147  void SetCamerasAspectRatio(const std::string& cameraDescription, float newAspectRatio);
148 
150  void SetAllCamerasAspectRatio(float newAspectRatio);
151 
153  void ChangeAllCamerasViewVolume(float horScale, float verScale);
154 
156  bool ComputeBoundingBox();
157 
160  const BoundingBox& GetBoundingBox() const { return bBox; }
161 
163  void SetBBoxVisibility(bool value) { bBox.visible = value; };
164 
166  void SetBoundingBox(double minX, double minY, double minZ,
167  double maxX, double maxY, double maxZ);
168 
170  void ToggleBBoxVisibility() { bBox.visible = !bBox.visible; }
171 
173  size_t GetNumLights() const { return lights.size(); }
174 
179  void MakeCameraViewAll();
180 
182  void SetDescription(const std::string& newDescr) { description = newDescr; }
183 
185  const std::string& GetDescription() { return description; }
186 
190  std::list<SceneNode*> GetAllSceneJoints();
191 
195  std::list<SceneNode*> GetAllSceneTypeObject(SceneNode::TypeID type);
196 
198  void Pick(int x, int y, std::list<GraphicObj*>* resultListPtr);
199 
201  void XmlPrintOn(std::ostream& os) const;
202 
203  protected:
204  // PROTECTED METHODS
205  // PROTECTED ATTRIBUTES
207  std::list<const Light*> lights;
208  // FixMe: Viewers should manipulate a local copy of the current camera, allowing
209  // pointers to be const.
210  std::list<Camera*> cameras;
211  std::list<SceneNode*> objects;
213  private:
214  // PRIVATE METHODS
218  GraphicObj* GetObject(unsigned int pickName);
219 
220  // PRIVATE ATTRIBUTES
221  // FixMe: Viewers should manipulate a local copy of the current camera, a different
222  // method to switch between cameras should be developed.
223  std::list<Camera*>::const_iterator currentCamera;
224  BoundingBox bBox;
225  std::string description;
226  }; // end class declaration
227 } // end namespace
228 #endif // VART_SCENE_H
SceneNode * GetObject(const std::string &objectName) const
Searches an object by its description.
Color background
Definition: scene.h:212
SceneNode * GetObjectRec(const std::string &objectName) const
Recursively searches an object by its description.
Definition: scene.cpp:151
Base class for objects that compose a scene graph.
Definition: scenenode.h:25
std::list< SceneNode * > GetObjects()
Definition: scene.cpp:49
void SetDescription(const std::string &newDescr)
Sets the scene description.
Definition: scene.h:182
void ToggleBBoxVisibility()
Toggles the bounding box visibility.
Definition: scene.h:170
Camera * GetCurrentCamera() const
Returns the current camera in the scene or NULL if no camera exists.
Definition: scene.cpp:221
bool visible
Indicates wether the bounding box is visible.
Definition: boundingbox.h:91
std::list< SceneNode * > GetAllSceneJoints()
Get all scenenodes of type 'joint' in the scene.
Definition: scene.cpp:358
const std::string & GetDescription()
Returns the scene description.
Definition: scene.h:185
Header file for V-ART class "Camera".
bool DrawLightsOGL() const
Set lights using OpenGL commands.
Definition: scene.cpp:206
void SetAllCamerasAspectRatio(float newAspectRatio)
Set the aspect ratio of all cameras.
Definition: scene.cpp:254
const Camera * GetCamera(const std::string &cameraName)
Finds an camera by its description.
Definition: scene.cpp:103
RGBA color representation.
Definition: color.h:24
Axis aligned bounding box.
Definition: boundingbox.h:23
std::list< SceneNode * > GetAllSceneTypeObject(SceneNode::TypeID type)
Get all scenenodes of type 'type' in the scene.
Definition: scene.cpp:370
const Camera * UsePreviousCamera()
Definition: scene.cpp:236
const Color & GetBackgroundColor()
Returns the background color.
Definition: scene.cpp:167
void AddCamera(Camera *newCamera)
Add a camera to the list of cameras.
Definition: scene.cpp:63
std::list< Camera * > cameras
Definition: scene.h:210
void ChangeAllCamerasViewVolume(float horScale, float verScale)
Changes the view volume of all cameras.
Definition: scene.cpp:261
Header file for V-ART class "Light".
virtual ~Scene()
Destructor.
Definition: scene.cpp:22
void SetBoundingBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
Sets the bounding box.
Definition: scene.cpp:328
const Camera * UseNextCamera()
Definition: scene.cpp:228
void AddLight(Light *newLight)
Adds a light to the list of lights.
Definition: scene.cpp:53
A set of objects, lights and cameras.
Definition: scene.h:35
std::list< const Light * > lights
Separate lights (not treated as common objects)
Definition: scene.h:207
const Light * GetLight(const std::string &lightName)
Finds a light by its name.
Definition: scene.cpp:93
Virtual camera.
Definition: camera.h:16
std::list< Camera * > GetCameras()
Returns a list of cameras.
Definition: scene.cpp:45
An scene node that is associated with a shape.
Definition: graphicobj.h:18
bool ComputeBoundingBox()
Computes the axis aligned bounding box of all objects.
Definition: scene.cpp:268
Header file for V-ART class "BoundingBox".
const BoundingBox & GetBoundingBox() const
Returns the scene bounding box. Attention: uses the ComputeBoundingBox method to refresh value of bou...
Definition: scene.h:160
Header file for V-ART class "Color".
size_t GetNumLights() const
Returns the number of light in the scene.
Definition: scene.h:173
void AddObject(SceneNode *newObjectPtr)
Add a object to the scene.
Definition: scene.cpp:69
void XmlPrintOn(std::ostream &os) const
Outputs XML representation of the scene.
Definition: scene.cpp:454
void Pick(int x, int y, std::list< GraphicObj * > *resultListPtr)
Picks objects from viewport coordinates.
Definition: scene.cpp:382
virtual bool DrawOGL(Camera *cameraPtr=NULL) const
Sets projection and draws graphics objects using OpenGL commands.
Definition: scene.cpp:176
void MakeCameraViewAll()
Fits the whole scene to drawing region.
Definition: scene.cpp:334
void SetCamerasAspectRatio(const std::string &cameraDescription, float newAspectRatio)
Set the aspect ratio of camera by its description.
Definition: scene.cpp:244
void SetCamera(const std::string &cameraName)
Sets the current camera by its description.
Definition: scene.cpp:113
void SetBackgroundColor(Color color)
Sets the background color.
Definition: scene.cpp:171
std::list< SceneNode * > objects
Definition: scene.h:211
void SetBBoxVisibility(bool value)
Sets the bounding box visibility.
Definition: scene.h:163
std::list< const Light * > GetLights()
Definition: scene.cpp:41
void Unreference(const SceneNode *sceneNodePtr)
Removes an object from scene graph.
Definition: scene.cpp:73
Represents a light source.
Definition: light.h:22