Scene.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2016 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/Vector2.hh>
31 #include <ignition/math/Vector3.hh>
32 
33 #include "gazebo/common/Events.hh"
34 #include "gazebo/common/Color.hh"
35 #include "gazebo/gazebo_config.h"
36 #include "gazebo/math/Vector2i.hh"
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 
74  class GZ_RENDERING_VISIBLE Scene :
75  public boost::enable_shared_from_this<Scene>
76  {
77  public: enum SkyXMode {
78  GZ_SKYX_ALL = 0x0FFFFFFF,
79  GZ_SKYX_CLOUDS = 0x0000001,
80  GZ_SKYX_MOON = 0x0000002,
81  GZ_SKYX_NONE = 0
82  };
83 
85  private: Scene();
86 
92  public: Scene(const std::string &_name,
93  const bool _enableVisualizations = false,
94  const bool _isServer = false);
95 
97  public: virtual ~Scene();
98 
101  public: void Load(sdf::ElementPtr _scene);
102 
104  public: void Load();
105 
107  public: void Init();
108 
110  public: void PreRender();
111 
115  public: Ogre::SceneManager *GetManager() const GAZEBO_DEPRECATED(7.0);
116 
119  public: Ogre::SceneManager *OgreSceneManager() const;
120 
124  public: std::string GetName() const GAZEBO_DEPRECATED(7.0);
125 
128  public: std::string Name() const;
129 
132  public: void SetAmbientColor(const common::Color &_color);
133 
137  public: common::Color GetAmbientColor() const GAZEBO_DEPRECATED(7.0);
138 
141  public: common::Color AmbientColor() const;
142 
145  public: void SetBackgroundColor(const common::Color &_color);
146 
150  public: common::Color GetBackgroundColor() const GAZEBO_DEPRECATED(7.0);
151 
154  public: common::Color BackgroundColor() const;
155 
161  public: void CreateGrid(const uint32_t _cellCount,
162  const float _cellLength, const float _lineWidth,
163  const common::Color &_color);
164 
168  public: Grid *GetGrid(uint32_t _index) const;
169 
173  public: uint32_t GetGridCount() const GAZEBO_DEPRECATED(7.0);
174 
177  public: uint32_t GridCount() const;
178 
184  public: CameraPtr CreateCamera(const std::string &_name,
185  const bool _autoRender = true);
186 
192  public: WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name,
193  const bool _autoRender = true);
194 
195 #ifdef HAVE_OCULUS
196  public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
200 
204  public: uint32_t GetOculusCameraCount() const GAZEBO_DEPRECATED(7.0);
205 
208  public: uint32_t OculusCameraCount() const;
209 #endif
210 
216  public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
217  const bool _autoRender = true);
218 
224  public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
225  const bool _autoRender = true);
226 
230  public: uint32_t GetCameraCount() const GAZEBO_DEPRECATED(7.0);
231 
234  public: uint32_t CameraCount() const;
235 
240  public: CameraPtr GetCamera(const uint32_t _index) const;
241 
245  public: CameraPtr GetCamera(const std::string &_name) const;
246 
254  public: UserCameraPtr CreateUserCamera(const std::string &_name,
255  const bool _stereoEnabled = false);
256 
260  public: uint32_t GetUserCameraCount() const GAZEBO_DEPRECATED(7.0);
261 
264  public: uint32_t UserCameraCount() const;
265 
271  public: UserCameraPtr GetUserCamera(const uint32_t _index) const;
272 
275  public: void RemoveCamera(const std::string &_name);
276 
280  public: LightPtr GetLight(const std::string &_name) const;
281 
285  public: uint32_t GetLightCount() const GAZEBO_DEPRECATED(7.0);
286 
289  public: uint32_t LightCount() const;
290 
295  public: LightPtr GetLight(const uint32_t _index) const;
296 
300  public: VisualPtr GetVisual(const std::string &_name) const;
301 
305  public: VisualPtr GetVisual(const uint32_t _id) const;
306 
310  public: void SelectVisual(const std::string &_name,
311  const std::string &_mode);
312 
320  public: VisualPtr GetVisualAt(CameraPtr _camera,
321  const math::Vector2i &_mousePos,
322  std::string &_mod) GAZEBO_DEPRECATED(7.0);
323 
330  public: VisualPtr VisualAt(CameraPtr _camera,
331  const ignition::math::Vector2i &_mousePos,
332  std::string &_mod);
333 
336  public: void SnapVisualToNearestBelow(const std::string &_visualName);
337 
344  public: VisualPtr GetVisualAt(CameraPtr _camera,
345  const math::Vector2i &_mousePos) GAZEBO_DEPRECATED(7.0);
346 
352  public: VisualPtr VisualAt(CameraPtr _camera,
353  const ignition::math::Vector2i &_mousePos);
354 
361  public: VisualPtr GetModelVisualAt(CameraPtr _camera,
362  const math::Vector2i &_mousePos) GAZEBO_DEPRECATED(7.0);
363 
369  public: VisualPtr ModelVisualAt(CameraPtr _camera,
370  const ignition::math::Vector2i &_mousePos);
371 
376  public: VisualPtr GetVisualBelow(const std::string &_visualName)
377  GAZEBO_DEPRECATED(7.0);
378 
382  public: VisualPtr VisualBelow(const std::string &_visualName);
383 
389  public: void GetVisualsBelowPoint(const math::Vector3 &_pt,
390  std::vector<VisualPtr> &_visuals) GAZEBO_DEPRECATED(7.0);
391 
396  public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
397  std::vector<VisualPtr> &_visuals);
398 
399 
405  public: double GetHeightBelowPoint(const math::Vector3 &_pt)
406  GAZEBO_DEPRECATED(7.0);
407 
412  public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
413 
420  public: bool GetFirstContact(CameraPtr _camera,
421  const math::Vector2i &_mousePos,
422  math::Vector3 &_position) GAZEBO_DEPRECATED(7.0);
423 
429  public: bool FirstContact(CameraPtr _camera,
430  const ignition::math::Vector2i &_mousePos,
431  ignition::math::Vector3d &_position);
432 
434  public: void PrintSceneGraph();
435 
440  public: void SetVisible(const std::string &_name, const bool _visible);
441 
447  public: void DrawLine(const math::Vector3 &_start,
448  const math::Vector3 &_end,
449  const std::string &_name) GAZEBO_DEPRECATED(7.0);
450 
455  public: void DrawLine(const ignition::math::Vector3d &_start,
456  const ignition::math::Vector3d &_end,
457  const std::string &_name);
458 
466  public: void SetFog(const std::string &_type,
467  const common::Color &_color,
468  const double _density, const double _start,
469  const double _end);
470 
474  public: uint32_t GetId() const GAZEBO_DEPRECATED(7.0);
475 
478  public: uint32_t Id() const;
479 
483  public: std::string GetIdString() const GAZEBO_DEPRECATED(7.0);
484 
487  public: std::string IdString() const;
488 
491  public: void SetShadowsEnabled(const bool _value);
492 
496  public: bool GetShadowsEnabled() const GAZEBO_DEPRECATED(7.0);
497 
500  public: bool ShadowsEnabled() const;
501 
504  public: void AddVisual(VisualPtr _vis);
505 
508  public: void RemoveVisual(VisualPtr _vis);
509 
512  public: void RemoveVisual(const uint32_t _id);
513 
519  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
520 
523  public: void AddLight(LightPtr _light);
524 
527  public: void RemoveLight(LightPtr _light);
528 
531  public: void SetGrid(const bool _enabled);
532 
535  public: void ShowOrigin(const bool _show);
536 
540  public: VisualPtr GetWorldVisual() const GAZEBO_DEPRECATED(7.0);
541 
544  public: VisualPtr WorldVisual() const;
545 
549  public: std::string StripSceneName(const std::string &_name) const;
550 
553  public: Heightmap *GetHeightmap() const;
554 
556  public: void Clear();
557 
562  public: VisualPtr GetSelectedVisual() const GAZEBO_DEPRECATED(7.0);
563 
567  public: VisualPtr SelectedVisual() const;
568 
571  public: void SetWireframe(const bool _show);
572 
575  public: void SetTransparent(const bool _show);
576 
579  public: void ShowCOMs(const bool _show);
580 
583  public: void ShowInertias(const bool _show);
584 
587  public: void ShowLinkFrames(const bool _show);
588 
591  public: void ShowJoints(const bool _show);
592 
595  public: void ShowCollisions(const bool _show);
596 
599  public: void ShowContacts(const bool _show);
600 
603  public: void ShowClouds(const bool _show);
604 
608  public: bool GetShowClouds() const GAZEBO_DEPRECATED(7.0);
609 
612  public: bool ShowClouds() const;
613 
618  public: void SetSkyXMode(const unsigned int _mode);
619 
622  public: SkyX::SkyX *GetSkyX() const;
623 
627  public: bool GetInitialized() const GAZEBO_DEPRECATED(7.0);
628 
631  public: bool Initialized() const;
632 
639  public: common::Time GetSimTime() const GAZEBO_DEPRECATED(7.0);
640 
646  public: common::Time SimTime() const;
647 
651  public: uint32_t GetVisualCount() const GAZEBO_DEPRECATED(7.0);
652 
655  public: uint32_t VisualCount() const;
656 
658  public: void RemoveProjectors();
659 
664  public: void ToggleLayer(const int32_t _layer);
665 
667  private: void SetSky();
668 
670  private: void InitDeferredShading();
671 
678  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
679  const ignition::math::Vector2i &_mousePos,
680  const bool _ignoreSelectionObj);
681 
691  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
692  private: void MeshInformation(const Ogre::Mesh *_mesh,
693  size_t &_vertexCount,
694  Ogre::Vector3* &_vertices,
695  size_t &_indexCount,
696  uint64_t* &_indices,
697  const ignition::math::Vector3d &_position,
698  const ignition::math::Quaterniond &_orient,
699  const ignition::math::Vector3d &_scale);
700 
704  private: void PrintSceneGraphHelper(const std::string &_prefix,
705  Ogre::Node *_node);
706 
710  private: void OnScene(ConstScenePtr &_msg);
711 
714  private: void OnResponse(ConstResponsePtr &_msg);
715 
718  private: void OnRequest(ConstRequestPtr &_msg);
719 
722  private: void OnJointMsg(ConstJointPtr &_msg);
723 
726  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
727 
730  private: bool ProcessJointMsg(ConstJointPtr &_msg);
731 
734  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
735 
738  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
739 
742  private: bool ProcessModelMsg(const msgs::Model &_msg);
743 
746  private: void OnSensorMsg(ConstSensorPtr &_msg);
747 
750  private: void OnVisualMsg(ConstVisualPtr &_msg);
751 
756  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
757  Visual::VisualType _type = Visual::VT_ENTITY);
758 
761  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
762 
765  private: void OnLightModifyMsg(ConstLightPtr &_msg);
766 
769  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
770 
773  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
774 
777  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
778 
781  private: void OnSkyMsg(ConstSkyPtr &_msg);
782 
785  private: void OnModelMsg(ConstModelPtr &_msg);
786 
789  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
790 
793  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
794 
798  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
799 
803  private: void CreateCOMVisual(sdf::ElementPtr _elem,
804  VisualPtr _linkVisual);
805 
809  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
810  VisualPtr _linkVisual);
811 
815  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
816  VisualPtr _linkVisual);
817 
821  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
822  VisualPtr _linkVisual);
823 
827  private: void RemoveVisualizations(VisualPtr _vis);
828 
831  private: std::unique_ptr<ScenePrivate> dataPtr;
832  };
834  }
835 }
836 #endif
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:92
Forward declarations for the common classes.
Definition: Animation.hh:33
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:104
SkyXMode
Definition: Scene.hh:77
Forward declarations for transport.
STL namespace.
A renderable object.
Definition: Visual.hh:59
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:53
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:96
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:68
Representation of an entire scene graph.
Definition: Scene.hh:74
Definition: JointMaker.hh:41
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< WideAngleCamera > WideAngleCameraPtr
Definition: RenderTypes.hh:100
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:84
Definition: Animation.hh:24
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:88
Definition: Scene.hh:43