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 
398  public: void AddVisual(VisualPtr _vis);
399 
402  public: void RemoveVisual(VisualPtr _vis);
403 
406  public: void RemoveVisual(const uint32_t _id);
407 
413  public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
414 
417  public: void AddLight(LightPtr _light);
418 
421  public: void RemoveLight(LightPtr _light);
422 
425  public: void SetGrid(const bool _enabled);
426 
429  public: void ShowOrigin(const bool _show);
430 
433  public: VisualPtr WorldVisual() const;
434 
438  public: std::string StripSceneName(const std::string &_name) const;
439 
442  public: Heightmap *GetHeightmap() const;
443 
445  public: void Clear();
446 
450  public: VisualPtr SelectedVisual() const;
451 
454  public: void SetWireframe(const bool _show);
455 
458  public: bool Wireframe() const;
459 
462  public: void SetTransparent(const bool _show);
463 
466  public: void ShowCOMs(const bool _show);
467 
470  public: void ShowInertias(const bool _show);
471 
474  public: void ShowLinkFrames(const bool _show);
475 
478  public: void ShowSkeleton(const bool _show);
479 
482  public: void ShowJoints(const bool _show);
483 
486  public: void ShowCollisions(const bool _show);
487 
490  public: void ShowContacts(const bool _show);
491 
494  public: void ShowClouds(const bool _show);
495 
498  public: bool ShowClouds() const;
499 
504  public: void SetSkyXMode(const unsigned int _mode);
505 
508  public: SkyX::SkyX *GetSkyX() const;
509 
512  public: bool Initialized() const;
513 
519  public: common::Time SimTime() const;
520 
523  public: uint32_t VisualCount() const;
524 
526  public: void RemoveProjectors();
527 
532  public: void ToggleLayer(const int32_t _layer);
533 
539  public: bool LayerState(const int32_t _layer) const;
540 
545  public: bool HasLayer(const int32_t _layer) const;
546 
548  private: void SetSky();
549 
551  private: void InitDeferredShading();
552 
559  private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
560  const ignition::math::Vector2i &_mousePos,
561  const bool _ignoreSelectionObj);
562 
572  // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
573  private: void MeshInformation(const Ogre::Mesh *_mesh,
574  size_t &_vertexCount,
575  Ogre::Vector3* &_vertices,
576  size_t &_indexCount,
577  uint64_t* &_indices,
578  const ignition::math::Vector3d &_position,
579  const ignition::math::Quaterniond &_orient,
580  const ignition::math::Vector3d &_scale);
581 
585  private: void PrintSceneGraphHelper(const std::string &_prefix,
586  Ogre::Node *_node);
587 
591  private: void OnScene(ConstScenePtr &_msg);
592 
595  private: void OnResponse(ConstResponsePtr &_msg);
596 
599  private: void OnRequest(ConstRequestPtr &_msg);
600 
603  private: void OnJointMsg(ConstJointPtr &_msg);
604 
607  private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
608 
611  private: bool ProcessJointMsg(ConstJointPtr &_msg);
612 
615  private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
616 
619  private: bool ProcessSceneMsg(ConstScenePtr &_msg);
620 
623  private: bool ProcessModelMsg(const msgs::Model &_msg);
624 
627  private: void OnSensorMsg(ConstSensorPtr &_msg);
628 
631  private: void OnVisualMsg(ConstVisualPtr &_msg);
632 
637  private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
638  Visual::VisualType _type = Visual::VT_ENTITY);
639 
642  private: void OnLightFactoryMsg(ConstLightPtr &_msg);
643 
646  private: void OnLightModifyMsg(ConstLightPtr &_msg);
647 
650  private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
651 
654  private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
655 
658  private: void ProcessRequestMsg(ConstRequestPtr &_msg);
659 
662  private: void OnSkyMsg(ConstSkyPtr &_msg);
663 
666  private: void OnModelMsg(ConstModelPtr &_msg);
667 
670  private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
671 
674  private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
675 
678  private: void OnRoadMsg(ConstRoadPtr &_msg);
679 
683  private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
684 
688  private: void CreateCOMVisual(sdf::ElementPtr _elem,
689  VisualPtr _linkVisual);
690 
694  private: void CreateInertiaVisual(ConstLinkPtr &_msg,
695  VisualPtr _linkVisual);
696 
700  private: void CreateInertiaVisual(sdf::ElementPtr _elem,
701  VisualPtr _linkVisual);
702 
706  private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
707  VisualPtr _linkVisual);
708 
712  private: void RemoveVisualizations(VisualPtr _vis);
713 
716  private: std::unique_ptr<ScenePrivate> dataPtr;
717  };
719  }
720 }
721 #endif
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:93
Forward declarations for the common classes.
Definition: Animation.hh:33
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:105
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:64
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:62
Representation of an entire scene graph.
Definition: Scene.hh:100
Definition: JointMaker.hh:39
Defines a color.
Definition: Color.hh:35
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
Definition: Scene.hh:42