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 /* Desc: Ogre Visual Class
18  * Author: Nate Koenig
19  * Date: 14 Dec 2007
20  */
21 
22 #ifndef _VISUAL_HH_
23 #define _VISUAL_HH_
24 
25 #include <boost/enable_shared_from_this.hpp>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #include <sdf/sdf.hh>
31 
32 #include "gazebo/common/Color.hh"
33 #include "gazebo/common/Mesh.hh"
34 #include "gazebo/common/Time.hh"
35 
36 #include "gazebo/msgs/MessageTypes.hh"
37 #include "gazebo/math/Box.hh"
38 #include "gazebo/math/Pose.hh"
40 #include "gazebo/math/Vector3.hh"
41 
43 #include "gazebo/util/system.hh"
44 
45 namespace Ogre
46 {
47  class MovableObject;
48  class SceneNode;
49 }
50 
51 namespace gazebo
52 {
53  namespace rendering
54  {
55  class VisualPrivate;
56 
59 
62  class GAZEBO_VISIBLE Visual : public boost::enable_shared_from_this<Visual>
63  {
69  public: Visual(const std::string &_name, VisualPtr _parent,
70  bool _useRTShader = true);
71 
77  public: Visual(const std::string &_name, ScenePtr _scene,
78  bool _useRTShader = true);
79 
81  public: virtual ~Visual();
82 
84  public: void Init();
85 
87  public: void Fini();
88 
93  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
94 
97  public: void LoadFromMsg(ConstVisualPtr &_msg);
98 
101  public: void Load(sdf::ElementPtr _sdf);
102 
104  public: virtual void Load();
105 
107  public: void Update();
108 
111  public: void SetName(const std::string &_name);
112 
115  public: std::string GetName() const;
116 
119  public: void AttachVisual(VisualPtr _vis);
120 
123  public: void DetachVisual(VisualPtr _vis);
124 
127  public: void DetachVisual(const std::string &_name);
128 
131  public: void AttachObject(Ogre::MovableObject *_obj);
132 
135  public: bool HasAttachedObject(const std::string &_name);
136 
139  public: unsigned int GetAttachedObjectCount() const;
140 
142  public: void DetachObjects();
143 
146  public: unsigned int GetChildCount();
147 
152  public: VisualPtr GetChild(unsigned int _index);
153 
161  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
162  const std::string &_subMesh="",
163  bool _centerSubmesh = false,
164  const std::string &_objName="");
165 
168  public: void SetScale(const math::Vector3 &_scale);
169 
172  public: math::Vector3 GetScale();
173 
176  public: void SetLighting(bool _lighting);
177 
183  public: void SetMaterial(const std::string &_materialName,
184  bool _unique = true);
185 
188  public: void SetAmbient(const common::Color &_color);
189 
192  public: void SetDiffuse(const common::Color &_color);
193 
196  public: void SetSpecular(const common::Color &_color);
197 
199  public: void AttachAxes();
200 
203  public: void SetWireframe(bool _show);
204 
207  private: void SetTransparencyInnerLoop();
208 
212  public: void SetTransparency(float _trans);
213 
216  public: float GetTransparency();
217 
221  public: void SetHighlighted(bool _highlighted);
222 
226  public: bool GetHighlighted() const;
227 
230  public: virtual void SetEmissive(const common::Color &_color);
231 
234  public: void SetCastShadows(bool _shadows);
235 
239  public: void SetVisible(bool _visible, bool _cascade = true);
240 
242  public: void ToggleVisible();
243 
246  public: bool GetVisible() const;
247 
250  public: void SetPosition(const math::Vector3 &_pos);
251 
254  public: void SetRotation(const math::Quaternion &_rot);
255 
258  public: void SetPose(const math::Pose &_pose);
259 
262  public: math::Vector3 GetPosition() const;
263 
266  public: math::Quaternion GetRotation() const;
267 
270  public: math::Pose GetPose() const;
271 
274  public: math::Pose GetWorldPose() const;
275 
278  public: void SetWorldPose(const math::Pose &_pose);
279 
282  public: void SetWorldPosition(const math::Vector3 &_pos);
283 
286  public: void SetWorldRotation(const math::Quaternion &_rot);
287 
290  public: Ogre::SceneNode *GetSceneNode() const;
291 
293  public: void MakeStatic();
294 
297  public: bool IsStatic() const;
298 
301  public: void EnableTrackVisual(VisualPtr _vis);
302 
304  public: void DisableTrackVisual();
305 
308  public: std::string GetNormalMap() const;
309 
312  public: void SetNormalMap(const std::string &_nmap);
313 
318  public: void SetRibbonTrail(bool _value,
319  const common::Color &_initialColor,
320  const common::Color &_changeColor);
321 
324  public: math::Box GetBoundingBox() const;
325 
329  public: DynamicLines *CreateDynamicLine(
331 
334  public: void DeleteDynamicLine(DynamicLines *_line);
335 
339  public: void AttachLineVertex(DynamicLines *_line,
340  unsigned int _index);
341 
344  public: std::string GetMaterialName() const;
345 
350  public: void InsertMesh(const std::string &_meshName,
351  const std::string &_subMesh = "",
352  bool _centerSubmesh = false);
353 
358  public: static void InsertMesh(const common::Mesh *_mesh,
359  const std::string &_subMesh = "",
360  bool _centerSubmesh = false);
361 
364  public: void UpdateFromMsg(ConstVisualPtr &_msg);
365 
368  public: bool IsPlane() const;
369 
372  public: VisualPtr GetParent() const;
373 
377  public: VisualPtr GetRootVisual();
378 
382  public: std::string GetShaderType() const;
383 
387  public: void SetShaderType(const std::string &_type);
388 
392  public: void MoveToPosition(const math::Pose &_pose, double _time);
393 
398  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
399  double _time,
400  boost::function<void()> _onComplete = NULL);
401 
407  public: void SetVisibilityFlags(uint32_t _flags);
408 
414  public: uint32_t GetVisibilityFlags();
415 
417  public: void ShowBoundingBox();
418 
422  public: void ShowCollision(bool _show);
423 
426  public: void ShowSkeleton(bool _show);
427 
430  public: void SetScene(ScenePtr _scene);
431 
434  public: ScenePtr GetScene() const;
435 
438  public: void ShowJoints(bool _show);
439 
442  public: void ShowCOM(bool _show);
443 
446  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
447 
452  public: void LoadPlugin(const std::string &_filename,
453  const std::string &_name,
454  sdf::ElementPtr _sdf);
455 
458  public: void RemovePlugin(const std::string &_name);
459 
461  public: uint32_t GetId() const;
462 
464  public: void SetId(uint32_t _id);
465 
468  public: std::string GetMeshName() const;
469 
473  public: std::string GetSubMeshName() const;
474 
476  public: void ClearParent();
477 
485  protected: Visual(VisualPrivate &_dataPtr,
486  const std::string &_name, VisualPtr _parent,
487  bool _useRTShader = true);
488 
496  protected: Visual(VisualPrivate &_dataPtr,
497  const std::string &_name, ScenePtr _scene,
498  bool _useRTShader = true);
499 
506  private: void Init(const std::string &_name, ScenePtr _scene,
507  bool _useRTShader);
508 
515  private: void Init(const std::string &_name, VisualPtr _parent,
516  bool _useRTShader);
517 
520  private: void LoadPlugins();
521 
522  private: void LoadPlugin(sdf::ElementPtr _sdf);
523 
527  private: void GetBoundsHelper(Ogre::SceneNode *_node,
528  math::Box &_box) const;
529 
533  private: bool GetCenterSubMesh() const;
534 
537  private: void DestroyAllAttachedMovableObjects(
538  Ogre::SceneNode *_sceneNode);
539 
543  private: void UpdateGeomSize(const math::Vector3 &_scale);
544 
547  protected: VisualPrivate *dataPtr;
548  };
550  }
551 }
552 #endif
A 3D mesh.
Definition: Mesh.hh:40
VisualPrivate * dataPtr
Definition: Visual.hh:547
Class for drawing lines that can change.
Definition: DynamicLines.hh:43
Encapsulates a position and rotation in three space.
Definition: Pose.hh:40
Private data for the Visual class.
Definition: VisualPrivate.hh:56
The Vector3 class represents the generic vector containing 3 elements.
Definition: Vector3.hh:43
Mathematical representation of a box and related functions.
Definition: Box.hh:33
A renderable object.
Definition: Visual.hh:62
RenderOpType
Type of render operation for a drawable.
Definition: RenderTypes.hh:172
A quaternion class.
Definition: Quaternion.hh:41
A strip of connected lines, 1 vertex per line plus 1 start vertex.
Definition: RenderTypes.hh:182
#define NULL
Definition: CommonTypes.hh:30
Defines a color.
Definition: Color.hh:39
boost::shared_ptr< Scene > ScenePtr
Definition: RenderTypes.hh:74
GAZEBO_VISIBLE void Init(google::protobuf::Message &_message, const std::string &_id="")
Initialize a message.
boost::shared_ptr< Visual > VisualPtr
Definition: RenderTypes.hh:102
#define GAZEBO_VISIBLE
Use to represent "symbol visible" if supported.
Definition: system.hh:48