Visual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2016 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 
18 #ifndef _GAZEBO_VISUAL_HH_
19 #define _GAZEBO_VISUAL_HH_
20 
21 #include <boost/enable_shared_from_this.hpp>
22 #include <boost/function.hpp>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 #include <sdf/sdf.hh>
28 
29 #include "gazebo/common/Color.hh"
30 #include "gazebo/common/Mesh.hh"
31 #include "gazebo/common/Time.hh"
32 
33 #include "gazebo/msgs/MessageTypes.hh"
34 #include "gazebo/math/Box.hh"
35 #include "gazebo/math/Pose.hh"
37 #include "gazebo/math/Vector3.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 
60  public std::enable_shared_from_this<Visual>
61  {
63  public: enum VisualType
64  {
80  VT_PHYSICS
81  };
82 
88  public: Visual(const std::string &_name, VisualPtr _parent,
89  bool _useRTShader = true);
90 
96  public: Visual(const std::string &_name, ScenePtr _scene,
97  bool _useRTShader = true);
98 
100  public: virtual ~Visual();
101 
103  public: void Init();
104 
106  public: virtual void Fini();
107 
112  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
113 
116  public: void LoadFromMsg(ConstVisualPtr &_msg);
117 
120  public: void Load(sdf::ElementPtr _sdf);
121 
123  public: virtual void Load();
124 
126  public: void Update();
127 
134  public: sdf::ElementPtr GetSDF() const;
135 
138  public: void SetName(const std::string &_name);
139 
142  public: std::string GetName() const;
143 
146  public: void AttachVisual(VisualPtr _vis);
147 
150  public: void DetachVisual(VisualPtr _vis);
151 
154  public: void DetachVisual(const std::string &_name);
155 
158  public: void AttachObject(Ogre::MovableObject *_obj);
159 
162  public: bool HasAttachedObject(const std::string &_name);
163 
166  public: unsigned int GetAttachedObjectCount() const;
167 
169  public: void DetachObjects();
170 
173  public: unsigned int GetChildCount();
174 
179  public: VisualPtr GetChild(unsigned int _index);
180 
188  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
189  const std::string &_subMesh="",
190  bool _centerSubmesh = false,
191  const std::string &_objName="");
192 
195  public: void SetScale(const math::Vector3 &_scale);
196 
199  public: math::Vector3 GetScale();
200 
203  public: ignition::math::Vector3d DerivedScale() const;
204 
207  public: bool GetLighting() const;
208 
211  public: void SetLighting(bool _lighting);
212 
219  public: void SetMaterial(const std::string &_materialName,
220  bool _unique = true, const bool _cascade = true);
221 
225  public: void SetAmbient(const common::Color &_color,
226  const bool _cascade = true);
227 
231  public: void SetDiffuse(const common::Color &_color,
232  const bool _cascade = true);
233 
237  public: void SetSpecular(const common::Color &_color,
238  const bool _cascade = true);
239 
243  public: virtual void SetEmissive(const common::Color &_color,
244  const bool _cascade = true);
245 
248  public: common::Color GetAmbient() const;
249 
252  public: common::Color GetDiffuse() const;
253 
256  public: common::Color GetSpecular() const;
257 
260  public: common::Color GetEmissive() const;
261 
264  public: void SetWireframe(bool _show);
265 
268  public: bool Wireframe() const;
269 
273  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
274 
278  public: void SetTransparency(float _trans);
279 
282  public: float GetTransparency();
283 
287  public: float DerivedTransparency() const;
288 
291  public: void SetInheritTransparency(const bool _inherit);
292 
295  public: bool InheritTransparency() const;
296 
300  public: virtual void SetHighlighted(bool _highlighted);
301 
305  public: bool GetHighlighted() const;
306 
309  public: bool GetCastShadows() const;
310 
313  public: void SetCastShadows(bool _shadows);
314 
318  public: virtual void SetVisible(bool _visible, bool _cascade = true);
319 
321  public: void ToggleVisible();
322 
325  public: bool GetVisible() const;
326 
329  public: void SetPosition(const math::Vector3 &_pos);
330 
333  public: void SetRotation(const math::Quaternion &_rot);
334 
337  public: void SetPose(const math::Pose &_pose);
338 
341  public: math::Vector3 GetPosition() const;
342 
345  public: math::Quaternion GetRotation() const;
346 
349  public: math::Pose GetPose() const;
350 
353  public: math::Pose GetWorldPose() const;
354 
357  public: void SetWorldPose(const math::Pose &_pose);
358 
361  public: void SetWorldPosition(const math::Vector3 &_pos);
362 
365  public: void SetWorldRotation(const math::Quaternion &_rot);
366 
369  public: Ogre::SceneNode *GetSceneNode() const;
370 
372  public: void MakeStatic();
373 
376  public: bool IsStatic() const;
377 
380  public: void EnableTrackVisual(VisualPtr _vis);
381 
383  public: void DisableTrackVisual();
384 
387  public: std::string GetNormalMap() const;
388 
391  public: void SetNormalMap(const std::string &_nmap);
392 
397  public: void SetRibbonTrail(bool _value,
398  const common::Color &_initialColor,
399  const common::Color &_changeColor);
400 
403  public: math::Box GetBoundingBox() const;
404 
408  public: DynamicLines *CreateDynamicLine(
410 
413  public: void DeleteDynamicLine(DynamicLines *_line);
414 
418  public: void AttachLineVertex(DynamicLines *_line,
419  unsigned int _index);
420 
423  public: std::string GetMaterialName() const;
424 
429  public: void InsertMesh(const std::string &_meshName,
430  const std::string &_subMesh = "",
431  bool _centerSubmesh = false);
432 
437  public: static void InsertMesh(const common::Mesh *_mesh,
438  const std::string &_subMesh = "",
439  bool _centerSubmesh = false);
440 
443  public: void UpdateFromMsg(ConstVisualPtr &_msg);
444 
447  public: bool IsPlane() const;
448 
451  public: VisualPtr GetParent() const;
452 
456  public: VisualPtr GetRootVisual();
457 
464  public: VisualPtr GetNthAncestor(unsigned int _n);
465 
469  public: bool IsAncestorOf(const rendering::VisualPtr _visual) const;
470 
474  public: bool IsDescendantOf(const rendering::VisualPtr _visual) const;
475 
479  public: unsigned int GetDepth() const;
480 
484  public: std::string GetShaderType() const;
485 
489  public: void SetShaderType(const std::string &_type);
490 
494  public: void MoveToPosition(const math::Pose &_pose, double _time);
495 
500  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
501  double _time,
502  boost::function<void()> _onComplete = NULL);
503 
509  public: void SetVisibilityFlags(uint32_t _flags);
510 
516  public: uint32_t GetVisibilityFlags();
517 
519  public: void ShowBoundingBox();
520 
524  public: void ShowCollision(bool _show);
525 
528  public: void ShowSkeleton(bool _show);
529 
532  public: void SetScene(ScenePtr _scene);
533 
536  public: ScenePtr GetScene() const;
537 
540  public: void ShowJoints(bool _show);
541 
544  public: void ShowCOM(bool _show);
545 
548  public: void ShowInertia(bool _show);
549 
552  public: void ShowLinkFrame(bool _show);
553 
556  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
557 
562  public: void LoadPlugin(const std::string &_filename,
563  const std::string &_name,
564  sdf::ElementPtr _sdf);
565 
568  public: void RemovePlugin(const std::string &_name);
569 
571  public: uint32_t GetId() const;
572 
574  public: void SetId(uint32_t _id);
575 
578  public: std::string GetGeometryType() const;
579 
582  public: ignition::math::Vector3d GetGeometrySize() const;
583 
586  public: std::string GetMeshName() const;
587 
591  public: std::string GetSubMeshName() const;
592 
594  public: void ClearParent();
595 
599  public: void ToggleLayer(const int32_t _layer);
600 
603  public: Visual::VisualType GetType() const;
604 
607  public: void SetType(const Visual::VisualType _type);
608 
611  public: bool UseRTShader() const;
612 
616  public: static Visual::VisualType ConvertVisualType(
617  const msgs::Visual::Type &_type);
618 
622  public: static msgs::Visual::Type ConvertVisualType(
623  const Visual::VisualType &_type);
624 
632  protected: Visual(VisualPrivate &_dataPtr,
633  const std::string &_name, VisualPtr _parent,
634  bool _useRTShader = true);
635 
643  protected: Visual(VisualPrivate &_dataPtr,
644  const std::string &_name, ScenePtr _scene,
645  bool _useRTShader = true);
646 
653  private: void Init(const std::string &_name, ScenePtr _scene,
654  bool _useRTShader);
655 
662  private: void Init(const std::string &_name, VisualPtr _parent,
663  bool _useRTShader);
664 
667  private: void LoadPlugins();
668 
669  private: void LoadPlugin(sdf::ElementPtr _sdf);
670 
674  private: void GetBoundsHelper(Ogre::SceneNode *_node,
675  math::Box &_box) const;
676 
680  private: bool GetCenterSubMesh() const;
681 
684  private: void DestroyAllAttachedMovableObjects(
685  Ogre::SceneNode *_sceneNode);
686 
690  private: void UpdateGeomSize(const ignition::math::Vector3d &_scale);
691 
694  private: void UpdateTransparency(const bool _cascade = true);
695 
698  protected: VisualPrivate *dataPtr;
699  };
701  }
702 }
703 #endif
A 3D mesh.
Definition: Mesh.hh:44
VisualPrivate * dataPtr
Definition: Visual.hh:698
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Encapsulates a position and rotation in three space.
Definition: Pose.hh:37
Private data for the Visual class.
Definition: VisualPrivate.hh:58
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:39
Mathematical representation of a box and related functions.
Definition: Box.hh:35
Visual visual.
Definition: Visual.hh:72
Sensor visual.
Definition: Visual.hh:76
std::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:112
VisualType
Type of visual.
Definition: Visual.hh:63
Model visual.
Definition: Visual.hh:68
A renderable object.
Definition: Visual.hh:59
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:206
#define GZ_RENDERING_VISIBLE
Definition: system.hh:209
Link visual.
Definition: Visual.hh:70
Collision visual.
Definition: Visual.hh:74
Entity visual.
Definition: Visual.hh:66
A quaternion class.
Definition: Quaternion.hh:42
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:216
#define NULL
Definition: CommonTypes.hh:31
Defines a color.
Definition: Color.hh:36
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:80
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
GUI visual.
Definition: Visual.hh:78