Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

NetworkViewer.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 #ifndef NETWORKVIEWER_H
00024 #define NETWORKVIEWER_H
00025 
00026 //SpikeStream includes
00027 #include "DBInterface.h"
00028 #include "NeuronGroupHolder.h"
00029 #include "ConnectionGroupHolder.h"
00030 #include "SpikeStreamApplication.h"
00031 
00032 //Qt includes
00033 #include <qaccel.h>
00034 #include <qgl.h>
00035 #include <qsplashscreen.h>
00036 #include <qprogressbar.h>
00037 #include <qprogressdialog.h>
00038 #include <qevent.h>
00039 #include <qtimer.h>
00040 
00041 //Other includes
00042 #include <vector>
00043 #include <map>
00044 #include <google/dense_hash_map>
00045 using HASH_NAMESPACE::hash;
00046 using GOOGLE_NAMESPACE::dense_hash_map;
00047 using namespace std;
00048 
00049 
00050 /*! A simple RGB color struct used to hold the highlight colour.
00051         Use this instead of QColor to minimise space. */
00052 struct RGBColor {
00053         float red;
00054         float green;
00055         float blue;
00056 };
00057 
00058 
00059 /*! The type of the map used to store highlighted neurons. */
00060 typedef dense_hash_map<unsigned int, RGBColor*> HighlightNeuronMap;
00061 
00062 /*! The type of the map used to store the color of highlighted neurons. */
00063 typedef map<RGBColor*, bool> HighlightColorMap;
00064 
00065 
00066 //-------------------------- Network Viewer -------------------------------
00067 /*! Generates a three dimensional view of the network and connections using
00068         OpenGL. Stores a data representation of all the neurons and connections.
00069         Parameters for this display are set using the Network Viewer Properties 
00070         widget. Some of the methods are adapted from gltools, provided in the 
00071         OpenGL Superbible, Third Edition.*/
00072 
00073 /* FIXME THERE IS CURRENTLY SOME CONFLIGT BETWEEN THIS CLASS IN FULL RENDER
00074         MODE AND THE NETWORK MONITOR DUE TO INTERLACING OF OPENGL COMMANDS. */
00075 //-------------------------------------------------------------------------
00076 
00077 class NetworkViewer : public QGLWidget {
00078         Q_OBJECT
00079 
00080         public:
00081                 NetworkViewer(QWidget *parent, QSplashScreen*, DBInterface*, unsigned int);
00082                 ~NetworkViewer();
00083                 void addHighlight(unsigned int neurID, RGBColor* highlightColor);
00084                 void cancelRenderProgress();
00085                 void clearHighlights();
00086                 void deleteConnectionGroup(unsigned int ID);
00087                 void deleteNeuronGroup(unsigned int ID);
00088                 vector<unsigned int>* getConnectionViewVector();
00089                 void loadConnectionGroup(unsigned int, bool);
00090                 void loadDefaultClippingVolume();
00091                 void loadNeuronGroup(unsigned int, bool);
00092                 void reloadEverything();
00093                 void refresh();
00094                 void resetView();
00095                 void setConnectionView(vector<unsigned int>);
00096                 void setFullRenderMode(bool);
00097                 void setLayerView(vector<unsigned int>);
00098                 void setMaxAutoLoadConnGrpSize(unsigned int);
00099                 void setNetworkViewerProperties(QWidget*);
00100                 void setNeuronConnectionMode(bool mode, unsigned int neuronGroup1, bool betwMode, unsigned int neuronGroup2);
00101                 void setNeuronFilterMode(bool mode, char minWeight, char maxWeight, bool showFrom, bool showTo, bool updateDisplay);
00102                 void setRenderDelay(double);
00103                 void setRenderProgressBar(QProgressBar*);
00104                 void showConnections(bool);
00105                 void zoomAboveLayer(unsigned int layID);
00106                 void zoomToLayer(unsigned int layID);
00107 
00108 
00109     protected:
00110                 //Methods inherited from QGLWidget
00111                 void initializeGL();
00112                 void paintGL();
00113                 void resizeGL(int width, int height);
00114 
00115 
00116         private slots:
00117                 void acceleratorKeyPressed (int acceleratorID);
00118                 void setFullRender();
00119 
00120 
00121         private:
00122                 //=========================== VARIABLES =======================================
00123                 /*! Links keys to changes in graphics, perspective etc..*/
00124                 QAccel *keyboardAccelerator;
00125 
00126                 /*! Hold a reference to the network viewer properties to enable the neuron number 
00127                 to be updated. Because of tricky stuff with headers, this is stored as a reference
00128                 to Widget, not the class itself which is then cast as network viewer properties at 
00129                 run time.*/
00130                 //FIXME CHANGE THIS TO SIGNALS/ SLOTS
00131                 QWidget *networkViewerProperties;
00132 
00133                 /*! Short version of reference to main QApplication */
00134                 SpikeStreamApplication *spikeStrApp;
00135 
00136                 /*! Reference to database handling class.*/
00137                 DBInterface* dbInterface;
00138 
00139                 /*! Angle in DEGREES for OpenGL perspective. Controls how much of scene is clipped.*/
00140                 GLfloat perspective_angle;
00141 
00142                 /*! For OpenGL perspective. Controls how much of scene is clipped.*/
00143                 GLfloat perspective_near;
00144 
00145                 /*! For OpenGL perspective. Controls how much of scene is clipped.*/
00146                 GLfloat perspective_far;
00147 
00148                 /*! Amount that scene is rotated around X axis.*/
00149                 GLfloat sceneRotateX;
00150 
00151                 /*! Amount that scene is rotated around Z axis.*/
00152                 GLfloat sceneRotateZ;
00153 
00154                 /*! CameraMatrix holds the location and coordinate system of the camera.*/
00155                 GLfloat cameraMatrix [16];
00156                 
00157                 /*! Used for rotating camera matrix.*/
00158                 GLfloat rotationMatrix [16];
00159 
00160                 /*! Default view in which all neuron groups should be visible.*/
00161                 ClippingVolume defaultClippingVol;
00162 
00163                 /*! Map holding neurons that are to be highlighted and their highlight color.*/
00164                 HighlightNeuronMap highlightNeuronMap;
00165 
00166                 /*! Stores all of the colors so that they can be deleted. Several neurons may
00167                          point to the same colour so need to track the colours separately. */
00168                 HighlightColorMap highlightColorMap;
00169 
00170                 /*! Reduces checking of highlight map. Set to true when highlighting is enabled.*/
00171                 bool highlightMode;
00172 
00173                 //Declare pointers here to save redeclaring them whilst drawing graphics
00174                 float* xPosPtr;
00175                 float* yPosPtr;
00176                 float* zPosPtr;
00177                 unsigned int *neuronIDPtr;
00178                 float* fromXPtr;
00179                 float* fromYPtr;
00180                 float* fromZPtr;
00181                 float* toXPtr;
00182                 float* toYPtr;
00183                 float* toZPtr;
00184                 char* weightPtr;
00185                 unsigned int *fromNeuronIDPtr;
00186                 unsigned int *toNeuronIDPtr;
00187 
00188                 /*! In full render mode, the network viewer sets full render to true after render delay
00189                         When full render is true the full render is displayed.*/
00190                 bool fullRenderMode;
00191 
00192                 /*! Determines whether we perform a full render or just vertices.*/
00193                 bool fullRender;
00194 
00195                 /*! Delay between the last keystroke and start of full render in full render mode.*/
00196                 int renderDelay_ms;
00197 
00198                 /*! Timer to start full render after the delay.*/
00199                 QTimer *renderTimer;
00200 
00201                 /*! Cancels render.*/
00202                 bool cancelRender;
00203 
00204                 /*! Reference to the progress bar in the network viewer properties.*/
00205                 QProgressBar *renderProgressBar;
00206                 
00207                 /*! Displays the progress as the neuron and connection groups are loaded.*/
00208                 QProgressDialog *loadProgressDialog;
00209                 
00210                 /*! In draw connections mode the connections are drawn.*/
00211                 bool drawConnections;
00212                 
00213                 /*! In neuron connection mode, the connections to a single neuron are shown
00214                         When neuron filter mode is on, these connections are filtered according to 
00215                         various criteria.*/
00216                 bool neuronConnectionMode;
00217                 bool neuronFilterMode;
00218                 
00219                 /*! Store the details about the neurons for drawing using OpenGL.*/
00220                 map<unsigned int, NeuronGroupHolder*> neuronGrpMap;
00221 
00222                 /*! Store the details about the connections for drawing using OpenGL.*/
00223                 map<unsigned int, ConnectionGroupHolder*> connectionGrpMap;
00224                 
00225                 /*! Vectors of the IDs of the visible neuron groups.*/
00226                 vector<unsigned int> layerViewVector;
00227 
00228                 /*! Vectors of the IDs of the visible connection groups.*/
00229                 vector<unsigned int> connectionViewVector;
00230                 
00231                 /*! The neuron that is normally displayed in single neuron mode.*/
00232                 unsigned int firstSingleNeuronID;
00233 
00234                 /*! In between mode, the connections between the firstSingle neuron and the second single neuron are displayed.*/
00235                 unsigned int secondSingleNeuronID;
00236 
00237                 //Used to navigate around the layer in single neuron mode
00238                 unsigned int maxFirstSingleNeuronID;
00239                 unsigned int minFirstSingleNeuronID;
00240                 unsigned int firstSingleNeuronGroupWidth;
00241                 unsigned int maxSecondSingleNeuronID;
00242                 unsigned int minSecondSingleNeuronID;
00243                 unsigned int secondSingleNeuronGroupWidth;
00244                 unsigned int firstSingleNeurGrpID;
00245                 unsigned int secondSingleNeurGrpID;
00246                 
00247                 /*! Used for filtering weights in single neuron mode.*/
00248                 char maxWeight;
00249 
00250                 /*! Used for filtering weights in single neuron mode.*/
00251                 char minWeight;
00252                 
00253                 /*! Show from connections in single neuron mode.*/
00254                 bool showFromConnections;
00255 
00256                 /*! Show to connections in single neuron mode.*/
00257                 bool showToConnections; 
00258                 
00259                 /*! Shows connections between two highlighted neurons.*/
00260                 bool showBetweenConnections;
00261                 
00262                 /*! Stores which neurons are connected to the single neuron in from filter mode.*/
00263                 map<unsigned int, bool>fromNeuronMap;
00264 
00265                 /*! Stores which neurons are connected to the single neuron in to filter mode.*/
00266                 map<unsigned int, bool>toNeuronMap;
00267 
00268                 /*! Maximum sizew of connection group that is automatically loaded. Groups bigger 
00269                         than this only when they are set visible. Set in spikestream.config.*/
00270                 unsigned int maxAutoLoadConnGrpSize;
00271 
00272                 /*! When this is true a new display list is created. Otherwise the existing
00273                         display list is used to draw the graphics. */
00274                 bool viewStateChanged;
00275 
00276                 /*! Reference to the display list for the graphics. This stores OpenGL
00277                         commands, which can then be played back as a block. */
00278                 GLuint mainDisplayList;
00279 
00280                 /*! Records when the rendering is taking place so that accelerator keys
00281                         do not change the settings mid render */
00282                 bool paintingGL;
00283 
00284                 /*! During full render, do not want to start render or resize, so record
00285                         whether paintGL() or resizeGL() have been called and then call them
00286                         again at the end of the render. newTempScreen width and height are the
00287                         latest values of the screen width and height if resizeGL() has been called. */
00288                 bool resizeSkipped;
00289 
00290                 /*! During full render, do not want to start render or resize, so record
00291                         whether paintGL() or resizeGL() have been called and then call them
00292                         again at the end of the render. newTempScreen width and height are the
00293                         latest values of the screen width and height if resizeGL() has been called. */
00294                 bool paintSkipped;
00295                 int newTempScreenWidth;
00296                 int newTempScreenHeight;
00297 
00298 
00299                 //=========================== METHODS =======================================
00300                 /*! Declare copy constructor private so it cannot be used inadvertently.*/
00301                 NetworkViewer (const NetworkViewer&);
00302 
00303                 /*! Declare assignment private so it cannot be used inadvertently.*/
00304                 NetworkViewer operator = (const NetworkViewer&);
00305 
00306                 void checkOpenGLErrors();
00307                 void deleteAllConnectionGroups();
00308                 void deleteAllNeuronGroups();
00309                 void disableFullRender();
00310                 void drawAxes();
00311                 void drawSolidSphere(GLdouble radius, GLint slices, GLint stacks);
00312                 void fillRotationMatrix(float, float, float, float);
00313                 float getFloat(string s);
00314                 void initialiseCameraParameters();
00315                 void initialiseFullRender();
00316                 void loadAllConnectionGroups(QSplashScreen* splashScreen = 0);
00317                 void loadAllNeuronGroups(QSplashScreen* splashScreen = 0);
00318                 void rotateVector(float, float, float, GLfloat[]);
00319                 void rotateXAxis(float angle);
00320                 void rotateZAxis(float angle);
00321                 void viewClippingVolume_Horizontal(ClippingVolume);
00322                 void viewClippingVolume_Vertical(ClippingVolume);
00323 
00324 };
00325 
00326 
00327 #endif//NETWORKVIEWER_H

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4