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/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/msgs/msgs.hh"
40 #include "gazebo/util/system.hh"
41 
42 namespace SkyX
43 {
44  class SkyX;
45 }
46 
47 namespace Ogre
48 {
49  class SceneManager;
50  class Node;
51  class Entity;
52  class Mesh;
53  class Vector3;
54  class Quaternion;
55 }
56 
57 namespace gazebo
58 {
59  namespace rendering
60  {
61  class Visual;
62  class Grid;
63  class Heightmap;
64  class ScenePrivate;
65 
68 
100  class GZ_RENDERING_VISIBLE Scene :
101  public boost::enable_shared_from_this<Scene>
102  {
103  public: enum SkyXMode {
104  GZ_SKYX_ALL = 0x0FFFFFFF,
105  GZ_SKYX_CLOUDS = 0x0000001,
106  GZ_SKYX_MOON = 0x0000002,
107  GZ_SKYX_NONE = 0
108  };
109 
111  private: Scene();
112 
118  public: Scene(const std::string &_name,
119  const bool _enableVisualizations = false,
120  const bool _isServer = false);
121 
123  public: virtual ~Scene();
124 
127  public: void Load(sdf::ElementPtr _scene);
128 
130  public: void Load();
131 
133  public: void Init();
134 
136  public: void PreRender();
137 
140  public: Ogre::SceneManager *OgreSceneManager() const;
141 
144  public: std::string Name() const;
145 
148  public: void SetAmbientColor(const common::Color &_color);
149 
152  public: common::Color AmbientColor() const;
153 
156  public: void SetBackgroundColor(const common::Color &_color);
157 
160  public: common::Color BackgroundColor() const;
161 
167  public: void CreateGrid(const uint32_t _cellCount,
168  const float _cellLength, const float _lineWidth,
169  const common::Color &_color);
170 
174  public: Grid *GetGrid(uint32_t _index) const;
175 
178  public: uint32_t GridCount() const;
179 
185  public: CameraPtr CreateCamera(const std::string &_name,
186  const bool _autoRender = true);
187 
193  public: WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name,
194  const bool _autoRender = true);
195 
196 #ifdef HAVE_OCULUS
197  public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
201 
204  public: uint32_t OculusCameraCount() const;
205 #endif
206 
212  public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
213  const bool _autoRender = true);
214 
220  public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
221  const bool _autoRender = true);
222 
225  public: uint32_t CameraCount() const;
226 
231  public: CameraPtr GetCamera(const uint32_t _index) const;
232 
236  public: CameraPtr GetCamera(const std::string &_name) const;
237 
245  public: UserCameraPtr CreateUserCamera(const std::string &_name,
246  const bool _stereoEnabled = false);
247 
250  public: uint32_t UserCameraCount() const;
251 
257  public: UserCameraPtr GetUserCamera(const uint32_t _index) const;
258 
261  public: void RemoveCamera(const std::string &_name);
262 
266  public: LightPtr GetLight(const std::string &_name) const;
267 
270  public: uint32_t LightCount() const;
271 
276  public: LightPtr GetLight(const uint32_t _index) const;
277 
281  public: VisualPtr GetVisual(const std::string &_name) const;
282 
286  public: VisualPtr GetVisual(const uint32_t _id) const;
287 
291  public: void SelectVisual(const std::string &_name,
292  const std::string &_mode);
293 
300  public: VisualPtr VisualAt(CameraPtr _camera,
301  const ignition::math::Vector2i &_mousePos,
302  std::string &_mod);
303 
306  public: void SnapVisualToNearestBelow(const std::string &_visualName);
307 
313  public: VisualPtr VisualAt(CameraPtr _camera,
314  const ignition::math::Vector2i &_mousePos);
315 
321  public: VisualPtr ModelVisualAt(CameraPtr _camera,
322  const ignition::math::Vector2i &_mousePos);
323 
327  public: VisualPtr VisualBelow(const std::string &_visualName);
328 
333  public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
334  std::vector<VisualPtr> &_visuals);
335 
340  public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
341 
347  public: bool FirstContact(CameraPtr _camera,
348  const ignition::math::Vector2i &_mousePos,
349  ignition::math::Vector3d &_position);
350 
352  public: void PrintSceneGraph();
353 
358  public: void SetVisible(const std::string &_name, const bool _visible);
359 
364  public: void DrawLine(const ignition::math::Vector3d &_start,
365  const ignition::math::Vector3d &_end,
366  const std::string &_name);
367 
375  public: void SetFog(const std::string &_type,
376  const common::Color &_color,
377  const double _density, const double _start,
378  const double _end);
379 
382  public: uint32_t Id() const;
383 
386  public: std::string IdString() const;
387 
390  public: void SetShadowsEnabled(const bool _value);
391 
394  public: bool ShadowsEnabled() const;
395 
400  public: bool SetShadowTextureSize(const unsigned int _size);
401 
404  public: unsigned int ShadowTextureSize() const;
405 
408  public: void AddVisual(VisualPtr _vis);
409 
412  public: void RemoveVisual(VisualPtr _vis);
413 
416  public: void RemoveVisual(const uint32_t _id);
417 
423  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
424 
427  public: void AddLight(LightPtr _light);
428 
431  public: void RemoveLight(LightPtr _light);
432 
435  public: void SetGrid(const bool _enabled);
436 
439  public: void ShowOrigin(const bool _show);
440 
443  public: VisualPtr WorldVisual() const;
444 
448  public: std::string StripSceneName(const std::string &_name) const;
449 
452  public: Heightmap *GetHeightmap() const;
453 
457  public: void SetHeightmapLOD(const unsigned int _value);
458 
462  public: unsigned int HeightmapLOD() const;
463 
465  public: void Clear();
466 
470  public: VisualPtr SelectedVisual() const;
471 
474  public: void SetWireframe(const bool _show);
475 
478  public: bool Wireframe() const;
479 
482  public: void SetTransparent(const bool _show);
483 
486  public: void ShowCOMs(const bool _show);
487 
490  public: void ShowInertias(const bool _show);
491 
494  public: void ShowLinkFrames(const bool _show);
495 
498  public: void ShowSkeleton(const bool _show);
499 
502  public: void ShowJoints(const bool _show);
503 
506  public: void ShowCollisions(const bool _show);
507 
510  public: void ShowContacts(const bool _show);
511 
514  public: void ShowClouds(const bool _show);
515 
518  public: bool ShowClouds() const;
519 
524  public: void SetSkyXMode(const unsigned int _mode);
525 
528  public: SkyX::SkyX *GetSkyX() const;
529 
532  public: bool Initialized() const;
533 
539  public: common::Time SimTime() const;
540 
543  public: uint32_t VisualCount() const;
544 
546  public: void RemoveProjectors();
547 
552  public: void ToggleLayer(const int32_t _layer);
553 
559  public: bool LayerState(const int32_t _layer) const;
560 
565  public: bool HasLayer(const int32_t _layer) const;
566 
571  public: void EnableVisualizations(const bool _enable);
572 
576  public: bool EnableVisualizations() const;
577 
579  private: void SetSky();
580 
582  private: void InitDeferredShading();
583 
590  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
591  const ignition::math::Vector2i &_mousePos,
592  const bool _ignoreSelectionObj);
593 
603  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
604  private: void MeshInformation(const Ogre::Mesh *_mesh,
605  size_t &_vertexCount,
606  Ogre::Vector3* &_vertices,
607  size_t &_indexCount,
608  uint64_t* &_indices,
609  const ignition::math::Vector3d &_position,
610  const ignition::math::Quaterniond &_orient,
611  const ignition::math::Vector3d &_scale);
612 
616  private: void PrintSceneGraphHelper(const std::string &_prefix,
617  Ogre::Node *_node);
618 
622  private: void OnScene(ConstScenePtr &_msg);
623 
626  private: void OnResponse(ConstResponsePtr &_msg);
627 
630  private: void OnRequest(ConstRequestPtr &_msg);
631 
634  private: void OnJointMsg(ConstJointPtr &_msg);
635 
638  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
639 
642  private: bool ProcessJointMsg(ConstJointPtr &_msg);
643 
646  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
647 
650  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
651 
654  private: bool ProcessModelMsg(const msgs::Model &_msg);
655 
658  private: void OnSensorMsg(ConstSensorPtr &_msg);
659 
662  private: void OnVisualMsg(ConstVisualPtr &_msg);
663 
668  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
670 
673  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
674 
677  private: void OnLightModifyMsg(ConstLightPtr &_msg);
678 
681  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
682 
685  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
686 
689  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
690 
693  private: void OnSkyMsg(ConstSkyPtr &_msg);
694 
697  private: void OnModelMsg(ConstModelPtr &_msg);
698 
701  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
702 
705  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
706 
709  private: void OnRoadMsg(ConstRoadPtr &_msg);
710 
714  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
715 
719  private: void CreateCOMVisual(sdf::ElementPtr _elem,
720  VisualPtr _linkVisual);
721 
725  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
726  VisualPtr _linkVisual);
727 
731  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
732  VisualPtr _linkVisual);
733 
737  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
738  VisualPtr _linkVisual);
739 
743  private: void RemoveVisualizations(VisualPtr _vis);
744 
747  private: std::unique_ptr<ScenePrivate> dataPtr;
748  };
750  }
751 }
752 #endif
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:93
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:105
Entity visual.
Definition: Visual.hh:71
SkyXMode
Definition: Scene.hh:103
Forward declarations for transport.
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:56
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:97
VisualType
Type of visual.
Definition: Visual.hh:68
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
Representation of an entire scene graph.
Definition: Scene.hh:100
Defines a color.
Definition: Color.hh:36
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:113
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< WideAngleCamera > WideAngleCameraPtr
Definition: RenderTypes.hh:101
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:85
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:89
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:44