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 GAZEBO_RENDERING_SCENE_HH_
19 #define GAZEBO_RENDERING_SCENE_HH_
20 
21 #include <memory>
22 #include <string>
23 #include <vector>
24 
25 #include <boost/enable_shared_from_this.hpp>
26 #include <boost/shared_ptr.hpp>
27 
28 #include <sdf/sdf.hh>
29 
30 #include <ignition/math/Color.hh>
31 #include <ignition/math/Vector2.hh>
32 #include <ignition/math/Vector3.hh>
33 
34 #include "gazebo/common/Events.hh"
35 #include "gazebo/common/Color.hh"
36 #include "gazebo/gazebo_config.h"
37 #include "gazebo/msgs/msgs.hh"
41 #include "gazebo/util/system.hh"
42 
43 namespace SkyX
44 {
45  class SkyX;
46 }
47 
48 namespace Ogre
49 {
50  class SceneManager;
51  class Node;
52  class Entity;
53  class Mesh;
54  class Vector3;
55  class Quaternion;
56 }
57 
58 namespace gazebo
59 {
60  namespace rendering
61  {
62  class Visual;
63  class Grid;
64  class Heightmap;
65  class ScenePrivate;
66 
69 
101  class GZ_RENDERING_VISIBLE Scene :
102  public boost::enable_shared_from_this<Scene>
103  {
104  public: enum SkyXMode {
105  GZ_SKYX_ALL = 0x0FFFFFFF,
106  GZ_SKYX_CLOUDS = 0x0000001,
107  GZ_SKYX_MOON = 0x0000002,
108  GZ_SKYX_NONE = 0
109  };
110 
112  private: Scene();
113 
119  public: Scene(const std::string &_name,
120  const bool _enableVisualizations = false,
121  const bool _isServer = false);
122 
124  public: virtual ~Scene();
125 
128  public: void Load(sdf::ElementPtr _scene);
129 
131  public: void Load();
132 
134  public: void Init();
135 
137  public: void PreRender();
138 
141  public: Ogre::SceneManager *OgreSceneManager() const;
142 
145  public: std::string Name() const;
146 
150  public: void SetAmbientColor(const common::Color &_color)
151  GAZEBO_DEPRECATED(9.0);
152 
155  public: void SetAmbientColor(const ignition::math::Color &_color);
156 
159  public: ignition::math::Color AmbientColor() const;
160 
164  public: void SetBackgroundColor(const common::Color &_color)
165  GAZEBO_DEPRECATED(9.0);
166 
169  public: void SetBackgroundColor(const ignition::math::Color &_color);
170 
173  public: ignition::math::Color BackgroundColor() const;
174 
181  public: void CreateGrid(const uint32_t _cellCount,
182  const float _cellLength, const float _lineWidth,
183  const common::Color &_color) GAZEBO_DEPRECATED(9.0);
184 
189  public: void CreateGrid(const uint32_t _cellCount,
190  const float _cellLength, const ignition::math::Color &_color);
191 
195  public: Grid *GetGrid(uint32_t _index) const;
196 
199  public: uint32_t GridCount() const;
200 
206  public: CameraPtr CreateCamera(const std::string &_name,
207  const bool _autoRender = true);
208 
214  public: WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name,
215  const bool _autoRender = true);
216 
217 #ifdef HAVE_OCULUS
218  public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
222 
225  public: uint32_t OculusCameraCount() const;
226 #endif
227 
233  public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
234  const bool _autoRender = true);
235 
241  public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
242  const bool _autoRender = true);
243 
246  public: uint32_t CameraCount() const;
247 
252  public: CameraPtr GetCamera(const uint32_t _index) const;
253 
257  public: CameraPtr GetCamera(const std::string &_name) const;
258 
266  public: UserCameraPtr CreateUserCamera(const std::string &_name,
267  const bool _stereoEnabled = false);
268 
271  public: uint32_t UserCameraCount() const;
272 
278  public: UserCameraPtr GetUserCamera(const uint32_t _index) const;
279 
282  public: void RemoveCamera(const std::string &_name);
283 
286  public: uint32_t LightCount() const;
287 
292  public: LightPtr GetLight(const std::string &_name) const
293  GAZEBO_DEPRECATED(9.1);
294 
300  public: LightPtr GetLight(const uint32_t _index) const
301  GAZEBO_DEPRECATED(9.1);
302 
306  public: LightPtr LightByName(const std::string &_name) const;
307 
312  public: LightPtr LightByIndex(const uint32_t _index) const;
313 
317  public: LightPtr LightById(const uint32_t _id) const;
318 
322  public: VisualPtr GetVisual(const std::string &_name) const;
323 
327  public: VisualPtr GetVisual(const uint32_t _id) const;
328 
332  public: void SelectVisual(const std::string &_name,
333  const std::string &_mode);
334 
341  public: VisualPtr VisualAt(CameraPtr _camera,
342  const ignition::math::Vector2i &_mousePos,
343  std::string &_mod);
344 
347  public: void SnapVisualToNearestBelow(const std::string &_visualName);
348 
354  public: VisualPtr VisualAt(CameraPtr _camera,
355  const ignition::math::Vector2i &_mousePos);
356 
362  public: VisualPtr ModelVisualAt(CameraPtr _camera,
363  const ignition::math::Vector2i &_mousePos);
364 
368  public: VisualPtr VisualBelow(const std::string &_visualName);
369 
374  public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
375  std::vector<VisualPtr> &_visuals);
376 
381  public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
382 
388  public: bool FirstContact(CameraPtr _camera,
389  const ignition::math::Vector2i &_mousePos,
390  ignition::math::Vector3d &_position);
391 
393  public: void PrintSceneGraph();
394 
399  public: void SetVisible(const std::string &_name, const bool _visible);
400 
405  public: void DrawLine(const ignition::math::Vector3d &_start,
406  const ignition::math::Vector3d &_end,
407  const std::string &_name);
408 
417  public: void SetFog(const std::string &_type,
418  const common::Color &_color,
419  const double _density, const double _start,
420  const double _end) GAZEBO_DEPRECATED(9.0);
421 
429  public: void SetFog(const std::string &_type,
430  const ignition::math::Color &_color,
431  const double _density, const double _start,
432  const double _end);
433 
436  public: uint32_t Id() const;
437 
440  public: std::string IdString() const;
441 
444  public: void SetShadowsEnabled(const bool _value);
445 
448  public: bool ShadowsEnabled() const;
449 
454  public: bool SetShadowTextureSize(const unsigned int _size);
455 
458  public: unsigned int ShadowTextureSize() const;
459 
462  public: void AddVisual(VisualPtr _vis);
463 
466  public: void RemoveVisual(VisualPtr _vis);
467 
470  public: void RemoveVisual(const uint32_t _id);
471 
477  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
478 
481  public: void AddLight(LightPtr _light);
482 
485  public: void RemoveLight(LightPtr _light);
486 
489  public: void SetGrid(const bool _enabled);
490 
493  public: void ShowOrigin(const bool _show);
494 
497  public: VisualPtr WorldVisual() const;
498 
502  public: std::string StripSceneName(const std::string &_name) const;
503 
506  public: Heightmap *GetHeightmap() const;
507 
511  public: void SetHeightmapLOD(const unsigned int _value);
512 
516  public: unsigned int HeightmapLOD() const;
517 
521  public: void SetHeightmapSkirtLength(const double _value);
522 
526  public: double HeightmapSkirtLength() const;
527 
529  public: void Clear();
530 
534  public: VisualPtr SelectedVisual() const;
535 
538  public: void SetWireframe(const bool _show);
539 
542  public: bool Wireframe() const;
543 
546  public: void SetTransparent(const bool _show);
547 
550  public: void ShowCOMs(const bool _show);
551 
554  public: void ShowInertias(const bool _show);
555 
558  public: void ShowLinkFrames(const bool _show);
559 
562  public: void ShowSkeleton(const bool _show);
563 
566  public: void ShowJoints(const bool _show);
567 
570  public: void ShowCollisions(const bool _show);
571 
574  public: void ShowContacts(const bool _show);
575 
578  public: void ShowClouds(const bool _show);
579 
582  public: bool ShowClouds() const;
583 
588  public: void SetSkyXMode(const unsigned int _mode);
589 
592  public: SkyX::SkyX *GetSkyX() const;
593 
596  public: bool Initialized() const;
597 
603  public: common::Time SimTime() const;
604 
607  public: uint32_t VisualCount() const;
608 
610  public: void RemoveProjectors();
611 
616  public: void ToggleLayer(const int32_t _layer);
617 
623  public: bool LayerState(const int32_t _layer) const;
624 
629  public: bool HasLayer(const int32_t _layer) const;
630 
635  public: void EnableVisualizations(const bool _enable);
636 
640  public: bool EnableVisualizations() const;
641 
643  private: void SetSky();
644 
646  private: void InitDeferredShading();
647 
654  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
655  const ignition::math::Vector2i &_mousePos,
656  const bool _ignoreSelectionObj);
657 
667  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
668  private: void MeshInformation(const Ogre::Mesh *_mesh,
669  size_t &_vertexCount,
670  Ogre::Vector3* &_vertices,
671  size_t &_indexCount,
672  uint64_t* &_indices,
673  const ignition::math::Vector3d &_position,
674  const ignition::math::Quaterniond &_orient,
675  const ignition::math::Vector3d &_scale);
676 
680  private: void PrintSceneGraphHelper(const std::string &_prefix,
681  Ogre::Node *_node);
682 
686  private: void OnScene(ConstScenePtr &_msg);
687 
690  private: void OnResponse(ConstResponsePtr &_msg);
691 
694  private: void OnRequest(ConstRequestPtr &_msg);
695 
698  private: void OnJointMsg(ConstJointPtr &_msg);
699 
702  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
703 
706  private: bool ProcessJointMsg(ConstJointPtr &_msg);
707 
710  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
711 
714  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
715 
718  private: bool ProcessModelMsg(const msgs::Model &_msg);
719 
722  private: void OnSensorMsg(ConstSensorPtr &_msg);
723 
726  private: void OnVisualMsg(ConstVisualPtr &_msg);
727 
732  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
734 
737  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
738 
741  private: void OnLightModifyMsg(ConstLightPtr &_msg);
742 
745  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
746 
749  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
750 
753  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
754 
757  private: void OnSkyMsg(ConstSkyPtr &_msg);
758 
761  private: void OnModelMsg(ConstModelPtr &_msg);
762 
765  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
766 
769  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
770 
773  private: void OnRoadMsg(ConstRoadPtr &_msg);
774 
778  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
779 
783  private: void CreateCOMVisual(sdf::ElementPtr _elem,
784  VisualPtr _linkVisual);
785 
789  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
790  VisualPtr _linkVisual);
791 
795  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
796  VisualPtr _linkVisual);
797 
801  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
802  VisualPtr _linkVisual);
803 
807  private: void RemoveVisualizations(VisualPtr _vis);
808 
811  private: std::unique_ptr<ScenePrivate> dataPtr;
812  };
814  }
815 }
816 #endif
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:94
Forward declarations for the common classes.
Definition: Animation.hh:26
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:106
Entity visual.
Definition: Visual.hh:68
SkyXMode
Definition: Scene.hh:104
Forward declarations for transport.
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:58
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:98
VisualType
Type of visual.
Definition: Visual.hh:65
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
Representation of an entire scene graph.
Definition: Scene.hh:101
Definition: JointMaker.hh:39
Defines a color.
Definition: Color.hh:36
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< WideAngleCamera > WideAngleCameraPtr
Definition: RenderTypes.hh:102
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:86
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:90
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44
Definition: Scene.hh:43