Skip to content
Snippets Groups Projects
Commit 4cf685c7 authored by Stuart Layton's avatar Stuart Layton
Browse files

began porting code from stereotrode plot to tetrode plot. It shows up in the...

began porting code from stereotrode plot to tetrode plot. It shows up in the canvas and actually shows spikes after the display is panned or zoomed at least once. Although spikes only show up in 2 of the 3 waveform axes
parent 6199ffcd
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* n) : processor(n),
totalScrollPix(0)
{
nCols = 3;
nCols = 2;
update();
......
......@@ -22,7 +22,6 @@
*/
#include "SpikeObject.h"
#include <iostream>
#include "memory.h"
#include <stdlib.h>
#include "time.h"
......@@ -30,36 +29,43 @@
// Simple method for serializing a SpikeObject into a string of bytes
int packSpike(SpikeObject *s, uint8_t* buffer, int bufferSize){
int reqBytes = 1 + 4 + 2 + 2 + 2 + 2 * s->nChannels * s->nSamples + 2 * s->nChannels * 2;
int idx = 0;
s->eventType = SPIKE_EVENT_CODE;
memcpy(buffer+idx, &(s->eventType), 1);
idx += 1;
memcpy(buffer+idx, &(s->timestamp), 4);
idx += 4;
memcpy(buffer+idx, &(s->source), 2);
idx +=2;
memcpy(buffer+idx, &(s->nChannels), 2);
idx +=2;
memcpy(buffer+idx, &(s->nSamples), 2);
idx +=2;
memcpy(buffer+idx, &(s->data), s->nChannels * s->nSamples * 2);
idx += s->nChannels * s->nSamples * 2;
memcpy(buffer+idx, &(s->gain), s->nChannels * 2);
idx += s->nChannels * 2;
memcpy(buffer+idx, &(s->threshold), s->nChannels * 2);
idx += s->nChannels * 2;
memcpy(buffer+idx, &(s->gain), s->nChannels);
idx += s->nChannels;
memcpy(buffer+idx, &(s->threshold), s->nChannels);
idx += s->nChannels;
if (idx >= bufferSize)
std::cout<<"Buffer Overrun! More data packaged than space provided!"<<std::endl;
if (idx >= MAX_SPIKE_BUFFER_LEN){
std::cout<<"Spike is larger than it should be. Size was:"<<idx<<" Max Size is:"<<MAX_SPIKE_BUFFER_LEN<<std::endl;
}
// makeBufferValid(buffer, bufferSize);
return idx;
......@@ -221,16 +227,15 @@ void generateEmptySpike(SpikeObject *s, int nChannels){
}
}
// std::ostream& operator<<(std::ostream &strm, const SpikeObject s){
// strm << " SpikeObject:\n";
// strm << "\tTimestamp:" << s.timestamp;
// strm << "\tSource:" << s.source;
// strm << "\tnChannels:" <<s.nChannels;
// strm <<"\tnSamples" << s.nSamples;
// strm <<"\n\t 8 Data Samples:";
// for (int i=0; i<8; i++)
// strm << s.data[i]<<" ";
// return strm;
// }
void printSpike(SpikeObject *s){
std::cout<< " SpikeObject:\n";
std::cout<< "\tTimestamp:" << s->timestamp;
std::cout<< "\tSource:" << s->source;
std::cout<< "\tnChannels:" <<s->nChannels;
std::cout<<"\tnSamples" << s->nSamples;
std::cout<<"\n\t 8 Data Samples:";
for (int i=0; i<8; i++)
std::cout<<s->data+i<<" ";
std::cout<<std::endl;
}
......@@ -24,13 +24,15 @@
#ifndef SPIKEOBJECT_H_
#define SPIKEOBJECT_H_
#include <iostream>
#include <stdint.h>
#include <math.h>
#define MAX_NUMBER_OF_SPIKE_CHANNELS 4
#define MAX_NUMBER_OF_SPIKE_CHANNEL_SAMPLES 256
#define MAX_NUMBER_OF_SPIKE_CHANNEL_SAMPLES 60
#define CHECK_BUFFER_VALIDITY true
#define SPIKE_EVENT_CODE 4;
#define MAX_SPIKE_BUFFER_LEN 512 // the true max calculated from the spike values below is actually 507
struct SpikeObject{
......@@ -83,5 +85,7 @@ void generateSimulatedSpike(SpikeObject *s, uint64_t timestamp, int noise);
// Helper function for zeroing out a spike object with a specified number of channels
void generateEmptySpike(SpikeObject *s, int nChannels);
void printSpike(SpikeObject *s);
#endif //SPIKEOBJECT_H_
\ No newline at end of file
......@@ -3,8 +3,9 @@
#include "PlotUtils.h"
TetrodePlot::TetrodePlot():
BaseUIElement(), limitsChanged(true)
BaseUIElement(), limitsChanged(true)
{
}
TetrodePlot::TetrodePlot(int x, int y, int w, int h):
......@@ -24,32 +25,30 @@ TetrodePlot::~TetrodePlot(){
// the right direction
void TetrodePlot::redraw(){
//std::cout<<"TetrodePlot() starting drawing"<<std::endl;\
BaseUIElement::clearNextDraw = true;
BaseUIElement::redraw();
for (int i=0; i<4; i++)
//std::cout<<"TetrodePlot() starting drawing"<<std::endl;\
//BaseUIElement::clearNextDraw = true;
//BaseUIElement::redraw();
for (int i = 0; i < 4; i++)
wAxes[i].redraw();
for (int i=0; i<6; i++)
for (int i = 0; i < 6; i++)
pAxes[i].redraw();
}
// This would normally happen for collection of axes but an electrode plot doesn't have a collection instead its a single axes
void TetrodePlot::processSpikeObject(SpikeObject s){
//std::cout<<"ElectrdePlot::processSpikeObject()"<<std::endl;
for (int i=0; i<4; i++)
for (int i = 0; i < 4; i++)
wAxes[i].updateSpikeData(s);
for (int i=0; i<6; i++)
for (int i = 0; i < 6; i++)
pAxes[i].updateSpikeData(s);
}
void TetrodePlot::setEnabled(bool e){
BaseUIElement::enabled = e;
for (int i=0; i<4; i++)
for (int i = 0; i < 4; i++)
wAxes[i].setEnabled(e);
for (int i=0; i<6; i++)
for (int i = 0; i < 6; i++)
pAxes[i].setEnabled(e);
}
......@@ -63,111 +62,67 @@ void TetrodePlot::initAxes(){
int minX = BaseUIElement::xpos;
int minY = BaseUIElement::ypos;
int axesWidth = BaseUIElement::width/4;
int axesHeight = BaseUIElement::height/2;
double axesWidth = BaseUIElement::width/4;
double axesHeight = BaseUIElement::height/2;
wAxes[0] = WaveAxes(minX, minY, axesWidth/2, axesHeight, WAVE1);
wAxes[1] = WaveAxes(minX + axesWidth/2, minY, axesWidth/2, axesHeight, WAVE2);
wAxes[2] = WaveAxes(minX, minY + axesHeight, axesWidth/2, axesHeight, WAVE3);
wAxes[3] = WaveAxes(minX + axesWidth/2, minY + axesHeight, axesWidth/2, axesHeight, WAVE4);
// for (int i=0; i<6; i++)
// {
// pAxes[i] = ProjectionAxes(
// minX + axesWidth * ((i%3)+1),
// minY + (i/3) * axesHeight,
// axesWidth ,
// axesHeight,
// i);
//}
//
// because the width of the plot doesn't always divide evenly into 4 we are going to pad the width
// of the 3rd and 6th projection plot to cover up the space cleared by the TetrodePlotElement
int xPad = 1;
pAxes[0] = ProjectionAxes(minX + axesWidth*1, minY, axesWidth, axesHeight, PROJ1x2);
pAxes[1] = ProjectionAxes(minX + axesWidth*2, minY, axesWidth, axesHeight, PROJ1x3);
pAxes[2] = ProjectionAxes(minX + axesWidth*3, minY, axesWidth+xPad, axesHeight, PROJ1x4);
pAxes[3] = ProjectionAxes(minX + axesWidth*1, minY + axesHeight, axesWidth, axesHeight, PROJ2x3);
pAxes[4] = ProjectionAxes(minX + axesWidth*2, minY + axesHeight, axesWidth, axesHeight, PROJ2x4);
pAxes[5] = ProjectionAxes(minX + axesWidth*3, minY + axesHeight, axesWidth+xPad, axesHeight, PROJ3x4);
// wAxes[0] = WaveAxes(minX, minY, axesWidth/2, axesHeight, WAVE1);
// wAxes[1] = WaveAxes(minX + axesWidth/2, minY, axesWidth/2, axesHeight, WAVE2);
// wAxes[2] = WaveAxes(minX, minY + axesHeight, axesWidth/2, axesHEight, WAVE3);
// wAxes[3] = WaveAxes(minX + axesWidth/2, minY + axesHeight, axesWidth/2, axesHEight, WAVE4);
//axes.setEnabled(false);
for (int i=0; i<4; i++){
wAxes[i].setYLims(-1*pow(2,11), pow(2,14)*1.6);
for (int i=0; i<4; i++)
wAxes[i] = WaveAxes(minX + (i/2)*(axesWidth/2), minY + (i%2)*(axesHeight), axesWidth/2, axesHeight, WAVE1 + i);
for (int i=0; i<6; i++)
pAxes[i] = ProjectionAxes(minX + (1 + i/2)*axesWidth, minY + (i%2)*(axesHeight), axesWidth, axesHeight, PROJ1x2+i);
for (int i=0; i<4; i++)
wAxes[i].setWaveformColor(1.0, 1.0, 1.0);
}
for (int i=0; i<6; i++)
{
pAxes[i].setXLims(-1*pow(2,11), pow(2,14)*1.6);
pAxes[i].setYLims(-1*pow(2,11), pow(2,14)*1.6);
pAxes[i].setPointColor(1.0, 1.0, 1.0);
}
setLimitsOnAxes();
}
void TetrodePlot::setLimitsOnAxes(){
std::cout<<"TetrodePlot::setLimitsOnAxes()"<<std::endl;
wAxes[0].setYLims(limits[0][0], limits[0][1]);
wAxes[1].setYLims(limits[1][0], limits[1][1]);
wAxes[2].setYLims(limits[0][0], limits[0][1]);
wAxes[3].setYLims(limits[1][0], limits[1][1]);
for (int i=0; i<4; i++)
wAxes[i].setYLims(limits[0][0], limits[0][1]);
for (int i=0; i<6; i++)
{
for (int i=0; i<6; i++){
pAxes[i].setYLims(limits[0][0], limits[0][1]);
pAxes[i].setXLims(limits[1][0], limits[1][1]);
}
}
void TetrodePlot::setPosition(int x, int y, double w, double h){
// std::cout<<"TetrodePlot::setPosition()"<<std::endl;
BaseUIElement::setPosition(x,y,w,h);
int minX = BaseUIElement::xpos;
int minY = BaseUIElement::ypos;
int axesWidth = BaseUIElement::width/4;
int axesHeight = BaseUIElement::height/2;
wAxes[0].setPosition(minX, minY, axesWidth/2, axesHeight);
wAxes[1].setPosition(minX + axesWidth/2, minY, axesWidth/2, axesHeight);
wAxes[2].setPosition(minX, minY + axesHeight, axesWidth/2, axesHeight);
wAxes[3].setPosition(minX + axesWidth/2, minY + axesHeight, axesWidth/2, axesHeight);
// pAxes[0].setPosition(minX + axesWidth*1, minY, axesWidth, axesHeight);
// pAxes[1].setPosition(minX + axesWidth*2, minY, axesWidth, axesHeight);
// pAxes[2].setPosition(minX + axesWidth*3, minY, axesWidth, axesHeight);
// pAxes[3].setPosition(minX + axesWidth*1, minY + axesHeight, axesWidth, axesHeight);
// pAxes[4].setPosition(minX + axesWidth*2, minY + axesHeight, axesWidth, axesHeight);
// pAxes[5].setPosition(minX + axesWidth*3, minY + axesHeight, axesWidth, axesHeight);
//titleBox.setPosition(x, y+h-titleHeight-3, w, titleHeight+3);
}
double axesWidth = BaseUIElement::width/4;
double axesHeight = BaseUIElement::height/2;
// void TetrodePlot::setPosition(int x, int y){
// setPosition(x,y, BaseUIElement::width, BaseUIElement::height );
// }
for (int i=0; i<4; i++)
wAxes[i] = WaveAxes(minX + (i/2)*(axesWidth/2), minY + (i%2)*(axesHeight), axesWidth/2, axesHeight, WAVE1 + i);
// void TetrodePlot::setDimensions(double w, double h){
// setPosition(BaseUIElement::xpos, BaseUIElement::ypos, w, h);
// }
for (int i=0; i<6; i++)
pAxes[i] = ProjectionAxes(minX + (1 + i/2)*axesWidth, minY + (i%2)*(axesHeight), axesWidth, axesHeight, PROJ1x2+i);
}
int TetrodePlot::getNumberOfAxes(){
return 4;
return 10;
}
void TetrodePlot::initLimits(){
for (int i=0; i<4; i++)
for (int i=0; i<2; i++)
{
limits[i][0] = -1*pow(2,11);
limits[i][1] = pow(2,14);
limits[i][1] = pow(2,14)*1.6;
}
}
......@@ -176,173 +131,18 @@ void TetrodePlot::getPreferredDimensions(double *w, double *h){
*w = 75;
*h = 75;
}
// void TetrodePlot::mouseDown(int x, int y){
// // selectedAxesN = -1;
// // std::list<GenericAxes>::iterator i;
// // int idx=-1;
// // bool hit = false;
// // selectedAxes = NULL;
// // for (i=axesList.begin(); i!=axesList.end(); ++i)
// // {
// // if (i->hitTest(x,y))
// // {
// // selectedAxes = addressof(*i);
// // selectedAxesN = i->getType();
// // hit = true;
// // // break;
// // }
// // idx++;
// // }
// // if (!hit)
// // selectedAxes = NULL;
// // if (selectedAxes != NULL)
// // std::cout<<"TetrodePlot::mouseDown() hit:"<<selectedAxes<<" AxesType:"<<selectedaxes.getType()<<std::endl;
// // else
// // std::cout<<"TetrodePlot::mouseDown() NO HIT!"<<std::endl;
// }
// void TetrodePlot::mouseDragX(int dx, bool shift, bool ctrl){
// // if (selectedAxes == NULL || dx==0)
// // return;
// // // zoomAxes(selectedaxes.getType(), true, dx>0);
// // if (shift)
// // zoomAxes(selectedAxesN, true, dx);
// // if (ctrl)
// // panAxes(selectedAxesN, true, dx);
// }
// void TetrodePlot::mouseDragY(int dy, bool shift, bool ctrl){
// if (selectedAxes == NULL || dy==0)
// return;
// if(shift)
// zoomAxes(selectedAxesN, false, dy);
// if(ctrl)
// panAxes(selectedAxesN, false, dy);
// }
// void TetrodePlot::zoomAxes(int n, bool xdim, int zoom){
// // std::cout<<"TetrodePlot::zoomAxes() n:"<< n<<" xdim"<< xdim<<" in:"<<zoomin<<std::endl;
// // If trying to zoom an invalid axes type
// if (n<WAVE1 || n>PROJ3x4)
// return;
// if (n<=WAVE4)
// zoomWaveform(n, xdim, zoom);
// else
// zoomProjection(n, xdim, zoom);
// }
// void TetrodePlot::zoomWaveform(int n, bool xdim, int zoom){
// // waveform plots don't have a xlimits
// if (xdim)
// return;
// // std::cout<<"Zooming Waveform:"<<n<<" zoomin:"<<zoomin<<" ";
// double min, max;
// if(xdim)
// return;
// min = limits[n][0];
// max = limits[n][1];
// double mean = (max + min)/2.0f;
// double delta = max - mean;
// delta = delta / pow(.99, -1*zoom);
// min = mean - delta;
// max = mean + delta;
// limits[n][0] = min;
// limits[n][1] = max;
// limitsChanged = true;
// }
// void TetrodePlot::panAxes(int n, bool xdim, int panval){
// // std::cout<<"TetrodePlot::zoomAxes() n:"<< n<<" xdim"<< xdim<<" in:"<<zoomin<<std::endl;
// // If trying to zoom an invalid axes type
// if (n<WAVE1 || n>PROJ3x4)
// return;
// if (n<=WAVE4)
// panWaveform(n, xdim, panval);
// else
// panProjection(n, xdim, panval);
// }
// void TetrodePlot::panWaveform(int n, bool xdim, int pan){
// // waveform plots don't have a xlimits
// if (xdim)
// return;
// // std::cout<<"Panning Waveform:"<<n<<" pan:"<<pan<<" "<<std::endl;
// double min, max;
// if(xdim)
// return;
// min = limits[n][0];
// max = limits[n][1];
// double dy = max-min;
// // Need to grab something if pan event is driven by the keyboard, which means that all the plots are getting panned so this should be okay
// if (selectedAxes == NULL)
// selectedAxes = &axesList.front();
// double yPixels = (BaseUIElement::height - titleHeight)/2.0;
// double pixelWidth = -1 * dy/yPixels;
// double delta = pan * pixelWidth;
// min = min + delta;
// max = max + delta;
// limits[n][0] = min;
// limits[n][1] = max;
// limitsChanged = true;
// }
bool TetrodePlot::processKeyEvent(SimpleKeyEvent k){
// std::cout<<"Key:"<<(char)k.key<<std::endl;
// switch(k.key)
// {
// case '=':
// for (int i=0; i<=WAVE4; i++)
// zoomWaveform(i, false, 3);
// break;
// case '+':
// for (int i=0; i<=WAVE4; i++)
// panWaveform(i, false, 3);
// break;
// case '-':
// for (int i=0; i<=WAVE4; i++)
// zoomWaveform(i, false, -3);
// break;
// case '_':
// for (int i=0; i<=WAVE4; i++)
// panWaveform(i, false, -3);
// break;
// case 'C':
// clearOnNextDraw(true);
// break;
// }
}
void TetrodePlot::clear(){
std::cout<<"TetrodePlot::clear()"<<std::endl;
for (int i = 0; i < 6; i++)
for (int i=0; i<6; i++)
pAxes[i].clear();
}
bool TetrodePlot::processKeyEvent(SimpleKeyEvent k){
return true;
}
void TetrodePlot::pan(int dim, bool up){
......@@ -383,3 +183,4 @@ void TetrodePlot::zoom(int dim, bool in){
setLimitsOnAxes();
}
......@@ -2,9 +2,9 @@
#define TETRODE_PLOT_H_
#if defined(__linux__)
#include <GL/glut.h>
#include <GL/glut.h>
#else
#include <GLUT/glut.h>
#include <GLUT/glut.h>
#endif
#include <list>
#include <math.h>
......@@ -17,17 +17,17 @@
class TetrodePlot : public BaseUIElement{
bool enabled;
bool enabled;
bool limitsChanged;
double limits[1][2];
double limits[2][2];
WaveAxes wAxes[4];
ProjectionAxes pAxes[6];
// void zoomAxes(int n, bool xdim, int zoomval);
// void zoomProjection (int n, bool xdim, int zoomval);
// void zoomWaveform (int n, bool xdim, int zoomval);
......@@ -38,25 +38,23 @@ class TetrodePlot : public BaseUIElement{
void initLimits();
void setLimitsOnAxes();
public:
TetrodePlot();
TetrodePlot(int x, int y,int w,int h);
virtual ~TetrodePlot();
TetrodePlot();
TetrodePlot(int x, int y,int w,int h);
virtual ~TetrodePlot();
void initAxes();
void redraw();
void initAxes();
void redraw();
void setEnabled(bool enabled);
bool getEnabled();
void setPosition(int,int,double,double);
//void setPosition(int, int);
//void setDimensions(double,double);
void setEnabled(bool enabled);
bool getEnabled();
void setPosition(int,int,double,double);
void getPreferredDimensions(double*, double*);
void getPreferredDimensions(double*, double*);
int getNumberOfAxes();
int getNumberOfAxes();
void mouseDown(int x, int y);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment