Commit f41491f4 authored by Jussi Lindgren's avatar Jussi Lindgren

contrib/various:

core/applications:
core/plugins:
 + Integrated scenarios, box tutorials and signals.
 * Moved electrode_sets back to the root of share/openvibe/.

git-svn-id: svn://scm.gforge.inria.fr/svn/openvibe@3671 c330d7e9-fc0c-0410-a5b3-fd85c6f5aa8f
parent ad1353ae
......@@ -49,5 +49,8 @@ INSTALL(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR})
#INSTALL(DIRECTORY signals DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/openvibe/scenarios/ PATTERN ".svn" EXCLUDE)
INSTALL(DIRECTORY box-tutorials DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/openvibe/scenarios/ PATTERN ".svn" EXCLUDE)
#INSTALL(DIRECTORY src/ DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE PATTERN "doc" EXCLUDE)
<OpenViBE-Scenario>
<Boxes>
<Box>
<Identifier>(0x441e2100, 0x610e711c)</Identifier>
<Name>Multiprocessing</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${__volatile_ScenarioDir}/scripts/python-multiprocessing.py</Value>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>224</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>57</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x5c654f10, 0xb451e467)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>180</Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
<Box>
<Identifier>(0x47008917, 0x4f6a4317)</Identifier>
<Name>Moving circle</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${__volatile_ScenarioDir}/scripts/python-moving-circle.py</Value>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>352</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>57</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x5c654f10, 0xb451e467)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>180</Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
<Box>
<Identifier>(0x51f53da2, 0x789994d2)</Identifier>
<Name>Star field</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${__volatile_ScenarioDir}/scripts/python-star-field.py</Value>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>416</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>57</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x5c654f10, 0xb451e467)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>180</Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
</Boxes>
<Links></Links>
<Comments>
<Comment>
<Identifier>(0x0ad104c8, 0x2ee0799b)</Identifier>
<Text>&lt;big&gt;Do not forget to look at the python scripts used
in all of the python boxes in this scenario.&lt;/big&gt;</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>368</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>-32</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x4e7de8aa, 0x561bc220)</Identifier>
<Text>&lt;b&gt;Multiprocessing&lt;/b&gt;
Creates a new processus
which works in the background.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>480</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>224</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x6bfbf8ad, 0x3b970ba1)</Identifier>
<Text>&lt;b&gt;Moving Circle&lt;/b&gt; and &lt;b&gt;Starfield&lt;/b&gt;
These two scripts illustrate running
several instances of pygame at
the same time.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>496</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>384</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x704b39c7, 0x74448e12)</Identifier>
<Text>&lt;big&gt;&lt;b&gt;&lt;span color=&quot;red&quot;&gt;Warning&lt;/span&gt;&lt;/b&gt;&lt;/big&gt;
For the time being multiprocessing and pygame only work
on &lt;b&gt;Linux&lt;/b&gt; operating system.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>368</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>80</Value>
</Attribute>
</Attributes>
</Comment>
</Comments>
<VisualisationTree>
<VisualisationWidget>
<Identifier>(0x71777b71, 0x7d9b955c)</Identifier>
<Name>Default window</Name>
<Type>1</Type>
<ParentIdentifier>(0xffffffff, 0xffffffff)</ParentIdentifier>
<BoxIdentifier>(0xffffffff, 0xffffffff)</BoxIdentifier>
<NumChildren>1</NumChildren>
<Attributes>
<Attribute>
<Identifier>(0x4c90d4ad, 0x7a2554ec)</Identifier>
<Value>1</Value>
</Attribute>
<Attribute>
<Identifier>(0x7b814cca, 0x271df6dd)</Identifier>
<Value>1</Value>
</Attribute>
</Attributes>
</VisualisationWidget>
<VisualisationWidget>
<Identifier>(0x3587c6af, 0x788f3c37)</Identifier>
<Name>Default tab</Name>
<Type>2</Type>
<ParentIdentifier>(0x71777b71, 0x7d9b955c)</ParentIdentifier>
<Index>0</Index>
<BoxIdentifier>(0xffffffff, 0xffffffff)</BoxIdentifier>
<NumChildren>1</NumChildren>
</VisualisationWidget>
<VisualisationWidget>
<Identifier>(0x5aab9723, 0x14698840)</Identifier>
<Name>Empty</Name>
<Type>0</Type>
<ParentIdentifier>(0x3587c6af, 0x788f3c37)</ParentIdentifier>
<Index>0</Index>
<BoxIdentifier>(0xffffffff, 0xffffffff)</BoxIdentifier>
<NumChildren>0</NumChildren>
</VisualisationWidget>
</VisualisationTree>
</OpenViBE-Scenario>
\ No newline at end of file
# We construct a box instance that inherits from the basic OVBox class
class MyOVBox(OVBox):
# the constructor creates the box and initializes object variables
def __init__(self):
OVBox.__init__(self)
self.stimLabel = None
self.stimCode = None
# the initialize method reads settings and outputs the first header
def initialize(self):
# the stim label is taken from the box setting
self.stimLabel = self.setting['Stimulation']
# we get the corresponding code using the OpenViBE_stimulation dictionnary
self.stimCode = OpenViBE_stimulation[self.stimLabel]
# we append to the box output a stimulation header. This is just a header, dates are 0.
self.output[0].append(OVStimulationHeader(0., 0.))
def process(self):
# During each process call we produce a stimulation
# A stimulation set is a chunk which starts at current time and end time is the time step between two calls
stimSet = OVStimulationSet(self.getCurrentTime(), self.getCurrentTime()+1./self.getClock())
# the date of the stimulation is simply the current openvibe time when calling the box process
stimSet.append(OVStimulation(self.stimCode, self.getCurrentTime(), 0.))
self.output[0].append(stimSet)
def uninitialize(self):
# we send a stream end.
end = self.getCurrentTime()
self.output[0].append(OVStimulationEnd(end, end))
box = MyOVBox()
from multiprocessing import Process, Event
import time
import pygame
from pygame.locals import *
import math
from random import randint, randrange
import sys
sys.argv = ['openvibe']
class OVProcess(Process):
def __init__(self):
Process.__init__(self)
self.initialized = Event()
self.stop_asked = Event()
def initialize(self):
pass
def process(self):
pass
def uninitialize(self):
pass
def stop(self):
self.stop_asked.set()
def run(self):
self.initialize()
self.initialized.set()
while not self.stop_asked.is_set():
self.process()
self.uninitialize()
class MovingCircle(OVProcess):
def __init__(self):
OVProcess.__init__(self)
self.screen = None
self.pos = [320,240]
self.speed = 5
self.dirx = -self.speed
self.diry = -self.speed
def initialize(self):
pygame.init()
pygame.display.set_caption(self.name)
self.screen = pygame.display.set_mode((640,480),0,32)
def process(self):
begining = time.time()
self.pos[0] += self.dirx
self.pos[1] += self.diry
if self.pos[0] > 640 or self.pos[0] < 0:
self.dirx = -self.dirx
if self.pos[1] > 480 or self.pos[1] < 0:
self.diry = -self.diry
self.screen.fill((255,255,255))
pygame.draw.circle(self.screen, (0,0,0), self.pos, 25, 0)
pygame.display.update()
while (time.time() - begining) < (1.0/60.0):
pass
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.p = None
def initialize(self):
self.p = MovingCircle()
self.p.start()
def process(self):
pass
def uninitialize(self):
self.p.stop()
self.p.join()
if __name__ == '__main__':
box = MyOVBox()
from multiprocessing import Process, Queue
import time
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.p = None
self.q = None
def f(self, queue):
while True:
queue.put('hello')
time.sleep(1)
def initialize(self):
print "process initialize!"
self.q = Queue()
self.p = Process(target=self.f, args=(self.q,))
self.p.start()
def process(self):
for i in range(self.q.qsize()):
print self.q.get()
def uninitialize(self):
print "process uninitialize!"
self.p.terminate()
self.p.join()
if __name__ == '__main__':
box = MyOVBox()
import numpy
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.signalHeader = None
def process(self):
for chunkIndex in range( len(self.input[0]) ):
if(type(self.input[0][chunkIndex]) == OVSignalHeader):
self.signalHeader = self.input[0].pop()
outputHeader = OVSignalHeader(
self.signalHeader.startTime,
self.signalHeader.endTime,
[1, self.signalHeader.dimensionSizes[1]],
['Mean']+self.signalHeader.dimensionSizes[1]*[''],
self.signalHeader.samplingRate)
self.output[0].append(outputHeader)
elif(type(self.input[0][chunkIndex]) == OVSignalBuffer):
chunk = self.input[0].pop()
numpyBuffer = numpy.array(chunk).reshape(tuple(self.signalHeader.dimensionSizes))
numpyBuffer = numpyBuffer.mean(axis=0)
chunk = OVSignalBuffer(chunk.startTime, chunk.endTime, numpyBuffer.tolist())
self.output[0].append(chunk)
elif(type(self.input[0][chunkIndex]) == OVSignalEnd):
self.output[0].append(self.input[0].pop())
box = MyOVBox()
from math import *
import random, time
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.channelCount = 0
self.samplingFrequency = 0
self.epochSampleCount = 0
self.startTime = 0
self.endTime = 0
self.dimensionSizes = list()
self.dimensionLabels = list()
self.timeBuffer = list()
self.signalBuffer = list()
self.signalHeader = None
def initialize(self):
random.seed(time.time())
self.channelCount = int(self.setting['Channel count'])
self.samplingFrequency = int(self.setting['Sampling frequency'])
self.epochSampleCount = int(self.setting['Generated epoch sample count'])
#creation of the signal header
for i in range(self.channelCount):
self.dimensionLabels.append( 'Sinus'+str(i) )
self.dimensionLabels += self.epochSampleCount*['']
self.dimensionSizes = [self.channelCount, self.epochSampleCount]
self.signalHeader = OVSignalHeader(0., 0., self.dimensionSizes, self.dimensionLabels, self.samplingFrequency)
self.output[0].append(self.signalHeader)
#creation of the first signal chunk
self.endTime = self.epochSampleCount
self.signalBuffer = [0.]*self.channelCount*self.epochSampleCount
self.update_timeBuffer()
self.update_signalBuffer()
def updateStartTime(self):
self.startTime += self.epochSampleCount
def updateEndTime(self):
self.endTime += self.epochSampleCount
def updateTimeBuffer(self):
self.timeBuffer = range(self.startTime, self.endTime)
for instant_index, instant in enumerate(self.timeBuffer):
self.timeBuffer[instant_index] = float(instant)/self.samplingFrequency
def updateSignalBuffer(self):
for channel in range(self.channelCount):
for instantIndex, instant in enumerate(self.timeBuffer):
newSample = 100.*sin(2.*pi*float(channel+1)*instant) + (1000.*random.random()-500.)
self.signalBuffer[channel*self.epochSampleCount+instantIndex] = newSample
def sendSignalBufferToOpenvibe(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1] + 1.0/self.samplingFrequency
self.output[0].append( OVSignalBuffer(start, end, self.signalBuffer) )
def process(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1]
if self.getCurrentTime() >= end:
self.sendSignalBufferToOpenvibe()
self.updateStartTime()
self.updateEndTime()
self.updateTimeBuffer()
self.updateSignalBuffer()
def uninitialize(self):
end = self.timeBuffer[-1]
self.output[0].append(OVSignalEnd(end, end))
box = MyOVBox()
import numpy
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.channelCount = 0
self.samplingFrequency = 0
self.epochSampleCount = 0
self.startTime = 0.