]> Git trees. - libqmvoc.git/commitdiff
Changes in kalziumglwidget:
authorBenoît Jacob <jacob.benoit.1@gmail.com>
Mon, 26 Jun 2006 10:18:33 +0000 (10:18 +0000)
committerBenoît Jacob <jacob.benoit.1@gmail.com>
Mon, 26 Jun 2006 10:18:33 +0000 (10:18 +0000)
- added FPS (frames per second) counter. Enable it by #defining
  USE_FPS_COUNTER. (Currently enabled).

- added option to cache the rendering of the molecule using a GL display
  list. This improves speed, especially for rendering complex
  molecules; I have measured a speed increase above +35% in some cases
  (depends also on the style and the widget size). Enable it by
  #defining USE_DISPLAY_LIST. (Currently enabled).

Change in latticedialog:

- I allowed myself to comment out ui.glWidget->update(); in
  LatticeDialog::slotUpdateView() because normally this is being
  taken care of by slotSetMolecule; also I think that for a GL widget,
  one should call updateGL() instead of update(); not 100% sure here.
  Carsten, I didn't see the "blank widget" bug in the lattice viewer;
  have you already solved it?

M    kalzium/src/kalziumglwidget.h
M    kalzium/src/kalziumglwidget.cpp
M    kalzium/src/latticedialog.cpp

svn path=/trunk/KDE/kdeedu/kalzium/src/kalziumglwidget.h; revision=555113

kalzium/kalziumglwidget.cpp
kalzium/kalziumglwidget.h

index 7dfb285171b1e02b442d9940618be51ccf5c6d47..15543d5571fad4be6ba770047ed284e812f0fd5f 100644 (file)
 #include <QMouseEvent>
 #include <QListWidget>
 
+#ifdef USE_FPS_COUNTER
+#include <QTime>
+#endif
+
 #include <openbabel/mol.h>
 #include <openbabel/obiter.h>
 
@@ -28,6 +32,7 @@ using namespace OpenBabel;
 KalziumGLWidget::KalziumGLWidget( QWidget * parent )
        : QGLWidget( parent )
 {
+       m_displayList = 0;
        m_isDragging = false;
        m_molecule = 0;
        m_detail = 0;
@@ -43,6 +48,14 @@ KalziumGLWidget::~KalziumGLWidget()
 {
 }
 
+void KalziumGLWidget::deleteDisplayList()
+{
+#ifdef USE_DISPLAY_LIST
+       if( m_displayList) glDeleteLists( m_displayList, 1 );
+       m_displayList = 0;
+#endif
+}
+
 void KalziumGLWidget::initializeGL()
 {
        glClearColor( 0.0, 0.0, 0.0, 1.0 );
@@ -119,6 +132,13 @@ void KalziumGLWidget::paintGL()
        }
        else glDisable( GL_FOG );
 
+#ifdef USE_DISPLAY_LIST
+       if ( ! m_displayList )
+       {
+       m_displayList = glGenLists( 1 );
+       glNewList( m_displayList, GL_COMPILE );
+#endif
+
        // render the atoms
        if( m_atomStyle == ATOM_SPHERE )
        {
@@ -204,6 +224,13 @@ void KalziumGLWidget::paintGL()
                }
        }
 
+#ifdef USE_DISPLAY_LIST
+       glEndList();
+       }
+
+       glCallList( m_displayList );
+#endif
+
        // now, paint a semitransparent sphere around the selected atom
 
        if( m_selectedAtom )
@@ -228,8 +255,41 @@ void KalziumGLWidget::paintGL()
                        c);
 
                glDisable( GL_BLEND );
+       }
+#ifdef USE_FPS_COUNTER
+       QTime t;
+
+       static bool firstTime = true;
+       static int old_time, new_time;
+       static int frames;
+       static QString s;
 
+       if( firstTime )
+       {
+               t.start();
+               firstTime = false;
+               old_time = t.elapsed();
+               frames = 0;
+       }
+
+       new_time = t.elapsed();
+       
+       frames++;
+
+       if( new_time - old_time > 200 )
+       {
+               s = QString::number( 1000 * frames /
+                       double( new_time - old_time ),
+                       'f', 1 );
+               s += " frames per second";
+               frames = 0;
+               old_time = new_time;
        }
+
+       renderText ( 20, 20, s );
+
+       update();
+#endif
 }
 
 void KalziumGLWidget::resizeGL( int width, int height )
@@ -291,6 +351,8 @@ void KalziumGLWidget::setupObjects()
 
        m_sphere.setup( sphere_detail, atomRadius() );
        m_cylinder.setup( cylinder_faces, bondRadius() );
+
+       deleteDisplayList();
 }
 
 void KalziumGLWidget::drawSphere( GLdouble x, GLdouble y, GLdouble z,
@@ -417,7 +479,11 @@ void KalziumGLWidget::ChooseStylePreset( StylePreset stylePreset )
 void KalziumGLWidget::prepareMoleculeData()
 {
        // translate the molecule so that center has coords 0,0,0
-       m_molecule->Center();
+       //m_molecule->Center();
+       std::map<std::string, std::string> m;
+       m["c"] = "c";
+       m_molecule->DoTransformations(&m);
+
 
        // calculate the radius of the molecule
        // that is, the maximal distance between an atom of the molecule
index aad5389744f7603c2c5a53c89f2676218fb1bf03..3e046a699c0c700a919346cf45bc457b8cede9cf 100644 (file)
@@ -18,6 +18,8 @@
 #include <openbabel/mol.h>
 
 #define USE_DOUBLE_PRECISION
+#define USE_DISPLAY_LIST
+#define USE_FPS_COUNTER
 
 #ifdef USE_DOUBLE_PRECISION
 #define FLOAT          double
@@ -216,6 +218,10 @@ class KalziumGLWidget : public QGLWidget
        Q_OBJECT
 
        protected:
+
+               GLuint m_displayList;
+               void deleteDisplayList();
+
                /**
                 * The geometric model of the sphere (used for atoms).
                 */