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
35#include "gazebo/gazebo_config.h"
36#include "gazebo/msgs/msgs.hh"
40#include "gazebo/util/system.hh"
41
42namespace SkyX
43{
44 class SkyX;
45}
46
47namespace Ogre
48{
49 class SceneManager;
50 class Node;
51 class Entity;
52 class Mesh;
53 class Vector3;
54 class Quaternion;
55}
56
57namespace 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 ignition::math::Color &_color);
149
152 public: ignition::math::Color AmbientColor() const;
153
156 public: void SetBackgroundColor(const ignition::math::Color &_color);
157
160 public: ignition::math::Color BackgroundColor() const;
161
166 public: void CreateGrid(const uint32_t _cellCount,
167 const float _cellLength, const ignition::math::Color &_color);
168
172 public: Grid *GetGrid(uint32_t _index) const;
173
176 public: uint32_t GridCount() const;
177
183 public: CameraPtr CreateCamera(const std::string &_name,
184 const bool _autoRender = true);
185
191 public: WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name,
192 const bool _autoRender = true);
193
194#ifdef HAVE_OCULUS
198 public: OculusCameraPtr CreateOculusCamera(const std::string &_name);
199
202 public: uint32_t OculusCameraCount() const;
203#endif
204
210 public: DepthCameraPtr CreateDepthCamera(const std::string &_name,
211 const bool _autoRender = true);
212
218 public: GpuLaserPtr CreateGpuLaser(const std::string &_name,
219 const bool _autoRender = true);
220
223 public: uint32_t CameraCount() const;
224
229 public: CameraPtr GetCamera(const uint32_t _index) const;
230
234 public: CameraPtr GetCamera(const std::string &_name) const;
235
243 public: UserCameraPtr CreateUserCamera(const std::string &_name,
244 const bool _stereoEnabled = false);
245
248 public: uint32_t UserCameraCount() const;
249
255 public: UserCameraPtr GetUserCamera(const uint32_t _index) const;
256
259 public: void RemoveCamera(const std::string &_name);
260
263 public: uint32_t LightCount() const;
264
269 public: LightPtr GetLight(const std::string &_name) const
271
277 public: LightPtr GetLight(const uint32_t _index) const
279
283 public: LightPtr LightByName(const std::string &_name) const;
284
289 public: LightPtr LightByIndex(const uint32_t _index) const;
290
294 public: LightPtr LightById(const uint32_t _id) const;
295
299 public: VisualPtr GetVisual(const std::string &_name) const;
300
304 public: VisualPtr GetVisual(const uint32_t _id) const;
305
309 public: void SelectVisual(const std::string &_name,
310 const std::string &_mode);
311
318 public: VisualPtr VisualAt(CameraPtr _camera,
319 const ignition::math::Vector2i &_mousePos,
320 std::string &_mod);
321
324 public: void SnapVisualToNearestBelow(const std::string &_visualName);
325
331 public: VisualPtr VisualAt(CameraPtr _camera,
332 const ignition::math::Vector2i &_mousePos);
333
340 const ignition::math::Vector2i &_mousePos);
341
345 public: VisualPtr VisualBelow(const std::string &_visualName);
346
351 public: void VisualsBelowPoint(const ignition::math::Vector3d &_pt,
352 std::vector<VisualPtr> &_visuals);
353
358 public: double HeightBelowPoint(const ignition::math::Vector3d &_pt);
359
365 public: bool FirstContact(CameraPtr _camera,
366 const ignition::math::Vector2i &_mousePos,
367 ignition::math::Vector3d &_position);
368
370 public: void PrintSceneGraph();
371
376 public: void SetVisible(const std::string &_name, const bool _visible);
377
382 public: void DrawLine(const ignition::math::Vector3d &_start,
383 const ignition::math::Vector3d &_end,
384 const std::string &_name);
385
393 public: void SetFog(const std::string &_type,
394 const ignition::math::Color &_color,
395 const double _density, const double _start,
396 const double _end);
397
400 public: uint32_t Id() const;
401
404 public: std::string IdString() const;
405
408 public: void SetShadowsEnabled(const bool _value);
409
412 public: bool ShadowsEnabled() const;
413
418 public: bool SetShadowTextureSize(const unsigned int _size);
419
422 public: unsigned int ShadowTextureSize() const;
423
426 public: void AddVisual(VisualPtr _vis);
427
430 public: void RemoveVisual(VisualPtr _vis);
431
434 public: void RemoveVisual(const uint32_t _id);
435
441 public: void SetVisualId(VisualPtr _vis, const uint32_t _id);
442
445 public: void AddLight(LightPtr _light);
446
449 public: void RemoveLight(LightPtr _light);
450
453 public: void SetGrid(const bool _enabled);
454
457 public: void ShowOrigin(const bool _show);
458
461 public: VisualPtr WorldVisual() const;
462
466 public: std::string StripSceneName(const std::string &_name) const;
467
470 public: Heightmap *GetHeightmap() const;
471
475 public: void SetHeightmapLOD(const unsigned int _value);
476
480 public: unsigned int HeightmapLOD() const;
481
485 public: void SetHeightmapSkirtLength(const double _value);
486
490 public: double HeightmapSkirtLength() const;
491
493 public: void Clear();
494
498 public: VisualPtr SelectedVisual() const;
499
502 public: void SetWireframe(const bool _show);
503
506 public: bool Wireframe() const;
507
510 public: void SetTransparent(const bool _show);
511
514 public: void ShowCOMs(const bool _show);
515
518 public: void ShowInertias(const bool _show);
519
522 public: void ShowLinkFrames(const bool _show);
523
526 public: void ShowSkeleton(const bool _show);
527
530 public: void ShowJoints(const bool _show);
531
534 public: void ShowCollisions(const bool _show);
535
538 public: void ShowContacts(const bool _show);
539
542 public: void ShowClouds(const bool _show);
543
546 public: bool ShowClouds() const;
547
552 public: void SetSkyXMode(const unsigned int _mode);
553
556 public: SkyX::SkyX *GetSkyX() const;
557
560 public: bool Initialized() const;
561
567 public: common::Time SimTime() const;
568
571 public: uint32_t VisualCount() const;
572
574 public: void RemoveProjectors();
575
580 public: void ToggleLayer(const int32_t _layer);
581
587 public: bool LayerState(const int32_t _layer) const;
588
593 public: bool HasLayer(const int32_t _layer) const;
594
599 public: void EnableVisualizations(const bool _enable);
600
604 public: bool EnableVisualizations() const;
605
607 private: void SetSky();
608
610 private: void InitDeferredShading();
611
618 private: Ogre::Entity *OgreEntityAt(CameraPtr _camera,
619 const ignition::math::Vector2i &_mousePos,
620 const bool _ignoreSelectionObj);
621
631 // Code found in Wiki: www.ogre3d.org/wiki/index.php/RetrieveVertexData
632 private: void MeshInformation(const Ogre::Mesh *_mesh,
633 size_t &_vertexCount,
634 Ogre::Vector3* &_vertices,
635 size_t &_indexCount,
636 uint64_t* &_indices,
637 const ignition::math::Vector3d &_position,
638 const ignition::math::Quaterniond &_orient,
639 const ignition::math::Vector3d &_scale);
640
644 private: void PrintSceneGraphHelper(const std::string &_prefix,
645 Ogre::Node *_node);
646
650 private: void OnScene(ConstScenePtr &_msg);
651
654 private: void OnResponse(ConstResponsePtr &_msg);
655
658 private: void OnRequest(ConstRequestPtr &_msg);
659
662 private: void OnJointMsg(ConstJointPtr &_msg);
663
666 private: bool ProcessSensorMsg(ConstSensorPtr &_msg);
667
670 private: bool ProcessJointMsg(ConstJointPtr &_msg);
671
674 private: bool ProcessLinkMsg(ConstLinkPtr &_msg);
675
678 private: bool ProcessSceneMsg(ConstScenePtr &_msg);
679
682 private: bool ProcessModelMsg(const msgs::Model &_msg);
683
686 private: void OnSensorMsg(ConstSensorPtr &_msg);
687
690 private: void OnVisualMsg(ConstVisualPtr &_msg);
691
696 private: bool ProcessVisualMsg(ConstVisualPtr &_msg,
697 Visual::VisualType _type = Visual::VT_ENTITY);
698
701 private: void OnLightFactoryMsg(ConstLightPtr &_msg);
702
705 private: void OnLightModifyMsg(ConstLightPtr &_msg);
706
709 private: bool ProcessLightFactoryMsg(ConstLightPtr &_msg);
710
713 private: bool ProcessLightModifyMsg(ConstLightPtr &_msg);
714
717 private: void ProcessRequestMsg(ConstRequestPtr &_msg);
718
721 private: void OnSkyMsg(ConstSkyPtr &_msg);
722
725 private: void OnModelMsg(ConstModelPtr &_msg);
726
729 private: void OnPoseMsg(ConstPosesStampedPtr &_msg);
730
733 private: void OnSkeletonPoseMsg(ConstPoseAnimationPtr &_msg);
734
737 private: void OnRoadMsg(ConstRoadPtr &_msg);
738
742 private: void CreateCOMVisual(ConstLinkPtr &_msg, VisualPtr _linkVisual);
743
747 private: void CreateCOMVisual(sdf::ElementPtr _elem,
748 VisualPtr _linkVisual);
749
753 private: void CreateInertiaVisual(ConstLinkPtr &_msg,
754 VisualPtr _linkVisual);
755
759 private: void CreateInertiaVisual(sdf::ElementPtr _elem,
760 VisualPtr _linkVisual);
761
765 private: void CreateLinkFrameVisual(ConstLinkPtr &_msg,
766 VisualPtr _linkVisual);
767
771 private: void RemoveVisualizations(VisualPtr _vis);
772
775 private: std::unique_ptr<ScenePrivate> dataPtr;
776 };
778 }
779}
780#endif
rendering
Definition: RenderEngine.hh:31
Forward declarations for transport.
A Time class, can be used to hold wall- or sim-time.
Definition: Time.hh:48
Displays a grid of cells, drawn with lines.
Definition: Grid.hh:54
Rendering a terrain using heightmap information.
Definition: Heightmap.hh:63
Representation of an entire scene graph.
Definition: Scene.hh:102
LightPtr GetLight(const std::string &_name) const GAZEBO_DEPRECATED(9.1)
Get a light by name.
uint32_t VisualCount() const
Get the number of visuals.
Heightmap * GetHeightmap() const
Get a pointer to the heightmap.
ignition::math::Color BackgroundColor() const
Get the background color.
LightPtr LightById(const uint32_t _id) const
Get a light by id.
void AddVisual(VisualPtr _vis)
Add a visual to the scene.
void Init()
Init rendering::Scene.
void AddLight(LightPtr _light)
Add a light to the scene.
VisualPtr ModelVisualAt(CameraPtr _camera, const ignition::math::Vector2i &_mousePos)
Get a model's visual at a mouse position.
uint32_t LightCount() const
Get the count of the lights.
void SetSkyXMode(const unsigned int _mode)
Set SkyX mode to enable/disable skyx components such as clouds and moon.
void ToggleLayer(const int32_t _layer)
Toggle layer visilibility.
VisualPtr VisualAt(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, std::string &_mod)
Get an entity at a pixel location using a camera.
void EnableVisualizations(const bool _enable)
Enable visualizations, currently only applies to sensor visuals.
void CreateGrid(const uint32_t _cellCount, const float _cellLength, const ignition::math::Color &_color)
Create a square grid of cells.
unsigned int ShadowTextureSize() const
Get the shadow texture size.
double HeightmapSkirtLength() const
Get the skirt length value for the heightmap LOD tiles.
void SelectVisual(const std::string &_name, const std::string &_mode)
Select a visual by name.
void RemoveVisual(const uint32_t _id)
Remove a visual from the scene.
void ShowSkeleton(const bool _show)
Enable or disable skeleton visualization.
std::string Name() const
Get the name of the scene.
bool ShowClouds() const
Get whether or not clouds are displayed.
void ShowOrigin(const bool _show)
Show/hide the world origin indicator.
bool SetShadowTextureSize(const unsigned int _size)
Set the shadow texture size.
void ShowCOMs(const bool _show)
Enable or disable center of mass visualization.
VisualPtr SelectedVisual() const
Get the currently selected visual.
void SetHeightmapLOD(const unsigned int _value)
Set the Level Of Detail (LOD) value for the heightmap.
unsigned int HeightmapLOD() const
Get the Level Of Detail (LOD) value for the heightmap.
void ShowCollisions(const bool _show)
Enable or disable collision visualization.
void RemoveLight(LightPtr _light)
Remove a light to the scene.
LightPtr LightByName(const std::string &_name) const
Get a light by name.
void SetHeightmapSkirtLength(const double _value)
Set the skirt length value for the heightmap LOD tiles.
void Load(sdf::ElementPtr _scene)
Load the scene from a set of parameters.
void ShowContacts(const bool _show)
Enable or disable contact visualization.
uint32_t CameraCount() const
Get the number of cameras in this scene.
Ogre::SceneManager * OgreSceneManager() const
Get the OGRE scene manager.
LightPtr LightByIndex(const uint32_t _index) const
Get a light based on an index.
bool HasLayer(const int32_t _layer) const
Return true if the layer exits.
void ShowJoints(const bool _show)
Enable or disable joint visualization.
CameraPtr GetCamera(const uint32_t _index) const
Get a camera based on an index.
void SetBackgroundColor(const ignition::math::Color &_color)
Set the background color.
void SetFog(const std::string &_type, const ignition::math::Color &_color, const double _density, const double _start, const double _end)
Set the fog parameters.
uint32_t UserCameraCount() const
Get the number of user cameras in this scene.
bool LayerState(const int32_t _layer) const
Return whether a layer is on or off.
LightPtr GetLight(const uint32_t _index) const GAZEBO_DEPRECATED(9.1)
Get a light based on an index.
uint32_t GridCount() const
Get the number of grids.
void RemoveCamera(const std::string &_name)
Remove a camera from the scene.
void PreRender()
Process all received messages.
void DrawLine(const ignition::math::Vector3d &_start, const ignition::math::Vector3d &_end, const std::string &_name)
Draw a named line.
SkyX::SkyX * GetSkyX() const
Get the sky in the scene.
bool ShadowsEnabled() const
Get whether shadows are on or off.
void ShowInertias(const bool _show)
Enable or disable inertia visualization.
Scene(const std::string &_name, const bool _enableVisualizations=false, const bool _isServer=false)
Constructor.
void Clear()
Clear rendering::Scene.
VisualPtr GetVisual(const uint32_t _id) const
Get a visual by id.
void SetGrid(const bool _enabled)
Set the grid on or off.
void ShowClouds(const bool _show)
Display clouds in the sky.
Grid * GetGrid(uint32_t _index) const
Get a grid based on an index.
VisualPtr VisualAt(CameraPtr _camera, const ignition::math::Vector2i &_mousePos)
Get a visual at a mouse position.
VisualPtr WorldVisual() const
Get the top level world visual.
UserCameraPtr CreateUserCamera(const std::string &_name, const bool _stereoEnabled=false)
Create a user camera.
void SetVisible(const std::string &_name, const bool _visible)
Hide or show a visual.
virtual ~Scene()
Destructor.
WideAngleCameraPtr CreateWideAngleCamera(const std::string &_name, const bool _autoRender=true)
Create a wide-angle camera.
void SetWireframe(const bool _show)
Enable or disable wireframe for all visuals.
CameraPtr CreateCamera(const std::string &_name, const bool _autoRender=true)
Create a camera.
GpuLaserPtr CreateGpuLaser(const std::string &_name, const bool _autoRender=true)
Create laser that generates data from rendering.
void SnapVisualToNearestBelow(const std::string &_visualName)
Move the visual to be ontop of the nearest visual below it.
void PrintSceneGraph()
Print the scene graph to std_out.
void RemoveProjectors()
Remove all projectors.
void VisualsBelowPoint(const ignition::math::Vector3d &_pt, std::vector< VisualPtr > &_visuals)
Get a visual directly below a point.
double HeightBelowPoint(const ignition::math::Vector3d &_pt)
Get the Z-value of the first object below the given point.
ignition::math::Color AmbientColor() const
Get the ambient color.
UserCameraPtr GetUserCamera(const uint32_t _index) const
Get a user camera by index.
uint32_t Id() const
Get the scene ID.
void RemoveVisual(VisualPtr _vis)
Remove a visual from the scene.
std::string StripSceneName(const std::string &_name) const
Remove the name of scene from a string.
void SetAmbientColor(const ignition::math::Color &_color)
Set the ambient color.
void Load()
Load the scene with default parameters.
bool Initialized() const
Return true if the Scene has been initialized.
std::string IdString() const
Get the scene Id as a string.
void SetShadowsEnabled(const bool _value)
Set whether shadows are on or off.
common::Time SimTime() const
Get the scene simulation time.
DepthCameraPtr CreateDepthCamera(const std::string &_name, const bool _autoRender=true)
Create depth camera.
void SetTransparent(const bool _show)
Enable or disable transparency for all visuals.
CameraPtr GetCamera(const std::string &_name) const
Get a camera by name.
bool Wireframe() const
Get whether wireframe is enabled for all visuals.
VisualPtr GetVisual(const std::string &_name) const
Get a visual by name.
VisualPtr VisualBelow(const std::string &_visualName)
Get the closest visual below a given visual.
bool EnableVisualizations() const
Check whether visualizations are enabled or not.
void SetVisualId(VisualPtr _vis, const uint32_t _id)
void ShowLinkFrames(const bool _show)
Enable or disable link frame visualization.
bool FirstContact(CameraPtr _camera, const ignition::math::Vector2i &_mousePos, ignition::math::Vector3d &_position)
Get the world pos of a the first contact at a pixel location.
SkyXMode
Definition: Scene.hh:103
@ GZ_SKYX_CLOUDS
Definition: Scene.hh:105
@ GZ_SKYX_MOON
Definition: Scene.hh:106
@ GZ_SKYX_NONE
Definition: Scene.hh:107
@ GZ_SKYX_ALL
Definition: Scene.hh:104
VisualType
Type of visual.
Definition: Visual.hh:65
@ VT_ENTITY
Entity visual.
Definition: Visual.hh:67
Definition: JointMaker.hh:40
Definition: Scene.hh:43
boost::shared_ptr< Light > LightPtr
Definition: RenderTypes.hh:86
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
boost::shared_ptr< DepthCamera > DepthCameraPtr
Definition: RenderTypes.hh:98
boost::shared_ptr< Camera > CameraPtr
Definition: RenderTypes.hh:90
boost::shared_ptr< WideAngleCamera > WideAngleCameraPtr
Definition: RenderTypes.hh:102
boost::shared_ptr< UserCamera > UserCameraPtr
Definition: RenderTypes.hh:94
boost::shared_ptr< GpuLaser > GpuLaserPtr
Definition: RenderTypes.hh:106
Forward declarations for the common classes.
Definition: Animation.hh:27
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:328