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 
287  public: LightPtr GetLight(const std::string &_name) const;
288 
291  public: uint32_t LightCount() const;
292 
297  public: LightPtr GetLight(const uint32_t _index) const;
298 
302  public: VisualPtr GetVisual(const std::string &_name) const;
303 
307  public: VisualPtr GetVisual(const uint32_t _id) const;
308 
312  public: void SelectVisual(const std::string &_name,
313  const std::string &_mode);
314 
321  public: VisualPtr VisualAt(CameraPtr _camera,
322  const ignition::math::Vector2i &_mousePos,
323  std::string &_mod);
324 
327  public: void SnapVisualToNearestBelow(const std::string &_visualName);
328 
334  public: VisualPtr VisualAt(CameraPtr _camera,
335  const ignition::math::Vector2i &_mousePos);
336 
342  public: VisualPtr ModelVisualAt(CameraPtr _camera,
343  const ignition::math::Vector2i &_mousePos);
344 
348  public: VisualPtr VisualBelow(const std::string &_visualName);
349 
354  public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
355  std::vector<VisualPtr> &_visuals);
356 
361  public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
362 
368  public: bool FirstContact(CameraPtr _camera,
369  const ignition::math::Vector2i &_mousePos,
370  ignition::math::Vector3d &_position);
371 
373  public: void PrintSceneGraph();
374 
379  public: void SetVisible(const std::string &_name, const bool _visible);
380 
385  public: void DrawLine(const ignition::math::Vector3d &_start,
386  const ignition::math::Vector3d &_end,
387  const std::string &_name);
388 
397  public: void SetFog(const std::string &_type,
398  const common::Color &_color,
399  const double _density, const double _start,
400  const double _end) GAZEBO_DEPRECATED(9.0);
401 
409  public: void SetFog(const std::string &_type,
410  const ignition::math::Color &_color,
411  const double _density, const double _start,
412  const double _end);
413 
416  public: uint32_t Id() const;
417 
420  public: std::string IdString() const;
421 
424  public: void SetShadowsEnabled(const bool _value);
425 
428  public: bool ShadowsEnabled() const;
429 
434  public: bool SetShadowTextureSize(const unsigned int _size);
435 
438  public: unsigned int ShadowTextureSize() const;
439 
442  public: void AddVisual(VisualPtr _vis);
443 
446  public: void RemoveVisual(VisualPtr _vis);
447 
450  public: void RemoveVisual(const uint32_t _id);
451 
457  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
458 
461  public: void AddLight(LightPtr _light);
462 
465  public: void RemoveLight(LightPtr _light);
466 
469  public: void SetGrid(const bool _enabled);
470 
473  public: void ShowOrigin(const bool _show);
474 
477  public: VisualPtr WorldVisual() const;
478 
482  public: std::string StripSceneName(const std::string &_name) const;
483 
486  public: Heightmap *GetHeightmap() const;
487 
491  public: void SetHeightmapLOD(const unsigned int _value);
492 
496  public: unsigned int HeightmapLOD() const;
497 
499  public: void Clear();
500 
504  public: VisualPtr SelectedVisual() const;
505 
508  public: void SetWireframe(const bool _show);
509 
512  public: bool Wireframe() const;
513 
516  public: void SetTransparent(const bool _show);
517 
520  public: void ShowCOMs(const bool _show);
521 
524  public: void ShowInertias(const bool _show);
525 
528  public: void ShowLinkFrames(const bool _show);
529 
532  public: void ShowSkeleton(const bool _show);
533 
536  public: void ShowJoints(const bool _show);
537 
540  public: void ShowCollisions(const bool _show);
541 
544  public: void ShowContacts(const bool _show);
545 
548  public: void ShowClouds(const bool _show);
549 
552  public: bool ShowClouds() const;
553 
558  public: void SetSkyXMode(const unsigned int _mode);
559 
562  public: SkyX::SkyX *GetSkyX() const;
563 
566  public: bool Initialized() const;
567 
573  public: common::Time SimTime() const;
574 
577  public: uint32_t VisualCount() const;
578 
580  public: void RemoveProjectors();
581 
586  public: void ToggleLayer(const int32_t _layer);
587 
593  public: bool LayerState(const int32_t _layer) const;
594 
599  public: bool HasLayer(const int32_t _layer) const;
600 
605  public: void EnableVisualizations(const bool _enable);
606 
610  public: bool EnableVisualizations() const;
611 
613  private: void SetSky();
614 
616  private: void InitDeferredShading();
617 
624  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
625  const ignition::math::Vector2i &_mousePos,
626  const bool _ignoreSelectionObj);
627 
637  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
638  private: void MeshInformation(const Ogre::Mesh *_mesh,
639  size_t &_vertexCount,
640  Ogre::Vector3* &_vertices,
641  size_t &_indexCount,
642  uint64_t* &_indices,
643  const ignition::math::Vector3d &_position,
644  const ignition::math::Quaterniond &_orient,
645  const ignition::math::Vector3d &_scale);
646 
650  private: void PrintSceneGraphHelper(const std::string &_prefix,
651  Ogre::Node *_node);
652 
656  private: void OnScene(ConstScenePtr &_msg);
657 
660  private: void OnResponse(ConstResponsePtr &_msg);
661 
664  private: void OnRequest(ConstRequestPtr &_msg);
665 
668  private: void OnJointMsg(ConstJointPtr &_msg);
669 
672  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
673 
676  private: bool ProcessJointMsg(ConstJointPtr &_msg);
677 
680  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
681 
684  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
685 
688  private: bool ProcessModelMsg(const msgs::Model &_msg);
689 
692  private: void OnSensorMsg(ConstSensorPtr &_msg);
693 
696  private: void OnVisualMsg(ConstVisualPtr &_msg);
697 
702  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
704 
707  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
708 
711  private: void OnLightModifyMsg(ConstLightPtr &_msg);
712 
715  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
716 
719  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
720 
723  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
724 
727  private: void OnSkyMsg(ConstSkyPtr &_msg);
728 
731  private: void OnModelMsg(ConstModelPtr &_msg);
732 
735  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
736 
739  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
740 
743  private: void OnRoadMsg(ConstRoadPtr &_msg);
744 
748  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
749 
753  private: void CreateCOMVisual(sdf::ElementPtr _elem,
754  VisualPtr _linkVisual);
755 
759  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
760  VisualPtr _linkVisual);
761 
765  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
766  VisualPtr _linkVisual);
767 
771  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
772  VisualPtr _linkVisual);
773 
777  private: void RemoveVisualizations(VisualPtr _vis);
778 
781  private: std::unique_ptr<ScenePrivate> dataPtr;
782  };
784  }
785 }
786 #endif
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:94
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
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