Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

osg::SimpleSceneManager Class Reference
[Window]

A helper class to simplify managing simple applications. More...

#include <OSGSimpleSceneManager.h>

List of all members.

Member

*WindowPtr _win
NodePtr _root
ImageForegroundPtr _foreground
StatisticsForegroundPtr _statforeground
bool _statstate
NodePtr _highlight
NodePtr _highlightNode
GeoPositions3fPtr _highlightPoints
NodePtr _internalRoot
DirectionalLightPtr _headlight
RenderAction_action
RenderAction_ownAction
TransformPtr _cart
PerspectiveCameraPtr _camera
Navigator _navigator
Int16 _lastx
Int16 _lasty
UInt16 _mousebuttons
static SimpleMaterialPtr _highlightMaterial

Public Types

Enums
enum  {
  MouseLeft = 0, MouseMiddle = 1, MouseRight = 2, MouseUp = 3,
  MouseDown = 4, NoButton = -1
}

Public Member Functions

Constructors
SimpleSceneManager (void)
SimpleSceneManagercreate (void)
Destructor
*virtual ~SimpleSceneManager (void)
Get
*virtual NodePtr getRoot (void)
virtual WindowPtr getWindow (void)
virtual NodePtr getHighlight (void)
virtual DrawActionBasegetAction (void)
virtual NavigatorgetNavigator (void)
virtual bool getHeadlightState (void)
virtual PerspectiveCameraPtr getCamera (void)
Set
*virtual void setAction (RenderAction *action)
virtual void setRoot (NodePtr root)
virtual void setWindow (WindowPtr win)
virtual void setHighlight (NodePtr obj)
virtual void setHeadlight (bool on)
virtual void turnHeadlightOn (void)
virtual void turnHeadlightOff (void)
virtual void showAll (void)
virtual void useOpenSGLogo (void)
void setNavigationMode (Navigator::Mode new_mode)
bool setClickCenter (bool mode)
virtual void setStatistics (bool on)
Interaction handling
*virtual void resize (UInt16 width, UInt16 height)
virtual void mouseMove (Int16 x, Int16 y)
virtual void mouseButtonPress (UInt16 button, Int16 x, Int16 y)
virtual void mouseButtonRelease (UInt16 button, Int16 x, Int16 y)
virtual void key (UChar8 key, Int16 x, Int16 y)
Line calcViewRay (Int16 x, Int16 y)
Actions
*virtual void redraw (void)
virtual void idle (void)
Comparison
*bool operator< (const SimpleSceneManager &other) const

Protected Member Functions

Updates
*void initialize (void)
virtual void highlightChanged (void)
virtual void updateHighlight (void)

Private Member Functions

 SimpleSceneManager (const SimpleSceneManager &source)
void operator= (const SimpleSceneManager &source)


Detailed Description

SimpleSceneManager manages the OpenSG components that are needed to do simple applications that just want to display some geometry. It takes the window to render into and the root node of the graph to display and takes care of creating the necessary additional OpenSG objects, like a viewport for the window,

Definition at line 68 of file OSGSimpleSceneManager.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
MouseLeft  The constant for the left mouse button.
MouseMiddle  The constant for the middle mouse button.
MouseRight  The constant for the right mouse button.
MouseUp  The constant for the mouse wheel up (away from the hand) motion.
MouseDown  The constant for the mouse wheel down (towards the hand) motion.
NoButton 

Definition at line 76 of file OSGSimpleSceneManager.h.

00076          {  MouseLeft   =  0,
00077             MouseMiddle =  1, 
00078             MouseRight  =  2,
00079             MouseUp     =  3,
00080             MouseDown   =  4,
00081             NoButton    =  -1
00082          };


Constructor & Destructor Documentation

SimpleSceneManager::SimpleSceneManager void   ) 
 

Constructor

Definition at line 189 of file OSGSimpleSceneManager.cpp.

00189                                            :
00190     _win            (NullFC),
00191     _root           (NullFC),
00192     _foreground     (NullFC),
00193     _statforeground (NullFC),
00194     _statstate      (false),
00195 
00196     _highlight      (NullFC),
00197     _highlightNode  (NullFC),
00198     _highlightPoints(NullFC),
00199 
00200     _internalRoot   (NullFC),
00201     _headlight      (NullFC),
00202     _action         (NULL  ),
00203     _ownAction      (NULL  ),
00204     _cart           (NullFC),
00205     _camera         (NullFC),
00206     _navigator      (      ),
00207 
00208     _lastx          (TypeTraits<Int16>::getMax()),
00209     _lasty          (TypeTraits<Int16>::getMax()),
00210     _mousebuttons   (0                             )
00211 {
00212 }

SimpleSceneManager::~SimpleSceneManager void   )  [virtual]
 

Destructor

Definition at line 225 of file OSGSimpleSceneManager.cpp.

References _camera, _internalRoot, _ownAction, osg::NullFC, setRoot(), and osg::subRefCP().

00226 {
00227     delete _ownAction;
00228 
00229     setRoot(NullFC); // sub root
00230     if(_internalRoot != NullFC)
00231         subRefCP(_internalRoot);
00232     if(_camera != NullFC)
00233         subRefCP(_camera);
00234 }

osg::SimpleSceneManager::SimpleSceneManager const SimpleSceneManager source  )  [private]
 


Member Function Documentation

SimpleSceneManager * SimpleSceneManager::create void   ) 
 

pseudo constructor. Standard interface for OpenSG object creation.

Definition at line 217 of file OSGSimpleSceneManager.cpp.

00218 {
00219     return new SimpleSceneManager;
00220 }

NodePtr SimpleSceneManager::getRoot void   )  [virtual]
 

get the root of the displayed tree

Definition at line 246 of file OSGSimpleSceneManager.cpp.

References _root.

00247 {
00248     return _root;
00249 }

WindowPtr SimpleSceneManager::getWindow void   )  [virtual]
 

get the window to be used for display

Definition at line 239 of file OSGSimpleSceneManager.cpp.

References _win.

Referenced by osg::OSGQGLManagedWidget::initializeGL(), and osg::OSGQGLManagedWidget::paintGL().

00240 {
00241     return _win;
00242 }

NodePtr SimpleSceneManager::getHighlight void   )  [virtual]
 

get the highlight object

Definition at line 283 of file OSGSimpleSceneManager.cpp.

References _highlight.

Referenced by highlightChanged().

00284 {
00285     return _highlight;
00286 }

DrawActionBase * SimpleSceneManager::getAction void   )  [virtual]
 

get the action used to render the scene

Definition at line 290 of file OSGSimpleSceneManager.cpp.

References _action.

00291 {
00292     return _action;
00293 }

Navigator * SimpleSceneManager::getNavigator void   )  [virtual]
 

get the navigator

Definition at line 253 of file OSGSimpleSceneManager.cpp.

References _navigator.

00254 {
00255     return &_navigator;
00256 }

bool SimpleSceneManager::getHeadlightState void   )  [virtual]
 

get the headlight state

Definition at line 260 of file OSGSimpleSceneManager.cpp.

References _headlight.

00261 {
00262     return _headlight->getOn();
00263 }

PerspectiveCameraPtr SimpleSceneManager::getCamera void   )  [virtual]
 

get the camera

Definition at line 267 of file OSGSimpleSceneManager.cpp.

References _camera.

00268 {
00269     return _camera;
00270 }

void SimpleSceneManager::setAction RenderAction action  )  [virtual]
 

set the action used to render the scene. Use NULL to set to internally created action.

Definition at line 298 of file OSGSimpleSceneManager.cpp.

References _action, _ownAction, _statstate, and setStatistics().

00299 {
00300     bool statstate = _statstate;
00301 
00302     if(_action != NULL && statstate)
00303         setStatistics(false);
00304 
00305     if(action == NULL)
00306     {
00307         _action = _ownAction;
00308     }
00309     else
00310     {
00311         _action = action;
00312     }
00313     
00314     if(statstate)
00315         setStatistics(true);
00316 }

void SimpleSceneManager::setRoot NodePtr  root  )  [virtual]
 

set the root of the displayed tree

Definition at line 320 of file OSGSimpleSceneManager.cpp.

