Skip to content
Snippets Groups Projects
Commit 97d5a603 authored by jsiegle's avatar jsiegle
Browse files

Allow spikes to be inverted in the Spike Display

parent fa4b2a30
Branches
Tags
No related merge requests found
......@@ -49,6 +49,13 @@ SpikeDisplayCanvas::SpikeDisplayCanvas(SpikeDisplayNode* n) :
lockThresholdsButton->setClickingTogglesState(true);
addAndMakeVisible(lockThresholdsButton);
invertSpikesButton = new UtilityButton("Invert Spikes", Font("Small Text", 13, Font::plain));
invertSpikesButton->setRadius(3.0f);
invertSpikesButton->addListener(this);
invertSpikesButton->setClickingTogglesState(true);
invertSpikesButton->setToggleState(false, true);
addAndMakeVisible(invertSpikesButton);
addAndMakeVisible(viewport);
setWantsKeyboardFocus(true);
......@@ -113,6 +120,8 @@ void SpikeDisplayCanvas::resized()
lockThresholdsButton->setBounds(130, getHeight()-40, 130,20);
invertSpikesButton->setBounds(270, getHeight()-40, 130,20);
}
void SpikeDisplayCanvas::paint(Graphics& g)
......@@ -164,15 +173,40 @@ void SpikeDisplayCanvas::buttonClicked(Button* button)
else if (button == lockThresholdsButton)
{
thresholdCoordinator->setLockThresholds(button->getToggleState());
}
}
else if (button == invertSpikesButton)
{
spikeDisplay->invertSpikes(button->getToggleState());
}
}
void SpikeDisplayCanvas::saveVisualizerParameters(XmlElement* xml)
{
XmlElement* xmlNode = xml->createNewChildElement("SPIKEDISPLAY");
xmlNode->setAttribute("LockThresholds",lockThresholdsButton->getToggleState());
xmlNode->setAttribute("InvertSpikes",invertSpikesButton->getToggleState());
}
void SpikeDisplayCanvas::loadVisualizerParameters(XmlElement* xml)
{
forEachXmlChildElement(*xml, xmlNode)
{
if (xmlNode->hasTagName("SPIKEDISPLAY"))
{
spikeDisplay->invertSpikes(xmlNode->getBoolAttribute("InvertSpikes"));
invertSpikesButton->setToggleState(xmlNode->getBoolAttribute("InvertSpikes"), false);
lockThresholdsButton->setToggleState(xmlNode->getBoolAttribute("LockThresholds"),true);
}
}
}
// ----------------------------------------------------------------
SpikeDisplay::SpikeDisplay(SpikeDisplayCanvas* sdc, Viewport* v) :
canvas(sdc), viewport(v), thresholdCoordinator(nullptr)
canvas(sdc), viewport(v), thresholdCoordinator(nullptr), shouldInvert(false)
{
totalHeight = 1000;
......@@ -211,6 +245,7 @@ SpikePlot* SpikeDisplay::addSpikePlot(int numChannels, int electrodeNum, String
SpikePlot* spikePlot = new SpikePlot(canvas, electrodeNum, 1000 + numChannels, name_);
spikePlots.add(spikePlot);
addAndMakeVisible(spikePlot);
spikePlot->invertSpikes(shouldInvert);
if (thresholdCoordinator)
{
spikePlot->registerThresholdCoordinator(thresholdCoordinator);
......@@ -335,6 +370,19 @@ void SpikeDisplay::mouseDown(const MouseEvent& event)
}
void SpikeDisplay::invertSpikes(bool shouldInvert_)
{
for (int i = 0; i < spikePlots.size(); i++)
{
spikePlots[i]->invertSpikes(shouldInvert);
}
//std::cout << "Invert spikes? " << shouldInvert_ << std::endl;
shouldInvert = shouldInvert_;
}
void SpikeDisplay::plotSpike(const SpikeObject& spike, int electrodeNum)
{
spikePlots[electrodeNum]->processSpikeObject(spike);
......@@ -684,6 +732,14 @@ void SpikePlot::setAllThresholds(float displayThreshold, float range)
setLimitsOnAxes();
}
void SpikePlot::invertSpikes(bool shouldInvert)
{
for (int i = 0; i < nWaveAx; i++)
{
wAxes[i]->invertSpikes(shouldInvert);
}
}
// --------------------------------------------------
......@@ -697,7 +753,8 @@ WaveAxes::WaveAxes(int channel) : GenericAxes(channel),
range(250.0f),
isOverThresholdSlider(false),
isDraggingThresholdSlider(false),
thresholdCoordinator(nullptr)
thresholdCoordinator(nullptr),
spikesInverted(false)
{
......@@ -790,9 +847,18 @@ void WaveAxes::plotSpike(const SpikeObject& s, Graphics& g)
if (*s.gain != 0)
{
float s1 = h/2 + float(s.data[sampIdx]-32768)/float(*s.gain)*1000.0f / range * h;
float s2 = h/2 + float(s.data[sampIdx+1]-32768)/float(*s.gain)*1000.0f / range * h;
float s1, s2;
if (!spikesInverted)
{
s1 = h/2 + float(s.data[sampIdx]-32768)/float(*s.gain)*1000.0f / range * h;
s2 = h/2 + float(s.data[sampIdx+1]-32768)/float(*s.gain)*1000.0f / range * h;
} else {
s1 = h/2 - float(s.data[sampIdx]-32768)/float(*s.gain)*1000.0f / range * h;
s2 = h/2 - float(s.data[sampIdx+1]-32768)/float(*s.gain)*1000.0f / range * h;
}
g.drawLine(x,
s1,
x+dx,
......@@ -811,14 +877,23 @@ void WaveAxes::drawThresholdSlider(Graphics& g)
{
// draw display threshold (editable)
float h = getHeight()*(0.5f - displayThresholdLevel/range);
float h;
if (!spikesInverted)
h = getHeight()*(0.5f - displayThresholdLevel/range);
else
h = getHeight()*(0.5f + displayThresholdLevel/range);
g.setColour(thresholdColour);
g.drawLine(0, h, getWidth(), h);
g.drawText(String(roundFloatToInt(displayThresholdLevel)),2,h,25,10,Justification::left, false);
// draw detector threshold (not editable)
h = getHeight()*(0.5f - detectorThresholdLevel/range);
if (!spikesInverted)
h = getHeight()*(0.5f - detectorThresholdLevel/range);
else
h = getHeight()*(0.5f + detectorThresholdLevel/range);
g.setColour(Colours::orange);
g.drawLine(0, h, getWidth(), h);
......@@ -912,6 +987,11 @@ void WaveAxes::mouseMove(const MouseEvent& event)
float h = getHeight()*(0.5f - displayThresholdLevel/range);
if (!spikesInverted)
h = getHeight()*(0.5f - displayThresholdLevel/range);
else
h = getHeight()*(0.5f + displayThresholdLevel/range);
// std::cout << y << " " << h << std::endl;
if (y > h - 10.0f && y < h + 10.0f && !isOverThresholdSlider)
......@@ -957,13 +1037,22 @@ void WaveAxes::mouseDrag(const MouseEvent& event)
float thresholdSliderPosition = float(event.y) / float(getHeight());
if (thresholdSliderPosition > 0.5f)
thresholdSliderPosition = 0.5f;
else if (thresholdSliderPosition < 0.0f)
thresholdSliderPosition = 0.0f;
displayThresholdLevel = (0.5f - thresholdSliderPosition) * range;
if (!spikesInverted)
{
if (thresholdSliderPosition > 0.5f)
thresholdSliderPosition = 0.5f;
else if (thresholdSliderPosition < 0.0f)
thresholdSliderPosition = 0.0f;
displayThresholdLevel = (0.5f - thresholdSliderPosition) * range;
} else {
if (thresholdSliderPosition < 0.5f)
thresholdSliderPosition = 0.5f;
else if (thresholdSliderPosition > 1.0f)
thresholdSliderPosition = 1.0f;
displayThresholdLevel = (thresholdSliderPosition-0.5f) * range;
}
//std::cout << "Threshold = " << thresholdLevel << std::endl;
......
......@@ -102,6 +102,10 @@ public:
SpikeDisplayNode* processor;
void saveVisualizerParameters(XmlElement* xml);
void loadVisualizerParameters(XmlElement* xml);
private:
ScopedPointer<SpikeDisplay> spikeDisplay;
......@@ -116,6 +120,7 @@ private:
ScopedPointer<SpikeThresholdCoordinator> thresholdCoordinator;
ScopedPointer<UtilityButton> lockThresholdsButton;
ScopedPointer<UtilityButton> invertSpikesButton;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(SpikeDisplayCanvas);
......@@ -139,6 +144,8 @@ public:
void plotSpike(const SpikeObject& spike, int electrodeNum);
void invertSpikes(bool);
int getTotalHeight()
{
return totalHeight;
......@@ -161,6 +168,8 @@ private:
OwnedArray<SpikePlot> spikePlots;
bool shouldInvert;
// float tetrodePlotMinWidth, stereotrodePlotMinWidth, singleElectrodePlotMinWidth;
// float tetrodePlotRatio, stereotrodePlotRatio, singleElectrodePlotRatio;
......@@ -203,6 +212,8 @@ public:
void clear();
void invertSpikes(bool);
float minWidth;
float aspectRatio;
......@@ -331,6 +342,11 @@ public:
void registerThresholdCoordinator(SpikeThresholdCoordinator *stc);
void setDisplaythreshold(float threshold);
void invertSpikes(bool shouldInvert)
{
spikesInverted = shouldInvert;
}
private:
Colour waveColour;
......@@ -363,6 +379,8 @@ private:
MouseCursor::StandardCursorType cursorType;
SpikeThresholdCoordinator *thresholdCoordinator;
bool spikesInverted;
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment