31 #include <osg/ShapeDrawable>
32 #include <osgDB/ReadFile>
33 #include <osgGA/AnimationPathManipulator>
34 #include <osgGA/DriveManipulator>
35 #include <osgGA/FlightManipulator>
36 #include <osgGA/KeySwitchMatrixManipulator>
37 #include <osgGA/StateSetManipulator>
38 #include <osgGA/TerrainManipulator>
39 #include <osgGA/UFOManipulator>
40 #include <osgViewer/View>
41 #include <osgViewer/ViewerEventHandlers>
43 #include "WGE2DManipulator.h"
44 #include "WGEGroupNode.h"
45 #include "WGENoOpManipulator.h"
46 #include "WGEViewer.h"
47 #include "WGEZoomTrackballManipulator.h"
48 #include "WGraphicsEngine.h"
49 #include "WMouseLocationHandler.h"
50 #include "WPickHandler.h"
51 #include "core/common/WConditionOneShot.h"
52 #include "core/common/WLogger.h"
53 #include "core/common/WThreadedRunner.h"
54 #include "exceptions/WGEInitFailed.h"
56 WGEViewer::WGEViewer( std::string name, osg::ref_ptr<osg::Referenced> wdata,
int x,
int y,
int width,
int height,
59 std::enable_shared_from_this<
WGEViewer >(),
64 m_inAnimationMode( false ),
72 m_View = osg::ref_ptr<osgViewer::Viewer>(
new osgViewer::Viewer );
74 osg::ref_ptr< WGECamera > cam(
new WGECamera( width, height, projectionMode ) );
82 m_View->getCamera()->getGraphicsContext()->getState()->setUseModelViewAndProjectionUniforms(
true );
87 switch( projectionMode )
89 case( WGECamera::ORTHOGRAPHIC ):
92 if( name != std::string(
"Main View" ) )
95 case( WGECamera::PERSPECTIVE ):
99 m_View->setLightingMode( osg::View::HEADLIGHT );
102 case( WGECamera::TWO_D ):
105 case( WGECamera::TWO_D_UNIT ):
110 throw WGEInitFailed( std::string(
"Unknown projection mode" ) );
114 m_View->addEventHandler(
new osgViewer::StatsHandler );
117 m_properties = std::shared_ptr< WProperties >(
new WProperties(
"Viewer Properties",
"The view's properties" ) );
118 m_bgColor =
m_properties->addProperty(
"Background Color",
"Default background color if not overwritten by a camera effect.",
121 m_throwing =
m_properties->addProperty(
"Throwing",
"If checked, you can grab the scene and throw it. It will keep the rotation impulse.",
125 WPropGroup effects =
m_properties->addPropertyGroup(
"Camera Effects",
"Several effects that to not depend on any scene content." );
143 throw WGEInitFailed( std::string(
"Initialization of WGEViewer failed" ) );
162 m_View->setCameraManipulator( manipulator );
168 return m_View->getCameraManipulator();
173 m_View->setCamera( camera );
232 m_View->getEventQueue()->windowResize( 0, 0, width, height );
237 m_View->getCamera()->setViewport( 0, 0, width, height );
304 const GLubyte* vendor = glGetString( GL_VENDOR );
305 m_vendor =
reinterpret_cast< const char*
>( vendor );
308 m_camera->setInitialDrawCallback( NULL );
336 m_View->setCameraManipulator( anim );
392 getVignette()->setEnabledByDefault( activeByDefault );
407 getView()->getScene()->getSceneData()->setNodeMask( visible * 0xFFFFFFFF );
412 getView()->requestContinuousUpdate( continuous );
Implements a WCondition, but can be fired only ONCE.
std::shared_ptr< WFlag< bool > > SPtr
Convenience typedef for a std::shared_ptr.
New OSG manipulator: AnimationManipulator.
osg::ref_ptr< WGEAnimationManipulator > RefPtr
Convenience typedef.
Class for wrapping around the OSG Camera class.
ProjectionMode
List of possible camera modes.
void resize()
Change camera parameters which should be changed on a resize.
Class managing a single graphics context and OSG GraphicsWindow.
virtual void close()
Initiates a close event for this viewer.
virtual void resize(int width, int height)
Updates size information.
osg::ref_ptr< osgViewer::GraphicsWindow > m_GraphicsWindow
OpenSceneGraph render window.
Class to wrap around the osg Group node and providing a thread safe add/removal mechanism.
Exception thrown if initialization of the graphics engine fails.
This is an OSG Manipulator implementation which does nothing.
This class is a screen recorder.
osg::ref_ptr< WGEScreenCapture > RefPtr
Convenience typedef.
osg::ref_ptr< const WGEViewerEffectHorizon > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGEViewerEffectHorizon >.
osg::ref_ptr< WGEViewerEffectHorizon > SPtr
Convenience typedef for a std::shared_ptr< WGEViewerEffectHorizon >.
osg::ref_ptr< const WGEViewerEffectImageOverlay > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGEViewerEffectImageOverlay >.
osg::ref_ptr< WGEViewerEffectImageOverlay > SPtr
Convenience typedef for a std::shared_ptr< WGEViewerEffectImageOverlay >.
osg::ref_ptr< const WGEViewerEffectVignette > ConstSPtr
Convenience typedef for a std::shared_ptr< const WGEViewerEffectVignette >.
osg::ref_ptr< WGEViewerEffectVignette > SPtr
Convenience typedef for a std::shared_ptr< WGEViewerEffectVignette >.
Small class used for querying glGet info during rendering.
QueryCallback(osg::ref_ptr< WGECamera > camera, WBoolFlag::SPtr run)
Constructor.
virtual void operator()(osg::RenderInfo &renderInfo) const
Query operator.
std::string getVendor() const
Returns the queried vendor string.
virtual ~QueryCallback()
Destructor.
Class for managing one view to the scene.
osg::ref_ptr< osgViewer::Viewer > m_View
The OpenSceneGraph view used in this (Composite)Viewer.
WBoolFlag::SPtr isFrameRendered() const
Returns the flag which denotes whether a frame was rendered.
osg::ref_ptr< osgGA::MatrixManipulator > getCameraManipulator()
Returns current active camera manipulator.
void handleVisibilityChange(bool visible)
If the widget is not visible, we might be able to reduce CPU load.
void reset()
Resets the view using the installed manipulator.
WGEScreenCapture::RefPtr m_screenCapture
The screen capture callback.
virtual ~WGEViewer()
Destructor.
WGEViewer(std::string name, osg::ref_ptr< osg::Referenced > wdata, int x, int y, int width, int height, WGECamera::ProjectionMode projectionMode=WGECamera::ORTHOGRAPHIC)
Default constructor.
std::string getName() const
Returns the name of the viewer.
WColor getBgColor() const
Returns the current default background color.
void setBgColor(const WColor &bgColor)
Determine the color of the viewer's background.
virtual void resize(int width, int height)
Updates size information.
void setEffectsActiveDefault(bool activeByDefault=true)
Activate viewer effects by default.
WGEViewerEffectHorizon::SPtr m_effectHorizon
Horizon effect.
osg::ref_ptr< WGECamera > getCamera()
Returns the camera currently in use.
WPropBool m_throwing
The switch to enable the throw- functionality of some OSG manipulators.
osg::ref_ptr< osgViewer::Viewer > getView()
Getter for OpenSceneGraph View instance.
osg::ref_ptr< WPickHandler > getPickHandler()
Getter for the pick handler Warning: At the moment only the orthographic projection mode supports a p...
bool isAnimationMode() const
Checks if the viewer is in animation mode.
std::shared_ptr< WGEViewer > SPtr
Convenience typedef.
WGEViewerEffectHorizon::SPtr getBackground()
Return the background render effect for modification.
osg::ref_ptr< QueryCallback > m_queryCallback
The callback used for querying OpenGL features.
WGEScreenCapture::RefPtr getScreenCapture() const
Returns the main cameras screen capture callback.
osg::ref_ptr< WGEGroupNode > m_scene
reference to the scene which is displayed by viewer
WGEViewerEffectImageOverlay::SPtr getImageOverlay()
Return the overlay render effect for modification.
void updateThrowing()
Update throw setting of the manipulator (if supported).
void setCameraManipulator(osg::ref_ptr< osgGA::MatrixManipulator > manipulator)
Sets the camera manipulator to use.
void setPaused(bool pause=true)
Pause rendering.
osg::ref_ptr< WPickHandler > m_pickHandler
Pointer to the pick handler of the viewer.
void setScene(osg::ref_ptr< WGEGroupNode > node)
Sets the scene graph node to be used for rendering.
void updateBgColor()
Update the default clear color (bg color).
std::string getOpenGLVendor() const
Queries the OpenGL vendor info.
WPropColor m_bgColor
The default clear color (bg color).
void requestContinuousUpdate(bool continuous=true)
Update the view automatically (the default).
osg::ref_ptr< WGEGroupNode > getScene()
Returns the currently set OSG node.
osg::ref_ptr< WGEGroupNode > m_sceneMainNode
Keep the currently set scene node.
WProperties::SPtr getProperties() const
Return a pointer to the properties object of the view.
WGEViewerEffectVignette::SPtr getVignette()
Return the vignette render effect for modification.
WGEAnimationManipulator::RefPtr animationMode(bool on=true)
The (de-)activates the animation mode.
WGEViewerEffectVignette::SPtr m_effectVignette
Vignette effect.
bool getPaused() const
Query whether the view is paused or not.
WBoolFlag::SPtr m_rendered
This flag is true and notifies after the first rendered frame.
osg::ref_ptr< WMouseLocationHandler > m_mouseLocationHandler
Pointer to the mouse location handler of the viewer.
WGEViewerEffectImageOverlay::SPtr m_effectImageOverlay
Image overlay effect.
osg::ref_ptr< osgGA::MatrixManipulator > m_animationModeManipulatorBackup
The manipulator that was set before entering animation mode.
virtual void close()
Close the viewer, but wait for the rendering thread to finish.
WProperties::SPtr m_properties
The property object for the view.
osg::ref_ptr< WMouseLocationHandler > getMouseLocationHandler()
Getter for the mouse loection handler.
bool m_inAnimationMode
True -> animation mode on.
bool m_paused
Flag denoting whether the view is paused or not.
void setCamera(osg::ref_ptr< WGECamera > camera)
Sets the current camera.
std::string m_name
The name of the viewer.
virtual void paint()
Repaints the contents.
New OSG manipulator: TrackballManipulator with added mouse wheel zoom.
void setThrow(bool allowThrow=true)
En-/Disables throwing.
Class to handle providing information about pixel position of mouse.
Class to handle events with a pick.
Class to manage properties of an object and to provide convenience methods for easy access and manipu...
std::shared_ptr< WPropertyGroup > SPtr
shared pointer to object of this type