References _internalRoot, _root, osg::beginEditCP(), osg::Node::ChildrenFieldMask, osg::endEditCP(), initialize(), and osg::NullFC.

Referenced by ~SimpleSceneManager().

00321 {
00322     if(_internalRoot == NullFC)
00323     {
00324         initialize();
00325     }
00326 
00327     if(_root != root)
00328     {
00329         if(_root != NullFC)
00330         {
00331             beginEditCP(_internalRoot, Node::ChildrenFieldMask);
00332             _internalRoot->subChild(_root);
00333             endEditCP(_internalRoot, Node::ChildrenFieldMask);
00334         }
00335 
00336         _root = root;
00337         if(_root != NullFC)
00338         {
00339             beginEditCP(_internalRoot, Node::ChildrenFieldMask);
00340             _internalRoot->addChild(_root);
00341             endEditCP(_internalRoot, Node::ChildrenFieldMask);
00342         }
00343     }
00344 }

void SimpleSceneManager::setWindow WindowPtr  win  )  [virtual]
 

set the window to be used for display

Definition at line 274 of file OSGSimpleSceneManager.cpp.

References _navigator, _win, osg::NullFC, and osg::Navigator::setViewport().

Referenced by osg::OSGQGLManagedWidget::OSGQGLManagedWidget().

00275 {
00276     _win = win;
00277     if(_win->getMFPort()->size() > 0 && _win->getPort(0) != NullFC)
00278         _navigator.setViewport(_win->getPort(0));
00279 }

void SimpleSceneManager::setHighlight NodePtr  highlight  )  [virtual]
 

set the highlight object

Definition at line 376 of file OSGSimpleSceneManager.cpp.

References _highlight, and highlightChanged().

00377 {
00378     _highlight = highlight;
00379     highlightChanged();
00380 }

void SimpleSceneManager::setHeadlight bool  on  )  [virtual]
 

set the headlight setting

Definition at line 348 of file OSGSimpleSceneManager.cpp.

References _headlight, _internalRoot, osg::beginEditCP(), osg::endEditCP(), initialize(), osg::NullFC, and osg::LightBase::OnFieldMask.

Referenced by turnHeadlightOff(), and turnHeadlightOn().

00349 {
00350     if(_internalRoot == NullFC)
00351     {
00352         initialize();
00353     }
00354 
00355     beginEditCP(_headlight, LightBase::OnFieldMask);
00356     _headlight->setOn(on);
00357     endEditCP(_headlight, LightBase::OnFieldMask);
00358 }

void SimpleSceneManager::turnHeadlightOn void   )  [virtual]
 

turn headlight on.

Definition at line 362 of file OSGSimpleSceneManager.cpp.

References setHeadlight().

00363 {
00364     setHeadlight(true);
00365 }

void SimpleSceneManager::turnHeadlightOff void   )  [virtual]
 

turn headlight off.

Definition at line 369 of file OSGSimpleSceneManager.cpp.

References setHeadlight().

00370 {
00371     setHeadlight(false);
00372 }

void SimpleSceneManager::showAll void   )  [virtual]
 

show the whole scene: move out far enough to see everything

Definition at line 532 of file OSGSimpleSceneManager.cpp.

References _camera, _navigator, _root, osg::beginEditCP(), osg::endEditCP(), osg::Eps, osg::VectorInterface< ValueTypeT, StorageInterfaceT >::length(), osg::NullFC, osg::osgMax(), osg::osgtan(), osg::Navigator::set(), osg::Navigator::setMotionFactor(), and osg::VecStorage3< ValueTypeT >::setValues().

Referenced by redraw().

