Scene.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Open Source Robotics Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16 */
17 
18 #ifndef _SCENE_HH_
19 #define _SCENE_HH_
20 
21 #include <string>
22 #include <vector>
23 #include <boost/enable_shared_from_this.hpp>
24 #include <boost/shared_ptr.hpp>
25 
26 #include <sdf/sdf.hh>
27 
28 #include "gazebo/common/Events.hh"
29 #include "gazebo/common/Color.hh"
30 #include "gazebo/gazebo_config.h"
31 #include "gazebo/math/Vector2i.hh"
32 #include "gazebo/msgs/msgs.hh"
35 #include "gazebo/util/system.hh"
36 
37 namespace SkyX
38 {
39  class SkyX;
40 }
41 
42 namespace Ogre
43 {
44  class SceneManager;
45  class Node;
46  class Entity;
47  class Mesh;
48  class Vector3;
49  class Quaternion;
50 }
51 
52 namespace gazebo
53 {
54  namespace rendering
55  {
56  class Visual;
57  class Grid;
58  class Heightmap;
59  class ScenePrivate;
60 
63 
68  class GAZEBO_VISIBLE Scene : public boost::enable_shared_from_this<Scene>
69  {
70  public: enum SkyXMode {
71  GZ_SKYX_ALL = 0x0FFFFFFF,
72  GZ_SKYX_CLOUDS = 0x0000001,
73  GZ_SKYX_MOON = 0x0000002,
74  GZ_SKYX_NONE = 0
75  };
76 
78  private: Scene() {}
79 
85  public: Scene(const std::string &_name,
86  bool _enableVisualizations = false,
87  bool _isServer = false);
88 
90  public: virtual ~Scene();
91 
94  public: void Load(sdf::ElementPtr _scene);
95 
97  public: void Load();
98 
100  public: void Init();
101 
103  public: void PreRender();
104 
107  public: Ogre::SceneManager *GetManager() const;
108 
111  public: std::string GetName() const;
112 
115  public: void SetAmbientColor(const common::Color &_color);
116 
119  public: common::Color GetAmbientColor() const;
120 
123  public: void SetBackgroundColor(const common::Color &_color);
124 
127  public: common::Color GetBackgroundColor() const;
128 
134  public: void CreateGrid(uint32_t _cellCount, float _cellLength,
135  float _lineWidth, const common::Color &_color);
136 
140  public: Grid *GetGrid(uint32_t _index) const;
141 
144  public: uint32_t GetGridCount() const;
145 
151  public: CameraPtr CreateCamera(const std::string &_name,
152  bool _autoRender = true);
153 
154 #ifdef HAVE_OCULUS
155  public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
159 
162  public: uint32_t GetOculusCameraCount() const;
163 #endif
164 
170  public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
171  bool _autoRender = true);
172 
178  public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
179  bool _autoRender = true);
180 
183  public: uint32_t GetCameraCount() const;
184 
189  public: CameraPtr GetCamera(uint32_t _index) const;
190 
194  public: CameraPtr GetCamera(const std::string &_name) const;
195 
201  public: UserCameraPtr CreateUserCamera(const std::string &_name);
202 
205  public: uint32_t GetUserCameraCount() const;
206 
212  public: UserCameraPtr GetUserCamera(uint32_t _index) const;
213 
216  public: void RemoveCamera(const std::string &_name);
217 
221  public: LightPtr GetLight(const std::string &_name) const;
222 
225  public: uint32_t GetLightCount() const;
226 
231  public: LightPtr GetLight(uint32_t _index) const;
232 
236  public: VisualPtr GetVisual(const std::string &_name) const;
237 
241  public: VisualPtr GetVisual(uint32_t _id) const;
242 
246  public: void SelectVisual(const std::string &_name,
247  const std::string &_mode);
248 
255  public: VisualPtr GetVisualAt(CameraPtr _camera,
256  const math::Vector2i &_mousePos,
257  std::string &_mod);
258 
261  public: void SnapVisualToNearestBelow(const std::string &_visualName);
262 
268  public: VisualPtr GetVisualAt(CameraPtr _camera,
269  const math::Vector2i &_mousePos);
270 
276  public: VisualPtr GetModelVisualAt(CameraPtr _camera,
277  const math::Vector2i &_mousePos);
278 
279 
283  public: VisualPtr GetVisualBelow(const std::string &_visualName);
284 
289  public: void GetVisualsBelowPoint(const math::Vector3 &_pt,
290  std::vector<VisualPtr> &_visuals);
291 
292 
297  public: double GetHeightBelowPoint(const math::Vector3 &_pt);
298 
304  public: bool GetFirstContact(CameraPtr _camera,
305  const math::Vector2i &_mousePos,
306  math::Vector3 &_position);
307 
309  public: void PrintSceneGraph();
310 
315  public: void SetVisible(const std::string &_name, bool _visible);
316 
321  public: void DrawLine(const math::Vector3 &_start,
322  const math::Vector3 &_end,
323  const std::string &_name);
324 
332  public: void SetFog(const std::string &_type,
333  const common::Color &_color,
334  double _density, double _start, double _end);
335 
338  public: uint32_t GetId() const;
339 
342  public: std::string GetIdString() const;
343 
346  public: void SetShadowsEnabled(bool _value);
347 
350  public: bool GetShadowsEnabled() const;
351 
354  public: void AddVisual(VisualPtr _vis);
355 
358  public: void RemoveVisual(VisualPtr _vis);
359 
362  public: void AddLight(LightPtr _light);
363 
366  public: void RemoveLight(LightPtr _light);
367 
370  public: void SetGrid(bool _enabled);
371 
374  public: VisualPtr GetWorldVisual() const;
375 
379  public: std::string StripSceneName(const std::string &_name) const;
380 
383  public: Heightmap *GetHeightmap() const;
384 
386  public: void Clear();
387 
391  public: VisualPtr GetSelectedVisual() const;
392 
395  public: void SetWireframe(bool _show);
396 
399  public: void SetTransparent(bool _show);
400 
403  public: void ShowCOMs(bool _show);
404 
407  public: void ShowJoints(bool _show);
408 
411  public: void ShowCollisions(bool _show);
412 
415  public: void ShowContacts(bool _show);
416 
419  public: void ShowClouds(bool _show);
420 
423  public: bool GetShowClouds() const;
424 
425 
430  public: void SetSkyXMode(unsigned int _mode);
431 
434  public: SkyX::SkyX *GetSkyX() const;
435 
437  public: bool GetInitialized() const;
438 
444  public: common::Time GetSimTime() const;
445 
448  public: uint32_t GetVisualCount() const;
449 
451  public: void RemoveProjectors();
452 
454  private: void SetSky();
455 
457  private: void InitDeferredShading();
458 
465  private: Ogre::Entity *GetOgreEntityAt(CameraPtr _camera,
466  const math::Vector2i &_mousePos,
467  bool _ignorSelectionObj);
468 
478  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
479  private: void GetMeshInformation(const Ogre::Mesh *_mesh,
480  size_t &_vertexCount,
481  Ogre::Vector3* &_vertices,
482  size_t &_indexCount,
483  uint64_t* &_indices,
484  const Ogre::Vector3 &_position,
485  const Ogre::Quaternion &_orient,
486  const Ogre::Vector3 &_scale);
487 
491  private: void PrintSceneGraphHelper(const std::string &_prefix,
492  Ogre::Node *_node);
493 
497  private: void OnScene(ConstScenePtr &_msg);
498 
501  private: void OnResponse(ConstResponsePtr &_msg);
502 
505  private: void OnRequest(ConstRequestPtr &_msg);
506 
509  private: void OnJointMsg(ConstJointPtr &_msg);
510 
513  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
514 
517  private: bool ProcessJointMsg(ConstJointPtr &_msg);
518 
521  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
522 
525  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
526 
529  private: bool ProcessModelMsg(const msgs::Model &_msg);
530 
533  private: void OnSensorMsg(ConstSensorPtr &_msg);
534 
537  private: void OnVisualMsg(ConstVisualPtr &_msg);
538 
541  private: bool ProcessVisualMsg(ConstVisualPtr &_msg);
542 
545  private: void OnLightMsg(ConstLightPtr &_msg);
546 
549  private: bool ProcessLightMsg(ConstLightPtr &_msg);
550 
553  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
554 
557  private: void OnSelectionMsg(ConstSelectionPtr &_msg);
558 
561  private: void OnSkyMsg(ConstSkyPtr &_msg);
562 
565  private: void OnModelMsg(ConstModelPtr &_msg);
566 
569  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
570 
573  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
574 
578  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
579 
583  private: void CreateCOMVisual(sdf::ElementPtr _elem,
584  VisualPtr _linkVisual);
585 
588  private: ScenePrivate *dataPtr;
589  };
591  }
592 }
593 #endif
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:90
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:78
Generic integer x, y vector.
Definition: Vector2i.hh:39
Forward declarations for transport.
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:82
SkyXMode
Definition: Scene.hh:70
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:94
Representation of an entire scene graph.
Definition: Scene.hh:68
SkyX(Ogre::SceneManager *sm, Controller *c)
Contructor.
Defines a color.
Definition: Color.hh:39
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:86
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:43
boost::shared_ptr< OculusCamera > OculusCameraPtr
Definition: RenderTypes.hh:167