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 2012 Nate Koenig
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 <list>
29 #include <vector>
30 
31 #include "common/Event.hh"
32 #include "math/Box.hh"
33 #include "math/Pose.hh"
34 #include "math/Quaternion.hh"
35 #include "math/Vector3.hh"
36 #include "math/Vector2d.hh"
37 
38 #include "sdf/sdf.hh"
39 #include "msgs/msgs.hh"
40 #include "rendering/RenderTypes.hh"
41 #include "common/CommonTypes.hh"
42 
43 namespace Ogre
44 {
45  class MovableObject;
46  class SceneNode;
47  class StaticGeometry;
48  class RibbonTrail;
49  class AnimationState;
50  class SkeletonInstance;
51 }
52 
53 namespace gazebo
54 {
55  namespace rendering
56  {
57  class WireBox;
58 
61 
64  class Visual : public boost::enable_shared_from_this<Visual>
65  {
71  public: Visual(const std::string &_name, VisualPtr _parent,
72  bool _useRTShader = true);
73 
79  public: Visual(const std::string &_name, ScenePtr _scene,
80  bool _useRTShader = true);
81 
83  public: virtual ~Visual();
84 
86  public: void Init();
87 
89  public: void Fini();
90 
95  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
96 
99  public: void LoadFromMsg(ConstVisualPtr &_msg);
100 
103  public: void Load(sdf::ElementPtr _sdf);
104 
106  public: virtual void Load();
107 
109  public: void Update();
110 
113  public: void SetName(const std::string &_name);
114 
117  public: std::string GetName() const;
118 
121  public: void AttachVisual(VisualPtr _vis);
122 
125  public: void DetachVisual(VisualPtr _vis);
126 
129  public: void DetachVisual(const std::string &_name);
130 
133  public: void AttachObject(Ogre::MovableObject *_obj);
134 
137  public: bool HasAttachedObject(const std::string &_name);
138 
141  public: unsigned int GetAttachedObjectCount() const;
142 
144  public: void DetachObjects();
145 
148  public: unsigned int GetChildCount();
149 
154  public: VisualPtr GetChild(unsigned int _index);
155 
160  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
161  const std::string &_objName="");
162 
165  public: void SetScale(const math::Vector3 &_scale);
166 
169  public: math::Vector3 GetScale();
170 
176  public: void SetMaterial(const std::string &_materialName,
177  bool _unique = true);
178 
181  public: void SetAmbient(const common::Color &_color);
182 
185  public: void SetDiffuse(const common::Color &_color);
186 
189  public: void SetSpecular(const common::Color &_color);
190 
192  public: void AttachAxes();
193 
197  public: void SetTransparency(float _trans);
198 
201  public: float GetTransparency();
202 
206  public: void SetHighlighted(bool _highlighted);
207 
210  public: virtual void SetEmissive(const common::Color &_color);
211 
214  public: void SetCastShadows(bool _shadows);
215 
219  public: void SetVisible(bool _visible, bool _cascade = true);
220 
222  public: void ToggleVisible();
223 
226  public: bool GetVisible() const;
227 
230  public: void SetPosition(const math::Vector3 &_pos);
231 
234  public: void SetRotation(const math::Quaternion &_rot);
235 
238  public: void SetPose(const math::Pose &_pose);
239 
242  public: math::Vector3 GetPosition() const;
243 
246  public: math::Quaternion GetRotation() const;
247 
250  public: math::Pose GetPose() const;
251 
254  public: math::Pose GetWorldPose() const;
255 
258  public: void SetWorldPose(const math::Pose _pose);
259 
262  public: void SetWorldPosition(const math::Vector3 &_pos);
263 
266  public: void SetWorldRotation(const math::Quaternion &_rot);
267 
270  public: Ogre::SceneNode *GetSceneNode() const;
271 
273  public: void MakeStatic();
274 
277  public: bool IsStatic() const;
278 
281  public: void EnableTrackVisual(VisualPtr _vis);
282 
284  public: void DisableTrackVisual();
285 
288  public: std::string GetNormalMap() const;
289 
292  public: void SetNormalMap(const std::string &_nmap);
293 
298  public: void SetRibbonTrail(bool _value,
299  const common::Color &_initialColor,
300  const common::Color &_changeColor);
301 
304  public: math::Box GetBoundingBox() const;
305 
311 
314  public: void DeleteDynamicLine(DynamicLines *_line);
315 
319  public: void AttachLineVertex(DynamicLines *_line,
320  unsigned int _index);
321 
324  public: std::string GetMaterialName() const;
325 
328  public: void InsertMesh(const std::string &_meshName);
329 
332  public: static void InsertMesh(const common::Mesh *_mesh);
333 
336  public: void UpdateFromMsg(ConstVisualPtr &_msg);
337 
340  public: bool IsPlane() const;
341 
344  public: VisualPtr GetParent() const;
345 
349  public: VisualPtr GetRootVisual();
350 
354  public: std::string GetShaderType() const;
355 
359  public: void SetShaderType(const std::string &_type);
360 
364  public: void MoveToPosition(const math::Pose &_pose, double _time);
365 
370  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
371  double _time,
372  boost::function<void()> _onComplete = NULL);
373 
379  public: void SetVisibilityFlags(uint32_t _flags);
380 
386  public: uint32_t GetVisibilityFlags();
387 
389  public: void ShowBoundingBox();
390 
394  public: void ShowCollision(bool _show);
395 
398  public: void ShowSkeleton(bool _show);
399 
402  public: void SetScene(ScenePtr _scene);
403 
406  public: ScenePtr GetScene() const;
407 
410  public: void ShowJoints(bool _show);
411 
414  public: void ShowCOM(bool _show);
415 
418  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
419 
424  public: void LoadPlugin(const std::string &_filename,
425  const std::string &_name,
426  sdf::ElementPtr _sdf);
427 
430  public: void RemovePlugin(const std::string &_name);
431 
435  private: void LoadPlugins();
436 
437  private: void LoadPlugin(sdf::ElementPtr _sdf);
438 
439  private: std::vector<VisualPluginPtr> plugins;
440 
444  private: void GetBoundsHelper(Ogre::SceneNode *_node,
445  math::Box &_box) const;
446 
449  private: std::string GetMeshName() const;
450 
452  public: void ClearParent();
453 
455  protected: ScenePtr scene;
456 
458  protected: Ogre::SceneNode *sceneNode;
459 
461  protected: VisualPtr parent;
462 
465  private: void DestroyAllAttachedMovableObjects(
466  Ogre::SceneNode *_sceneNode);
467 
469  private: sdf::ElementPtr sdf;
470 
472  private: std::string myMaterialName;
473 
475  private: std::string origMaterialName;
476 
478  private: float transparency;
479 
482  private: bool isStatic;
483 
485  private: Ogre::StaticGeometry *staticGeom;
486 
488  private: bool visible;
489 
491  private: Ogre::RibbonTrail *ribbonTrail;
492 
494  private: Ogre::SkeletonInstance *skeleton;
495 
497  private: event::ConnectionPtr preRenderConnection;
498 
500  private: std::list<DynamicLines*> lines;
501 
503  private: std::list< std::pair<DynamicLines*, unsigned int> > lineVertices;
504 
506  private: std::string name;
507 
509  private: std::vector<VisualPtr> children;
510 
512  private: Ogre::AnimationState *animState;
513 
515  private: common::Time prevAnimTime;
516 
518  private: boost::function<void()> onAnimationComplete;
519 
521  private: bool useRTShader;
522 
524  private: bool initialized;
525 
527  private: WireBox *boundingBox;
528  };
530  }
531 }
532 #endif