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 <list>
29 #include <vector>
30 
31 #include <sdf/sdf.hh>
32 
33 #include "gazebo/msgs/msgs.hh"
34 #include "gazebo/common/Event.hh"
35 #include "gazebo/math/Box.hh"
36 #include "gazebo/math/Pose.hh"
38 #include "gazebo/math/Vector3.hh"
39 #include "gazebo/math/Vector2d.hh"
40 
43 
44 namespace Ogre
45 {
46  class MovableObject;
47  class SceneNode;
48  class StaticGeometry;
49  class RibbonTrail;
50  class AnimationState;
51  class SkeletonInstance;
52 }
53 
54 namespace gazebo
55 {
56  namespace rendering
57  {
58  class WireBox;
59 
62 
65  class Visual : public boost::enable_shared_from_this<Visual>
66  {
72  public: Visual(const std::string &_name, VisualPtr _parent,
73  bool _useRTShader = true);
74 
80  public: Visual(const std::string &_name, ScenePtr _scene,
81  bool _useRTShader = true);
82 
84  public: virtual ~Visual();
85 
87  public: void Init();
88 
90  public: void Fini();
91 
96  public: VisualPtr Clone(const std::string &_name, VisualPtr _newParent);
97 
100  public: void LoadFromMsg(ConstVisualPtr &_msg);
101 
104  public: void Load(sdf::ElementPtr _sdf);
105 
107  public: virtual void Load();
108 
110  public: void Update();
111 
114  public: void SetName(const std::string &_name);
115 
118  public: std::string GetName() const;
119 
122  public: void AttachVisual(VisualPtr _vis);
123 
126  public: void DetachVisual(VisualPtr _vis);
127 
130  public: void DetachVisual(const std::string &_name);
131 
134  public: void AttachObject(Ogre::MovableObject *_obj);
135 
138  public: bool HasAttachedObject(const std::string &_name);
139 
142  public: unsigned int GetAttachedObjectCount() const;
143 
145  public: void DetachObjects();
146 
149  public: unsigned int GetChildCount();
150 
155  public: VisualPtr GetChild(unsigned int _index);
156 
164  public: Ogre::MovableObject *AttachMesh(const std::string &_meshName,
165  const std::string &_subMesh="",
166  bool _centerSubmesh = false,
167  const std::string &_objName="");
168 
171  public: void SetScale(const math::Vector3 &_scale);
172 
175  public: math::Vector3 GetScale();
176 
182  public: void SetMaterial(const std::string &_materialName,
183  bool _unique = true);
184 
187  public: void SetAmbient(const common::Color &_color);
188 
191  public: void SetDiffuse(const common::Color &_color);
192 
195  public: void SetSpecular(const common::Color &_color);
196 
198  public: void AttachAxes();
199 
202  public: void SetWireframe(bool _show);
203 
207  public: void SetTransparency(float _trans);
208 
211  public: float GetTransparency();
212 
216  public: void SetHighlighted(bool _highlighted);
217 
220  public: virtual void SetEmissive(const common::Color &_color);
221 
224  public: void SetCastShadows(bool _shadows);
225 
229  public: void SetVisible(bool _visible, bool _cascade = true);
230 
232  public: void ToggleVisible();
233 
236  public: bool GetVisible() const;
237 
240  public: void SetPosition(const math::Vector3 &_pos);
241 
244  public: void SetRotation(const math::Quaternion &_rot);
245 
248  public: void SetPose(const math::Pose &_pose);
249 
252  public: math::Vector3 GetPosition() const;
253 
256  public: math::Quaternion GetRotation() const;
257 
260  public: math::Pose GetPose() const;
261 
264  public: math::Pose GetWorldPose() const;
265 
268  public: void SetWorldPose(const math::Pose _pose);
269 
272  public: void SetWorldPosition(const math::Vector3 &_pos);
273 
276  public: void SetWorldRotation(const math::Quaternion &_rot);
277 
280  public: Ogre::SceneNode *GetSceneNode() const;
281 
283  public: void MakeStatic();
284 
287  public: bool IsStatic() const;
288 
291  public: void EnableTrackVisual(VisualPtr _vis);
292 
294  public: void DisableTrackVisual();
295 
298  public: std::string GetNormalMap() const;
299 
302  public: void SetNormalMap(const std::string &_nmap);
303 
308  public: void SetRibbonTrail(bool _value,
309  const common::Color &_initialColor,
310  const common::Color &_changeColor);
311 
314  public: math::Box GetBoundingBox() const;
315 
321 
324  public: void DeleteDynamicLine(DynamicLines *_line);
325 
329  public: void AttachLineVertex(DynamicLines *_line,
330  unsigned int _index);
331 
334  public: std::string GetMaterialName() const;
335 
340  public: void InsertMesh(const std::string &_meshName,
341  const std::string &_subMesh = "",
342  bool _centerSubmesh = false);
343 
348  public: static void InsertMesh(const common::Mesh *_mesh,
349  const std::string &_subMesh = "",
350  bool _centerSubmesh = false);
351 
354  public: void UpdateFromMsg(ConstVisualPtr &_msg);
355 
358  public: bool IsPlane() const;
359 
362  public: VisualPtr GetParent() const;
363 
367  public: VisualPtr GetRootVisual();
368 
372  public: std::string GetShaderType() const;
373 
377  public: void SetShaderType(const std::string &_type);
378 
382  public: void MoveToPosition(const math::Pose &_pose, double _time);
383 
388  public: void MoveToPositions(const std::vector<math::Pose> &_pts,
389  double _time,
390  boost::function<void()> _onComplete = NULL);
391 
397  public: void SetVisibilityFlags(uint32_t _flags);
398 
404  public: uint32_t GetVisibilityFlags();
405 
407  public: void ShowBoundingBox();
408 
412  public: void ShowCollision(bool _show);
413 
416  public: void ShowSkeleton(bool _show);
417 
420  public: void SetScene(ScenePtr _scene);
421 
424  public: ScenePtr GetScene() const;
425 
428  public: void ShowJoints(bool _show);
429 
432  public: void ShowCOM(bool _show);
433 
436  public: void SetSkeletonPose(const msgs::PoseAnimation &_pose);
437 
442  public: void LoadPlugin(const std::string &_filename,
443  const std::string &_name,
444  sdf::ElementPtr _sdf);
445 
448  public: void RemovePlugin(const std::string &_name);
449 
451  public: uint32_t GetId() const;
452 
454  public: void SetId(uint32_t _id);
455 
459  private: void LoadPlugins();
460 
461  private: void LoadPlugin(sdf::ElementPtr _sdf);
462 
463  private: std::vector<VisualPluginPtr> plugins;
464 
468  private: void GetBoundsHelper(Ogre::SceneNode *_node,
469  math::Box &_box) const;
470 
473  public: std::string GetMeshName() const;
474 
478  public: std::string GetSubMeshName() const;
479 
481  public: void ClearParent();
482 
484  protected: ScenePtr scene;
485 
487  protected: Ogre::SceneNode *sceneNode;
488 
490  protected: VisualPtr parent;
491 
495  private: bool GetCenterSubMesh() const;
496 
499  private: void DestroyAllAttachedMovableObjects(
500  Ogre::SceneNode *_sceneNode);
501 
503  private: sdf::ElementPtr sdf;
504 
506  private: std::string myMaterialName;
507 
509  private: std::string origMaterialName;
510 
512  private: float transparency;
513 
516  private: bool isStatic;
517 
519  private: Ogre::StaticGeometry *staticGeom;
520 
522  private: bool visible;
523 
525  private: Ogre::RibbonTrail *ribbonTrail;
526 
528  private: Ogre::SkeletonInstance *skeleton;
529 
531  private: event::ConnectionPtr preRenderConnection;
532 
534  private: std::list<DynamicLines*> lines;
535 
537  private: std::list< std::pair<DynamicLines*, unsigned int> > lineVertices;
538 
540  private: std::string name;
541 
543  private: std::vector<VisualPtr> children;
544 
546  private: Ogre::AnimationState *animState;
547 
549  private: common::Time prevAnimTime;
550 
552  private: boost::function<void()> onAnimationComplete;
553 
555  private: bool useRTShader;
556 
558  private: bool initialized;
559 
561  private: WireBox *boundingBox;
562 
564  private: uint32_t id;
565 
567  private: static uint32_t visualIdCount;
568 
570  private: math::Vector3 scale;
571  };
573  }
574 }
575 #endif