WGEViewer.h 5.02 KB
Newer Older
ebaum's avatar
ebaum committed
1 2
//---------------------------------------------------------------------------
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
ebaum's avatar
ebaum committed
4
//
5 6
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
// For more information see http://www.openwalnut.org/copying
ebaum's avatar
ebaum committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
//
// This file is part of OpenWalnut.
//
// OpenWalnut is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenWalnut is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
//
//---------------------------------------------------------------------------

#ifndef WGEVIEWER_H
#define WGEVIEWER_H

28 29
#include <string>

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
30
#include <boost/shared_ptr.hpp>
31
#include <boost/enable_shared_from_this.hpp>
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
32

ebaum's avatar
ebaum committed
33 34
#include <osg/Node>

ebaum's avatar
ebaum committed
35 36 37 38 39 40 41 42 43
#include <osgGA/FlightManipulator>
#include <osgGA/DriveManipulator>
#include <osgGA/TerrainManipulator>
#include <osgGA/UFOManipulator>

#include <osgViewer/Viewer>
#include <osgViewer/CompositeViewer>
#include <osgViewer/View>

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
44
#include "../common/WThreadedRunner.h"
45

ebaum's avatar
ebaum committed
46
#include "WGEGraphicsWindow.h"
47
#include "WGECamera.h"
schurade's avatar
schurade committed
48
#include "WPickHandler.h"
49
#include "WGEZoomTrackballManipulator.h"
ebaum's avatar
ebaum committed
50

51 52 53

class WColor;

ebaum's avatar
ebaum committed
54 55 56
/**
 * Class for managing one viewer to the scene. This includes viewport, camera and graphics context.
 * It is, besides WGraphicsEngine, the ONLY entry point for each widget for accessing the graphics engine.
wiebel's avatar
wiebel committed
57
 * \ingroup ge
ebaum's avatar
ebaum committed
58
 */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
59
class WGEViewer: public WGEGraphicsWindow,
60
                 public boost::enable_shared_from_this< WGEViewer >
ebaum's avatar
ebaum committed
61 62 63 64 65
{
public:
    /**
     * Default constructor.
     *
66
     * \param name the name of the viewer
ebaum's avatar
ebaum committed
67 68 69 70 71
     * \param wdata the WindowData instance for the widget to use as render widget
     * \param x X coordinate of widget where to create the context.
     * \param y Y coordinate of widget where to create the context.
     * \param width Width of the widget.
     * \param height Height of the Widget.
72
     * \param projectionMode Projection mode of the viewer.
ebaum's avatar
ebaum committed
73 74
     * \exception WGEInitFailed thrown if initialization of graphics context or graphics window has failed.
     */
75
    WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, int y, int width, int height,
76
        WGECamera::ProjectionMode projectionMode = WGECamera::ORTHOGRAPHIC );
ebaum's avatar
ebaum committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90

    /**
     * Destructor.
     */
    virtual ~WGEViewer();

    /**
     * Updates size information. Also updates camera.
     *
     * \param width new width.
     * \param height new height.
     */
    virtual void resize( int width, int height );

91
    /**
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
92 93 94 95
     * Close the viewer, but wait for the rendering thread to finish.
     */
    virtual void close();

ebaum's avatar
ebaum committed
96 97 98 99 100
    /**
     * Getter for OpenSceneGraph Viewer instance.
     *
     * \return the OSG Viewer instance.
     */
101
    osg::ref_ptr<osgViewer::Viewer> getViewer();
ebaum's avatar
ebaum committed
102 103 104 105 106 107

    /**
     * Sets the camera manipulator to use.
     *
     * \param manipulator the manipulator to use.
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
108
    void setCameraManipulator( osg::ref_ptr<osgGA::MatrixManipulator> manipulator );
ebaum's avatar
ebaum committed
109 110 111 112 113 114

    /**
     * Returns current active camera manipulator
     *
     * \return the active camera manipulator.
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
115
    osg::ref_ptr<osgGA::MatrixManipulator> getCameraManipulator();
ebaum's avatar
ebaum committed
116

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
117
    /**
ebaum's avatar
ebaum committed
118
     * Sets the current camera.
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
119
     *
ebaum's avatar
ebaum committed
120 121
     * \param camera the OSG camera instance.
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
122
    void setCamera( osg::ref_ptr<osg::Camera> camera );
ebaum's avatar
ebaum committed
123

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
124
    /**
ebaum's avatar
ebaum committed
125
     * Returns the camera currently in use.
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
126
     *
ebaum's avatar
ebaum committed
127 128
     * \return the camera currently in use.
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
129
    osg::ref_ptr<osg::Camera> getCamera();
ebaum's avatar
ebaum committed
130

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
131
    /**
ebaum's avatar
ebaum committed
132
     * Sets the scene graph node to be used for rendering.
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
133
     *
ebaum's avatar
ebaum committed
134 135
     * \param node part of the scene graph
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
136
    void setScene( osg::ref_ptr<osg::Node> node );
ebaum's avatar
ebaum committed
137

Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
138
    /**
ebaum's avatar
ebaum committed
139
     * Returns the currently set OSG node.
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
140
     *
ebaum's avatar
ebaum committed
141 142
     * \return the node.
     */
Sebastian Eichelbaum's avatar
Sebastian Eichelbaum committed
143
    osg::ref_ptr<osg::Node> getNode();
ebaum's avatar
ebaum committed
144

145 146
    /**
     * Returns the name of the viewer.
schurade's avatar
schurade committed
147 148
     *
     * \return the name
149
     */
150
    std::string getName() const;
151

152 153
    /**
     * Determine the color of the viewer's background.
Alexander Wiebel's avatar
Alexander Wiebel committed
154
     * \param bgColor the new background color
155 156 157
     */
    void setBgColor( WColor bgColor );

schurade's avatar
schurade committed
158 159 160 161 162
    /**
     * Getter for the pick handler
     *
     * \return the pick handler
     */
163
    osg::ref_ptr< WPickHandler > getPickHandler();
schurade's avatar
schurade committed
164

ebaum's avatar
ebaum committed
165 166 167 168 169
protected:

    /**
     * The OpenSceneGraph view used in this (Composite)Viewer.
     */
170
    osg::ref_ptr< osgViewer::Viewer > m_View;
ebaum's avatar
ebaum committed
171

172 173 174 175 176
    /**
     * The name of the viewer.
     */
    std::string m_name;

177 178 179 180 181
    /**
     * The projection mode of the viewer.
     */
    WGECamera::ProjectionMode m_projectionMode;

schurade's avatar
schurade committed
182
    /**
183
     * Pointer to the pick handler of the viewer.
schurade's avatar
schurade committed
184
     */
185
    osg::ref_ptr<WPickHandler> m_pickHandler;
schurade's avatar
schurade committed
186

ebaum's avatar
ebaum committed
187 188 189 190
private:
};

#endif  // WGEVIEWER_H