00533 {
00534     if(_root == NullFC)
00535         return;
00536 
00537     _root->updateVolume();
00538 
00539     Vec3f min,max;
00540     _root->getVolume().getBounds( min, max );
00541     Vec3f d = max - min;
00542 
00543     if(d.length() < Eps) // Nothing loaded? Use a unity box
00544     {
00545         min.setValues(-1.f,-1.f,-1.f);
00546         max.setValues( 1.f, 1.f, 1.f);
00547         d = max - min;
00548     }
00549 
00550     Real32 dist = osgMax(d[0],d[1]) / (2 * osgtan(_camera->getFov() / 2.f));
00551 
00552     Vec3f up(0,1,0);
00553     Pnt3f at((min[0] + max[0]) * .5f,(min[1] + max[1]) * .5f,(min[2] + max[2]) * .5f);
00554     Pnt3f from=at;
00555     from[2]+=(dist+fabs(max[2]-min[2])*0.5f); 
00556 
00557     _navigator.set(from,at,up);
00558 
00559     // adjust the translation factors so that motions are sort of scaled
00560     _navigator.setMotionFactor((d[0] + d[1] + d[2]) / 100.f);
00561 
00562     // set the camera to go from 1% of the object to twice its size
00563     Real32 diag = osgMax(osgMax(d[0], d[1]), d[2]);
00564     beginEditCP(_camera);
00565     _camera->setNear (diag / 100.f);
00566     _camera->setFar  (10 * diag);
00567     endEditCP(_camera);
00568 }

void SimpleSceneManager::useOpenSGLogo void   )  [virtual]
 

add the "Powered by OpenSG" logo to the lower left corner

Definition at line 572 of file OSGSimpleSceneManager.cpp.

References _foreground, osg::beginEditCP(), osg::ImageBase::create(), osg::endEditCP(), osg::LogoData, and osg::ImageFileType::restore().

00573 {
00574     ImagePtr lo = Image::create();
00575     ImageFileType::restore( lo, (UChar8*)LogoData, -1 );
00576 
00577     beginEditCP(_foreground);
00578     _foreground->addImage( lo, Pnt2f( 0,0 ) );
00579     endEditCP  (_foreground);
00580 }

void SimpleSceneManager::setNavigationMode Navigator::Mode  new_mode  ) 
 

Sets the navigation mode

Definition at line 584 of file OSGSimpleSceneManager.cpp.

References _navigator, osg::Navigator::getMatrix(), osg::Navigator::set(), and osg::Navigator::setMode().

00585 {
00586     Matrix m=_navigator.getMatrix();
00587     _navigator.setMode(new_mode);
00588     _navigator.set(m);
00589 }

bool osg::SimpleSceneManager::setClickCenter bool  mode  )  [inline]
 

set the click center mode of the navigator

Definition at line 46 of file OSGSimpleSceneManager.inl.

References _navigator, and osg::Navigator::setClickCenter().

00047 {
00048     return _navigator.setClickCenter(mode);
00049 }

void SimpleSceneManager::setStatistics bool  on  )  [virtual]
 

set the statistics setting. Only works after the window has been created.

Definition at line 384 of file OSGSimpleSceneManager.cpp.

References _action, _statforeground, _statstate, _win, osg::NullFC, and osg::DrawActionBase::setStatistics().

Referenced by setAction().

00385 {
00386     if(_statforeground != NullFC && on != _statstate)
00387     {
00388         ViewportPtr vp = _win->getPort()[0];
00389 
00390         if(on)
00391         {
00392             vp->getForegrounds().push_back(_statforeground);
00393 
00394             _action->setStatistics(&_statforeground->getCollector());
00395         }
00396         else
00397         {
00398             MFForegroundPtr::iterator it;
00399 
00400             it = vp->getForegrounds().find(_statforeground);
00401             vp->getForegrounds().erase(it);
00402 
00403             _action->setStatistics(NULL);
00404         }
00405 
00406         _statstate = on;
00407     }
00408 }

void SimpleSceneManager::resize UInt16  width,
UInt16  height
[virtual]
 

resize

Definition at line 760 of file OSGSimpleSceneManager.cpp.

References _win.

Referenced by osg::OSGQGLManagedWidget::resizeGL().

00761 {
00762     _win->resize(width, height);
00763 }

void SimpleSceneManager::mouseMove Int16  x,
Int16  y
[virtual]
 

motion

Definition at line 767 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, and osg::Navigator::moveTo().

Referenced by osg::OSGQGLManagedWidget::mouseMoveEvent().

00768 {
00769     if ( _mousebuttons) _navigator.moveTo(x,y);
00770     _lastx = x;
00771     _lasty = y;
00772 
00773 }

