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 
42 namespace Ogre
43 {
44  class MovableObject;
45  class SceneNode;
46 }
47 
48 namespace 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  {
64  public: enum VisualType
65  {
81  VT_PHYSICS
82  };
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 
425  public: DynamicLines *CreateDynamicLine(
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 
473  public: VisualPtr GetRootVisual();
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 
625  public: Visual::VisualType GetType() const;
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 
650  public: static Visual::VisualType ConvertVisualType(
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
A 3D mesh.
Definition: Mesh.hh:42
Class for drawing lines that can change.
Definition: DynamicLines.hh:42
Link visual.
Definition: Visual.hh:71
Forward declarations for the common classes.
Definition: Animation.hh:26
VisualPrivate * dataPtr
Definition: Visual.hh:741
Entity visual.
Definition: Visual.hh:67
GUI visual.
Definition: Visual.hh:79
A renderable object.
Definition: Visual.hh:59
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:216
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
Model visual.
Definition: Visual.hh:69
VisualType
Type of visual.
Definition: Visual.hh:64
Definition: JointMaker.hh:39
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Visual visual.
Definition: Visual.hh:73
Collision visual.
Definition: Visual.hh:75
Sensor visual.
Definition: Visual.hh:77