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 <string>
23 #include <utility>
24 #include <vector>
25 
26 #include <sdf/sdf.hh>
27 
28 #include "gazebo/common/Color.hh"
29 #include "gazebo/common/Mesh.hh"
30 #include "gazebo/common/Time.hh"
31 
32 #include "gazebo/msgs/MessageTypes.hh"
33 #include "gazebo/math/Box.hh"
34 #include "gazebo/math/Pose.hh"
36 #include "gazebo/math/Vector3.hh"
37 
39 #include "gazebo/util/system.hh"
40 
41 namespace Ogre
42 {
43  class MovableObject;
44  class SceneNode;
45 }
46 
47 namespace gazebo
48 {
49  namespace rendering
50  {
51  class VisualPrivate;
52 
55 
59  public boost::enable_shared_from_this<Visual>
60  {
62  public: enum VisualType
63  {
79  VT_PHYSICS
80  };
81 
87  public: Visual(const std::string &_name, VisualPtr _parent,
88  bool _useRTShader = true);
89 
95  public: Visual(const std::string &_name, ScenePtr _scene,
96  bool _useRTShader = true);
97 
99  public: virtual ~Visual();
100 
102  public: void Init();
103 
105  public: virtual void Fini();
106 
111  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
112 
115  public: void LoadFromMsg(ConstVisualPtr &_msg);
116 
119  public: void Load(sdf::ElementPtr _sdf);
120 
122  public: virtual void Load();
123 
125  public: void Update();
126 
133  public: sdf::ElementPtr GetSDF() const;
134 
137  public: void SetName(const std::string &_name);
138 
141  public: std::string GetName() const;
142 
145  public: void AttachVisual(VisualPtr _vis);
146 
149  public: void DetachVisual(VisualPtr _vis);
150 
153  public: void DetachVisual(const std::string &_name);
154 
157  public: void AttachObject(Ogre::MovableObject *_obj);
158 
161  public: bool HasAttachedObject(const std::string &_name);
162 
165  public: unsigned int GetAttachedObjectCount() const;
166 
168  public: void DetachObjects();
169 
172  public: unsigned int GetChildCount();
173 
178  public: VisualPtr GetChild(unsigned int _index);
179 
187  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
188  const std::string &_subMesh="",
189  bool _centerSubmesh = false,
190  const std::string &_objName="");
191 
194  public: void SetScale(const math::Vector3 &_scale);
195 
198  public: math::Vector3 GetScale();
199 
202  public: bool GetLighting() const;
203 
206  public: void SetLighting(bool _lighting);
207 
213  public: void SetMaterial(const std::string &_materialName,
214  bool _unique = true);
215 
218  public: void SetAmbient(const common::Color &_color);
219 
222  public: void SetDiffuse(const common::Color &_color);
223 
226  public: void SetSpecular(const common::Color &_color);
227 
230  public: common::Color GetAmbient() const;
231 
234  public: common::Color GetDiffuse() const;
235 
238  public: common::Color GetSpecular() const;
239 
242  public: common::Color GetEmissive() const;
243 
246  public: void SetWireframe(bool _show);
247 
251  private: void SetTransparencyInnerLoop(Ogre::SceneNode *_sceneNode);
252 
256  public: void SetTransparency(float _trans);
257 
260  public: float GetTransparency();
261 
265  public: virtual void SetHighlighted(bool _highlighted);
266 
270  public: bool GetHighlighted() const;
271 
274  public: virtual void SetEmissive(const common::Color &_color);
275 
278  public: bool GetCastShadows() const;
279 
282  public: void SetCastShadows(bool _shadows);
283 
287  public: void SetVisible(bool _visible, bool _cascade = true);
288 
290  public: void ToggleVisible();
291 
294  public: bool GetVisible() const;
295 
298  public: void SetPosition(const math::Vector3 &_pos);
299 
302  public: void SetRotation(const math::Quaternion &_rot);
303 
306  public: void SetPose(const math::Pose &_pose);
307 
310  public: math::Vector3 GetPosition() const;
311 
314  public: math::Quaternion GetRotation() const;
315 
318  public: math::Pose GetPose() const;
319 
322  public: math::Pose GetWorldPose() const;
323 
326  public: void SetWorldPose(const math::Pose &_pose);
327 
330  public: void SetWorldPosition(const math::Vector3 &_pos);
331 
334  public: void SetWorldRotation(const math::Quaternion &_rot);
335 
338  public: Ogre::SceneNode *GetSceneNode() const;
339 
341  public: void MakeStatic();
342 
345  public: bool IsStatic() const;
346 
349  public: void EnableTrackVisual(VisualPtr _vis);
350 
352  public: void DisableTrackVisual();
353 
356  public: std::string GetNormalMap() const;
357 
360  public: void SetNormalMap(const std::string &_nmap);
361 
366  public: void SetRibbonTrail(bool _value,
367  const common::Color &_initialColor,
368  const common::Color &_changeColor);
369 
372  public: math::Box GetBoundingBox() const;
373 
377  public: DynamicLines *CreateDynamicLine(
379 
382  public: void DeleteDynamicLine(DynamicLines *_line);
383 
387  public: void AttachLineVertex(DynamicLines *_line,
388  unsigned int _index);
389 
392  public: std::string GetMaterialName() const;
393 
398  public: void InsertMesh(const std::string &_meshName,
399  const std::string &_subMesh = "",
400  bool _centerSubmesh = false);
401 
406  public: static void InsertMesh(const common::Mesh *_mesh,
407  const std::string &_subMesh = "",
408  bool _centerSubmesh = false);
409 
412  public: void UpdateFromMsg(ConstVisualPtr &_msg);
413 
416  public: bool IsPlane() const;
417 
420  public: VisualPtr GetParent() const;
421 
425  public: VisualPtr GetRootVisual();
426 
433  public: VisualPtr GetNthAncestor(unsigned int _n);
434 
438  public: unsigned int GetDepth() const;
439 
443  public: std::string GetShaderType() const;
444 
448  public: void SetShaderType(const std::string &_type);
449 
453  public: void MoveToPosition(const math::Pose &_pose, double _time);
454 
459  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
460  double _time,
461  boost::function<void()> _onComplete = NULL);
462 
468  public: void SetVisibilityFlags(uint32_t _flags);
469 
475  public: uint32_t GetVisibilityFlags();
476 
478  public: void ShowBoundingBox();
479 
483  public: void ShowCollision(bool _show);
484 
487  public: void ShowSkeleton(bool _show);
488 
491  public: void SetScene(ScenePtr _scene);
492 
495  public: ScenePtr GetScene() const;
496 
499  public: void ShowJoints(bool _show);
500 
503  public: void ShowCOM(bool _show);
504 
507  public: void ShowInertia(bool _show);
508 
511  public: void ShowLinkFrame(bool _show);
512 
515  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
516 
521  public: void LoadPlugin(const std::string &_filename,
522  const std::string &_name,
523  sdf::ElementPtr _sdf);
524 
527  public: void RemovePlugin(const std::string &_name);
528 
530  public: uint32_t GetId() const;
531 
533  public: void SetId(uint32_t _id);
534 
537  public: std::string GetGeometryType() const;
538 
541  public: std::string GetMeshName() const;
542 
546  public: std::string GetSubMeshName() const;
547 
549  public: void ClearParent();
550 
554  public: void ToggleLayer(const int32_t _layer);
555 
558  public: Visual::VisualType GetType() const;
559 
562  public: void SetType(const Visual::VisualType _type);
563 
567  public: static Visual::VisualType ConvertVisualType(
568  const msgs::Visual::Type &_type);
569 
573  public: static msgs::Visual::Type ConvertVisualType(
574  const Visual::VisualType &_type);
575 
583  protected: Visual(VisualPrivate &_dataPtr,
584  const std::string &_name, VisualPtr _parent,
585  bool _useRTShader = true);
586 
594  protected: Visual(VisualPrivate &_dataPtr,
595  const std::string &_name, ScenePtr _scene,
596  bool _useRTShader = true);
597 
604  private: void Init(const std::string &_name, ScenePtr _scene,
605  bool _useRTShader);
606 
613  private: void Init(const std::string &_name, VisualPtr _parent,
614  bool _useRTShader);
615 
618  private: void LoadPlugins();
619 
620  private: void LoadPlugin(sdf::ElementPtr _sdf);
621 
625  private: void GetBoundsHelper(Ogre::SceneNode *_node,
626  math::Box &_box) const;
627 
631  private: bool GetCenterSubMesh() const;
632 
635  private: void DestroyAllAttachedMovableObjects(
636  Ogre::SceneNode *_sceneNode);
637 
641  private: void UpdateGeomSize(const math::Vector3 &_scale);
642 
645  protected: VisualPrivate *dataPtr;
646  };
648  }
649 }
650 #endif
A 3D mesh.
Definition: Mesh.hh:44
VisualPrivate * dataPtr
Definition: Visual.hh:645
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:57
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:71
Sensor visual.
Definition: Visual.hh:75
VisualType
Type of visual.
Definition: Visual.hh:62
Model visual.
Definition: Visual.hh:67
A renderable object.
Definition: Visual.hh:58
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:197
#define GZ_RENDERING_VISIBLE
Definition: system.hh:241
Link visual.
Definition: Visual.hh:69
Collision visual.
Definition: Visual.hh:73
Entity visual.
Definition: Visual.hh:65
A quaternion class.
Definition: Quaternion.hh:42
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:207
#define NULL
Definition: CommonTypes.hh:30
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
GUI visual.
Definition: Visual.hh:77