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 2011 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  {
59 
62  class 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 
158  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
159  const std::string &_objName="");
160 
163  public: void SetScale(const math::Vector3 &_scale);
164 
167  public: math::Vector3 GetScale();
168 
174  public: void SetMaterial(const std::string &_materialName,
175  bool _unique = true);
176 
179  public: void SetAmbient(const common::Color &_color);
180 
183  public: void SetDiffuse(const common::Color &_color);
184 
187  public: void SetSpecular(const common::Color &_color);
188 
190  public: void AttachAxes();
191 
195  public: void SetTransparency(float _trans);
196 
199  public: float GetTransparency();
200 
201  public: void SetHighlighted(bool _highlighted);
202 
205  public: virtual void SetEmissive(const common::Color &_color);
206 
209  public: void SetCastShadows(bool _shadows);
210 
214  public: void SetVisible(bool _visible, bool _cascade = true);
215 
217  public: void ToggleVisible();
218 
221  public: bool GetVisible() const;
222 
225  public: void SetPosition(const math::Vector3 &_pos);
226 
229  public: void SetRotation(const math::Quaternion &_rot);
230 
233  public: void SetPose(const math::Pose &_pose);
234 
237  public: math::Vector3 GetPosition() const;
238 
241  public: math::Quaternion GetRotation() const;
242 
245  public: math::Pose GetPose() const;
246 
249  public: math::Pose GetWorldPose() const;
250 
253  public: void SetWorldPose(const math::Pose _pose);
254 
257  public: void SetWorldPosition(const math::Vector3 &_pos);
258 
261  public: void SetWorldRotation(const math::Quaternion &_rot);
262 
265  public: Ogre::SceneNode *GetSceneNode() const;
266 
268  public: void MakeStatic();
269 
272  public: bool IsStatic() const;
273 
276  public: void EnableTrackVisual(VisualPtr _vis);
277 
279  public: void DisableTrackVisual();
280 
283  public: std::string GetNormalMap() const;
284 
287  public: void SetNormalMap(const std::string &nmap);
288 
293  public: void SetRibbonTrail(bool _value,
294  const common::Color &_initialColor,
295  const common::Color &_changeColor);
296 
299  public: math::Box GetBoundingBox() const;
300 
306 
309  public: void DeleteDynamicLine(DynamicLines *_line);
310 
314  public: void AttachLineVertex(DynamicLines *_line,
315  unsigned int _index);
316 
319  public: std::string GetMaterialName() const;
320 
323  public: void InsertMesh(const std::string &_meshName);
324 
327  public: static void InsertMesh(const common::Mesh *_mesh);
328 
331  public: void UpdateFromMsg(ConstVisualPtr &_msg);
332 
335  public: bool IsPlane() const;
336 
339  public: VisualPtr GetParent() const;
340 
344  public: VisualPtr GetRootVisual();
345 
349  public: std::string GetShaderType() const;
350 
354  public: void SetShaderType(const std::string &_type);
355 
359  public: void MoveToPosition(const math::Pose &_pose, double _time);
360 
365  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
366  double _time,
367  boost::function<void()> _onComplete = NULL);
368 
374  public: void SetVisibilityFlags(uint32_t _flags);
375 
381  public: uint32_t GetVisibilityFlags();
382 
384  public: void ShowBoundingBox();
385 
389  public: void ShowCollision(bool _show);
390 
393  public: void ShowSkeleton(bool _show);
394 
397  public: void SetScene(ScenePtr _scene);
398 
401  public: ScenePtr GetScene() const;
402 
405  public: void ShowJoints(bool _show);
406 
409  public: void ShowCOM(bool _show);
410 
413  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
414 
419  public: void LoadPlugin(const std::string &_filename,
420  const std::string &_name,
421  sdf::ElementPtr _sdf);
422 
425  public: void RemovePlugin(const std::string &_name);
426 
430  private: void LoadPlugins();
431 
432  private: void LoadPlugin(sdf::ElementPtr _sdf);
433 
434  private: std::vector<VisualPluginPtr> plugins;
435 
439  private: void GetBoundsHelper(Ogre::SceneNode *_node,
440  math::Box &_box) const;
441 
444  private: std::string GetMeshName() const;
445 
447  public: void ClearParent();
448 
450  protected: ScenePtr scene;
451 
453  protected: Ogre::SceneNode *sceneNode;
454 
456  protected: VisualPtr parent;
457 
460  private: void DestroyAllAttachedMovableObjects(
461  Ogre::SceneNode *_sceneNode);
462 
464  private: sdf::ElementPtr sdf;
465 
467  private: std::string myMaterialName;
468 
470  private: std::string origMaterialName;
471 
473  private: float transparency;
474 
477  private: bool isStatic;
478 
480  private: Ogre::StaticGeometry *staticGeom;
481 
483  private: bool visible;
484 
486  private: Ogre::RibbonTrail *ribbonTrail;
487 
489  private: Ogre::SkeletonInstance *skeleton;
490 
492  private: event::ConnectionPtr preRenderConnection;
493 
495  private: std::list<DynamicLines*> lines;
496 
498  private: std::list< std::pair<DynamicLines*, unsigned int> > lineVertices;
499 
501  private: std::string name;
502 
504  private: std::vector<VisualPtr> children;
505 
507  private: Ogre::AnimationState *animState;
508 
510  private: common::Time prevAnimTime;
511 
513  private: boost::function<void()> onAnimationComplete;
514 
516  private: bool useRTShader;
517 
518  private: bool initialized;
519  };
521  }
522 }
523 #endif