| 1 |
/* |
| 2 |
* This file is part of MUSIC. |
| 3 |
* Copyright (C) 2009 INCF |
| 4 |
* |
| 5 |
* MUSIC is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 3 of the License, or |
| 8 |
* (at your option) any later version. |
| 9 |
* |
| 10 |
* MUSIC is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
* GNU General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
// VisualiseNeurons.h written by Johannes Hjorth, [email protected] |
| 20 |
|
| 21 |
|
| 22 |
#ifdef __APPLE__ |
| 23 |
#include <OpenGL/gl.h> |
| 24 |
#else |
| 25 |
#include <GL/gl.h> |
| 26 |
#endif |
| 27 |
#include <GL/freeglut.h> |
| 28 |
#include <math.h> |
| 29 |
#include <mpi.h> |
| 30 |
#include <music.hh> |
| 31 |
#include <iostream> |
| 32 |
#include <sstream> |
| 33 |
#include <vector> |
| 34 |
#include "datafile.h" |
| 35 |
#include <assert.h> |
| 36 |
#include <pthread.h> |
| 37 |
#include <sys/time.h> |
| 38 |
#include <sys/select.h> |
| 39 |
#include <getopt.h> |
| 40 |
#include <string.h> |
| 41 |
#include <vector> |
| 42 |
#include <queue> |
| 43 |
|
| 44 |
#ifndef _VISUALISE_NEURONS |
| 45 |
#define _VISUALISE_NEURONS |
| 46 |
|
| 47 |
#define DEFAULT_TIMESTEP 1e-3 |
| 48 |
#define PI 3.141592653589793 |
| 49 |
|
| 50 |
|
| 51 |
// Inner class used in priority queue |
| 52 |
class TimeIdPair |
| 53 |
{ |
| 54 |
public: |
| 55 |
|
| 56 |
TimeIdPair() { time_ = -1; }; |
| 57 |
TimeIdPair(double time, MUSIC::GlobalIndex id) { time_ = time; id_ = id; } |
| 58 |
|
| 59 |
//bool operator<(const TimeIdPair&) const; |
| 60 |
bool operator<(const TimeIdPair&) const; |
| 61 |
|
| 62 |
double getTime() const { return time_; } |
| 63 |
MUSIC::GlobalIndex getId() const { return id_; } |
| 64 |
|
| 65 |
private: |
| 66 |
double time_; |
| 67 |
MUSIC::GlobalIndex id_; |
| 68 |
}; |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
class VisualiseNeurons : public MUSIC::EventHandlerGlobalIndex { |
| 73 |
|
| 74 |
public: |
| 75 |
VisualiseNeurons() { |
| 76 |
tau_ = 10e-3; // How fast does activity decay in visualisation? |
| 77 |
time_ = 0; // Current time |
| 78 |
dt_ = DEFAULT_TIMESTEP; |
| 79 |
stopTime_ = 0; // End of simulation time |
| 80 |
oldTime_ = 0; // Time of previous timestep |
| 81 |
done_ = 0; // Are we there yet? |
| 82 |
|
| 83 |
maxDist_ = 0; // Radie of a thought sphere containing all neurons |
| 84 |
is3dFlag_ = 0; // If it is 3d structure, then lets rotate. |
| 85 |
|
| 86 |
synchFlag_ = 0; // Should we try to keep a steady pace or go full speed? |
| 87 |
scaleTime_ = 1; |
| 88 |
|
| 89 |
gettimeofday(&tickStartTime_,NULL); |
| 90 |
windowTitle_ = "viewevents"; |
| 91 |
} |
| 92 |
|
| 93 |
void run(int argc, char **argv); |
| 94 |
void readConfigFile(string filename); |
| 95 |
void finalize(); |
| 96 |
|
| 97 |
// Event handler for incomming spikes |
| 98 |
void operator () ( double t, MUSIC::GlobalIndex id ); |
| 99 |
|
| 100 |
void display(); |
| 101 |
void rotateTimer(); |
| 102 |
void tick(); |
| 103 |
|
| 104 |
void addNeuron(double x, double y, double z, double r, double cIdx); |
| 105 |
|
| 106 |
// Static wrapper functions |
| 107 |
static void displayWrapper(); |
| 108 |
static void rotateTimerWrapper(int v); |
| 109 |
static void* runMusic(void *arg); |
| 110 |
|
| 111 |
typedef struct { |
| 112 |
GLdouble x; |
| 113 |
GLdouble y; |
| 114 |
GLdouble z; |
| 115 |
GLdouble r; // radie of neuron |
| 116 |
}neuronCoord; |
| 117 |
|
| 118 |
typedef struct { |
| 119 |
GLdouble r; |
| 120 |
GLdouble g; |
| 121 |
GLdouble b; |
| 122 |
}neuronColour; |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
private: |
| 127 |
|
| 128 |
void getArgs(int argc, char* argv[]); |
| 129 |
void printHelp(); |
| 130 |
|
| 131 |
MUSIC::Setup* setup_; // ONLY to be used during setup phase |
| 132 |
MUSIC::Runtime* runtime_; // Music runtime object |
| 133 |
|
| 134 |
GLuint neuronList_; // OpenGL list for drawing object |
| 135 |
|
| 136 |
std::vector<neuronCoord> coords_; // Coordinates of neuron population |
| 137 |
std::vector<double> volt_; // Activity of neuron population |
| 138 |
std::vector<int> cMap_; // Which colour does neurons have |
| 139 |
|
| 140 |
std::vector<neuronColour> baseLineCol_; // Colour of resting neuron |
| 141 |
std::vector<neuronColour> excitedCol_; // Colour of spiking neuron |
| 142 |
double spikeScale_; // eg, 0.1 = scale up spiking neurons by 10% |
| 143 |
|
| 144 |
string windowTitle_; |
| 145 |
|
| 146 |
double dt_; |
| 147 |
double tau_; // Tau decay of activity |
| 148 |
double time_; // Current time |
| 149 |
double oldTime_; // Previous timestep |
| 150 |
double stopTime_; // End of simulations |
| 151 |
int done_; // Simulation done? |
| 152 |
|
| 153 |
double rotAngle_; // Current rotation angle |
| 154 |
|
| 155 |
int rank_; // Rank of this process |
| 156 |
|
| 157 |
double maxDist_; // Distance from origo to outermost neuron |
| 158 |
// Used when calculating camera position |
| 159 |
|
| 160 |
int is3dFlag_; |
| 161 |
|
| 162 |
pthread_t tickThreadID_; |
| 163 |
|
| 164 |
int synchFlag_; // Do we try to synch, or run full throttle? |
| 165 |
double scaleTime_; // real time / simulated time |
| 166 |
struct timeval tickStartTime_; |
| 167 |
struct timeval tickEndTime_; |
| 168 |
struct timeval tickDelay_; |
| 169 |
|
| 170 |
|
| 171 |
string confFile_; // Config file with colours and coordinates |
| 172 |
|
| 173 |
//priority_queue <TimeIdPair> priorityQueue_; |
| 174 |
std::priority_queue<TimeIdPair> priorityQueue_; |
| 175 |
}; |
| 176 |
|
| 177 |
static std::vector<VisualiseNeurons*> objTable_; |
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
#endif |