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 <OGRE/OgrePrerequisites.h>
29 
30 #include <sdf/sdf.hh>
31 
32 #include <ignition/math/Color.hh>
33 #include <ignition/math/Vector2.hh>
34 #include <ignition/math/Vector3.hh>
35 
36 #include "gazebo/common/Events.hh"
37 #include "gazebo/gazebo_config.h"
38 #include "gazebo/msgs/msgs.hh"
42 #include "gazebo/util/system.hh"
43 
44 namespace SkyX
45 {
46  class SkyX;
47 }
48 
49 namespace gazebo
50 {
51  namespace rendering
52  {
53  class Visual;
54  class Grid;
55  class Heightmap;
56  class ScenePrivate;
57 
60 
92  class GZ_RENDERING_VISIBLE Scene :
93  public boost::enable_shared_from_this<Scene>
94  {
95  public: enum SkyXMode {
96  GZ_SKYX_ALL = 0x0FFFFFFF,
97  GZ_SKYX_CLOUDS = 0x0000001,
98  GZ_SKYX_MOON = 0x0000002,
99  GZ_SKYX_NONE = 0
100  };
101 
103  private: Scene();
104 
110  public: Scene(const std::string &_name,
111  const bool _enableVisualizations = false,
112  const bool _isServer = false);
113 
115  public: virtual ~Scene();
116 
119  public: void Load(sdf::ElementPtr _scene);
120 
122  public: void Load();
123 
125  public: void Init();
126 
128  public: void PreRender();
129 
132  public: Ogre::SceneManager *OgreSceneManager() const;
133 
136  public: std::string Name() const;
137 
140  public: void SetAmbientColor(const ignition::math::Color &_color);
141 
144  public: ignition::math::Color AmbientColor() const;
145 
148  public: void SetBackgroundColor(const ignition::math::Color &_color);
149 
152  public: ignition::math::Color BackgroundColor() const;
153 
158  public: void CreateGrid(const uint32_t _cellCount,
159  const float _cellLength, const ignition::math::Color &_color);
160 
164  public: Grid *GetGrid(uint32_t _index) const;
165 
168  public: uint32_t GridCount() const;
169 
175  public: CameraPtr CreateCamera(const std::string &_name,
176  const bool _autoRender = true);
177 
183  public: WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name,
184  const bool _autoRender = true);
185 
186 #ifdef HAVE_OCULUS
187  public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
191 
194  public: uint32_t OculusCameraCount() const;
195 #endif
196 
202  public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
203  const bool _autoRender = true);
204 
210  public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
211  const bool _autoRender = true);
212 
215  public: uint32_t CameraCount() const;
216 
221  public: CameraPtr GetCamera(const uint32_t _index) const;
222 
226  public: CameraPtr GetCamera(const std::string &_name) const;
227 
235  public: UserCameraPtr CreateUserCamera(const std::string &_name,
236  const bool _stereoEnabled = false);
237 
240  public: uint32_t UserCameraCount() const;
241 
247  public: UserCameraPtr GetUserCamera(const uint32_t _index) const;
248 
251  public: void RemoveCamera(const std::string &_name);
252 
255  public: uint32_t LightCount() const;
256 
261  public: LightPtr GetLight(const std::string &_name) const
262  GAZEBO_DEPRECATED(9.1);
263 
269  public: LightPtr GetLight(const uint32_t _index) const
270  GAZEBO_DEPRECATED(9.1);
271 
275  public: LightPtr LightByName(const std::string &_name) const;
276 
281  public: LightPtr LightByIndex(const uint32_t _index) const;
282 
286  public: LightPtr LightById(const uint32_t _id) const;
287 
291  public: VisualPtr GetVisual(const std::string &_name) const;
292 
296  public: VisualPtr GetVisual(const uint32_t _id) const;
297 
301  public: void SelectVisual(const std::string &_name,
302  const std::string &_mode);
303 
310  public: VisualPtr VisualAt(CameraPtr _camera,
311  const ignition::math::Vector2i &_mousePos,
312  std::string &_mod);
313 
316  public: void SnapVisualToNearestBelow(const std::string &_visualName);
317 
323  public: VisualPtr VisualAt(CameraPtr _camera,
324  const ignition::math::Vector2i &_mousePos);
325 
331  public: VisualPtr ModelVisualAt(CameraPtr _camera,
332  const ignition::math::Vector2i &_mousePos);
333 
337  public: VisualPtr VisualBelow(const std::string &_visualName);
338 
343  public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
344  std::vector<VisualPtr> &_visuals);
345 
350  public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
351 
357  public: bool FirstContact(CameraPtr _camera,
358  const ignition::math::Vector2i &_mousePos,
359  ignition::math::Vector3d &_position);
360 
362  public: void PrintSceneGraph();
363 
368  public: void SetVisible(const std::string &_name, const bool _visible);
369 
374  public: void DrawLine(const ignition::math::Vector3d &_start,
375  const ignition::math::Vector3d &_end,
376  const std::string &_name);
377 
385  public: void SetFog(const std::string &_type,
386  const ignition::math::Color &_color,
387  const double _density, const double _start,
388  const double _end);
389 
392  public: uint32_t Id() const;
393 
396  public: std::string IdString() const;
397 
400  public: void SetShadowsEnabled(const bool _value);
401 
404  public: bool ShadowsEnabled() const;
405 
410  public: bool SetShadowTextureSize(const unsigned int _size);
411 
414  public: unsigned int ShadowTextureSize() const;
415 
418  public: void AddVisual(VisualPtr _vis);
419 
422  public: void RemoveVisual(VisualPtr _vis);
423 
426  public: void RemoveVisual(const uint32_t _id);
427 
433  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
434 
437  public: void AddLight(LightPtr _light);
438 
441  public: void RemoveLight(LightPtr _light);
442 
445  public: void SetGrid(const bool _enabled);
446 
449  public: void ShowOrigin(const bool _show);
450 
453  public: VisualPtr WorldVisual() const;
454 
458  public: std::string StripSceneName(const std::string &_name) const;
459 
462  public: Heightmap *GetHeightmap() const;
463 
467  public: void SetHeightmapLOD(const unsigned int _value);
468 
472  public: unsigned int HeightmapLOD() const;
473 
477  public: void SetHeightmapSkirtLength(const double _value);
478 
482  public: double HeightmapSkirtLength() const;
483 
485  public: void Clear();
486 
490  public: VisualPtr SelectedVisual() const;
491 
494  public: void SetWireframe(const bool _show);
495 
498  public: bool Wireframe() const;
499 
502  public: void SetTransparent(const bool _show);
503 
506  public: void ShowCOMs(const bool _show);
507 
510  public: void ShowInertias(const bool _show);
511 
514  public: void ShowLinkFrames(const bool _show);
515 
518  public: void ShowSkeleton(const bool _show);
519 
522  public: void ShowJoints(const bool _show);
523 
526  public: void ShowCollisions(const bool _show);
527 
530  public: void ShowContacts(const bool _show);
531 
534  public: void ShowClouds(const bool _show);
535 
538  public: bool ShowClouds() const;
539 
544  public: void SetSkyXMode(const unsigned int _mode);
545 
548  public: SkyX::SkyX *GetSkyX() const;
549 
552  public: bool Initialized() const;
553 
559  public: common::Time SimTime() const;
560 
564  public: void UpdatePoses(const msgs::PosesStamped& _msg);
565 
568  public: uint32_t VisualCount() const;
569 
571  public: void RemoveProjectors();
572 
577  public: void ToggleLayer(const int32_t _layer);
578 
584  public: bool LayerState(const int32_t _layer) const;
585 
590  public: bool HasLayer(const int32_t _layer) const;
591 
596  public: void EnableVisualizations(const bool _enable);
597 
601  public: bool EnableVisualizations() const;
602 
604  private: void SetSky();
605 
607  private: void InitDeferredShading();
608 
615  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
616  const ignition::math::Vector2i &_mousePos,
617  const bool _ignoreSelectionObj);
618 
628  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
629  private: void MeshInformation(const Ogre::Mesh *_mesh,
630  size_t &_vertexCount,
631  Ogre::Vector3* &_vertices,
632  size_t &_indexCount,
633  uint64_t* &_indices,
634  const ignition::math::Vector3d &_position,
635  const ignition::math::Quaterniond &_orient,
636  const ignition::math::Vector3d &_scale);
637 
641  private: void PrintSceneGraphHelper(const std::string &_prefix,
642  Ogre::Node *_node);
643 
647  private: void OnScene(ConstScenePtr &_msg);
648 
651  private: void OnResponse(ConstResponsePtr &_msg);
652 
655  private: void OnRequest(ConstRequestPtr &_msg);
656 
659  private: void OnJointMsg(ConstJointPtr &_msg);
660 
663  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
664 
667  private: bool ProcessJointMsg(ConstJointPtr &_msg);
668 
671  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
672 
675  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
676 
679  private: bool ProcessModelMsg(const msgs::Model &_msg);
680 
683  private: void OnSensorMsg(ConstSensorPtr &_msg);
684 
687  private: void OnVisualMsg(ConstVisualPtr &_msg);
688 
693  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
694  Visual::VisualType _type = Visual::VT_ENTITY);
695 
698  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
699 
702  private: void OnLightModifyMsg(ConstLightPtr &_msg);
703 
706  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
707 
710  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
711 
714  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
715 
718  private: void OnSkyMsg(ConstSkyPtr &_msg);
719 
722  private: void OnModelMsg(ConstModelPtr &_msg);
723 
726  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
727 
730  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
731 
734  private: void OnRoadMsg(ConstRoadPtr &_msg);
735 
739  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
740 
744  private: void CreateCOMVisual(sdf::ElementPtr _elem,
745  VisualPtr _linkVisual);
746 
750  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
751  VisualPtr _linkVisual);
752 
756  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
757  VisualPtr _linkVisual);
758 
762  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
763  VisualPtr _linkVisual);
764 
768  private: void RemoveVisualizations(VisualPtr _vis);
769 
772  private: std::unique_ptr<ScenePrivate> dataPtr;
773  };
775  }
776 }
777 #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
SkyXMode
Definition: Scene.hh:95
Forward declarations for transport.
rendering
Definition: RenderEngine.hh:31
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:53
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:98
VisualType
Type of visual.
Definition: Visual.hh:64
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
Representation of an entire scene graph.
Definition: Scene.hh:92
#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:47
Definition: Scene.hh:44