void SimpleSceneManager::mouseButtonPress UInt16  button,
Int16  x,
Int16  y
[virtual]
 

call when a mouse button is pressed. button is the number of the pressed button, starting at 0, ordered from left to right. A wheel should be mapped to buttons 3 and 4. The position is in pixel, starting at the upper left corner.

Definition at line 781 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, osg::Navigator::buttonPress(), osg::Navigator::DOWN_MOUSE, osg::Navigator::LEFT_MOUSE, osg::Navigator::MIDDLE_MOUSE, MouseDown, MouseLeft, MouseMiddle, MouseRight, MouseUp, osg::Navigator::RIGHT_MOUSE, and osg::Navigator::UP_MOUSE.

Referenced by osg::OSGQGLManagedWidget::mousePressEvent(), and osg::OSGQGLManagedWidget::wheelEvent().

00782 {
00783     switch (button)
00784     {
00785     case MouseLeft:    _navigator.buttonPress(Navigator::LEFT_MOUSE,x,y);
00786       break;
00787     case MouseMiddle:  _navigator.buttonPress(Navigator::MIDDLE_MOUSE,x,y);
00788       break;
00789     case MouseRight:   _navigator.buttonPress(Navigator::RIGHT_MOUSE,x,y);
00790       break;
00791     case MouseUp:      _navigator.buttonPress(Navigator::UP_MOUSE,x,y);
00792       break;
00793     case MouseDown:    _navigator.buttonPress(Navigator::DOWN_MOUSE,x,y);
00794       break;
00795     }
00796     
00797     _mousebuttons |= 1 << button;
00798     _lastx = x;
00799     _lasty = y;
00800 }

void SimpleSceneManager::mouseButtonRelease UInt16  button,
Int16  x,
Int16  y
[virtual]
 

call when a mouse button is released. button is the number of the pressed button, starting at 0, ordered from left to right. A wheel should be mapped to buttons 3 and 4. The position is in pixel, starting at the upper left corner.

Definition at line 808 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, osg::Navigator::buttonRelease(), osg::Navigator::DOWN_MOUSE, osg::Navigator::LEFT_MOUSE, osg::Navigator::MIDDLE_MOUSE, MouseDown, MouseLeft, MouseMiddle, MouseRight, MouseUp, osg::Navigator::RIGHT_MOUSE, and osg::Navigator::UP_MOUSE.

Referenced by osg::OSGQGLManagedWidget::mouseReleaseEvent().

00809 {
00810     switch (button)
00811     {
00812     case MouseLeft:     _navigator.buttonRelease(Navigator::LEFT_MOUSE,x,y);
00813                         break;
00814     case MouseMiddle:   _navigator.buttonRelease(Navigator::MIDDLE_MOUSE,x,y);
00815                         break;
00816     case MouseRight:    _navigator.buttonRelease(Navigator::RIGHT_MOUSE,x,y);
00817                         break;
00818     case MouseUp:       _navigator.buttonRelease(Navigator::UP_MOUSE,x,y);
00819                         break;
00820     case MouseDown:     _navigator.buttonRelease(Navigator::DOWN_MOUSE,x,y);
00821                         break;
00822     }
00823     _mousebuttons &= ~(1 << button);
00824     _lastx = x;
00825     _lasty = y;
00826 }

void SimpleSceneManager::key UChar8  key,
Int16  x,
Int16  y
[virtual]
 

resize

Definition at line 828 of file OSGSimpleSceneManager.cpp.

References _navigator, osg::Navigator::BACKWARDS, osg::Navigator::FORWARDS, osg::Navigator::keyPress(), osg::Navigator::LEFT, osg::Navigator::LEFTROT, osg::Navigator::RIGHT, and osg::Navigator::RIGHTROT.

00829 {
00830     switch ( key )
00831     {
00832         case 'j': _navigator.keyPress(Navigator::LEFT,x,y); break;
00833         case 'g': _navigator.keyPress(Navigator::RIGHT,x,y); break;
00834         case 'u': _navigator.keyPress(Navigator::LEFTROT,x,y); break;
00835         case 't': _navigator.keyPress(Navigator::RIGHTROT,x,y); break;
00836         case 'y': _navigator.keyPress(Navigator::FORWARDS,x,y); break;
00837         case 'h': _navigator.keyPress(Navigator::BACKWARDS,x,y); break;
00838     }
00839 }

