All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Visual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012-2014 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 
208  public: void SetTransparency(float _trans);
209 
212  public: float GetTransparency();
213 
217  public: void SetHighlighted(bool _highlighted);
218 
222  public: bool GetHighlighted() const;
223 
226  public: virtual void SetEmissive(const common::Color &_color);
227 
230  public: void SetCastShadows(bool _shadows);
231 
235  public: void SetVisible(bool _visible, bool _cascade = true);
236 
238  public: void ToggleVisible();
239 
242  public: bool GetVisible() const;
243 
246  public: void SetPosition(const math::Vector3 &_pos);
247 
250  public: void SetRotation(const math::Quaternion &_rot);
251 
254  public: void SetPose(const math::Pose &_pose);
255 
258  public: math::Vector3 GetPosition() const;
259 
262  public: math::Quaternion GetRotation() const;
263 
266  public: math::Pose GetPose() const;
267 
270  public: math::Pose GetWorldPose() const;
271 
274  public: void SetWorldPose(const math::Pose &_pose);
275 
278  public: void SetWorldPosition(const math::Vector3 &_pos);
279 
282  public: void SetWorldRotation(const math::Quaternion &_rot);
283 
286  public: Ogre::SceneNode *GetSceneNode() const;
287 
289  public: void MakeStatic();
290 
293  public: bool IsStatic() const;
294 
297  public: void EnableTrackVisual(VisualPtr _vis);
298 
300  public: void DisableTrackVisual();
301 
304  public: std::string GetNormalMap() const;
305 
308  public: void SetNormalMap(const std::string &_nmap);
309 
314  public: void SetRibbonTrail(bool _value,
315  const common::Color &_initialColor,
316  const common::Color &_changeColor);
317 
320  public: math::Box GetBoundingBox() const;
321 
325  public: DynamicLines *CreateDynamicLine(
327 
330  public: void DeleteDynamicLine(DynamicLines *_line);
331 
335  public: void AttachLineVertex(DynamicLines *_line,
336  unsigned int _index);
337 
340  public: std::string GetMaterialName() const;
341 
346  public: void InsertMesh(const std::string &_meshName,
347  const std::string &_subMesh = "",
348  bool _centerSubmesh = false);
349 
354  public: static void InsertMesh(const common::Mesh *_mesh,
355  const std::string &_subMesh = "",
356  bool _centerSubmesh = false);
357 
360  public: void UpdateFromMsg(ConstVisualPtr &_msg);
361 
364  public: bool IsPlane() const;
365 
368  public: VisualPtr GetParent() const;
369 
373  public: VisualPtr GetRootVisual();
374 
378  public: std::string GetShaderType() const;
379 
383  public: void SetShaderType(const std::string &_type);
384 
388  public: void MoveToPosition(const math::Pose &_pose, double _time);
389 
394  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
395  double _time,
396  boost::function<void()> _onComplete = NULL);
397 
403  public: void SetVisibilityFlags(uint32_t _flags);
404 
410  public: uint32_t GetVisibilityFlags();
411 
413  public: void ShowBoundingBox();
414 
418  public: void ShowCollision(bool _show);
419 
422  public: void ShowSkeleton(bool _show);
423 
426  public: void SetScene(ScenePtr _scene);
427 
430  public: ScenePtr GetScene() const;
431 
434  public: void ShowJoints(bool _show);
435 
438  public: void ShowCOM(bool _show);
439 
442  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
443 
448  public: void LoadPlugin(const std::string &_filename,
449  const std::string &_name,
450  sdf::ElementPtr _sdf);
451 
454  public: void RemovePlugin(const std::string &_name);
455 
457  public: uint32_t GetId() const;
458 
460  public: void SetId(uint32_t _id);
461 
464  public: std::string GetMeshName() const;
465 
469  public: std::string GetSubMeshName() const;
470 
472  public: void ClearParent();
473 
481  protected: Visual(VisualPrivate &_dataPtr,
482  const std::string &_name, VisualPtr _parent,
483  bool _useRTShader = true);
484 
492  protected: Visual(VisualPrivate &_dataPtr,
493  const std::string &_name, ScenePtr _scene,
494  bool _useRTShader = true);
495 
502  private: void Init(const std::string &_name, ScenePtr _scene,
503  bool _useRTShader);
504 
511  private: void Init(const std::string &_name, VisualPtr _parent,
512  bool _useRTShader);
513 
516  private: void LoadPlugins();
517 
518  private: void LoadPlugin(sdf::ElementPtr _sdf);
519 
523  private: void GetBoundsHelper(Ogre::SceneNode *_node,
524  math::Box &_box) const;
525 
529  private: bool GetCenterSubMesh() const;
530 
533  private: void DestroyAllAttachedMovableObjects(
534  Ogre::SceneNode *_sceneNode);
535 
538  protected: VisualPrivate *dataPtr;
539  };
541  }
542 }
543 #endif