window-manager.h
Go to the documentation of this file.
1 //
2 // window-manager.h
3 // ScneViewer
4 //
5 // Created by Justin Carpentier, Mathieu Geisert in November 2014.
6 // Copyright (c) 2014 LAAS-CNRS. All rights reserved.
7 //
8 
9 #ifndef GEPETTO_VIEWER_WINDOWMANAGER_HH
10 #define GEPETTO_VIEWER_WINDOWMANAGER_HH
11 
12 #include <osgGA/KeySwitchMatrixManipulator>
13 #include <osgViewer/Viewer>
14 #include <osgViewer/ViewerEventHandlers>
16 
17 namespace gepetto {
18 namespace viewer {
19 
20  DEF_CLASS_SMART_PTR(WindowManager)
21 
22 
23  class WindowManager : public GroupNode
25  {
26  private:
27  const int nodeTrackerManipulatorIndex;
28 
30  GroupNodePtr_t scene_ptr_;
31 
33  ::osgViewer::ViewerRefPtr viewer_ptr_;
34 
36  ::osg::CameraRefPtr main_camera_;
37  ::osg::GraphicsContextRefPtr gc_;
38 
40  ::osg::CameraRefPtr bg_camera_;
41  ::osg::Vec4 bg_color1_;
42  ::osg::Vec4 bg_color2_;
43  ::osg::GeometryRefPtr bg_geom_;
44 
45  /* OSG Screen capture handler */
46  osg::ref_ptr < ::osgViewer::ScreenCaptureHandler> screen_capture_ptr_;
47 
49  ::osg::CameraRefPtr hud_camera_;
50  osg::ref_ptr<osgText::Text> texts_[3][3];
51  osg::ref_ptr<osg::Geode> textGeode_;
52  bool textActive_[3][3];
53 
54  bool lastSceneWasDisrty_;
55 
56  osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> manipulator_ptr;
58  WindowManagerWeakPtr weak_ptr_;
59 
60  void createManipulator();
61 
62  void createBackground();
63  void applyBackgroundColor();
64 
65  void createHUDcamera();
66 
67  void init(osg::GraphicsContext* gc);
68 
69  void init(osgViewer::Viewer* v, osg::GraphicsContext* gc);
70 
71  void init(const unsigned int& x, const unsigned int& y, const unsigned int& width, const unsigned int& height);
72 
73  WindowManager();
74 
75  WindowManager (osgViewer::Viewer* v, osg::GraphicsContext* gc);
76 
77  WindowManager (osg::GraphicsContext* gc);
78 
79  WindowManager(const unsigned int& x, const unsigned int& y, const unsigned int& width, const unsigned int& height);
80 
81  WindowManager(const WindowManager& other);
82 
84  void initWeakPtr (WindowManagerWeakPtr other_weak_ptr);
85  protected:
86 
87  public:
89  TOP = 0,
90  CENTER = 1,
91  BOTTOM = 2,
92  RIGHT = 0,
93  LEFT = 2
94  };
95 
98  static WindowManagerPtr_t create();
99 
102  static WindowManagerPtr_t create(osg::GraphicsContext* gc);
103 
104  static WindowManagerPtr_t create(osgViewer::Viewer* v, osg::GraphicsContext* gc);
105 
108  static WindowManagerPtr_t create(const unsigned int& x, const unsigned int& y, const unsigned int& width, const unsigned int& height);
109 
113 
116  virtual WindowManagerPtr_t clone(void) const;
117 
120  WindowManagerPtr_t self(void) const;
121 
124  virtual bool addNode(NodePtr_t graphical_object_ptr);
125 
128  virtual GroupNodePtr_t getScene() const { return self(); }
129 
132  virtual bool done ();
133 
136  virtual bool frame ();
137 
140  virtual bool run ();
141 
145  virtual void setWindowDimension (const osgVector2& size);
146 
150  virtual void setWindowPosition (const osgVector2& position);
151 
153  osgVector2 getWindowPosition () const;
154 
157 
158  std::string getText (TextAlignment verticalPos, TextAlignment horizontalPos) const;
159 
161  void setText (TextAlignment verticalPos, TextAlignment horizontalPos,
162  const std::string& text, float size = 20);
163 
165  ::osgViewer::ViewerRefPtr getViewerClone();
166 
167  virtual ~WindowManager();
168 
169  void captureFrame (const std::string& filename);
170 
171  void startCapture (const std::string& filename,
172  const std::string& extension);
173 
174  void stopCapture ();
175 
176  bool writeNodeFile (const std::string& filename);
177 
178  void setBackgroundColor1(const osg::Vec4 & color)
179  { bg_color1_ = color; applyBackgroundColor(); }
180 
181  void setBackgroundColor2(const osg::Vec4 & color)
182  { bg_color2_ = color; applyBackgroundColor(); }
183 
184  void getCameraTransform(osg::Vec3d &pos, osg::Quat &rot);
185  void setCameraTransform(const osg::Vec3d &pos, const osg::Quat &rot);
186 
187  void attachCameraToNode(NodePtr_t node);
188  void detachCamera();
189 
190  };
191 } /* namespace viewer */
192 } /* namespace gepetto */
193 
194 #endif /* GEPETTO_VIEWER_WINDOWMANAGER_HH */
std::string getText(TextAlignment verticalPos, TextAlignment horizontalPos) const
void attachCameraToNode(NodePtr_t node)
void startCapture(const std::string &filename, const std::string &extension)
TextAlignment
Definition: window-manager.h:88
virtual void setWindowDimension(const osgVector2 &size)
Definition: window-manager.h:89
viewer::WindowManagerPtr_t WindowManagerPtr_t
Definition: osgwidget.hh:40
osgVector2 getWindowPosition() const
virtual bool addNode(NodePtr_t graphical_object_ptr)
void getCameraTransform(osg::Vec3d &pos, osg::Quat &rot)
void setBackgroundColor2(const osg::Vec4 &color)
Definition: window-manager.h:181
::osg::Vec2f osgVector2
Definition: config-osg.h:108
static WindowManagerPtr_t createCopy(WindowManagerPtr_t other)
Definition: window-manager.h:92
void captureFrame(const std::string &filename)
Definition: window-manager.h:93
Definition: window-manager.h:91
viewer::NodePtr_t NodePtr_t
Definition: fwd.hh:47
Definition: action-search-bar.hh:27
::osgViewer::ViewerRefPtr getViewerClone()
Definition: window-manager.h:90
viewer::GroupNodePtr_t GroupNodePtr_t
Definition: fwd.hh:50
void setCameraTransform(const osg::Vec3d &pos, const osg::Quat &rot)
bool writeNodeFile(const std::string &filename)
void setText(TextAlignment verticalPos, TextAlignment horizontalPos, const std::string &text, float size=20)
#define DEF_CLASS_SMART_PTR(className)
Definition: macros.h:50
virtual GroupNodePtr_t getScene() const
Definition: window-manager.h:128
virtual void setWindowPosition(const osgVector2 &position)
osgVector2 getWindowDimension() const
virtual WindowManagerPtr_t clone(void) const
void setBackgroundColor1(const osg::Vec4 &color)
Definition: window-manager.h:178
static WindowManagerPtr_t create()