Line |
Branch |
Exec |
Source |
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 <gepetto/viewer/group-node.h> |
13 |
|
|
|
14 |
|
|
#include <osgGA/KeySwitchMatrixManipulator> |
15 |
|
|
#include <osgViewer/Viewer> |
16 |
|
|
#include <osgViewer/ViewerEventHandlers> |
17 |
|
|
|
18 |
|
|
namespace gepetto { |
19 |
|
|
namespace viewer { |
20 |
|
|
|
21 |
|
|
DEF_CLASS_SMART_PTR(WindowManager) |
22 |
|
|
|
23 |
|
|
/// Manage a window that renders a scene. |
24 |
|
|
/// The root of the rendered scene is a \ref GroupNode. |
25 |
|
|
class WindowManager : public GroupNode { |
26 |
|
|
private: |
27 |
|
|
const int nodeTrackerManipulatorIndex; |
28 |
|
|
|
29 |
|
|
/** Scene Graphical Group */ |
30 |
|
|
GroupNodePtr_t scene_ptr_; |
31 |
|
|
|
32 |
|
|
/** OSG viewer */ |
33 |
|
|
::osgViewer::ViewerRefPtr viewer_ptr_; |
34 |
|
|
|
35 |
|
|
/** OSG cameras */ |
36 |
|
|
::osg::CameraRefPtr main_camera_; |
37 |
|
|
::osg::GraphicsContextRefPtr gc_; |
38 |
|
|
|
39 |
|
|
/** Backgound camera */ |
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 |
|
|
|
48 |
|
|
/** Heads-Up Display (HUD) camera */ |
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; |
57 |
|
|
/** Associated weak pointer */ |
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, |
72 |
|
|
const unsigned int& width, const unsigned int& height); |
73 |
|
|
|
74 |
|
|
WindowManager(); |
75 |
|
|
|
76 |
|
|
WindowManager(osgViewer::Viewer* v, osg::GraphicsContext* gc); |
77 |
|
|
|
78 |
|
|
WindowManager(osg::GraphicsContext* gc); |
79 |
|
|
|
80 |
|
|
WindowManager(const unsigned int& x, const unsigned int& y, |
81 |
|
|
const unsigned int& width, const unsigned int& height); |
82 |
|
|
|
83 |
|
|
WindowManager(const WindowManager& other); |
84 |
|
|
|
85 |
|
|
/** Initialize weak_ptr */ |
86 |
|
|
void initWeakPtr(WindowManagerWeakPtr other_weak_ptr); |
87 |
|
|
|
88 |
|
|
protected: |
89 |
|
|
public: |
90 |
|
|
enum TextAlignment { TOP = 0, CENTER = 1, BOTTOM = 2, RIGHT = 0, LEFT = 2 }; |
91 |
|
|
|
92 |
|
|
/** Create and initialize a graphical engine of type OSG |
93 |
|
|
*/ |
94 |
|
|
static WindowManagerPtr_t create(); |
95 |
|
|
|
96 |
|
|
/** Create and initialize a graphical engine with a GraphicsContext |
97 |
|
|
*/ |
98 |
|
|
static WindowManagerPtr_t create(osg::GraphicsContext* gc); |
99 |
|
|
|
100 |
|
|
static WindowManagerPtr_t create(osgViewer::Viewer* v, |
101 |
|
|
osg::GraphicsContext* gc); |
102 |
|
|
|
103 |
|
|
/** Create and initialize a graphical engine of type OSG with some parameters |
104 |
|
|
* : position + dimension |
105 |
|
|
*/ |
106 |
|
|
static WindowManagerPtr_t create(const unsigned int& x, const unsigned int& y, |
107 |
|
|
const unsigned int& width, |
108 |
|
|
const unsigned int& height); |
109 |
|
|
|
110 |
|
|
/** Static method for creating a clone of box other with the copy constructor |
111 |
|
|
*/ |
112 |
|
|
static WindowManagerPtr_t createCopy(WindowManagerPtr_t other); |
113 |
|
|
|
114 |
|
|
/** Proceed to a clonage of the current object defined by the copy constructor |
115 |
|
|
*/ |
116 |
|
|
virtual WindowManagerPtr_t clone(void) const; |
117 |
|
|
|
118 |
|
|
/** Return a shared pointer of the current object |
119 |
|
|
*/ |
120 |
|
|
WindowManagerPtr_t self(void) const; |
121 |
|
|
|
122 |
|
|
/** Add a graphical object to the scene |
123 |
|
|
*/ |
124 |
|
|
virtual bool addNode(NodePtr_t graphical_object_ptr); |
125 |
|
|
|
126 |
|
|
/** Return the scene group |
127 |
|
|
*/ |
128 |
|
✗ |
virtual GroupNodePtr_t getScene() const { return self(); } |
129 |
|
|
|
130 |
|
|
/** Return the current doing of procedure |
131 |
|
|
*/ |
132 |
|
|
virtual bool done(); |
133 |
|
|
|
134 |
|
|
/** Generate a new frame rendering |
135 |
|
|
*/ |
136 |
|
|
virtual bool frame(); |
137 |
|
|
|
138 |
|
|
/** Run the scene process |
139 |
|
|
*/ |
140 |
|
|
virtual bool run(); |
141 |
|
|
|
142 |
|
|
/** Define dimension of the window |
143 |
|
|
* \param size (width, height) |
144 |
|
|
**/ |
145 |
|
|
virtual void setWindowDimension(const osgVector2& size); |
146 |
|
|
|
147 |
|
|
/** Define the window position |
148 |
|
|
* \param position (x_pos, y_pos) |
149 |
|
|
**/ |
150 |
|
|
virtual void setWindowPosition(const osgVector2& position); |
151 |
|
|
|
152 |
|
|
/** Return the window x and y position as a 2D vector */ |
153 |
|
|
osgVector2 getWindowPosition() const; |
154 |
|
|
|
155 |
|
|
/** Return the window width and height as a 2D vector */ |
156 |
|
|
osgVector2 getWindowDimension() const; |
157 |
|
|
|
158 |
|
|
std::string getText(TextAlignment verticalPos, |
159 |
|
|
TextAlignment horizontalPos) const; |
160 |
|
|
|
161 |
|
|
/** Set the HUD text */ |
162 |
|
|
void setText(TextAlignment verticalPos, TextAlignment horizontalPos, |
163 |
|
|
const std::string& text, float size = 20); |
164 |
|
|
|
165 |
|
|
/** Return a ref to the viewer */ |
166 |
|
|
::osgViewer::ViewerRefPtr getViewerClone(); |
167 |
|
|
|
168 |
|
|
virtual ~WindowManager(); |
169 |
|
|
|
170 |
|
|
void captureFrame(const std::string& filename); |
171 |
|
|
|
172 |
|
|
void startCapture(const std::string& filename, 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; |
180 |
|
✗ |
applyBackgroundColor(); |
181 |
|
|
} |
182 |
|
|
|
183 |
|
✗ |
void setBackgroundColor2(const osg::Vec4& color) { |
184 |
|
✗ |
bg_color2_ = color; |
185 |
|
✗ |
applyBackgroundColor(); |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
void getCameraTransform(osg::Vec3d& pos, osg::Quat& rot); |
189 |
|
|
void setCameraTransform(const osg::Vec3d& pos, const osg::Quat& rot); |
190 |
|
|
|
191 |
|
|
void attachCameraToNode(NodePtr_t node); |
192 |
|
|
void detachCamera(); |
193 |
|
|
}; |
194 |
|
|
} /* namespace viewer */ |
195 |
|
|
} /* namespace gepetto */ |
196 |
|
|
|
197 |
|
|
#endif /* GEPETTO_VIEWER_WINDOWMANAGER_HH */ |
198 |
|
|
|