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/Pose3.hh>
29 #include <ignition/math/Quaternion.hh>
30 #include <ignition/math/Vector3.hh>
31 #include <ignition/msgs/MessageTypes.hh>
32 
33 #include "gazebo/common/Color.hh"
34 #include "gazebo/common/Mesh.hh"
35 #include "gazebo/common/Time.hh"
36 
37 #include "gazebo/msgs/MessageTypes.hh"
38 #include "gazebo/math/Box.hh"
39 #include "gazebo/math/Pose.hh"
41 #include "gazebo/math/Vector3.hh"
42 
44 #include "gazebo/util/system.hh"
45 
46 namespace Ogre
47 {
48  class MovableObject;
49  class SceneNode;
50 }
51 
52 namespace gazebo
53 {
54  namespace rendering
55  {
56  class VisualPrivate;
57 
60 
63  class GZ_RENDERING_VISIBLE Visual :
64  public std::enable_shared_from_this<Visual>
65  {
68  public: enum VisualType
69  {
85  VT_PHYSICS
86  };
87 
93  public: Visual(const std::string &_name, VisualPtr _parent,
94  bool _useRTShader = true);
95 
101  public: Visual(const std::string &_name, ScenePtr _scene,
102  bool _useRTShader = true);
103 
105  public: virtual ~Visual();
106 
108  public: void Init();
109 
111  public: virtual void Fini();
112 
117  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
118 
121  public: void LoadFromMsg(ConstVisualPtr &_msg);
122 
125  public: void Load(sdf::ElementPtr _sdf);
126 
128  public: virtual void Load();
129 
131  public: void Update();
132 
139  public: sdf::ElementPtr GetSDF() const;
140 
143  public: void SetName(const std::string &_name);
144 
148  public: std::string GetName() const GAZEBO_DEPRECATED(8.0);
149 
152  public: std::string Name() const;
153 
156  public: void AttachVisual(VisualPtr _vis);
157 
160  public: void DetachVisual(VisualPtr _vis);
161 
164  public: void DetachVisual(const std::string &_name);
165 
168  public: void AttachObject(Ogre::MovableObject *_obj);
169 
172  public: bool HasAttachedObject(const std::string &_name);
173 
176  public: unsigned int GetAttachedObjectCount() const;
177 
179  public: void DetachObjects();
180 
183  public: unsigned int GetChildCount();
184 
189  public: VisualPtr GetChild(unsigned int _index);
190 
198  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
199  const std::string &_subMesh="",
200  bool _centerSubmesh = false,
201  const std::string &_objName="");
202 
206  public: void SetScale(const math::Vector3 &_scale) GAZEBO_DEPRECATED(8.0);
207 
210  public: void SetScale(const ignition::math::Vector3d &_scale);
211 
215  public: math::Vector3 GetScale() GAZEBO_DEPRECATED(8.0);
216 
219  public: ignition::math::Vector3d Scale() const;
220 
223  public: ignition::math::Vector3d DerivedScale() const;
224 
227  public: bool GetLighting() const;
228 
231  public: void SetLighting(bool _lighting);
232 
239  public: void SetMaterial(const std::string &_materialName,
240  bool _unique = true, const bool _cascade = true);
241 
251  public: void SetMaterialShaderParam(const std::string &_paramName,
252  const std::string &_shaderType, const std::string &_value);
253 
257  public: void SetAmbient(const common::Color &_color,
258  const bool _cascade = true);
259 
263  public: void SetDiffuse(const common::Color &_color,
264  const bool _cascade = true);
265 
269  public: void SetSpecular(const common::Color &_color,
270  const bool _cascade = true);
271 
275  public: virtual void SetEmissive(const common::Color &_color,
276  const bool _cascade = true);
277 
280  public: common::Color GetAmbient() const;
281 
284  public: common::Color GetDiffuse() const;
285 
288  public: common::Color GetSpecular() const;
289 
292  public: common::Color GetEmissive() const;
293 
296  public: void SetWireframe(bool _show);
297 
300  public: bool Wireframe() const;
301 
305  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
306 
310  public: void SetTransparency(float _trans);
311 
314  public: float GetTransparency();
315 
319  public: float DerivedTransparency() const;
320 
323  public: void SetInheritTransparency(const bool _inherit);
324 
327  public: bool InheritTransparency() const;
328 
332  public: virtual void SetHighlighted(bool _highlighted);
333 
337  public: bool GetHighlighted() const;
338 
341  public: bool GetCastShadows() const;
342 
345  public: void SetCastShadows(bool _shadows);
346 
350  public: virtual void SetVisible(bool _visible, bool _cascade = true);
351 
353  public: void ToggleVisible();
354 
357  public: bool GetVisible() const;
358 
362  public: void SetPosition(const math::Vector3 &_pos)
363  GAZEBO_DEPRECATED(8.0);
364 
367  public: void SetPosition(const ignition::math::Vector3d &_pos);
368 
372  public: void SetRotation(const math::Quaternion &_rot)
373  GAZEBO_DEPRECATED(8.0);
374 
377  public: void SetRotation(const ignition::math::Quaterniond &_rot);
378 
382  public: void SetPose(const math::Pose &_pose) GAZEBO_DEPRECATED(8.0);
383 
386  public: void SetPose(const ignition::math::Pose3d &_pose);
387 
391  public: math::Vector3 GetPosition() const GAZEBO_DEPRECATED(8.0);
392 
395  public: ignition::math::Vector3d Position() const;
396 
400  public: math::Quaternion GetRotation() const GAZEBO_DEPRECATED(8.0);
401 
404  public: ignition::math::Quaterniond Rotation() const;
405 
409  public: math::Pose GetPose() const GAZEBO_DEPRECATED(8.0);
410 
414  public: ignition::math::Pose3d Pose() const;
415 
418  public: ignition::math::Pose3d InitialRelativePose() const;
419 
423  public: math::Pose GetWorldPose() const GAZEBO_DEPRECATED(8.0);
424 
427  public: ignition::math::Pose3d WorldPose() const;
428 
432  public: void SetWorldPose(const math::Pose &_pose) GAZEBO_DEPRECATED(8.0);
433 
436  public: void SetWorldPose(const ignition::math::Pose3d &_pose);
437 
441  public: void SetWorldPosition(const math::Vector3 &_pos)
442  GAZEBO_DEPRECATED(8.0);
443 
446  public: void SetWorldPosition(const ignition::math::Vector3d &_pos);
447 
451  public: void SetWorldRotation(const math::Quaternion &_rot)
452  GAZEBO_DEPRECATED(8.0);
453 
456  public: void SetWorldRotation(const ignition::math::Quaterniond &_rot);
457 
460  public: Ogre::SceneNode *GetSceneNode() const;
461 
463  public: void MakeStatic();
464 
467  public: bool IsStatic() const;
468 
471  public: void EnableTrackVisual(VisualPtr _vis);
472 
474  public: void DisableTrackVisual();
475 
478  public: std::string GetNormalMap() const;
479 
482  public: void SetNormalMap(const std::string &_nmap);
483 
488  public: void SetRibbonTrail(bool _value,
489  const common::Color &_initialColor,
490  const common::Color &_changeColor);
491 
495  public: math::Box GetBoundingBox() const GAZEBO_DEPRECATED(8.0);
496 
499  public: ignition::math::Box BoundingBox() const;
500 
504  public: DynamicLines *CreateDynamicLine(
506 
509  public: void DeleteDynamicLine(DynamicLines *_line);
510 
514  public: void AttachLineVertex(DynamicLines *_line,
515  unsigned int _index);
516 
519  public: std::string GetMaterialName() const;
520 
525  public: void InsertMesh(const std::string &_meshName,
526  const std::string &_subMesh = "",
527  bool _centerSubmesh = false);
528 
533  public: static void InsertMesh(const common::Mesh *_mesh,
534  const std::string &_subMesh = "",
535  bool _centerSubmesh = false);
536 
539  public: void UpdateFromMsg(ConstVisualPtr &_msg);
540 
543  public: bool IsPlane() const;
544 
547  public: VisualPtr GetParent() const;
548 
552  public: VisualPtr GetRootVisual();
553 
560  public: VisualPtr GetNthAncestor(unsigned int _n);
561 
565  public: bool IsAncestorOf(const rendering::VisualPtr _visual) const;
566 
570  public: bool IsDescendantOf(const rendering::VisualPtr _visual) const;
571 
575  public: unsigned int GetDepth() const;
576 
580  public: std::string GetShaderType() const;
581 
585  public: void SetShaderType(const std::string &_type);
586 
591  public: void MoveToPosition(const math::Pose &_pose, double _time)
592  GAZEBO_DEPRECATED(8.0);
593 
597  public: void MoveToPosition(const ignition::math::Pose3d &_pose,
598  const double _time);
599 
605  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
606  double _time,
607  std::function<void()> _onComplete = nullptr)
608  GAZEBO_DEPRECATED(8.0);
609 
614  public: void MoveToPositions(
615  const std::vector<ignition::math::Pose3d> &_pts, const double _time,
616  std::function<void()> _onComplete = nullptr);
617 
623  public: void SetVisibilityFlags(uint32_t _flags);
624 
630  public: uint32_t GetVisibilityFlags();
631 
633  public: void ShowBoundingBox();
634 
638  public: void ShowCollision(bool _show);
639 
642  public: void ShowSkeleton(bool _show);
643 
646  public: void SetScene(ScenePtr _scene);
647 
650  public: ScenePtr GetScene() const;
651 
654  public: void ShowJoints(bool _show);
655 
658  public: void ShowCOM(bool _show);
659 
662  public: void ShowInertia(bool _show);
663 
666  public: void ShowLinkFrame(bool _show);
667 
670  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
671 
676  public: void LoadPlugin(const std::string &_filename,
677  const std::string &_name,
678  sdf::ElementPtr _sdf);
679 
682  public: void RemovePlugin(const std::string &_name);
683 
685  public: uint32_t GetId() const;
686 
688  public: void SetId(uint32_t _id);
689 
692  public: std::string GetGeometryType() const;
693 
696  public: ignition::math::Vector3d GetGeometrySize() const;
697 
700  public: std::string GetMeshName() const;
701 
705  public: std::string GetSubMeshName() const;
706 
708  public: void ClearParent();
709 
713  public: void ToggleLayer(const int32_t _layer);
714 
717  public: void SetLayer(const int32_t _layer);
718 
721  public: Visual::VisualType GetType() const;
722 
725  public: void SetType(const Visual::VisualType _type);
726 
729  public: bool UseRTShader() const;
730 
734  public: void SetTypeMsg(const google::protobuf::Message *_msg);
735 
740  public: void AddPendingChild(std::pair<VisualType,
741  const google::protobuf::Message *> _pair);
742 
746  public: static Visual::VisualType ConvertVisualType(
747  const msgs::Visual::Type &_type);
748 
752  public: static msgs::Visual::Type ConvertVisualType(
753  const Visual::VisualType &_type);
754 
758  public: void FillMaterialMsg(ignition::msgs::Material &_msg) const;
759 
767  protected: Visual(VisualPrivate &_dataPtr,
768  const std::string &_name, VisualPtr _parent,
769  bool _useRTShader = true);
770 
778  protected: Visual(VisualPrivate &_dataPtr,
779  const std::string &_name, ScenePtr _scene,
780  bool _useRTShader = true);
781 
784  protected: void ProcessMaterialMsg(const ignition::msgs::Material &_msg);
785 
792  private: void Init(const std::string &_name, ScenePtr _scene,
793  bool _useRTShader);
794 
801  private: void Init(const std::string &_name, VisualPtr _parent,
802  bool _useRTShader);
803 
806  private: void LoadPlugins();
807 
808  private: void LoadPlugin(sdf::ElementPtr _sdf);
809 
813  private: void BoundsHelper(Ogre::SceneNode *_node,
814  ignition::math::Box &_box) const;
815 
819  private: bool GetCenterSubMesh() const;
820 
823  private: void DestroyAllAttachedMovableObjects(
824  Ogre::SceneNode *_sceneNode);
825 
829  private: void UpdateGeomSize(const ignition::math::Vector3d &_scale);
830 
833  private: void UpdateTransparency(const bool _cascade = true);
834 
837  protected: VisualPrivate *dataPtr;
838  };
840  }
841 }
842 #endif
Class for drawing lines that can change.
Definition: DynamicLines.hh:37
Link visual.
Definition: Visual.hh:75
Forward declarations for the common classes.
Definition: Animation.hh:33
Entity visual.
Definition: Visual.hh:71
STL namespace.
GUI visual.
Definition: Visual.hh:83
A renderable object.
Definition: Visual.hh:63
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:73
VisualType
Type of visual.
Definition: Visual.hh:68
Definition: JointMaker.hh:39
#define GAZEBO_DEPRECATED(version)
Definition: system.hh:302
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:114
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
Definition: ConfigWidget.hh:32
Visual visual.
Definition: Visual.hh:77
Definition: Animation.hh:24
Collision visual.
Definition: Visual.hh:79
Sensor visual.
Definition: Visual.hh:81