Commit fcc7e35d authored by Jan Möbius's avatar Jan Möbius

Speedup:

Modified the resetScenegraph stuff which ran the bounding box and multipass actions too often. 
Now these traversals are only done once, resulting in a speedup of approximatly 4 for this part in updated Object and AddEmpty.


git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@15092 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5cf07313
......@@ -47,6 +47,7 @@
#include "Core.hh"
#include <ACG/QtWidgets/QtFileDialog.hh>
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
#include "OpenFlipper/common/GlobalOptions.hh"
#include <OpenFlipper/common/RecentFiles.hh>
......@@ -61,12 +62,17 @@
#include <OpenFlipper/common/DataTypes.hh>
void Core::resetScenegraph( bool _resetTrackBall ) {
if ( OpenFlipper::Options::gui() && !OpenFlipper::Options::loadingSettings() ) {
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
// update scene graph (get new bounding box and set projection right, including near and far plane)
PluginFunctions::viewerProperties(i).lockUpdate();
coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_, _resetTrackBall );
coreWidget_->examiner_widgets_[i]->sceneGraph(root_node_scenegraph_,maxPases,bbmin,bbmax, _resetTrackBall );
PluginFunctions::viewerProperties(i).unLockUpdate();
coreWidget_->examiner_widgets_[i]->updateGL();
}
......
......@@ -66,6 +66,8 @@
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
// -------------------- Qt event Includes
#include <QEvent>
#include <QWhatsThisClickedEvent>
......@@ -304,6 +306,11 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// Create examiner
// ======================================================================
// First we analyze the scenegraph
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);
if ( !OpenFlipperSettings().value("Core/Gui/glViewer/useMultipleViewers",true).toBool() ) {
glViewer* examinerWidget = new glViewer(glScene_,
......@@ -313,7 +320,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
examiner_widgets_.push_back(examinerWidget);
examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
examinerWidget->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
baseLayout_->addItem(examinerWidget, 0);
......@@ -345,7 +352,7 @@ CoreWidget( QVector<ViewMode*>& _viewModes,
// Initialize all examiners
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
cursorPainter_->registerViewer (examiner_widgets_[i]);
}
......
......@@ -57,6 +57,7 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/common/GlobalOptions.hh>
#include <OpenFlipper/widgets/glWidget/CursorPainter.hh>
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
//-----------------------------------------------------------------------------
......@@ -127,10 +128,14 @@ void CoreWidget::setActionMode(const Viewer::ActionMode _am){
break;
}
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);
//update Viewers
for ( unsigned int i = 0 ; i < OpenFlipper::Options::examinerWidgets() ; ++i ) {
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode() );
examiner_widgets_[i]->sceneGraph( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax );
examiner_widgets_[i]->trackMouse(false);
if(_am == Viewer::PickingMode) {
......
......@@ -55,9 +55,11 @@
#include "QtBaseViewer.hh"
#include "QtGLViewerLayout.hh"
#include "CursorPainter.hh"
#include <ACG/QtWidgets/QtWheel.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Scenegraph/CoordsysNode.hh>
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
#include <ACG/GL/gl.hh>
#include <iostream>
......@@ -259,60 +261,49 @@ void glViewer::swapBuffers() {
//-----------------------------------------------------------------------------
void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root, const bool _resetTrackBall)
void glViewer::sceneGraph(ACG::SceneGraph::BaseNode* _root,
unsigned int _maxPasses,
ACG::Vec3d _bbmin,
ACG::Vec3d _bbmax,
const bool _resetTrackBall)
{
sceneGraphRoot_ = _root;
if (sceneGraphRoot_ )
{
// set max number of render pass
// Single pass action, this info is static during multipass
ACG::SceneGraph::MultiPassInfoAction info_act;
ACG::SceneGraph::traverse(sceneGraphRoot_, info_act);
glstate_->set_max_render_passes(info_act.getMaxPasses());
// get scene size
// Single pass action, as the bounding box is not influenced by multipass traversal
ACG::SceneGraph::BoundingBoxAction act;
ACG::SceneGraph::traverse(sceneGraphRoot_, act);
ACG::Vec3d bbmin = (ACG::Vec3d) act.bbMin();
ACG::Vec3d bbmax = (ACG::Vec3d) act.bbMax();
// set max number of render pass
glstate_->set_max_render_passes(_maxPasses);
if ( ( bbmin[0] > bbmax[0] ) ||
( bbmin[1] > bbmax[1] ) ||
( bbmin[2] > bbmax[2] ) ) {
if ( ( _bbmin[0] > _bbmax[0] ) ||
( _bbmin[1] > _bbmax[1] ) ||
( _bbmin[2] > _bbmax[2] ) ) {
// Invalid bounding box, try to recover
setScenePos( properties_.sceneCenter() , properties_.sceneRadius(), _resetTrackBall );
// Update bounding box to match the scene geometry after recovery
bbmin = ACG::Vec3d(-1.0,-1.0,-1.0);
bbmax = ACG::Vec3d( 1.0, 1.0, 1.0);
_bbmin = ACG::Vec3d(-1.0,-1.0,-1.0);
_bbmax = ACG::Vec3d( 1.0, 1.0, 1.0);
} else {
// For very small scenes, we set the scene radius to 0.1
// otherwise we take the real radius
if ( ( bbmax - bbmin ).max() < OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble() ) {
setScenePos( ( bbmin + bbmax ) * 0.5,
if ( ( _bbmax - _bbmin ).max() < OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble() ) {
setScenePos( ( _bbmin + _bbmax ) * 0.5,
OpenFlipperSettings().value("Core/Gui/glViewer/minimalSceneSize",0.1).toDouble(),
_resetTrackBall);
} else {
setScenePos( ( bbmin + bbmax ) * 0.5,
( bbmax - bbmin ).norm() * 0.5,
setScenePos( ( _bbmin + _bbmax ) * 0.5,
( _bbmax - _bbmin ).norm() * 0.5,
_resetTrackBall);
}
}
// remember the new bounding box for the state
glstate_->set_bounding_box(bbmin,bbmax);
glstate_->set_bounding_box(_bbmin,_bbmax);
}
......@@ -835,7 +826,11 @@ void glViewer::viewAll()
if (aspect > 1.0)
properties_.orthoWidth( aspect * properties_.orthoWidth() ) ;
sceneGraph(PluginFunctions::getSceneGraphRootNode(), true);
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);
sceneGraph ( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax,true);
properties_.unLockUpdate();
updateProjectionMatrix();
......@@ -913,8 +908,13 @@ void glViewer::initializeGL()
if (sceneGraphRoot_)
{
sceneGraph(sceneGraphRoot_, true);
viewAll ();
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(sceneGraphRoot_,maxPases,bbmin,bbmax);
sceneGraph ( sceneGraphRoot_, maxPases,bbmin,bbmax,true);
viewAll();
}
}
......
......@@ -183,8 +183,11 @@ public:
@param _root The root node of the scene graph
@param _resetTrackBall Reset the trackball center?
*/
void sceneGraph(ACG::SceneGraph::BaseNode* _root, const bool _resetTrackBall = false);
void sceneGraph(ACG::SceneGraph::BaseNode* _root,
unsigned int _maxPasses,
ACG::Vec3d _bbmin,
ACG::Vec3d _bbmax,
const bool _resetTrackBall = false);
/// projection mode
enum ProjectionMode {
......
......@@ -55,8 +55,10 @@
#include <OpenFlipper/BasePlugin/PluginFunctions.hh>
#include <OpenFlipper/widgets/glWidget/QtBaseViewer.hh>
#include <ACG/Scenegraph/DrawModes.hh>
#include <ACG/Scenegraph/SceneGraphAnalysis.hh>
#include "simpleGLGraphicsScene.hh"
#include "simpleViewer.hh"
//== NAMESPACES ===============================================================
......@@ -123,7 +125,11 @@ void SimpleViewer::initialize (const QGLFormat & _format, QGLWidget *_shareWidge
mainWidget_->setGeometry (QRect(QPoint(0, 0), size()));
setFrameStyle(QFrame::NoFrame);
mainWidget_->sceneGraph (PluginFunctions::getSceneGraphRootNode (), true);
unsigned int maxPases = 1;
ACG::Vec3d bbmin,bbmax;
ACG::SceneGraph::analyzeSceneGraph(PluginFunctions::getSceneGraphRootNode(),maxPases,bbmin,bbmax);
mainWidget_->sceneGraph ( PluginFunctions::getSceneGraphRootNode(), maxPases,bbmin,bbmax,true);
props_.drawMode (OpenFlipper::Options::defaultDrawMode(0));
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment