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 
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 
226  public: void SetAmbient(const common::Color &_color,
227  const bool _cascade = true);
228 
232  public: void SetDiffuse(const common::Color &_color,
233  const bool _cascade = true);
234 
238  public: void SetSpecular(const common::Color &_color,
239  const bool _cascade = true);
240 
244  public: virtual void SetEmissive(const common::Color &_color,
245  const bool _cascade = true);
246 
249  public: common::Color GetAmbient() const;
250 
253  public: common::Color GetDiffuse() const;
254 
257  public: common::Color GetSpecular() const;
258 
261  public: common::Color GetEmissive() const;
262 
265  public: void SetWireframe(bool _show);
266 
269  public: bool Wireframe() const;
270 
274  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
275 
279  public: void SetTransparency(float _trans);
280 
283  public: float GetTransparency();
284 
288  public: float DerivedTransparency() const;
289 
292  public: void SetInheritTransparency(const bool _inherit);
293 
296  public: bool InheritTransparency() const;
297 
301  public: virtual void SetHighlighted(bool _highlighted);
302 
306  public: bool GetHighlighted() const;
307 
310  public: bool GetCastShadows() const;
311 
314  public: void SetCastShadows(bool _shadows);
315 
319  public: virtual void SetVisible(bool _visible, bool _cascade = true);
320 
322  public: void ToggleVisible();
323 
326  public: bool GetVisible() const;
327 
330  public: void SetPosition(const ignition::math::Vector3d &_pos);
331 
334  public: void SetRotation(const ignition::math::Quaterniond &_rot);
335 
338  public: void SetPose(const ignition::math::Pose3d &_pose);
339 
342  public: ignition::math::Vector3d Position() const;
343 
346  public: ignition::math::Quaterniond Rotation() const;
347 
350  public: ignition::math::Pose3d Pose() const;
351 
354  public: ignition::math::Pose3d InitialRelativePose() const;
355 
358  public: ignition::math::Pose3d WorldPose() const;
359 
362  public: void SetWorldPose(const ignition::math::Pose3d &_pose);
363 
366  public: void SetWorldPosition(const ignition::math::Vector3d &_pos);
367 
370  public: void SetWorldRotation(const ignition::math::Quaterniond &_rot);
371 
374  public: Ogre::SceneNode *GetSceneNode() const;
375 
377  public: void MakeStatic();
378 
381  public: bool IsStatic() const;
382 
385  public: void EnableTrackVisual(VisualPtr _vis);
386 
388  public: void DisableTrackVisual();
389 
392  public: std::string GetNormalMap() const;
393 
396  public: void SetNormalMap(const std::string &_nmap);
397 
402  public: void SetRibbonTrail(bool _value,
403  const common::Color &_initialColor,
404  const common::Color &_changeColor);
405 
408  public: ignition::math::Box BoundingBox() const;
409 
413  public: DynamicLines *CreateDynamicLine(
415 
418  public: void DeleteDynamicLine(DynamicLines *_line);
419 
423  public: void AttachLineVertex(DynamicLines *_line,
424  unsigned int _index);
425 
428  public: std::string GetMaterialName() const;
429 
434  public: void InsertMesh(const std::string &_meshName,
435  const std::string &_subMesh = "",
436  bool _centerSubmesh = false);
437 
442  public: static void InsertMesh(const common::Mesh *_mesh,
443  const std::string &_subMesh = "",
444  bool _centerSubmesh = false);
445 
448  public: void UpdateFromMsg(ConstVisualPtr &_msg);
449 
452  public: bool IsPlane() const;
453 
456  public: VisualPtr GetParent() const;
457 
461  public: VisualPtr GetRootVisual();
462 
469  public: VisualPtr GetNthAncestor(unsigned int _n);
470 
474  public: bool IsAncestorOf(const rendering::VisualPtr _visual) const;
475 
479  public: bool IsDescendantOf(const rendering::VisualPtr _visual) const;
480 
484  public: unsigned int GetDepth() const;
485 
489  public: std::string GetShaderType() const;
490 
494  public: void SetShaderType(const std::string &_type);
495 
499  public: void MoveToPosition(const ignition::math::Pose3d &_pose,
500  const double _time);
501 
506  public: void MoveToPositions(
507  const std::vector<ignition::math::Pose3d> &_pts, const double _time,
508  std::function<void()> _onComplete = nullptr);
509 
515  public: void SetVisibilityFlags(uint32_t _flags);
516 
522  public: uint32_t GetVisibilityFlags();
523 
525  public: void ShowBoundingBox();
526 
530  public: void ShowCollision(bool _show);
531 
534  public: void ShowSkeleton(bool _show);
535 
538  public: void SetScene(ScenePtr _scene);
539 
542  public: ScenePtr GetScene() const;
543 
546  public: void ShowJoints(bool _show);
547 
550  public: void ShowCOM(bool _show);
551 
554  public: void ShowInertia(bool _show);
555 
558  public: void ShowLinkFrame(bool _show);
559 
562  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
563 
568  public: void LoadPlugin(const std::string &_filename,
569  const std::string &_name,
570  sdf::ElementPtr _sdf);
571 
574  public: void RemovePlugin(const std::string &_name);
575 
577  public: uint32_t GetId() const;
578 
580  public: void SetId(uint32_t _id);
581 
584  public: std::string GetGeometryType() const;
585 
588  public: ignition::math::Vector3d GetGeometrySize() const;
589 
592  public: std::string GetMeshName() const;
593 
597  public: std::string GetSubMeshName() const;
598 
600  public: void ClearParent();
601 
605  public: void ToggleLayer(const int32_t _layer);
606 
609  public: void SetLayer(const int32_t _layer);
610 
613  public: Visual::VisualType GetType() const;
614 
617  public: void SetType(const Visual::VisualType _type);
618 
621  public: bool UseRTShader() const;
622 
626  public: void SetTypeMsg(const google::protobuf::Message *_msg);
627 
632  public: void AddPendingChild(std::pair<VisualType,
633  const google::protobuf::Message *> _pair);
634 
638  public: static Visual::VisualType ConvertVisualType(
639  const msgs::Visual::Type &_type);
640 
644  public: static msgs::Visual::Type ConvertVisualType(
645  const Visual::VisualType &_type);
646 
650  public: void FillMaterialMsg(ignition::msgs::Material &_msg) const;
651 
659  protected: Visual(VisualPrivate &_dataPtr,
660  const std::string &_name, VisualPtr _parent,
661  bool _useRTShader = true);
662 
670  protected: Visual(VisualPrivate &_dataPtr,
671  const std::string &_name, ScenePtr _scene,
672  bool _useRTShader = true);
673 
676  protected: void ProcessMaterialMsg(const ignition::msgs::Material &_msg);
677 
684  private: void Init(const std::string &_name, ScenePtr _scene,
685  bool _useRTShader);
686 
693  private: void Init(const std::string &_name, VisualPtr _parent,
694  bool _useRTShader);
695 
698  private: void LoadPlugins();
699 
700  private: void LoadPlugin(sdf::ElementPtr _sdf);
701 
705  private: void BoundsHelper(Ogre::SceneNode *_node,
706  ignition::math::Box &_box) const;
707 
711  private: bool GetCenterSubMesh() const;
712 
715  private: void DestroyAllAttachedMovableObjects(
716  Ogre::SceneNode *_sceneNode);
717 
721  private: void UpdateGeomSize(const ignition::math::Vector3d &_scale);
722 
725  private: void UpdateTransparency(const bool _cascade = true);
726 
729  protected: VisualPrivate *dataPtr;
730  };
732  }
733 }
734 #endif
A 3D mesh.
Definition: Mesh.hh:42
Class for drawing lines that can change.
Definition: DynamicLines.hh:37
Link visual.
Definition: Visual.hh:71
Forward declarations for the common classes.
Definition: Animation.hh:33
VisualPrivate * dataPtr
Definition: Visual.hh:729
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:211
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:221
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:81
Model visual.
Definition: Visual.hh:69
VisualType
Type of visual.
Definition: Visual.hh:64
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.
Visual visual.
Definition: Visual.hh:73
Collision visual.
Definition: Visual.hh:75
Sensor visual.
Definition: Visual.hh:77