Visual.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2012 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#ifndef GAZEBO_RENDERING_VISUAL_HH_
18#define GAZEBO_RENDERING_VISUAL_HH_
19
20#include <boost/enable_shared_from_this.hpp>
21#include <boost/function.hpp>
22#include <string>
23#include <utility>
24#include <vector>
25
26#include <sdf/sdf.hh>
27#include <ignition/math/Box.hh>
28#include <ignition/math/Color.hh>
29#include <ignition/math/Pose3.hh>
30#include <ignition/math/Quaternion.hh>
31#include <ignition/math/Vector3.hh>
32#include <ignition/msgs/MessageTypes.hh>
33
34#include "gazebo/common/Mesh.hh"
35#include "gazebo/common/Time.hh"
36
37#include "gazebo/msgs/MessageTypes.hh"
38
40#include "gazebo/util/system.hh"
41
42namespace Ogre
43{
44 class MovableObject;
45 class SceneNode;
46}
47
48namespace gazebo
49{
50 namespace rendering
51 {
52 class VisualPrivate;
53
56
59 class GZ_RENDERING_VISIBLE Visual :
60 public std::enable_shared_from_this<Visual>
61 {
83
89 public: Visual(const std::string &_name, VisualPtr _parent,
90 bool _useRTShader = true);
91
97 public: Visual(const std::string &_name, ScenePtr _scene,
98 bool _useRTShader = true);
99
101 public: virtual ~Visual();
102
104 public: void Init();
105
107 public: virtual void Fini();
108
113 public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
114
117 public: void LoadFromMsg(ConstVisualPtr &_msg);
118
121 public: void Load(sdf::ElementPtr _sdf);
122
124 public: virtual void Load();
125
127 public: void Update();
128
135 public: sdf::ElementPtr GetSDF() const;
136
139 public: void SetName(const std::string &_name);
140
143 public: std::string Name() const;
144
147 public: void AttachVisual(VisualPtr _vis);
148
151 public: void DetachVisual(VisualPtr _vis);
152
155 public: void DetachVisual(const std::string &_name);
156
159 public: void AttachObject(Ogre::MovableObject *_obj);
160
163 public: bool HasAttachedObject(const std::string &_name);
164
167 public: unsigned int GetAttachedObjectCount() const;
168
170 public: void DetachObjects();
171
174 public: unsigned int GetChildCount();
175
180 public: VisualPtr GetChild(unsigned int _index);
181
189 public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
190 const std::string &_subMesh="",
191 bool _centerSubmesh = false,
192 const std::string &_objName="");
193
196 public: void SetScale(const ignition::math::Vector3d &_scale);
197
200 public: ignition::math::Vector3d Scale() const;
201
204 public: ignition::math::Vector3d DerivedScale() const;
205
208 public: bool GetLighting() const;
209
212 public: void SetLighting(bool _lighting);
213
220 public: void SetMaterial(const std::string &_materialName,
221 bool _unique = true, const bool _cascade = true);
222
232 public: void SetMaterialShaderParam(const std::string &_paramName,
233 const std::string &_shaderType, const std::string &_value);
234
238 public: void SetAmbient(const ignition::math::Color &_color,
239 const bool _cascade = true);
240
244 public: void SetDiffuse(const ignition::math::Color &_color,
245 const bool _cascade = true);
246
250 public: void SetSpecular(const ignition::math::Color &_color,
251 const bool _cascade = true);
252
256 public: virtual void SetEmissive(const ignition::math::Color &_color,
257 const bool _cascade = true);
258
261 public: ignition::math::Color Ambient() const;
262
265 public: ignition::math::Color Diffuse() const;
266
269 public: ignition::math::Color Specular() const;
270
273 public: ignition::math::Color Emissive() const;
274
277 public: void SetWireframe(bool _show);
278
281 public: bool Wireframe() const;
282
286 private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
287
291 public: void SetTransparency(float _trans);
292
295 public: float GetTransparency();
296
300 public: float DerivedTransparency() const;
301
304 public: void SetInheritTransparency(const bool _inherit);
305
308 public: bool InheritTransparency() const;
309
313 public: virtual void SetHighlighted(bool _highlighted);
314
318 public: bool GetHighlighted() const;
319
322 public: bool GetCastShadows() const;
323
326 public: void SetCastShadows(bool _shadows);
327
331 public: virtual void SetVisible(bool _visible, bool _cascade = true);
332
334 public: void ToggleVisible();
335
338 public: bool GetVisible() const;
339
342 public: void SetPosition(const ignition::math::Vector3d &_pos);
343
346 public: void SetRotation(const ignition::math::Quaterniond &_rot);
347
350 public: void SetPose(const ignition::math::Pose3d &_pose);
351
354 public: ignition::math::Vector3d Position() const;
355
358 public: ignition::math::Quaterniond Rotation() const;
359
362 public: ignition::math::Pose3d Pose() const;
363
366 public: ignition::math::Pose3d InitialRelativePose() const;
367
370 public: ignition::math::Pose3d WorldPose() const;
371
374 public: void SetWorldPose(const ignition::math::Pose3d &_pose);
375
378 public: void SetWorldPosition(const ignition::math::Vector3d &_pos);
379
382 public: void SetWorldRotation(const ignition::math::Quaterniond &_rot);
383
386 public: Ogre::SceneNode *GetSceneNode() const;
387
389 public: void MakeStatic();
390
393 public: bool IsStatic() const;
394
397 public: void EnableTrackVisual(VisualPtr _vis);
398
400 public: void DisableTrackVisual();
401
404 public: std::string GetNormalMap() const;
405
408 public: void SetNormalMap(const std::string &_nmap);
409
414 public: void SetRibbonTrail(bool _value,
415 const ignition::math::Color &_initialColor,
416 const ignition::math::Color &_changeColor);
417
420 public: ignition::math::Box BoundingBox() const;
421
426 RenderOpType _type = RENDERING_LINE_STRIP);
427
430 public: void DeleteDynamicLine(DynamicLines *_line);
431
435 public: void AttachLineVertex(DynamicLines *_line,
436 unsigned int _index);
437
440 public: std::string GetMaterialName() const;
441
446 public: void InsertMesh(const std::string &_meshName,
447 const std::string &_subMesh = "",
448 bool _centerSubmesh = false);
449
454 public: static void InsertMesh(const common::Mesh *_mesh,
455 const std::string &_subMesh = "",
456 bool _centerSubmesh = false);
457
460 public: void UpdateFromMsg(ConstVisualPtr &_msg);
461
464 public: bool IsPlane() const;
465
468 public: VisualPtr GetParent() const;
469
474
481 public: VisualPtr GetNthAncestor(unsigned int _n);
482
486 public: bool IsAncestorOf(const rendering::VisualPtr _visual) const;
487
491 public: bool IsDescendantOf(const rendering::VisualPtr _visual) const;
492
496 public: unsigned int GetDepth() const;
497
501 public: std::string GetShaderType() const;
502
506 public: void SetShaderType(const std::string &_type);
507
511 public: void MoveToPosition(const ignition::math::Pose3d &_pose,
512 const double _time);
513
518 public: void MoveToPositions(
519 const std::vector<ignition::math::Pose3d> &_pts, const double _time,
520 std::function<void()> _onComplete = nullptr);
521
527 public: void SetVisibilityFlags(uint32_t _flags);
528
534 public: uint32_t GetVisibilityFlags();
535
537 public: void ShowBoundingBox();
538
542 public: void ShowCollision(bool _show);
543
546 public: void ShowSkeleton(bool _show);
547
550 public: void SetScene(ScenePtr _scene);
551
554 public: ScenePtr GetScene() const;
555
558 public: void ShowJoints(bool _show);
559
562 public: void ShowCOM(bool _show);
563
566 public: void ShowInertia(bool _show);
567
570 public: void ShowLinkFrame(bool _show);
571
574 public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
575
580 public: void LoadPlugin(const std::string &_filename,
581 const std::string &_name,
582 sdf::ElementPtr _sdf);
583
586 public: void RemovePlugin(const std::string &_name);
587
589 public: uint32_t GetId() const;
590
592 public: void SetId(uint32_t _id);
593
596 public: std::string GetGeometryType() const;
597
600 public: ignition::math::Vector3d GetGeometrySize() const;
601
604 public: std::string GetMeshName() const;
605
609 public: std::string GetSubMeshName() const;
610
612 public: void ClearParent();
613
617 public: void ToggleLayer(const int32_t _layer);
618
621 public: void SetLayer(const int32_t _layer);
622
626
629 public: void SetType(const Visual::VisualType _type);
630
633 public: bool UseRTShader() const;
634
638 public: void SetTypeMsg(const google::protobuf::Message *_msg);
639
644 public: void AddPendingChild(std::pair<VisualType,
645 const google::protobuf::Message *> _pair);
646
651 const msgs::Visual::Type &_type);
652
656 public: static msgs::Visual::Type ConvertVisualType(
657 const Visual::VisualType &_type);
658
662 public: void FillMaterialMsg(ignition::msgs::Material &_msg) const;
663
671 protected: Visual(VisualPrivate &_dataPtr,
672 const std::string &_name, VisualPtr _parent,
673 bool _useRTShader = true);
674
682 protected: Visual(VisualPrivate &_dataPtr,
683 const std::string &_name, ScenePtr _scene,
684 bool _useRTShader = true);
685
688 protected: void ProcessMaterialMsg(const ignition::msgs::Material &_msg);
689
696 private: void Init(const std::string &_name, ScenePtr _scene,
697 bool _useRTShader);
698
705 private: void Init(const std::string &_name, VisualPtr _parent,
706 bool _useRTShader);
707
710 private: void LoadPlugins();
711
712 private: void LoadPlugin(sdf::ElementPtr _sdf);
713
717 private: void BoundsHelper(Ogre::SceneNode *_node,
718 ignition::math::Box &_box) const;
719
723 private: bool GetCenterSubMesh() const;
724
727 private: void DestroyAllAttachedMovableObjects(
728 Ogre::SceneNode *_sceneNode);
729
733 private: void UpdateGeomSize(const ignition::math::Vector3d &_scale);
734
737 private: void UpdateTransparency(const bool _cascade = true);
738
741 protected: VisualPrivate *dataPtr;
742 };
744 }
745}
746#endif
rendering
Definition RenderEngine.hh:31
A 3D mesh.
Definition Mesh.hh:43
Class for drawing lines that can change.
Definition DynamicLines.hh:43
A renderable object.
Definition Visual.hh:61
void SetRibbonTrail(bool _value, const ignition::math::Color &_initialColor, const ignition::math::Color &_changeColor)
True on or off a ribbon trail.
bool GetVisible() const
Get whether the visual is visible.
ignition::math::Color Diffuse() const
Get the diffuse color of the visual.
std::string GetMaterialName() const
Get the name of the material.
virtual void SetEmissive(const ignition::math::Color &_color, const bool _cascade=true)
Set the emissive value.
void UpdateFromMsg(ConstVisualPtr &_msg)
Update a visual based on a message.
void SetId(uint32_t _id)
Set the id associated with this visual.
void SetWorldPose(const ignition::math::Pose3d &_pose)
Set the world pose of the visual.
void SetName(const std::string &_name)
Set the name of the visual.
std::string GetShaderType() const
Get the shader type.
Visual(VisualPrivate &_dataPtr, const std::string &_name, VisualPtr _parent, bool _useRTShader=true)
void SetMaterial(const std::string &_materialName, bool _unique=true, const bool _cascade=true)
Set the material.
void DetachObjects()
Detach all objects.
unsigned int GetDepth() const
Get the depth of this visual, where 0 is the depth of the world visual.
void DetachVisual(const std::string &_name)
Detach a visual.
void Init()
Helper for the contructor.
void MakeStatic()
Make the visual objects static renderables.
VisualPtr GetParent() const
Get the parent visual, if one exists.
VisualPtr Clone(const std::string &_name, VisualPtr _newParent)
Clone the visual with a new name.
void ToggleLayer(const int32_t _layer)
Toggle layer visibility.
void AttachVisual(VisualPtr _vis)
Attach a visual to this visual.
bool HasAttachedObject(const std::string &_name)
Returns true if an object with _name is attached.
uint32_t GetVisibilityFlags()
Get visibility flags for this visual and all children.
virtual void Fini()
Helper for the destructor.
DynamicLines * CreateDynamicLine(RenderOpType _type=RENDERING_LINE_STRIP)
Add a line to the visual.
ignition::math::Pose3d InitialRelativePose() const
Get the initial relative pose of the visual.
VisualPtr GetRootVisual()
Get the root visual.
bool IsAncestorOf(const rendering::VisualPtr _visual) const
Check if this visual is an ancestor of another visual.
static Visual::VisualType ConvertVisualType(const msgs::Visual::Type &_type)
Convert from msgs::Visual::Type to VisualType.
void RemovePlugin(const std::string &_name)
Remove a running plugin.
virtual ~Visual()
Destructor.
ignition::math::Color Emissive() const
Get the emissive color of the visual.
ignition::math::Vector3d DerivedScale() const
Get the scale of the visual as inherited from all parents.
std::string Name() const
Get the name of the visual.
void ShowInertia(bool _show)
Display inertia visuals.
sdf::ElementPtr GetSDF() const
Get the visual SDF.
void ShowLinkFrame(bool _show)
Display link frame visuals.
ignition::math::Vector3d GetGeometrySize() const
Get the geometry size.
void SetDiffuse(const ignition::math::Color &_color, const bool _cascade=true)
Set the diffuse color of the visual.
void SetCastShadows(bool _shadows)
Set whether the visual should cast shadows.
ignition::math::Vector3d Position() const
Get the position of the visual.
void SetLighting(bool _lighting)
Set whether or not to enable or disable lighting.
void SetScene(ScenePtr _scene)
Set current scene.
void DetachVisual(VisualPtr _vis)
Detach a visual.
std::string GetNormalMap() const
Get the normal map.
Visual(const std::string &_name, ScenePtr _scene, bool _useRTShader=true)
Constructor.
void SetRotation(const ignition::math::Quaterniond &_rot)
Set the rotation of the visual.
virtual void Load()
Load the visual with default parameters.
void DeleteDynamicLine(DynamicLines *_line)
Delete a dynamic line.
void SetAmbient(const ignition::math::Color &_color, const bool _cascade=true)
Set the ambient color of the visual.
void SetWorldPosition(const ignition::math::Vector3d &_pos)
Set the world linear position of the visual.
ScenePtr GetScene() const
Get current.
bool UseRTShader() const
Get whether this visual uses RT shader system.
void SetSpecular(const ignition::math::Color &_color, const bool _cascade=true)
Set the specular color of the visual.
void AttachObject(Ogre::MovableObject *_obj)
Attach a renerable object to the visual.
void AddPendingChild(std::pair< VisualType, const google::protobuf::Message * > _pair)
Push a message for a child of this visual which hasn't been loaded yet.
void ShowSkeleton(bool _show)
Display the skeleton visuals.
ignition::math::Color Specular() const
Get the specular color of the visual.
void SetTypeMsg(const google::protobuf::Message *_msg)
Set a message specific for this visual type.
void LoadFromMsg(ConstVisualPtr &_msg)
Load from a message.
bool IsPlane() const
Return true if the visual is a plane.
bool IsStatic() const
Return true if the visual is a static geometry.
std::string GetGeometryType() const
Get the geometry type.
bool GetHighlighted() const
Get whether or not the visual is visually highlighted.
Ogre::SceneNode * GetSceneNode() const
Return the scene Node of this visual entity.
void ToggleVisible()
Toggle whether this visual is visible.
VisualPtr GetChild(unsigned int _index)
Get an attached visual based on an index.
static msgs::Visual::Type ConvertVisualType(const Visual::VisualType &_type)
Convert from msgs::Visual::Type to VisualType.
void SetWireframe(bool _show)
Enable or disable wireframe for this visual.
static void InsertMesh(const common::Mesh *_mesh, const std::string &_subMesh="", bool _centerSubmesh=false)
Insert a mesh into Ogre.
void EnableTrackVisual(VisualPtr _vis)
Set one visual to track/follow another.
void SetMaterialShaderParam(const std::string &_paramName, const std::string &_shaderType, const std::string &_value)
Set a shader program parameter associated to this visual's material.
void ShowCOM(bool _show)
Display Center of Mass visuals.
void AttachLineVertex(DynamicLines *_line, unsigned int _index)
Attach a vertex of a line to the position of the visual.
void SetShaderType(const std::string &_type)
Set the shader type for the visual's material.
virtual void SetHighlighted(bool _highlighted)
Set the visual to be visually highlighted.
void SetNormalMap(const std::string &_nmap)
Set the normal map.
Ogre::MovableObject * AttachMesh(const std::string &_meshName, const std::string &_subMesh="", bool _centerSubmesh=false, const std::string &_objName="")
Attach a mesh to this visual by name.
VisualPrivate * dataPtr
Definition Visual.hh:741
unsigned int GetAttachedObjectCount() const
Return the number of attached movable objects.
ignition::math::Box BoundingBox() const
Get the bounding box for the visual.
void DisableTrackVisual()
Disable tracking of a visual.
ignition::math::Quaterniond Rotation() const
Get the rotation of the visual.
Visual(const std::string &_name, VisualPtr _parent, bool _useRTShader=true)
Constructor.
ignition::math::Pose3d WorldPose() const
Get the global pose of the visual.
VisualType
Type of visual.
Definition Visual.hh:65
@ VT_COLLISION
Collision visual.
Definition Visual.hh:75
@ VT_MODEL
Model visual.
Definition Visual.hh:69
@ VT_SENSOR
Sensor visual.
Definition Visual.hh:77
@ VT_GUI
GUI visual.
Definition Visual.hh:79
@ VT_VISUAL
Visual visual.
Definition Visual.hh:73
@ VT_LINK
Link visual.
Definition Visual.hh:71
@ VT_ENTITY
Entity visual.
Definition Visual.hh:67
@ VT_PHYSICS
Physics data visual.
Definition Visual.hh:81
bool InheritTransparency() const
Get whether this visual inherits transparency from parent.
ignition::math::Pose3d Pose() const
Get the pose of the visual.
unsigned int GetChildCount()
Get the number of attached visuals.
void SetVisibilityFlags(uint32_t _flags)
Set visibility flags for this visual and all children.
void SetTransparency(float _trans)
Set the transparency.
void LoadPlugin(const std::string &_filename, const std::string &_name, sdf::ElementPtr _sdf)
Load a plugin.
void MoveToPositions(const std::vector< ignition::math::Pose3d > &_pts, const double _time, std::function< void()> _onComplete=nullptr)
Move to a series of pose and over a given time.
void SetWorldRotation(const ignition::math::Quaterniond &_rot)
Set the world orientation of the visual.
void SetInheritTransparency(const bool _inherit)
Set whether to inherit transparency from parent.
uint32_t GetId() const
Get the id associated with this visual.
bool GetCastShadows() const
Get whether the visual casts shadows.
void SetType(const Visual::VisualType _type)
Set type of visual.
bool IsDescendantOf(const rendering::VisualPtr _visual) const
Check if this visual is a descendant of another visual.
void MoveToPosition(const ignition::math::Pose3d &_pose, const double _time)
Move to a pose and over a given time.
void Load(sdf::ElementPtr _sdf)
Load the visual with a set of parameters.
void ShowBoundingBox()
Display the bounding box visual.
bool GetLighting() const
Get whether or not lighting is enabled.
void ShowCollision(bool _show)
Display the collision visuals.
void FillMaterialMsg(ignition::msgs::Material &_msg) const
Fill an ignition::msgs::Material message based on this visual's material properties.
void InsertMesh(const std::string &_meshName, const std::string &_subMesh="", bool _centerSubmesh=false)
Insert a mesh into Ogre.
ignition::math::Vector3d Scale() const
Get the scale.
float DerivedTransparency() const
Get the transparency of the visual as inherited from all parents.
void SetPose(const ignition::math::Pose3d &_pose)
Set the pose of the visual.
std::string GetMeshName() const
The name of the mesh set in the visual's SDF.
void Update()
Update the visual.
VisualPtr GetNthAncestor(unsigned int _n)
Get the nth ancestor counting from the world visual.
Visual(VisualPrivate &_dataPtr, const std::string &_name, ScenePtr _scene, bool _useRTShader=true)
Visual::VisualType GetType() const
Get type of visual.
bool Wireframe() const
Get whether wireframe is enabled for this visual.
void SetSkeletonPose(const msgs::PoseAnimation &_pose)
Set animation skeleton pose.
void SetPosition(const ignition::math::Vector3d &_pos)
Set the position of the visual.
void SetLayer(const int32_t _layer)
Set the layer this visual belongs to.
void ProcessMaterialMsg(const ignition::msgs::Material &_msg)
Process a material message.
float GetTransparency()
Get the transparency.
void ClearParent()
Clear parents.
ignition::math::Color Ambient() const
Get the ambient color of the visual.
void SetScale(const ignition::math::Vector3d &_scale)
Set the scale.
std::string GetSubMeshName() const
Get the name of the sub mesh set in the visual's SDF.
virtual void SetVisible(bool _visible, bool _cascade=true)
Set whether the visual is visible.
void ShowJoints(bool _show)
Display joint visuals.
Definition JointMaker.hh:40
std::shared_ptr< Visual > VisualPtr
Definition RenderTypes.hh:114
RenderOpType
Type of render operation for a drawable.
Definition RenderTypes.hh:217
@ RENDERING_LINE_STRIP
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition RenderTypes.hh:226
boost::shared_ptr< Scene > ScenePtr
Definition RenderTypes.hh:82
Forward declarations for the common classes.
Definition Animation.hh:27