Visual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2015 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 boost::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: bool GetLighting() const;
204 
207  public: void SetLighting(bool _lighting);
208 
214  public: void SetMaterial(const std::string &_materialName,
215  bool _unique = true);
216 
219  public: void SetAmbient(const common::Color &_color);
220 
223  public: void SetDiffuse(const common::Color &_color);
224 
227  public: void SetSpecular(const common::Color &_color);
228 
231  public: common::Color GetAmbient() const;
232 
235  public: common::Color GetDiffuse() const;
236 
239  public: common::Color GetSpecular() const;
240 
243  public: common::Color GetEmissive() const;
244 
247  public: void SetWireframe(bool _show);
248 
252  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
253 
257  public: void SetTransparency(float _trans);
258 
261  public: float GetTransparency();
262 
266  public: virtual void SetHighlighted(bool _highlighted);
267 
271  public: bool GetHighlighted() const;
272 
275  public: virtual void SetEmissive(const common::Color &_color);
276 
279  public: bool GetCastShadows() const;
280 
283  public: void SetCastShadows(bool _shadows);
284 
288  public: void SetVisible(bool _visible, bool _cascade = true);
289 
291  public: void ToggleVisible();
292 
295  public: bool GetVisible() const;
296 
299  public: void SetPosition(const math::Vector3 &_pos);
300 
303  public: void SetRotation(const math::Quaternion &_rot);
304 
307  public: void SetPose(const math::Pose &_pose);
308 
311  public: math::Vector3 GetPosition() const;
312 
315  public: math::Quaternion GetRotation() const;
316 
319  public: math::Pose GetPose() const;
320 
323  public: math::Pose GetWorldPose() const;
324 
327  public: void SetWorldPose(const math::Pose &_pose);
328 
331  public: void SetWorldPosition(const math::Vector3 &_pos);
332 
335  public: void SetWorldRotation(const math::Quaternion &_rot);
336 
339  public: Ogre::SceneNode *GetSceneNode() const;
340 
342  public: void MakeStatic();
343 
346  public: bool IsStatic() const;
347 
350  public: void EnableTrackVisual(VisualPtr _vis);
351 
353  public: void DisableTrackVisual();
354 
357  public: std::string GetNormalMap() const;
358 
361  public: void SetNormalMap(const std::string &_nmap);
362 
367  public: void SetRibbonTrail(bool _value,
368  const common::Color &_initialColor,
369  const common::Color &_changeColor);
370 
373  public: math::Box GetBoundingBox() const;
374 
378  public: DynamicLines *CreateDynamicLine(
380 
383  public: void DeleteDynamicLine(DynamicLines *_line);
384 
388  public: void AttachLineVertex(DynamicLines *_line,
389  unsigned int _index);
390 
393  public: std::string GetMaterialName() const;
394 
399  public: void InsertMesh(const std::string &_meshName,
400  const std::string &_subMesh = "",
401  bool _centerSubmesh = false);
402 
407  public: static void InsertMesh(const common::Mesh *_mesh,
408  const std::string &_subMesh = "",
409  bool _centerSubmesh = false);
410 
413  public: void UpdateFromMsg(ConstVisualPtr &_msg);
414 
417  public: bool IsPlane() const;
418 
421  public: VisualPtr GetParent() const;
422 
426  public: VisualPtr GetRootVisual();
427 
434  public: VisualPtr GetNthAncestor(unsigned int _n);
435 
439  public: unsigned int GetDepth() const;
440 
444  public: std::string GetShaderType() const;
445 
449  public: void SetShaderType(const std::string &_type);
450 
454  public: void MoveToPosition(const math::Pose &_pose, double _time);
455 
460  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
461  double _time,
462  boost::function<void()> _onComplete = NULL);
463 
469  public: void SetVisibilityFlags(uint32_t _flags);
470 
476  public: uint32_t GetVisibilityFlags();
477 
479  public: void ShowBoundingBox();
480 
484  public: void ShowCollision(bool _show);
485 
488  public: void ShowSkeleton(bool _show);
489 
492  public: void SetScene(ScenePtr _scene);
493 
496  public: ScenePtr GetScene() const;
497 
500  public: void ShowJoints(bool _show);
501 
504  public: void ShowCOM(bool _show);
505 
508  public: void ShowInertia(bool _show);
509 
512  public: void ShowLinkFrame(bool _show);
513 
516  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
517 
522  public: void LoadPlugin(const std::string &_filename,
523  const std::string &_name,
524  sdf::ElementPtr _sdf);
525 
528  public: void RemovePlugin(const std::string &_name);
529 
531  public: uint32_t GetId() const;
532 
534  public: void SetId(uint32_t _id);
535 
538  public: std::string GetGeometryType() const;
539 
542  public: std::string GetMeshName() const;
543 
547  public: std::string GetSubMeshName() const;
548 
550  public: void ClearParent();
551 
555  public: void ToggleLayer(const int32_t _layer);
556 
559  public: Visual::VisualType GetType() const;
560 
563  public: void SetType(const Visual::VisualType _type);
564 
568  public: static Visual::VisualType ConvertVisualType(
569  const msgs::Visual::Type &_type);
570 
574  public: static msgs::Visual::Type ConvertVisualType(
575  const Visual::VisualType &_type);
576 
584  protected: Visual(VisualPrivate &_dataPtr,
585  const std::string &_name, VisualPtr _parent,
586  bool _useRTShader = true);
587 
595  protected: Visual(VisualPrivate &_dataPtr,
596  const std::string &_name, ScenePtr _scene,
597  bool _useRTShader = true);
598 
605  private: void Init(const std::string &_name, ScenePtr _scene,
606  bool _useRTShader);
607 
614  private: void Init(const std::string &_name, VisualPtr _parent,
615  bool _useRTShader);
616 
619  private: void LoadPlugins();
620 
621  private: void LoadPlugin(sdf::ElementPtr _sdf);
622 
626  private: void GetBoundsHelper(Ogre::SceneNode *_node,
627  math::Box &_box) const;
628 
632  private: bool GetCenterSubMesh() const;
633 
636  private: void DestroyAllAttachedMovableObjects(
637  Ogre::SceneNode *_sceneNode);
638 
642  private: void UpdateGeomSize(const math::Vector3 &_scale);
643 
646  protected: VisualPrivate *dataPtr;
647  };
649  }
650 }
651 #endif
A 3D mesh.
Definition: Mesh.hh:44
VisualPrivate * dataPtr
Definition: Visual.hh:646
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Visual visual.
Definition: Visual.hh:72
Forward declarations for the common classes.
Definition: Animation.hh:33
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
A renderable object.
Definition: Visual.hh:59
Entity visual.
Definition: Visual.hh:66
Sensor visual.
Definition: Visual.hh:76
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:197
Model visual.
Definition: Visual.hh:68
#define GZ_RENDERING_VISIBLE
Definition: system.hh:241
GUI visual.
Definition: Visual.hh:78
A quaternion class.
Definition: Quaternion.hh:42
Link visual.
Definition: Visual.hh:70
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:207
#define NULL
Definition: CommonTypes.hh:30
VisualType
Type of visual.
Definition: Visual.hh:63
Definition: JointMaker.hh:36
Defines a color.
Definition: Color.hh:36
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:79
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:107
Collision visual.
Definition: Visual.hh:74