Line SimpleSceneManager::calcViewRay Int16  x,
Int16  y
 

Calculate a ray that starts at the eye and goes through the position on the screen given by x,y.

Definition at line 845 of file OSGSimpleSceneManager.cpp.

References _camera, and _win.

00846 {
00847     Line l;
00848 
00849     _camera->calcViewRay( l, x, y, *_win->getPort()[0] );
00850 
00851     return l;
00852 }

void SimpleSceneManager::redraw void   )  [virtual]
 

Draw the next frame, update if needed.

Definition at line 601 of file OSGSimpleSceneManager.cpp.

References _action, _internalRoot, _navigator, _win, initialize(), osg::NullFC, showAll(), osg::Navigator::updateCameraTransformation(), and updateHighlight().

Referenced by osg::OSGQGLManagedWidget::paintGL().

00602 {
00603     if (_internalRoot == NullFC)
00604     {
00605         initialize();
00606         showAll();
00607     }
00608 
00609 //    _cart->getSFMatrix()->setValue(_navigator.getMatrix());
00610     _navigator.updateCameraTransformation();
00611 
00612     updateHighlight();
00613 
00614     _win->render(_action);
00615 }

void SimpleSceneManager::idle void   )  [virtual]
 

Draw the next frame, update if needed.

Definition at line 594 of file OSGSimpleSceneManager.cpp.

References _lastx, _lasty, _mousebuttons, _navigator, and osg::Navigator::idle().

00595 {
00596   _navigator.idle(_mousebuttons,_lastx, _lasty);
00597 }

bool SimpleSceneManager::operator< const SimpleSceneManager other  )  const
 

less

Definition at line 867 of file OSGSimpleSceneManager.cpp.

00868 {
00869     return this < &other;
00870 }

void SimpleSceneManager::initialize void   )  [protected]
 

create the parts that the app needs: viewport, camera, base graph etc.

Definition at line 415 of file OSGSimpleSceneManager.cpp.

References _action, _camera, _cart, _foreground, _headlight, _internalRoot, _navigator, _ownAction, _statforeground, _win, osg::addRefCP(), osg::beginEditCP(), osg::ViewportBase::create(), osg::SimpleStatisticsForegroundBase::create(), osg::ImageForegroundBase::create(), osg::SolidBackgroundBase::create(), osg::PerspectiveCameraBase::create(), osg::DirectionalLightBase::create(), osg::TransformBase::create(), osg::Node::create(), osg::RenderAction::create(), osg::deg2rad(), osg::endEditCP(), osg::StatCollector::getElem(), osg::NullFC, osg::Navigator::setCameraTransformation(), osg::Navigator::setMode(), osg::Navigator::setViewport(), osg::DrawActionBase::statCulledNodes, osg::DrawActionBase::statCullTestedNodes, osg::DirectionalLight::statNDirectionalLights, osg::RenderAction::statNGeometries, osg::Drawable::statNLines, osg::RenderAction::statNMaterials, osg::RenderAction::statNMatrices, osg::PointLight::statNPointLights, osg::Drawable::statNPoints, osg::SpotLight::statNSpotLights, osg::RenderAction::statNTexBytes, osg::RenderAction::statNTextures, osg::RenderAction::statNTransGeometries, osg::Drawable::statNTriangles, osg::Drawable::statNVertices, osg::DrawActionBase::statTravTime, and osg::Navigator::TRACKBALL.

Referenced by redraw(), setHeadlight(), and setRoot().

00416 {
00417     // the rendering action
00418     _ownAction = RenderAction::create();
00419     _action = _ownAction;
00420 
00421     // the camera and light beacon
00422     NodePtr cartN = Node::create();
00423     _cart = Transform::create();
00424 
00425     beginEditCP(cartN);
00426     cartN->setCore(_cart);
00427     endEditCP(cartN);
00428 
00429     // the headlight
00430     _internalRoot = Node::cr