GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/gepetto/viewer/window-manager.h Lines: 0 5 0.0 %
Date: 2020-05-14 11:23:33 Branches: 0 0 - %

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 <osgGA/KeySwitchMatrixManipulator>
13
#include <osgViewer/Viewer>
14
#include <osgViewer/ViewerEventHandlers>
15
#include <gepetto/viewer/group-node.h>
16
17
namespace gepetto {
18
namespace viewer {
19
20
    DEF_CLASS_SMART_PTR(WindowManager)
21
22
    /// Manage a window that renders a scene.
23
    /// The root of the rendered scene is a \ref GroupNode.
24
    class WindowManager : public GroupNode
25
    {
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, 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
83
        /** Initialize weak_ptr */
84
        void initWeakPtr (WindowManagerWeakPtr other_weak_ptr);
85
    protected:
86
87
    public:
88
        enum TextAlignment {
89
          TOP    = 0,
90
          CENTER = 1,
91
          BOTTOM = 2,
92
          RIGHT  = 0,
93
          LEFT   = 2
94
        };
95
96
        /** Create and initialize a graphical engine of type OSG
97
         */
98
        static WindowManagerPtr_t create();
99
100
        /** Create and initialize a graphical engine with a GraphicsContext
101
         */
102
        static WindowManagerPtr_t create(osg::GraphicsContext* gc);
103
104
        static WindowManagerPtr_t create(osgViewer::Viewer* v, osg::GraphicsContext* gc);
105
106
        /** Create and initialize a graphical engine of type OSG with some parameters : position + dimension
107
         */
108
        static WindowManagerPtr_t create(const unsigned int& x, const unsigned int& y, const unsigned int& width, 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, TextAlignment horizontalPos) const;
159
160
        /** Set the HUD text */
161
        void setText (TextAlignment verticalPos, TextAlignment horizontalPos,
162
            const std::string& text, float size = 20);
163
164
        /** Return a ref to the viewer */
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 */