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 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 <list>
29 #include <vector>
30 
31 #include "gazebo/msgs/msgs.hh"
32 #include "gazebo/common/Event.hh"
33 #include "gazebo/math/Box.hh"
34 #include "gazebo/math/Pose.hh"
36 #include "gazebo/math/Vector3.hh"
37 #include "gazebo/math/Vector2d.hh"
38 
39 #include "gazebo/sdf/sdf.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 
163  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
164  const std::string &_subMesh="",
165  bool _centerSubmesh = false,
166  const std::string &_objName="");
167 
170  public: void SetScale(const math::Vector3 &_scale);
171 
174  public: math::Vector3 GetScale();
175 
181  public: void SetMaterial(const std::string &_materialName,
182  bool _unique = true);
183 
186  public: void SetAmbient(const common::Color &_color);
187 
190  public: void SetDiffuse(const common::Color &_color);
191 
194  public: void SetSpecular(const common::Color &_color);
195 
197  public: void AttachAxes();
198 
201  public: void SetWireframe(bool _show);
202 
206  public: void SetTransparency(float _trans);
207 
210  public: float GetTransparency();
211 
215  public: void SetHighlighted(bool _highlighted);
216 
219  public: virtual void SetEmissive(const common::Color &_color);
220 
223  public: void SetCastShadows(bool _shadows);
224 
228  public: void SetVisible(bool _visible, bool _cascade = true);
229 
231  public: void ToggleVisible();
232 
235  public: bool GetVisible() const;
236 
239  public: void SetPosition(const math::Vector3 &_pos);
240 
243  public: void SetRotation(const math::Quaternion &_rot);
244 
247  public: void SetPose(const math::Pose &_pose);
248 
251  public: math::Vector3 GetPosition() const;
252 
255  public: math::Quaternion GetRotation() const;
256 
259  public: math::Pose GetPose() const;
260 
263  public: math::Pose GetWorldPose() const;
264 
267  public: void SetWorldPose(const math::Pose _pose);
268 
271  public: void SetWorldPosition(const math::Vector3 &_pos);
272 
275  public: void SetWorldRotation(const math::Quaternion &_rot);
276 
279  public: Ogre::SceneNode *GetSceneNode() const;
280 
282  public: void MakeStatic();
283 
286  public: bool IsStatic() const;
287 
290  public: void EnableTrackVisual(VisualPtr _vis);
291 
293  public: void DisableTrackVisual();
294 
297  public: std::string GetNormalMap() const;
298 
301  public: void SetNormalMap(const std::string &_nmap);
302 
307  public: void SetRibbonTrail(bool _value,
308  const common::Color &_initialColor,
309  const common::Color &_changeColor);
310 
313  public: math::Box GetBoundingBox() const;
314 
320 
323  public: void DeleteDynamicLine(DynamicLines *_line);
324 
328  public: void AttachLineVertex(DynamicLines *_line,
329  unsigned int _index);
330 
333  public: std::string GetMaterialName() const;
334 
339  public: void InsertMesh(const std::string &_meshName,
340  const std::string &_subMesh = "",
341  bool _centerSubmesh = false);
342 
347  public: static void InsertMesh(const common::Mesh *_mesh,
348  const std::string &_subMesh = "",
349  bool _centerSubmesh = false);
350 
353  public: void UpdateFromMsg(ConstVisualPtr &_msg);
354 
357  public: bool IsPlane() const;
358 
361  public: VisualPtr GetParent() const;
362 
366  public: VisualPtr GetRootVisual();
367 
371  public: std::string GetShaderType() const;
372 
376  public: void SetShaderType(const std::string &_type);
377 
381  public: void MoveToPosition(const math::Pose &_pose, double _time);
382 
387  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
388  double _time,
389  boost::function<void()> _onComplete = NULL);
390 
396  public: void SetVisibilityFlags(uint32_t _flags);
397 
403  public: uint32_t GetVisibilityFlags();
404 
406  public: void ShowBoundingBox();
407 
411  public: void ShowCollision(bool _show);
412 
415  public: void ShowSkeleton(bool _show);
416 
419  public: void SetScene(ScenePtr _scene);
420 
423  public: ScenePtr GetScene() const;
424 
427  public: void ShowJoints(bool _show);
428 
431  public: void ShowCOM(bool _show);
432 
435  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
436 
441  public: void LoadPlugin(const std::string &_filename,
442  const std::string &_name,
443  sdf::ElementPtr _sdf);
444 
447  public: void RemovePlugin(const std::string &_name);
448 
452  private: void LoadPlugins();
453 
454  private: void LoadPlugin(sdf::ElementPtr _sdf);
455 
456  private: std::vector<VisualPluginPtr> plugins;
457 
461  private: void GetBoundsHelper(Ogre::SceneNode *_node,
462  math::Box &_box) const;
463 
466  public: std::string GetMeshName() const;
467 
471  public: std::string GetSubMeshName() const;
472 
474  public: void ClearParent();
475 
477  protected: ScenePtr scene;
478 
480  protected: Ogre::SceneNode *sceneNode;
481 
483  protected: VisualPtr parent;
484 
488  private: bool GetCenterSubMesh() const;
489 
492  private: void DestroyAllAttachedMovableObjects(
493  Ogre::SceneNode *_sceneNode);
494 
496  private: sdf::ElementPtr sdf;
497 
499  private: std::string myMaterialName;
500 
502  private: std::string origMaterialName;
503 
505  private: float transparency;
506 
509  private: bool isStatic;
510 
512  private: Ogre::StaticGeometry *staticGeom;
513 
515  private: bool visible;
516 
518  private: Ogre::RibbonTrail *ribbonTrail;
519 
521  private: Ogre::SkeletonInstance *skeleton;
522 
524  private: event::ConnectionPtr preRenderConnection;
525 
527  private: std::list<DynamicLines*> lines;
528 
530  private: std::list< std::pair<DynamicLines*, unsigned int> > lineVertices;
531 
533  private: std::string name;
534 
536  private: std::vector<VisualPtr> children;
537 
539  private: Ogre::AnimationState *animState;
540 
542  private: common::Time prevAnimTime;
543 
545  private: boost::function<void()> onAnimationComplete;
546 
548  private: bool useRTShader;
549 
551  private: bool initialized;
552 
554  private: WireBox *boundingBox;
555  };
557  }
558 }
559 #endif