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/Color.hh"
35 #include "gazebo/common/Mesh.hh"
36 #include "gazebo/common/Time.hh"
37 
38 #include "gazebo/msgs/MessageTypes.hh"
39 
41 #include "gazebo/util/system.hh"
42 
43 namespace Ogre
44 {
45  class MovableObject;
46  class SceneNode;
47 }
48 
49 namespace gazebo
50 {
51  namespace rendering
52  {
53  class VisualPrivate;
54 
57 
60  class GZ_RENDERING_VISIBLE Visual :
61  public std::enable_shared_from_this<Visual>
62  {
65  public: enum VisualType
66  {
82  VT_PHYSICS
83  };
84 
90  public: Visual(const std::string &_name, VisualPtr _parent,
91  bool _useRTShader = true);
92 
98  public: Visual(const std::string &_name, ScenePtr _scene,
99  bool _useRTShader = true);
100 
102  public: virtual ~Visual();
103 
105  public: void Init();
106 
108  public: virtual void Fini();
109 
114  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
115 
118  public: void LoadFromMsg(ConstVisualPtr &_msg);
119 
122  public: void Load(sdf::ElementPtr _sdf);
123 
125  public: virtual void Load();
126 
128  public: void Update();
129 
136  public: sdf::ElementPtr GetSDF() const;
137 
140  public: void SetName(const std::string &_name);
141 
144  public: std::string Name() const;
145 
148  public: void AttachVisual(VisualPtr _vis);
149 
152  public: void DetachVisual(VisualPtr _vis);
153 
156  public: void DetachVisual(const std::string &_name);
157 
160  public: void AttachObject(Ogre::MovableObject *_obj);
161 
164  public: bool HasAttachedObject(const std::string &_name);
165 
168  public: unsigned int GetAttachedObjectCount() const;
169 
171  public: void DetachObjects();
172 
175  public: unsigned int GetChildCount();
176 
181  public: VisualPtr GetChild(unsigned int _index);
182 
190  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
191  const std::string &_subMesh="",
192  bool _centerSubmesh = false,
193  const std::string &_objName="");
194 
197  public: void SetScale(const ignition::math::Vector3d &_scale);
198 
201  public: ignition::math::Vector3d Scale() const;
202 
205  public: ignition::math::Vector3d DerivedScale() const;
206 
209  public: bool GetLighting() const;
210 
213  public: void SetLighting(bool _lighting);
214 
221  public: void SetMaterial(const std::string &_materialName,
222  bool _unique = true, const bool _cascade = true);
223 
228  public: void SetAmbient(const common::Color &_color,
229  const bool _cascade = true) GAZEBO_DEPRECATED(9.0);
230 
234  public: void SetAmbient(const ignition::math::Color &_color,
235  const bool _cascade = true);
236 
241  public: void SetDiffuse(const common::Color &_color,
242  const bool _cascade = true) GAZEBO_DEPRECATED(9.0);
243 
247  public: void SetDiffuse(const ignition::math::Color &_color,
248  const bool _cascade = true);
249 
254  public: void SetSpecular(const common::Color &_color,
255  const bool _cascade = true) GAZEBO_DEPRECATED(9.0);
256 
260  public: void SetSpecular(const ignition::math::Color &_color,
261  const bool _cascade = true);
262 
267  public: virtual void SetEmissive(const common::Color &_color,
268  const bool _cascade = true) GAZEBO_DEPRECATED(9.0);
269 
273  public: virtual void SetEmissive(const ignition::math::Color &_color,
274  const bool _cascade = true);
275 
279  public: common::Color GetAmbient() const GAZEBO_DEPRECATED(9.0);
280 
283  public: ignition::math::Color Ambient() const;
284 
288  public: common::Color GetDiffuse() const GAZEBO_DEPRECATED(9.0);
289 
292  public: ignition::math::Color Diffuse() const;
293 
297  public: common::Color GetSpecular() const GAZEBO_DEPRECATED(9.0);
298 
301  public: ignition::math::Color Specular() const;
302 
306  public: common::Color GetEmissive() const GAZEBO_DEPRECATED(9.0);
307 
310  public: ignition::math::Color Emissive() const;
311 
314  public: void SetWireframe(bool _show);
315 
318  public: bool Wireframe() const;
319 
323  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
324 
328  public: void SetTransparency(float _trans);
329 
332  public: float GetTransparency();
333 
337  public: float DerivedTransparency() const;
338 
341  public: void SetInheritTransparency(const bool _inherit);
342 
345  public: bool InheritTransparency() const;
346 
350  public: virtual void SetHighlighted(bool _highlighted);
351 
355  public: bool GetHighlighted() const;
356 
359  public: bool GetCastShadows() const;
360 
363  public: void SetCastShadows(bool _shadows);
364 
368  public: virtual void SetVisible(bool _visible, bool _cascade = true);
369 
371  public: void ToggleVisible();
372 
375  public: bool GetVisible() const;
376 
379  public: void SetPosition(const ignition::math::Vector3d &_pos);
380 
383  public: void SetRotation(const ignition::math::Quaterniond &_rot);
384 
387  public: void SetPose(const ignition::math::Pose3d &_pose);
388 
391  public: ignition::math::Vector3d Position() const;
392 
395  public: ignition::math::Quaterniond Rotation() const;
396 
399  public: ignition::math::Pose3d Pose() const;
400 
403  public: ignition::math::Pose3d InitialRelativePose() const;
404 
407  public: ignition::math::Pose3d WorldPose() const;
408 
411  public: void SetWorldPose(const ignition::math::Pose3d &_pose);
412 
415  public: void SetWorldPosition(const ignition::math::Vector3d &_pos);
416 
419  public: void SetWorldRotation(const ignition::math::Quaterniond &_rot);
420 
423  public: Ogre::SceneNode *GetSceneNode() const;
424 
426  public: void MakeStatic();
427 
430  public: bool IsStatic() const;
431 
434  public: void EnableTrackVisual(VisualPtr _vis);
435 
437  public: void DisableTrackVisual();
438 
441  public: std::string GetNormalMap() const;
442 
445  public: void SetNormalMap(const std::string &_nmap);
446 
452  public: void SetRibbonTrail(bool _value,
453  const common::Color &_initialColor,
454  const common::Color &_changeColor) GAZEBO_DEPRECATED(9.0);
455 
460  public: void SetRibbonTrail(bool _value,
461  const ignition::math::Color &_initialColor,
462  const ignition::math::Color &_changeColor);
463 
466  public: ignition::math::Box BoundingBox() const;
467 
471  public: DynamicLines *CreateDynamicLine(
472  RenderOpType _type = RENDERING_LINE_STRIP);
473 
476  public: void DeleteDynamicLine(DynamicLines *_line);
477 
481  public: void AttachLineVertex(DynamicLines *_line,
482  unsigned int _index);
483 
486  public: std::string GetMaterialName() const;
487 
492  public: void InsertMesh(const std::string &_meshName,
493  const std::string &_subMesh = "",
494  bool _centerSubmesh = false);
495 
500  public: static void InsertMesh(const common::Mesh *_mesh,
501  const std::string &_subMesh = "",
502  bool _centerSubmesh = false);
503 
506  public: void UpdateFromMsg(ConstVisualPtr &_msg);
507 
510  public: bool IsPlane() const;
511 
514  public: VisualPtr GetParent() const;
515 
519  public: VisualPtr GetRootVisual();
520 
527  public: VisualPtr GetNthAncestor(unsigned int _n);
528 
532  public: bool IsAncestorOf(const rendering::VisualPtr _visual) const;
533 
537  public: bool IsDescendantOf(const rendering::VisualPtr _visual) const;
538 
542  public: unsigned int GetDepth() const;
543 
547  public: std::string GetShaderType() const;
548 
552  public: void SetShaderType(const std::string &_type);
553 
557  public: void MoveToPosition(const ignition::math::Pose3d &_pose,
558  const double _time);
559 
564  public: void MoveToPositions(
565  const std::vector<ignition::math::Pose3d> &_pts, const double _time,
566  std::function<void()> _onComplete = nullptr);
567 
573  public: void SetVisibilityFlags(uint32_t _flags);
574 
580  public: uint32_t GetVisibilityFlags();
581 
583  public: void ShowBoundingBox();
584 
588  public: void ShowCollision(bool _show);
589 
592  public: void ShowSkeleton(bool _show);
593 
596  public: void SetScene(ScenePtr _scene);
597 
600  public: ScenePtr GetScene() const;
601 
604  public: void ShowJoints(bool _show);
605 
608  public: void ShowCOM(bool _show);
609 
612  public: void ShowInertia(bool _show);
613 
616  public: void ShowLinkFrame(bool _show);
617 
620  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
621 
626  public: void LoadPlugin(const std::string &_filename,
627  const std::string &_name,
628  sdf::ElementPtr _sdf);
629 
632  public: void RemovePlugin(const std::string &_name);
633 
635  public: uint32_t GetId() const;
636 
638  public: void SetId(uint32_t _id);
639 
642  public: std::string GetGeometryType() const;
643 
646  public: ignition::math::Vector3d GetGeometrySize() const;
647 
650  public: std::string GetMeshName() const;
651 
655  public: std::string GetSubMeshName() const;
656 
658  public: void ClearParent();
659 
663  public: void ToggleLayer(const int32_t _layer);
664 
667  public: void SetLayer(const int32_t _layer);
668 
671  public: Visual::VisualType GetType() const;
672 
675  public: void SetType(const Visual::VisualType _type);
676 
679  public: bool UseRTShader() const;
680 
684  public: void SetTypeMsg(const google::protobuf::Message *_msg);
685 
690  public: void AddPendingChild(std::pair<VisualType,
691  const google::protobuf::Message *> _pair);
692 
696  public: static Visual::VisualType ConvertVisualType(
697  const msgs::Visual::Type &_type);
698 
702  public: static msgs::Visual::Type ConvertVisualType(
703  const Visual::VisualType &_type);
704 
708  public: void FillMaterialMsg(ignition::msgs::Material &_msg) const;
709 
717  protected: Visual(VisualPrivate &_dataPtr,
718  const std::string &_name, VisualPtr _parent,
719  bool _useRTShader = true);
720 
728  protected: Visual(VisualPrivate &_dataPtr,
729  const std::string &_name, ScenePtr _scene,
730  bool _useRTShader = true);
731 
734  protected: void ProcessMaterialMsg(const ignition::msgs::Material &_msg);
735 
742  private: void Init(const std::string &_name, ScenePtr _scene,
743  bool _useRTShader);
744 
751  private: void Init(const std::string &_name, VisualPtr _parent,
752  bool _useRTShader);
753 
756  private: void LoadPlugins();
757 
758  private: void LoadPlugin(sdf::ElementPtr _sdf);
759 
763  private: void BoundsHelper(Ogre::SceneNode *_node,
764  ignition::math::Box &_box) const;
765 
769  private: bool GetCenterSubMesh() const;
770 
773  private: void DestroyAllAttachedMovableObjects(
774  Ogre::SceneNode *_sceneNode);
775 
779  private: void UpdateGeomSize(const ignition::math::Vector3d &_scale);
780 
783  private: void UpdateTransparency(const bool _cascade = true);
784 
787  protected: VisualPrivate *dataPtr;
788  };
790  }
791 }
792 #endif
Class for drawing lines that can change.
Definition: DynamicLines.hh:42
Link visual.
Definition: Visual.hh:72
Entity visual.
Definition: Visual.hh:68
GUI visual.
Definition: Visual.hh:80
A renderable object.
Definition: Visual.hh:60
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:216
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:82
Model visual.
Definition: Visual.hh:70
Defines a color.
Definition: Color.hh:36
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:74
Collision visual.
Definition: Visual.hh:76
Sensor visual.
Definition: Visual.hh:78