SpikeStream Nemo Plugin
0.2
|
00001 //SpikeStream includes 00002 #include "RasterModel.h" 00003 using namespace spikestream; 00004 00005 //Qt includes 00006 #include <QDebug> 00007 00008 //Other includes 00009 #include <math.h> 00010 00012 RasterModel::RasterModel(QList<NeuronGroup*>& neuronGroupList) : QwtRasterData(){ 00013 //Find the maximum neuron ID 00014 maxNeuronID = 0; 00015 for(QList<NeuronGroup*>::iterator neurGrpIter = neuronGroupList.begin(); neurGrpIter != neuronGroupList.end(); ++neurGrpIter){ 00016 maxNeuronID += (*neurGrpIter)->size(); 00017 } 00018 00019 //Initialize variables 00020 numTimeSteps = 1000; 00021 dataArray = new QHash<unsigned, bool>[numTimeSteps]; 00022 dataCount = 0; 00023 readIndex = 0; 00024 writeIndex = 0; 00025 minTimeStep = 0; 00026 } 00027 00028 00030 RasterModel::~RasterModel(){ 00031 delete [] dataArray; 00032 } 00033 00034 00035 /*----------------------------------------------------------*/ 00036 /*------ PUBLIC METHODS ------*/ 00037 /*----------------------------------------------------------*/ 00038 00041 void RasterModel::addData(const QList<unsigned>& firingNeuronIDs, unsigned timeStep){ 00042 qDebug()<<"Adding data: timestep="<<timeStep; 00043 00044 //Fix minimum time step and reading location 00045 if(timeStep > (minTimeStep + numTimeSteps)) 00046 minTimeStep = timeStep - numTimeSteps; 00047 readIndex = minTimeStep % numTimeSteps; 00048 00049 //Clear data at write position 00050 dataArray[writeIndex].clear(); 00051 00052 //Add data to hash map at write index 00053 QList<unsigned>::const_iterator firingNeuronIDsEnd = firingNeuronIDs.end(); 00054 for(QList<unsigned>::const_iterator neurIter = firingNeuronIDs.begin(); neurIter != firingNeuronIDsEnd; ++neurIter){ 00055 for(QList<NeuronGroup*>::iterator neurGrpIter = neuronGroupList.begin(); neurGrpIter != neuronGroupList.end(); ++neurGrpIter){ 00056 if((*neurGrpIter)->contains(*neurIter)){ 00057 dataArray[writeIndex][*neurIter - (*neurGrpIter)->getStartNeuronID()] = true;//FIXME: ADD OFFSET FOR EACH NEURON GROUP 00058 break; 00059 } 00060 } 00061 } 00062 00063 //Increase write index in a circular fashion 00064 ++writeIndex; 00065 writeIndex %= numTimeSteps; 00066 } 00067 00068 00069 //Inherited from QwtData 00070 QwtRasterData* RasterModel::copy() const{ 00071 return (QwtRasterData*)this; 00072 } 00073 00074 00076 int RasterModel::getMinX(){ 00077 return minTimeStep; 00078 } 00079 00080 00082 int RasterModel::getMaxX(){ 00083 return minTimeStep + numTimeSteps; 00084 } 00085 00086 00088 int RasterModel::getMinY(){ 00089 return 0; 00090 } 00091 00092 00094 int RasterModel::getMaxY(){ 00095 return maxNeuronID; 00096 } 00097 00098 00099 //Inherited from QwtData 00100 double RasterModel::value (double x, double y) const{ 00101 int tmpX = (int)rint(x); 00102 int tmpY = (int)rint(y); 00103 00104 int tmpIndx = (readIndex + tmpX) % numTimeSteps; 00105 qDebug()<<"Reading x="<<x<<"; y="<<y; 00106 00107 if(dataArray[tmpIndx].contains(tmpY)) 00108 return 1.0; 00109 return 0.0; 00110 } 00111 00112 00113 //Inherited from QwtData 00114 QwtDoubleInterval RasterModel::range() const{ 00115 return QwtDoubleInterval(minTimeStep, minTimeStep + numTimeSteps); 00116 } 00117 00118 00119