init
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
||||
PROJECT(openvibe-plugins-contrib-file-io)
|
||||
|
||||
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
|
||||
SET(PROJECT_VERSION ${OV_GLOBAL_VERSION_STRING})
|
||||
|
||||
FILE(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.inl src/*.c)
|
||||
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRC_FILES})
|
||||
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
|
||||
VERSION ${PROJECT_VERSION}
|
||||
SOVERSION ${PROJECT_VERSION_MAJOR}
|
||||
FOLDER ${PLUGINS_FOLDER}
|
||||
COMPILE_FLAGS "-DOVP_Exports -DOVP_Shared -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE")
|
||||
|
||||
# ---------------------------------
|
||||
INCLUDE("FindOpenViBE")
|
||||
INCLUDE("FindOpenViBECommon")
|
||||
INCLUDE("FindOpenViBEToolkit")
|
||||
INCLUDE("FindOpenViBEModuleEBML")
|
||||
INCLUDE("FindThirdPartyBoost")
|
||||
|
||||
# -----------------------------
|
||||
# Install files
|
||||
# -----------------------------
|
||||
INSTALL(TARGETS ${PROJECT_NAME}
|
||||
RUNTIME DESTINATION ${DIST_BINDIR}
|
||||
LIBRARY DESTINATION ${DIST_LIBDIR}
|
||||
ARCHIVE DESTINATION ${DIST_LIBDIR})
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* \page BoxAlgorithm_EDFFileWriter EDF File Writer
|
||||
__________________________________________________________________
|
||||
|
||||
Detailed description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Description|
|
||||
|
||||
* Writes EEG data in European Data Format (EDF).
|
||||
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Description|
|
||||
__________________________________________________________________
|
||||
|
||||
Inputs description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Inputs|
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Inputs|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Input1|
|
||||
* Experiment Information stream, coming from an acquisition client/server.
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Input1|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Input2|
|
||||
* EEG signal.
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Input2|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Input3|
|
||||
* Stimulation stream.
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Input3|
|
||||
|
||||
Settings description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Settings|
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Settings|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Setting1|
|
||||
* The file name to be written.
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Setting1|
|
||||
|
||||
__________________________________________________________________
|
||||
|
||||
Examples description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Examples|
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Examples|
|
||||
__________________________________________________________________
|
||||
|
||||
Miscellaneous description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_EDFFileWriter_Miscellaneous|
|
||||
EDF format can be read by several programs, (e.g EDF browser).
|
||||
This box is based on the free software EDFlib by Teunis van Beelen.
|
||||
* |OVP_DocEnd_BoxAlgorithm_EDFFileWriter_Miscellaneous|
|
||||
*/
|
||||
+4419
File diff suppressed because it is too large
Load Diff
+535
@@ -0,0 +1,535 @@
|
||||
/*
|
||||
*****************************************************************************
|
||||
*
|
||||
* Copyright (c) 2009, 2010, 2011 Teunis van Beelen
|
||||
* All rights reserved.
|
||||
*
|
||||
* email: teuniz@gmail.com
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY Teunis van Beelen ''AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL Teunis van Beelen BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*****************************************************************************
|
||||
*/
|
||||
|
||||
|
||||
/* compile with options "-D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE" */
|
||||
|
||||
|
||||
#ifndef EDFLIB_INCLUDED
|
||||
#define EDFLIB_INCLUDED
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#define EDFLIB_TIME_DIMENSION (10000000LL)
|
||||
#define EDFLIB_MAXSIGNALS 256
|
||||
#define EDFLIB_MAX_ANNOTATION_LEN 512
|
||||
|
||||
#define EDFSEEK_SET 0
|
||||
#define EDFSEEK_CUR 1
|
||||
#define EDFSEEK_END 2
|
||||
|
||||
|
||||
/* the following defines are used in the member "filetype" of the edf_hdr_struct */
|
||||
/* and as return value for the function edfopen_file_readonly() */
|
||||
#define EDFLIB_FILETYPE_EDF 0
|
||||
#define EDFLIB_FILETYPE_EDFPLUS 1
|
||||
#define EDFLIB_FILETYPE_BDF 2
|
||||
#define EDFLIB_FILETYPE_BDFPLUS 3
|
||||
#define EDFLIB_MALLOC_ERROR -1
|
||||
#define EDFLIB_NO_SUCH_FILE_OR_DIRECTORY -2
|
||||
#define EDFLIB_FILE_CONTAINS_FORMAT_ERRORS -3
|
||||
#define EDFLIB_MAXFILES_REACHED -4
|
||||
#define EDFLIB_FILE_READ_ERROR -5
|
||||
#define EDFLIB_FILE_ALREADY_OPENED -6
|
||||
#define EDFLIB_FILETYPE_ERROR -7
|
||||
#define EDFLIB_FILE_WRITE_ERROR -8
|
||||
#define EDFLIB_NUMBER_OF_SIGNALS_INVALID -9
|
||||
#define EDFLIB_FILE_IS_DISCONTINUOUS -10
|
||||
#define EDFLIB_INVALID_READ_ANNOTS_VALUE -11
|
||||
|
||||
/* values for annotations */
|
||||
#define EDFLIB_DO_NOT_READ_ANNOTATIONS 0
|
||||
#define EDFLIB_READ_ANNOTATIONS 1
|
||||
#define EDFLIB_READ_ALL_ANNOTATIONS 2
|
||||
|
||||
/* the following defines are possible errors returned by edfopen_file_writeonly() */
|
||||
#define EDFLIB_NO_SIGNALS -20
|
||||
#define EDFLIB_TOO_MANY_SIGNALS -21
|
||||
#define EDFLIB_NO_SAMPLES_IN_RECORD -22
|
||||
#define EDFLIB_DIGMIN_IS_DIGMAX -23
|
||||
#define EDFLIB_DIGMAX_LOWER_THAN_DIGMIN -24
|
||||
#define EDFLIB_PHYSMIN_IS_PHYSMAX -25
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
struct edf_param_struct // this structure contains all the relevant EDF-signal parameters of one signal
|
||||
{
|
||||
char label[17]; // label (name) of the signal, null-terminated string
|
||||
long long smp_in_file; // number of samples of this signal in the file
|
||||
double phys_max; // physical maximum
|
||||
double phys_min; // physical minimum
|
||||
int dig_max; // digital maximum
|
||||
int dig_min; // digital minimum
|
||||
int smp_in_datarecord; // number of samples of this signal in a datarecord
|
||||
char physdimension[9]; // physical dimension (uV, bpm, mA, etc.), null-terminated string
|
||||
char prefilter[81]; // null-terminated string
|
||||
char transducer[81]; // null-terminated string
|
||||
};
|
||||
|
||||
|
||||
struct edf_annotation_struct // this structure is used for annotations
|
||||
{
|
||||
long long onset; // onset time of the event, expressed in units of 100 nanoSeconds
|
||||
char duration[16]; // duration time, this is a null-terminated ASCII text-string
|
||||
char annotation[EDFLIB_MAX_ANNOTATION_LEN + 1]; // description of the event in UTF-8, this is a null terminated string
|
||||
};
|
||||
|
||||
|
||||
struct edf_hdr_struct // this structure contains all the relevant EDF header info and will be filled when calling the function edf_open_file_readonly()
|
||||
{
|
||||
int handle; // a handle (identifier) used to distinguish the different files
|
||||
int filetype; // 0: EDF, 1: EDFplus, 2: BDF, 3: BDFplus, a negative number means an error
|
||||
int edfsignals; // number of EDF signals in the file, annotation channels are NOT included
|
||||
long long file_duration; // duration of the file expressed in units of 100 nanoSeconds
|
||||
int startdate_day;
|
||||
int startdate_month;
|
||||
int startdate_year;
|
||||
long long
|
||||
starttime_subsecond; // starttime offset expressed in units of 100 nanoSeconds. Is always less than 10000000 (one second). Only used by EDFplus and BDFplus
|
||||
int starttime_second;
|
||||
int starttime_minute;
|
||||
int starttime_hour;
|
||||
char patient[81]; // null-terminated string, contains patientfield of header, is always empty when filetype is EDFPLUS or BDFPLUS
|
||||
char recording[81
|
||||
]; // null-terminated string, contains recordingfield of header, is always empty when filetype is EDFPLUS or BDFPLUS
|
||||
char patientcode[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char gender[16]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char birthdate[16]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char patient_name[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char patient_additional[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char admincode[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char technician[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char equipment[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
char recording_additional[81]; // null-terminated string, is always empty when filetype is EDF or BDF
|
||||
long long datarecord_duration; // duration of a datarecord expressed in units of 100 nanoSeconds
|
||||
long long datarecords_in_file; // number of datarecords in the file
|
||||
long long annotations_in_file; // number of annotations in the file
|
||||
struct edf_param_struct signalparam[EDFLIB_MAXSIGNALS]; // array of structs which contain the relevant signal parameters
|
||||
};
|
||||
|
||||
|
||||
int edflib_version();
|
||||
|
||||
/* Returns the version number of this library, multiplied by hundred. if version is "1.00" than it will return 100 */
|
||||
|
||||
|
||||
/***************** the following functions are used to read files **************************/
|
||||
|
||||
|
||||
int EdfopenFileReadonly(const char* path, struct edf_hdr_struct* edfhdr, const int readAnnotations);
|
||||
|
||||
/* opens an existing file for reading */
|
||||
/* path is a null-terminated string containing the path to the file */
|
||||
/* hdr is a pointer to an edf_hdr_struct, all fields in this struct will be overwritten */
|
||||
/* the edf_hdr_struct will be filled with all the relevant header- and signalinfo/parameters */
|
||||
|
||||
/* read_annotations must have one of the following values: */
|
||||
/* EDFLIB_DO_NOT_READ_ANNOTATIONS annotations will not be read (this saves time when opening a very large EDFplus or BDFplus file */
|
||||
/* EDFLIB_READ_ANNOTATIONS annotations will be read immediately, stops when an annotation has */
|
||||
/* been found which contains the description "Recording ends" */
|
||||
/* EDFLIB_READ_ALL_ANNOTATIONS all annotations will be read immediately */
|
||||
|
||||
/* returns 0 on success, in case of an error it returns -1 and an errorcode will be set in the member "filetype" of struct edf_hdr_struct */
|
||||
/* This function is required if you want to read a file */
|
||||
|
||||
|
||||
int EdfcloseFile(const int handle);
|
||||
|
||||
/* closes and finalizes the file */
|
||||
/* returns -1 in case of an error, 0 on success */
|
||||
/* this function MUST be called when you are finished reading or writing */
|
||||
/* This function is required after reading or writing. Failing to do so will cause */
|
||||
/* unnessecary memory usage and in case of writing it will cause a corrupted and incomplete file */
|
||||
|
||||
|
||||
int EdfreadPhysicalSamples(const int handle, const int edfsignal, int n, double* buf);
|
||||
|
||||
/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) */
|
||||
/* the values are converted to their physical values e.g. microVolts, beats per minute, etc. */
|
||||
/* bufsize should be equal to or bigger than sizeof(double[n]) */
|
||||
/* the sample position indicator will be increased with the amount of samples read */
|
||||
/* returns the amount of samples read (this can be less than n or zero!) */
|
||||
/* or -1 in case of an error */
|
||||
|
||||
|
||||
int EdfreadDigitalSamples(const int handle, const int edfsignal, int n, int* buf);
|
||||
|
||||
/* reads n samples from edfsignal, starting from the current sample position indicator, into buf (edfsignal starts at 0) */
|
||||
/* the values are the "raw" digital values */
|
||||
/* bufsize should be equal to or bigger than sizeof(int[n]) */
|
||||
/* the sample position indicator will be increased with the amount of samples read */
|
||||
/* returns the amount of samples read (this can be less than n or zero!) */
|
||||
/* or -1 in case of an error */
|
||||
|
||||
|
||||
long long edfseek(const int handle, const int edfsignal, const long long offset, const int whence);
|
||||
|
||||
/* The edfseek() function sets the sample position indicator for the edfsignal pointed to by edfsignal. */
|
||||
/* The new position, measured in samples, is obtained by adding offset samples to the position specified by whence. */
|
||||
/* If whence is set to EDFSEEK_SET, EDFSEEK_CUR, or EDFSEEK_END, the offset is relative to the start of the file, */
|
||||
/* the current position indicator, or end-of-file, respectively. */
|
||||
/* Returns the current offset. Otherwise, -1 is returned. */
|
||||
/* note that every signal has it's own independent sample position indicator and edfseek() affects only one of them */
|
||||
|
||||
|
||||
long long edftell(const int handle, const int edfsignal);
|
||||
|
||||
/* The edftell() function obtains the current value of the sample position indicator for the edfsignal pointed to by edfsignal. */
|
||||
/* Returns the current offset. Otherwise, -1 is returned */
|
||||
/* note that every signal has it's own independent sample position indicator and edftell() affects only one of them */
|
||||
|
||||
|
||||
void edfrewind(const int handle, const int edfsignal);
|
||||
|
||||
/* The edfrewind() function sets the sample position indicator for the edfsignal pointed to by edfsignal to the beginning of the file. */
|
||||
/* It is equivalent to: () edfseek(int handle, int edfsignal, 0LL, EDFSEEK_SET) */
|
||||
/* note that every signal has it's own independent sample position indicator and edfrewind() affects only one of them */
|
||||
|
||||
|
||||
int EdfGetAnnotation(const int handle, const int n, struct edf_annotation_struct* annot);
|
||||
|
||||
/* Fills the edf_annotation_struct with the annotation n, returns 0 on success, otherwise -1 */
|
||||
/* To obtain the number of annotations in a file, check edf_hdr_struct -> annotations_in_file */
|
||||
|
||||
/*
|
||||
Notes:
|
||||
|
||||
Annotationsignals
|
||||
|
||||
EDFplus and BDFplus store the annotations in one or more signals (in order to be backwards compatibel with EDF and BDF).
|
||||
The counting of the signals in the file starts at 0. Signals used for annotations are skipped by EDFlib.
|
||||
This means that the annotationsignal(s) in the file are hided.
|
||||
Use the function edf_get_annotation() to get the annotations.
|
||||
|
||||
So, when a file contains 5 signals and the third signal is used to store the annotations, the library will
|
||||
report that there are only 4 signals in the file.
|
||||
The library will "map" the signalnumbers as follows: 0->0, 1->1, 2->3, 3->4.
|
||||
This way you don't need to worry about which signals are annotationsignals. The library will do it for you.
|
||||
|
||||
How the library stores time-values
|
||||
|
||||
To avoid rounding errors, the library stores some timevalues in variables of type long long int.
|
||||
In order not to loose the subsecond precision, all timevalues have been multiplied by 10000000.
|
||||
This will limit the timeresolution to 100 nanoSeconds. To calculate the amount of seconds, divide
|
||||
the timevalue by 10000000 or use the macro EDFLIB_TIME_DIMENSION which is declared in edflib.h.
|
||||
The following variables do use this when you open a file in read mode: "file_duration", "starttime_subsecond" and "onset".
|
||||
*/
|
||||
|
||||
|
||||
/***************** the following functions are used to write files **************************/
|
||||
|
||||
|
||||
int EdfopenFileWriteonly(const char* path, const int filetype, const int nSignals);
|
||||
|
||||
/* opens an new file for writing. warning, an already existing file with the same name will be silently overwritten without advance warning!! */
|
||||
/* path is a null-terminated string containing the path and name of the file */
|
||||
/* filetype must be EDFLIB_FILETYPE_EDFPLUS or EDFLIB_FILETYPE_BDFPLUS */
|
||||
/* returns a handle on success, you need this handle for the other functions */
|
||||
/* in case of an error it returns a negative number corresponding to one of the following values: */
|
||||
/* EDFLIB_MALLOC_ERROR */
|
||||
/* EDFLIB_NO_SUCH_FILE_OR_DIRECTORY */
|
||||
/* EDFLIB_MAXFILES_REACHED */
|
||||
/* EDFLIB_FILE_ALREADY_OPENED */
|
||||
/* EDFLIB_NUMBER_OF_SIGNALS_INVALID */
|
||||
/* This function is required if you want to write a file */
|
||||
|
||||
|
||||
int EdfSetSampling(const int handle, const int edfsignal, const int sampling);
|
||||
|
||||
/* Sets the sampling of signal edfsignal. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is required for every signal and can be called only after opening a */
|
||||
/* file in writemode and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPhysicalMaximum(const int handle, const int edfsignal, const double max);
|
||||
|
||||
/* Sets the maximum physical value of signal edfsignal. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is required for every signal and can be called only after opening a */
|
||||
/* file in writemode and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPhysicalMinimum(const int handle, const int edfsignal, const double min);
|
||||
|
||||
/* Sets the minimum physical value of signal edfsignal. */
|
||||
/* Usually this will be (-(phys_max)) */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is required for every signal and can be called only after opening a */
|
||||
/* file in writemode and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetDigitalMaximum(const int handle, const int edfsignal, const int max);
|
||||
|
||||
/* Sets the maximum digital value of signal edfsignal. Usually, the value 32767 is used for EDF+ and 8388607 for BDF+ */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is required for every signal and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetDigitalMinimum(const int handle, const int edfsignal, const int min);
|
||||
|
||||
/* Sets the minimum digital value of signal edfsignal. Usually, the value -32768 is used for EDF+ and -8388608 for BDF+ */
|
||||
/* Usually this will be (-(dig_max + 1)) */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is required for every signal and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetLabel(const int handle, const int edfsignal, const char* label);
|
||||
|
||||
/* Sets the label (name) of signal edfsignal. ("FP1", "SaO2", etc.) */
|
||||
/* label is a pointer to a NULL-terminated ASCII-string containing the label (name) of the signal edfsignal */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is recommended for every signal when you want to write a file */
|
||||
/* and can be called only after opening a file in writemode and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPrefilter(const int handle, const int edfsignal, const char* prefilter);
|
||||
|
||||
/* Sets the prefilter of signal edfsignal ("HP:0.1Hz", "LP:75Hz N:50Hz", etc.). */
|
||||
/* prefilter is a pointer to a NULL-terminated ASCII-string containing the prefilter text of the signal edfsignal */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode and before */
|
||||
/* the first sample write action */
|
||||
|
||||
|
||||
int EdfSetTransducer(const int handle, const int edfsignal, const char* transducer);
|
||||
|
||||
/* Sets the transducer of signal edfsignal ("AgAgCl cup electrodes", etc.). */
|
||||
/* transducer is a pointer to a NULL-terminated ASCII-string containing the transducer text of the signal edfsignal */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode and before */
|
||||
/* the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPhysicalDimension(const int handle, const int edfsignal, const char* dim);
|
||||
|
||||
/* Sets the physical dimension of signal edfsignal. ("uV", "BPM", "mA", "Degr.", etc.) */
|
||||
/* phys_dim is a pointer to a NULL-terminated ASCII-string containing the physical dimension of the signal edfsignal */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is recommended for every signal when you want to write a file */
|
||||
/* and can be called only after opening a file in writemode and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetStartdatetime(const int handle, const int year, const int month, const int day, const int hour, const int minute, const int second);
|
||||
|
||||
/* Sets the startdate and starttime. */
|
||||
/* year: 1970 - 3000, month: 1 - 12, day: 1 - 31 */
|
||||
/* hour: 0 - 23, minute: 0 - 59, second: 0 - 59 */
|
||||
/* If not called, the library will use the system date and time at runtime */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPatientname(const int handle, const char* patientname);
|
||||
|
||||
/* Sets the patientname. patientname is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPatientcode(const int handle, const char* patientcode);
|
||||
|
||||
/* Sets the patientcode. patientcode is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetGender(const int handle, const int gender);
|
||||
|
||||
/* Sets the gender. 1 is male, 0 is female. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetBirthdate(const int handle, const int year, const int month, const int day);
|
||||
|
||||
/* Sets the birthdate. */
|
||||
/* year: 1800 - 3000, month: 1 - 12, day: 1 - 31 */
|
||||
/* This function is optional */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetPatientAdditional(const int handle, const char* additional);
|
||||
|
||||
/* Sets the additional patientinfo. patient_additional is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetAdmincode(const int handle, const char* admincode);
|
||||
|
||||
/* Sets the admincode. admincode is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetTechnician(const int handle, const char* technician);
|
||||
|
||||
/* Sets the technicians name. technician is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetEquipment(const int handle, const char* equipment);
|
||||
|
||||
/* Sets the name of the equipment used during the aquisition. equipment is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfSetRecordingAdditional(const int handle, const char* additional);
|
||||
|
||||
/* Sets the additional recordinginfo. recording_additional is a pointer to a null-terminated ASCII-string. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before the first sample write action */
|
||||
|
||||
|
||||
int EdfwritePhysicalSamples(const int handle, const double* buf);
|
||||
|
||||
/* Writes n physical samples (uV, mA, Ohm) from *buf belonging to one signal */
|
||||
/* where n is the sampling of the signal. */
|
||||
/* The physical samples will be converted to digital samples using the */
|
||||
/* values of physical maximum, physical minimum, digital maximum and digital minimum */
|
||||
/* The number of samples written is equal to the sampling of the signal */
|
||||
/* Size of buf should be equal to or bigger than sizeof(double[sampling]) */
|
||||
/* Call this function for every signal in the file. The order is important! */
|
||||
/* When there are 4 signals in the file, the order of calling this function */
|
||||
/* must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
|
||||
|
||||
int EdfBlockwritePhysicalSamples(const int handle, const double* buf);
|
||||
|
||||
/* Writes physical samples (uV, mA, Ohm) from *buf */
|
||||
/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */
|
||||
/* where n is the sampling of the signal. */
|
||||
/* buf must be filled with samples from all signals, starting with signal 0, 1, 2, etc. */
|
||||
/* one block equals one second */
|
||||
/* The physical samples will be converted to digital samples using the */
|
||||
/* values of physical maximum, physical minimum, digital maximum and digital minimum */
|
||||
/* The number of samples written is equal to the sum of the samplefrequencies of all signals */
|
||||
/* Size of buf should be equal to or bigger than sizeof(double) multiplied by the sum of the samplefrequencies of all signals */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
|
||||
|
||||
int EdfwriteDigitalSamples(const int handle, const int* buf);
|
||||
|
||||
/* Writes n "raw" digital samples from *buf belonging to one signal */
|
||||
/* where n is the sampling of the signal. */
|
||||
/* The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the */
|
||||
/* file without any conversion. */
|
||||
/* The number of samples written is equal to the sampling of the signal */
|
||||
/* Size of buf should be equal to or bigger than sizeof(int[sampling]) */
|
||||
/* Call this function for every signal in the file. The order is important! */
|
||||
/* When there are 4 signals in the file, the order of calling this function */
|
||||
/* must be: signal 0, signal 1, signal 2, signal 3, signal 0, signal 1, signal 2, etc. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
|
||||
|
||||
int EdfBlockwriteDigitalSamples(const int handle, const int* buf);
|
||||
|
||||
/* Writes "raw" digital samples from *buf. */
|
||||
/* buf must be filled with samples from all signals, starting with n samples of signal 0, n samples of signal 1, n samples of signal 2, etc. */
|
||||
/* where n is the sampling of the signal. */
|
||||
/* One block equals one second. */
|
||||
/* The 16 (or 24 in case of BDF) least significant bits of the sample will be written to the */
|
||||
/* file without any conversion. */
|
||||
/* The number of samples written is equal to the sum of the samplefrequencies of all signals. */
|
||||
/* Size of buf should be equal to or bigger than sizeof(int) multiplied by the sum of the samplefrequencies of all signals */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
|
||||
|
||||
int EdfwriteAnnotationUTF8(const int handle, const long long onset, const long long duration, const char* description);
|
||||
|
||||
/* writes an annotation/event to the file */
|
||||
/* onset is relative to the starttime and startdate of the file */
|
||||
/* onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! */
|
||||
/* for example: 34.071 seconds must be written as 340710 */
|
||||
/* if duration is unknown or not applicable: set a negative number (-1) */
|
||||
/* description is a null-terminated UTF8-string containing the text that describes the event */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before closing the file */
|
||||
|
||||
|
||||
int EdfwriteAnnotationLatin1(const int handle, const long long onset, const long long duration, const char* description);
|
||||
|
||||
/* writes an annotation/event to the file */
|
||||
/* onset is relative to the starttime and startdate of the file */
|
||||
/* onset and duration are in units of 100 microSeconds! resolution is 0.0001 second! */
|
||||
/* for example: 34.071 seconds must be written as 340710 */
|
||||
/* if duration is unknown or not applicable: set a negative number (-1) */
|
||||
/* description is a null-terminated Latin1-string containing the text that describes the event */
|
||||
/* This function is optional and can be called only after opening a file in writemode */
|
||||
/* and before closing the file */
|
||||
|
||||
|
||||
int EdfSetDatarecordDuration(const int handle, const int duration);
|
||||
|
||||
/* Sets the datarecord duration. The default value is 1 second. */
|
||||
/* ATTENTION: the argument "duration" is expressed in units of 10 microSeconds! */
|
||||
/* So, if you want to set the datarecord duration to 0.1 second, you must give */
|
||||
/* the argument "duration" a value of "10000". */
|
||||
/* This function is optional, normally you don't need to change the default value. */
|
||||
/* The datarecord duration must be in the range 0.025 to 20.0 seconds. */
|
||||
/* Returns 0 on success, otherwise -1 */
|
||||
/* This function is NOT REQUIRED but can be called after opening a */
|
||||
/* file in writemode and before the first sample write action. */
|
||||
/* This function can be used when you want to use a samplerate */
|
||||
/* which is not an integer. For example, if you want to use a samplerate of 0.5 Hz, */
|
||||
/* set the sampling to 5 Hz and the datarecord duration to 10 seconds, */
|
||||
/* or set the sampling to 1 Hz and the datarecord duration to 2 seconds. */
|
||||
/* Do not use this function, except when absolutely necessary! */
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
+315
@@ -0,0 +1,315 @@
|
||||
/* Project: Gipsa-lab plugins for OpenVibe
|
||||
* AUTHORS AND CONTRIBUTORS: Andreev A., Barachant A., Congedo M., Ionescu,Gelu,
|
||||
|
||||
* This file is part of "Gipsa-lab plugins for OpenVibe".
|
||||
* You can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
* This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License along with Brain Invaders. If not, see http://www.gnu.org/licenses/.
|
||||
*/
|
||||
|
||||
#include "ovpCBoxAlgorithmBrainampFileWriterGipsa.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace FileIO {
|
||||
|
||||
|
||||
//documentation Appendix B EEG file format: http://tsgdoc.socsci.ru.nl/images/d/d1/BrainVision_Recorder_UM.pdf
|
||||
|
||||
bool CBoxAlgorithmBrainampFileWriterGipsa::initialize()
|
||||
{
|
||||
m_isVmrkHeaderFileWritten = false;
|
||||
|
||||
//init input signal 1
|
||||
m_streamDecoder = new Toolkit::TSignalDecoder<CBoxAlgorithmBrainampFileWriterGipsa>(*this, 0);
|
||||
|
||||
//init input stimulation 1
|
||||
m_stimDecoder = new Toolkit::TStimulationDecoder<CBoxAlgorithmBrainampFileWriterGipsa>(*this, 1);
|
||||
|
||||
//Get parameters:
|
||||
const CString filename = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
|
||||
|
||||
const CString tmp = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
|
||||
const CIdentifier binaryFormatID = this->getTypeManager().getEnumerationEntryValueFromName(OVP_TypeId_BinaryFormat, tmp);
|
||||
|
||||
if (binaryFormatID == OVP_TypeId_BinaryFormat_int16_t) { m_binaryFormat = BinaryFormat_Integer16; }
|
||||
else if (binaryFormatID == OVP_TypeId_BinaryFormat_uint16_t) { m_binaryFormat = BinaryFormat_UnsignedInteger16; }
|
||||
else if (binaryFormatID == OVP_TypeId_BinaryFormat_float) { m_binaryFormat = BinaryFormat_Float32; }
|
||||
else
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "Unknown binary format: " << binaryFormatID << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//Perform checks:
|
||||
if (std::string(filename).empty())
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "Header file path is empty!\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (std::string(filename).substr(filename.length() - 5, 5) != std::string(".vhdr"))
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Warning << "The supplied output file does not end with .vhdr\n";
|
||||
}
|
||||
|
||||
m_headerFilename = filename;
|
||||
|
||||
m_headerFile.open(m_headerFilename.c_str());
|
||||
if (!m_headerFile.good())
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "Could not open header file [" << m_headerFilename << "]\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
//this->getLogManager() << Kernel::LogLevel_ImportantWarning << m_sHeaderFilename << "\n";
|
||||
|
||||
m_dataFilename = m_headerFilename.substr(0, m_headerFilename.length() - 5) + std::string(".eeg");
|
||||
|
||||
m_dataFile.open(m_dataFilename.c_str(), std::ios::binary);
|
||||
if (!m_dataFile.good())
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "Could not open data file [" << m_dataFilename << "]\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_markerFilename = m_headerFilename.substr(0, m_headerFilename.length() - 5) + std::string(".vmrk");
|
||||
|
||||
m_markerFile.open(m_markerFilename.c_str());
|
||||
if (!m_markerFile.good())
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "Could not open marker file [" << m_markerFilename << "]\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmBrainampFileWriterGipsa::uninitialize()
|
||||
{
|
||||
if (m_streamDecoder)
|
||||
{
|
||||
m_streamDecoder->uninitialize();
|
||||
delete m_streamDecoder;
|
||||
}
|
||||
|
||||
// uninit input stimulation
|
||||
if (m_stimDecoder)
|
||||
{
|
||||
m_stimDecoder->uninitialize();
|
||||
delete m_stimDecoder;
|
||||
}
|
||||
|
||||
//close files
|
||||
m_headerFile.flush();
|
||||
m_headerFile.close();
|
||||
|
||||
m_dataFile.flush();
|
||||
m_dataFile.close();
|
||||
|
||||
m_markerFile.flush();
|
||||
m_markerFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmBrainampFileWriterGipsa::processInput(const size_t /*index*/)
|
||||
{
|
||||
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmBrainampFileWriterGipsa::process()
|
||||
{
|
||||
Kernel::IBoxIO& boxContext = this->getDynamicBoxContext();
|
||||
|
||||
//1. Process signal
|
||||
for (size_t i = 0; i < boxContext.getInputChunkCount(0); ++i) //first input channel data
|
||||
{
|
||||
m_streamDecoder->decode(i);
|
||||
|
||||
//HEADER
|
||||
if (m_streamDecoder->isHeaderReceived())
|
||||
{
|
||||
m_matrix = m_streamDecoder->getOutputMatrix();
|
||||
m_sampling = m_streamDecoder->getOutputSamplingRate();
|
||||
|
||||
writeHeaderFile();
|
||||
}
|
||||
|
||||
//BUFFER
|
||||
if (m_streamDecoder->isBufferReceived())
|
||||
{
|
||||
// size_t channelCount = m_Matrix->getDimensionSize(0);
|
||||
switch (m_binaryFormat)
|
||||
{
|
||||
case BinaryFormat_Integer16:
|
||||
saveBuffer(int16_t(0));
|
||||
break;
|
||||
|
||||
case BinaryFormat_UnsignedInteger16:
|
||||
saveBuffer(uint16_t(0));
|
||||
break;
|
||||
|
||||
case BinaryFormat_Float32:
|
||||
saveBuffer(float(0));
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
//END
|
||||
if (m_streamDecoder->isEndReceived()) { }
|
||||
|
||||
boxContext.markInputAsDeprecated(0, i);
|
||||
}
|
||||
|
||||
// Make sure the marker file header is written in any case
|
||||
if (!m_isVmrkHeaderFileWritten)
|
||||
{
|
||||
const boost::posix_time::ptime now = boost::posix_time::second_clock::local_time();
|
||||
const std::string formated(formatTime(now));
|
||||
|
||||
m_markerFile << "Brain Vision Data Exchange Marker File, Version 1.0" << std::endl << std::endl
|
||||
<< "[Common Infos]" << std::endl
|
||||
<< "Codepage=ANSI" << std::endl
|
||||
<< "DataFile=" << getShortName(m_dataFilename) << std::endl << std::endl
|
||||
<< "[Marker Infos]" << std::endl
|
||||
<< "; Each entry: Mk<Marker number>=<Type>,<Description>,<Position in data points>," << std::endl
|
||||
<< "; <Size in data points>, <Channel number (0 = marker is related to all channels)>" << std::endl
|
||||
<< "; Fields are delimited by commas, some fields might be omitted (empty)." << std::endl
|
||||
<< "; Commas in type or description text are coded as \"\\1\"." << std::endl
|
||||
<< "Mk1=New Segment,,1,1,0," << formated << "000000" << std::endl;
|
||||
|
||||
m_isVmrkHeaderFileWritten = true;
|
||||
}
|
||||
|
||||
//2. Process stimulations - input channel 1
|
||||
for (size_t i = 0; i < boxContext.getInputChunkCount(1); ++i)
|
||||
{
|
||||
// uint64_t chunkStartTime =boxContext.getInputChunkStartTime(0, i);
|
||||
|
||||
m_stimDecoder->decode(i);
|
||||
|
||||
//buffer
|
||||
if (m_stimDecoder->isBufferReceived())
|
||||
{
|
||||
IStimulationSet* stimSet = m_stimDecoder->getOutputStimulationSet();
|
||||
|
||||
// Loop on stimulations
|
||||
for (size_t j = 0; j < stimSet->getStimulationCount(); ++j)
|
||||
{
|
||||
const uint64_t code = stimSet->getStimulationIdentifier(j);
|
||||
const uint64_t position = CTime(stimSet->getStimulationDate(j)).toSampleCount(m_sampling) + 1;
|
||||
|
||||
m_markerFile << "Mk" << m_stimulationCounter << "=Stimulus," << "S" << std::right << std::setw(3) << code << "," << position << ",1,0" << std::
|
||||
endl;
|
||||
|
||||
m_stimulationCounter++;
|
||||
}
|
||||
}
|
||||
|
||||
boxContext.markInputAsDeprecated(1, i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CBoxAlgorithmBrainampFileWriterGipsa::writeHeaderFile()
|
||||
{
|
||||
const size_t nChannel = m_matrix->getDimensionSize(0);
|
||||
// size_t samplesPerChunk = m_Matrix->getDimensionSize(1);
|
||||
|
||||
const double samplingInterval = 1000000.0 / double(m_sampling);
|
||||
|
||||
CString format("UNKNOWN");
|
||||
switch (m_binaryFormat)
|
||||
{
|
||||
case BinaryFormat_Integer16:
|
||||
format = "INT_16";
|
||||
break;
|
||||
|
||||
case BinaryFormat_UnsignedInteger16:
|
||||
format = "UINT_16";
|
||||
break;
|
||||
|
||||
case BinaryFormat_Float32:
|
||||
format = "IEEE_FLOAT_32";
|
||||
break;
|
||||
default:
|
||||
this->getLogManager() << Kernel::LogLevel_Error << "EEG format unknown!\n";
|
||||
break;
|
||||
}
|
||||
|
||||
m_headerFile << "Brain Vision Data Exchange Header File Version 1.0" << std::endl
|
||||
<< "; Data created by the Vision Recorder" << std::endl << std::endl
|
||||
<< "[Common Infos]" << std::endl
|
||||
<< "Codepage=ANSI" << std::endl
|
||||
<< "DataFile=" << getShortName(m_dataFilename) << std::endl
|
||||
<< "MarkerFile=" << getShortName(m_markerFilename) << std::endl
|
||||
<< "DataFormat=BINARY" << std::endl
|
||||
<< "; Data orientation: MULTIPLEXED=ch1,pt1, ch2,pt1 ..." << std::endl //sample 1, sample 2 ...
|
||||
<< "DataOrientation=MULTIPLEXED" << std::endl
|
||||
<< "NumberOfChannels=" << nChannel << std::endl
|
||||
<< "; Sampling interval in microseconds" << std::endl
|
||||
<< "SamplingInterval=" << std::fixed << std::setprecision(5) << samplingInterval << std::endl
|
||||
<< std::endl
|
||||
<< "[Binary Infos]" << std::endl
|
||||
<< "BinaryFormat=" << format.toASCIIString() << std::endl
|
||||
<< std::endl;
|
||||
|
||||
m_headerFile << "[Channel Infos]" << std::endl
|
||||
<< "; Each entry: Ch<Channel number>=<Name>,<Reference channel name>," << std::endl
|
||||
<< "; <Resolution in \"Unit\">,<Unit>, Future extensions.." << std::endl
|
||||
<< "; Fields are delimited by commas, some fields might be omitted (empty)." << std::endl
|
||||
<< "; Commas in channel names are coded as \"\\1\"." << std::endl;
|
||||
|
||||
for (size_t i = 0; i < nChannel; ++i)
|
||||
{
|
||||
m_headerFile << "Ch" << (i + 1) << "=" << m_matrix->getDimensionLabel(0, i) << ",,1," << std::endl; //resolution = 1
|
||||
}
|
||||
|
||||
m_headerFile << std::endl;
|
||||
|
||||
m_headerFile << "[Comment]" << std::endl << std::endl
|
||||
<< "A m p l i f i e r S e t u p" << std::endl
|
||||
<< "============================" << std::endl
|
||||
<< "Number of channels: " << nChannel << std::endl
|
||||
<< "Sampling Rate [Hz]: " << m_sampling << std::endl
|
||||
<< "Interval [µS]: " << std::fixed << std::setprecision(5) << samplingInterval << std::endl
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string CBoxAlgorithmBrainampFileWriterGipsa::getShortName(std::string fullpath)
|
||||
{
|
||||
size_t pos = fullpath.find_last_of('\\');
|
||||
if (pos == std::string::npos) { pos = fullpath.find_last_of('/'); }
|
||||
if (pos != std::string::npos) { return fullpath.substr(pos + 1, fullpath.size() - pos); }
|
||||
return fullpath;
|
||||
}
|
||||
|
||||
std::string CBoxAlgorithmBrainampFileWriterGipsa::formatTime(const boost::posix_time::ptime now)
|
||||
{
|
||||
using namespace boost::posix_time;
|
||||
|
||||
static std::locale loc(std::wcout.getloc(), new wtime_facet(L"%Y%m%d%H%M%S"));
|
||||
|
||||
std::basic_stringstream<wchar_t> wss;
|
||||
wss.imbue(loc);
|
||||
wss << now;
|
||||
std::wstring wstr = wss.str();
|
||||
std::string str(wstr.begin(), wstr.end());
|
||||
|
||||
return str;
|
||||
}
|
||||
} // namespace FileIO
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
+152
@@ -0,0 +1,152 @@
|
||||
/* Project: Gipsa-lab plugins for OpenVibe
|
||||
* AUTHORS AND CONTRIBUTORS: Andreev A., Barachant A., Congedo M., Ionescu,Gelu,
|
||||
|
||||
* This file is part of "Gipsa-lab plugins for OpenVibe".
|
||||
* You can redistribute it and/or modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
* This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
* You should have received a copy of the GNU General Public License along with Brain Invaders. If not, see http://www.gnu.org/licenses/.*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../ovp_defines.h"
|
||||
#include <openvibe/ov_all.h>
|
||||
#include <toolkit/ovtk_all.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace FileIO {
|
||||
class CBoxAlgorithmBrainampFileWriterGipsa final : public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
||||
{
|
||||
public:
|
||||
|
||||
CBoxAlgorithmBrainampFileWriterGipsa() { }
|
||||
void release() override { delete this; }
|
||||
|
||||
bool initialize() override;
|
||||
bool uninitialize() override;
|
||||
bool processInput(const size_t index) override;
|
||||
bool process() override;
|
||||
|
||||
bool writeHeaderFile(); //write the .vhdr file
|
||||
|
||||
static std::string getShortName(std::string fullpath); //of a file
|
||||
static std::string formatTime(boost::posix_time::ptime now);
|
||||
|
||||
|
||||
template <class T>
|
||||
bool saveBuffer(const T /*myDummy*/)
|
||||
{
|
||||
std::vector<T> output(m_matrix->getBufferElementCount());
|
||||
|
||||
if (output.size() != m_matrix->getBufferElementCount()) { return false; }
|
||||
|
||||
const size_t nChannel = m_matrix->getDimensionSize(0);
|
||||
const size_t nSamplesPerChunk = m_matrix->getDimensionSize(1);
|
||||
double* input = m_matrix->getBuffer();
|
||||
|
||||
for (size_t k = 0; k < nChannel; ++k)
|
||||
{
|
||||
for (size_t j = 0; j < nSamplesPerChunk; ++j)
|
||||
{
|
||||
const size_t index = (k * nSamplesPerChunk) + j;
|
||||
output[j * nChannel + k] = T(input[index]);
|
||||
}
|
||||
}
|
||||
|
||||
m_dataFile.write((char*)&output[0], m_matrix->getBufferElementCount() * sizeof(T));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_BrainampFileWriterGipsa)
|
||||
|
||||
protected:
|
||||
|
||||
enum EBinaryFormat
|
||||
{
|
||||
BinaryFormat_Integer16,
|
||||
BinaryFormat_UnsignedInteger16,
|
||||
BinaryFormat_Float32,
|
||||
};
|
||||
|
||||
//input signal 1
|
||||
Toolkit::TSignalDecoder<CBoxAlgorithmBrainampFileWriterGipsa>* m_streamDecoder = nullptr;
|
||||
CMatrix* m_matrix = nullptr;
|
||||
uint64_t m_sampling = 0;
|
||||
|
||||
//input stimulation 1
|
||||
Toolkit::TStimulationDecoder<CBoxAlgorithmBrainampFileWriterGipsa>* m_stimDecoder = nullptr;
|
||||
//Kernel::TParameterHandler <const IMemoryBuffer* > ip_bufferToDecodeTrigger;
|
||||
//Kernel::TParameterHandler < IStimulationSet* > op_pStimulationSetTrigger;
|
||||
|
||||
std::string m_headerFilename;
|
||||
std::string m_dataFilename;
|
||||
std::string m_markerFilename;
|
||||
|
||||
std::ofstream m_headerFile;
|
||||
std::ofstream m_dataFile;
|
||||
std::ofstream m_markerFile;
|
||||
|
||||
size_t m_binaryFormat = 0;
|
||||
size_t m_stimulationCounter = 2; //because the first is outputed manually
|
||||
|
||||
bool m_isVmrkHeaderFileWritten = false; //Is the beginning of the .vmrk (file with stimulations is written)
|
||||
};
|
||||
|
||||
class CBoxAlgorithmBrainampFileWriterGipsaListener final : public Toolkit::TBoxListener<IBoxListener>
|
||||
{
|
||||
public:
|
||||
|
||||
bool onInputTypeChanged(Kernel::IBox& /*box*/, const size_t /*index*/) override { return true; }
|
||||
|
||||
_IsDerivedFromClass_Final_(Toolkit::TBoxListener<IBoxListener>, CIdentifier::undefined())
|
||||
};
|
||||
|
||||
class CBoxAlgorithmBrainampFileWriterGipsaDesc final : public IBoxAlgorithmDesc
|
||||
{
|
||||
public:
|
||||
|
||||
void release() override { }
|
||||
|
||||
CString getName() const override { return CString("BrainVision Format file writer (Gipsa)"); }
|
||||
CString getAuthorName() const override { return CString("Anton Andreev"); }
|
||||
CString getAuthorCompanyName() const override { return CString("Gipsa-lab"); }
|
||||
CString getShortDescription() const override { return CString("Writes signal in the Brainamp file format."); }
|
||||
|
||||
CString getDetailedDescription() const override
|
||||
{
|
||||
return CString(
|
||||
"You must select the location of the output header file .vhdr. The .eeg and .vmrk files will be created with the same name and in the same folder. Integer codes of OpenVibe stimulations are saved in the .vmrk file. OV Stimulation with code 233 will be saved as S233 on the .vmrk file.");
|
||||
}
|
||||
|
||||
CString getCategory() const override { return CString("File reading and writing/BrainVision Format"); }
|
||||
CString getVersion() const override { return CString("1.1"); }
|
||||
CString getStockItemName() const override { return CString("gtk-save"); }
|
||||
|
||||
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_BrainampFileWriterGipsa; }
|
||||
IPluginObject* create() override { return new CBoxAlgorithmBrainampFileWriterGipsa; }
|
||||
IBoxListener* createBoxListener() const override { return new CBoxAlgorithmBrainampFileWriterGipsaListener; }
|
||||
void releaseBoxListener(IBoxListener* listener) const override { delete listener; }
|
||||
|
||||
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
|
||||
{
|
||||
prototype.addInput("Streamed matrix", OV_TypeId_Signal);
|
||||
prototype.addInput("Input stimulation channel", OV_TypeId_Stimulations);
|
||||
|
||||
prototype.addSetting("Header filename", OV_TypeId_Filename, "record-[$core{date}-$core{time}].vhdr");
|
||||
prototype.addSetting("Binary format", OVP_TypeId_BinaryFormat, "INT_16");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_BrainampFileWriterGipsaDesc)
|
||||
};
|
||||
} // namespace FileIO
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
+314
@@ -0,0 +1,314 @@
|
||||
#include "ovpCBoxAlgorithmEDFFileWriter.h"
|
||||
|
||||
#include <limits>
|
||||
#include <sstream>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace FileIO {
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
bool CBoxAlgorithmEDFFileWriter::initialize()
|
||||
{
|
||||
m_experimentInfoDecoder.initialize(*this, 0);
|
||||
m_signalDecoder.initialize(*this, 1);
|
||||
m_stimDecoder.initialize(*this, 2);
|
||||
|
||||
m_filename = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
|
||||
|
||||
m_sampling = 0;
|
||||
m_nChannels = 0;
|
||||
|
||||
m_isFileOpened = false;
|
||||
m_fileHandle = -1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
bool CBoxAlgorithmEDFFileWriter::uninitialize()
|
||||
{
|
||||
if (!m_isFileOpened)
|
||||
{
|
||||
// Fine, we didn't manage to write anything
|
||||
this->getLogManager() << Kernel::LogLevel_Warning << "Exiting without writing a file (open failed or no signal header received).\n";
|
||||
|
||||
// Clear the queue
|
||||
std::queue<double> empty;
|
||||
std::swap(m_buffer, empty);
|
||||
|
||||
m_experimentInfoDecoder.uninitialize();
|
||||
m_signalDecoder.uninitialize();
|
||||
m_stimDecoder.uninitialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
this->getLogManager() << Kernel::LogLevel_Info << "Writing the file, this may take a moment.\n";
|
||||
|
||||
for (size_t c = 0; c < m_nChannels; ++c)
|
||||
{
|
||||
if (EdfSetSampling(m_fileHandle, c, m_sampling) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_sampling failed!\n";
|
||||
return false;
|
||||
}
|
||||
if (EdfSetPhysicalMaximum(m_fileHandle, c, m_channelInfo[c].max) == -1)//1.7*10^308)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_physical_maximum failed!\n";
|
||||
return false;
|
||||
}
|
||||
if (EdfSetPhysicalMinimum(m_fileHandle, c, m_channelInfo[c].min) == -1)//-1.7*10^308)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_physical_minimum failed!\n";
|
||||
return false;
|
||||
}
|
||||
if (EdfSetDigitalMaximum(m_fileHandle, c, 32767) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_digital_maximum failed!\n";
|
||||
return false;
|
||||
}
|
||||
if (EdfSetDigitalMinimum(m_fileHandle, c, -32768) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_digital_minimum failed!\n";
|
||||
return false;
|
||||
}
|
||||
if (EdfSetLabel(m_fileHandle, c, m_signalDecoder.getOutputMatrix()->getDimensionLabel(0, c)) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_set_label failed!\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
const size_t n = m_sampling * m_nChannels;
|
||||
std::vector<double> tmpBuffer(n), tmpBufferToWrite(n); // A buffer chunk and Transposed buffer chunk
|
||||
|
||||
// Write out all the complete buffers
|
||||
if (m_buffer.size() >= n)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Trace << "((int) buffer.size() >= m_sampling*m_NChannels)\n";
|
||||
while (m_buffer.size() >= n)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Trace << "while((int)buffer.size() >= m_sampling*m_NChannels)\n";
|
||||
for (size_t i = 0; i < n; ++i)
|
||||
{
|
||||
tmpBuffer[i] = double(m_buffer.front());
|
||||
m_buffer.pop();
|
||||
}
|
||||
|
||||
for (size_t c = 0; c < m_nChannels; ++c)
|
||||
{
|
||||
for (size_t s = 0; s < m_sampling; ++s) { tmpBufferToWrite[c * m_sampling + s] = tmpBuffer[s * m_nChannels + c]; }
|
||||
}
|
||||
|
||||
if (EdfBlockwritePhysicalSamples(m_fileHandle, tmpBufferToWrite.data()) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_blockwrite_physical_samples: Could not write samples in file [" << m_filename << "]\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do we have a partial buffer? If so, write it out padded by zeroes
|
||||
if (!m_buffer.empty())
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_Trace << "if(buffer.size() > 0))\n";
|
||||
for (size_t i = 0; i < n; ++i) { tmpBuffer[i] = 0; }
|
||||
|
||||
for (size_t i = 0; i < m_buffer.size(); ++i)
|
||||
{
|
||||
tmpBuffer[i] = double(m_buffer.front());
|
||||
m_buffer.pop();
|
||||
}
|
||||
|
||||
for (size_t c = 0; c < m_nChannels; ++c)
|
||||
{
|
||||
for (size_t s = 0; s < m_sampling; ++s) { tmpBufferToWrite[c * m_sampling + s] = tmpBuffer[s * m_nChannels + c]; }
|
||||
}
|
||||
|
||||
if (EdfBlockwritePhysicalSamples(m_fileHandle, tmpBufferToWrite.data()) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edf_blockwrite_physical_samples: Could not write samples in file [" << m_filename << "]\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (EdfcloseFile(m_fileHandle) == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edfclose_file: Could not close file [" << m_filename << "]\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
m_experimentInfoDecoder.uninitialize();
|
||||
m_signalDecoder.uninitialize();
|
||||
m_stimDecoder.uninitialize();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
bool CBoxAlgorithmEDFFileWriter::processInput(const size_t /*index*/)
|
||||
{
|
||||
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
||||
return true;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
||||
bool CBoxAlgorithmEDFFileWriter::process()
|
||||
{
|
||||
Kernel::IBoxIO& boxContext = this->getDynamicBoxContext();
|
||||
|
||||
//iterate over all chunk on signal input
|
||||
for (size_t i = 0; i < boxContext.getInputChunkCount(1); ++i)
|
||||
{
|
||||
m_signalDecoder.decode(i);
|
||||
|
||||
if (m_signalDecoder.isHeaderReceived())
|
||||
{
|
||||
m_sampling = size_t(m_signalDecoder.getOutputSamplingRate());
|
||||
m_nChannels = m_signalDecoder.getOutputMatrix()->getDimensionSize(0);
|
||||
m_nSamplesPerChunk = m_signalDecoder.getOutputMatrix()->getDimensionSize(1);
|
||||
|
||||
m_fileHandle = EdfopenFileWriteonly(m_filename.toASCIIString(), EDFLIB_FILETYPE_EDFPLUS, m_nChannels);
|
||||
if (m_fileHandle < 0)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "Could not open file [" << m_filename << "]\n";
|
||||
switch (m_fileHandle)
|
||||
{
|
||||
case EDFLIB_MALLOC_ERROR:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_MALLOC_ERROR: ";
|
||||
break;
|
||||
case EDFLIB_NO_SUCH_FILE_OR_DIRECTORY:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_NO_SUCH_FILE_OR_DIRECTORY: ";
|
||||
break;
|
||||
case EDFLIB_MAXFILES_REACHED:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_MAXFILES_REACHED: ";
|
||||
break;
|
||||
case EDFLIB_FILE_ALREADY_OPENED:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_FILE_ALREADY_OPENED: ";
|
||||
break;
|
||||
case EDFLIB_NUMBER_OF_SIGNALS_INVALID:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_NUMBER_OF_SIGNALS_INVALID: ";
|
||||
break;
|
||||
default:
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "EDFLIB_UNKNOWN_ERROR: ";
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//set file parameters
|
||||
EdfSetStartdatetime(m_fileHandle, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
for (size_t c = 0; c < m_nChannels; ++c)
|
||||
{
|
||||
//Creation of one information channel structure per channel
|
||||
channel_info_t channelInfo = { std::numeric_limits<double>::max(), -std::numeric_limits<double>::max() };
|
||||
m_channelInfo.push_back(channelInfo);
|
||||
}
|
||||
|
||||
m_isFileOpened = true;
|
||||
}
|
||||
|
||||
if (m_signalDecoder.isBufferReceived())
|
||||
{
|
||||
//put sample in the buffer
|
||||
CMatrix* matrix = m_signalDecoder.getOutputMatrix();
|
||||
for (size_t s = 0; s < m_nSamplesPerChunk; ++s)
|
||||
{
|
||||
for (size_t c = 0; c < m_nChannels; ++c)
|
||||
{
|
||||
double value = matrix->getBuffer()[c * m_nSamplesPerChunk + s];
|
||||
if (value > m_channelInfo[c].max) { m_channelInfo[c].max = value; }
|
||||
if (value < m_channelInfo[c].min) { m_channelInfo[c].min = value; }
|
||||
m_buffer.push(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_signalDecoder.isEndReceived()) { }
|
||||
}
|
||||
|
||||
if (m_isFileOpened)
|
||||
{
|
||||
//iterate over all chunk on experiment information input
|
||||
for (size_t i = 0; i < boxContext.getInputChunkCount(0); ++i)
|
||||
{
|
||||
m_experimentInfoDecoder.decode(i);
|
||||
|
||||
if (m_experimentInfoDecoder.isHeaderReceived())
|
||||
{
|
||||
//set patient code
|
||||
EdfSetPatientcode(m_fileHandle, std::to_string(m_experimentInfoDecoder.getOutputSubjectID()).c_str());
|
||||
|
||||
//set patient gender
|
||||
switch (m_experimentInfoDecoder.getOutputSubjectGender())
|
||||
{
|
||||
case 2: //female
|
||||
EdfSetGender(m_fileHandle, 0);
|
||||
break;
|
||||
case 1: //male
|
||||
EdfSetGender(m_fileHandle, 1);
|
||||
break;
|
||||
case 0: //unknown
|
||||
break;
|
||||
case 9: //unspecified
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//set patient age
|
||||
const char* patientAge = ("Patient age = " + std::to_string(m_experimentInfoDecoder.getOutputSubjectAge())).c_str();
|
||||
EdfSetPatientAdditional(m_fileHandle, patientAge);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//iterate over all chunk on stimulation input
|
||||
for (size_t i = 0; i < boxContext.getInputChunkCount(2); ++i)
|
||||
{
|
||||
m_stimDecoder.decode(i);
|
||||
|
||||
if (m_stimDecoder.isHeaderReceived()) { }
|
||||
|
||||
if (m_stimDecoder.isBufferReceived())
|
||||
{
|
||||
const IStimulationSet* stimSet = m_stimDecoder.getOutputStimulationSet();
|
||||
for (size_t j = 0; j < stimSet->getStimulationCount(); ++j)
|
||||
{
|
||||
const uint64_t date = stimSet->getStimulationDate(j);
|
||||
const int64_t stimDate = int64_t(CTime(date).toSeconds() / 0.0001);
|
||||
|
||||
const uint64_t duration = stimSet->getStimulationDuration(j);
|
||||
const int64_t stimDuration = int64_t(CTime(duration).toSeconds() / 0.0001);
|
||||
|
||||
const uint64_t id = stimSet->getStimulationIdentifier(j);
|
||||
CString stimID = this->getTypeManager().getEnumerationEntryNameFromValue(OV_TypeId_Stimulation, id);
|
||||
if (stimID.length() == 0)
|
||||
{
|
||||
// If the stimulation number has not been registered as an enum, just pass the number
|
||||
std::stringstream ss;
|
||||
ss << id;
|
||||
stimID = ss.str().c_str();
|
||||
}
|
||||
const int result = EdfwriteAnnotationUTF8(m_fileHandle, stimDate, stimDuration, stimID.toASCIIString());
|
||||
if (result == -1)
|
||||
{
|
||||
this->getLogManager() << Kernel::LogLevel_ImportantWarning << "edfwrite_annotation_utf8 failed!\n";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (m_stimDecoder.isEndReceived()) { }
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
} // namespace FileIO
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ovp_defines.h"
|
||||
#include <openvibe/ov_all.h>
|
||||
#include <toolkit/ovtk_all.h>
|
||||
|
||||
#include "edf/edflib.h"
|
||||
#include <queue>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace FileIO {
|
||||
typedef struct
|
||||
{
|
||||
double min;
|
||||
double max;
|
||||
} channel_info_t;
|
||||
|
||||
|
||||
class CBoxAlgorithmEDFFileWriter final : public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
||||
{
|
||||
public:
|
||||
|
||||
//CBoxAlgorithmEDFFileWriter();
|
||||
void release() override { delete this; }
|
||||
|
||||
bool initialize() override;
|
||||
bool uninitialize() override;
|
||||
bool processInput(const size_t index) override;
|
||||
bool process() override;
|
||||
|
||||
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_EDFFileWriter)
|
||||
|
||||
protected:
|
||||
|
||||
Toolkit::TExperimentInfoDecoder<CBoxAlgorithmEDFFileWriter> m_experimentInfoDecoder;
|
||||
Toolkit::TSignalDecoder<CBoxAlgorithmEDFFileWriter> m_signalDecoder;
|
||||
Toolkit::TStimulationDecoder<CBoxAlgorithmEDFFileWriter> m_stimDecoder;
|
||||
|
||||
CString m_filename;
|
||||
bool m_isFileOpened = false;
|
||||
int m_fileHandle = 0;
|
||||
size_t m_sampling = 0;
|
||||
size_t m_nChannels = 0;
|
||||
size_t m_nSamplesPerChunk = 0;
|
||||
std::queue<double, std::deque<double>> m_buffer;
|
||||
//int * m_pTemporyBuffer;
|
||||
//int * m_pTemporyBufferToWrite;
|
||||
|
||||
std::vector<channel_info_t> m_channelInfo;
|
||||
};
|
||||
|
||||
class CBoxAlgorithmEDFFileWriterDesc final : public IBoxAlgorithmDesc
|
||||
{
|
||||
public:
|
||||
|
||||
void release() override { }
|
||||
|
||||
CString getName() const override { return CString("EDF File Writer"); }
|
||||
CString getAuthorName() const override { return CString("Aurelien Van Langhenhove"); }
|
||||
CString getAuthorCompanyName() const override { return CString("CICIT Garches"); }
|
||||
|
||||
CString getShortDescription() const override { return CString("Writes experiment information, signal and stimulations in a EDF file"); }
|
||||
|
||||
CString getDetailedDescription() const override { return CString(""); }
|
||||
CString getCategory() const override { return CString("File reading and writing/EDF"); }
|
||||
CString getVersion() const override { return CString("1.0"); }
|
||||
CString getStockItemName() const override { return CString("gtk-save"); }
|
||||
|
||||
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_EDFFileWriter; }
|
||||
IPluginObject* create() override { return new CBoxAlgorithmEDFFileWriter; }
|
||||
|
||||
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
|
||||
{
|
||||
prototype.addInput("Experiment information", OV_TypeId_ExperimentInfo);
|
||||
prototype.addInput("Signal", OV_TypeId_Signal);
|
||||
prototype.addInput("Stimulations", OV_TypeId_Stimulations);
|
||||
|
||||
prototype.addSetting("Filename", OV_TypeId_Filename, "record-[$core{date}-$core{time}].edf");
|
||||
|
||||
//prototype.addFlag(Kernel::BoxFlag_IsUnstable);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_EDFFileWriterDesc)
|
||||
};
|
||||
} // namespace FileIO
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
// Boxes
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
#define OVP_ClassId_BoxAlgorithm_EDFFileWriter OpenViBE::CIdentifier(0x0D454DCE, 0x470A4C02)
|
||||
#define OVP_ClassId_BoxAlgorithm_EDFFileWriterDesc OpenViBE::CIdentifier(0x0D454DCE, 0x470A4C02)
|
||||
#define OVP_ClassId_BoxAlgorithm_BrainampFileWriterGipsa OpenViBE::CIdentifier(0x0C7E0BDE, 0x4EC90F95)
|
||||
#define OVP_ClassId_BoxAlgorithm_BrainampFileWriterGipsaDesc OpenViBE::CIdentifier(0x0A77142C, 0x316B6E47)
|
||||
|
||||
#define OVP_TypeId_BinaryFormat OpenViBE::CIdentifier(0x567234C5, 0x3D870DC3)
|
||||
#define OVP_TypeId_BinaryFormat_int16_t OpenViBE::CIdentifier(0x1C777556, 0x123861C3)
|
||||
#define OVP_TypeId_BinaryFormat_uint16_t OpenViBE::CIdentifier(0x6A7B6C73, 0x4B9D129D)
|
||||
#define OVP_TypeId_BinaryFormat_float OpenViBE::CIdentifier(0x15183866, 0x7AAC69FC)
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
#include <vector>
|
||||
#include <openvibe/ov_all.h>
|
||||
|
||||
// @BEGIN CICIT-GARCHES
|
||||
#include "box-algorithms/ovpCBoxAlgorithmEDFFileWriter.h"
|
||||
// @END CICIT-GARCHES
|
||||
|
||||
// @BEGIN GIPSA
|
||||
#include "box-algorithms/ovpCBoxAlgorithmBrainampFileWriterGipsa.h"
|
||||
// @END GIPSA
|
||||
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace FileIO {
|
||||
|
||||
OVP_Declare_Begin()
|
||||
// @BEGIN CICIT-GARCHES
|
||||
OVP_Declare_New(CBoxAlgorithmEDFFileWriterDesc)
|
||||
// @END CICIT_GARCHES
|
||||
|
||||
// @BEGIN GIPSA
|
||||
//Register dropdowns
|
||||
context.getTypeManager().registerEnumerationType(OVP_TypeId_BinaryFormat, "Binary format select");
|
||||
context.getTypeManager().registerEnumerationEntry(OVP_TypeId_BinaryFormat, "INT_16", OVP_TypeId_BinaryFormat_int16_t.id());
|
||||
context.getTypeManager().registerEnumerationEntry(OVP_TypeId_BinaryFormat, "UINT_16", OVP_TypeId_BinaryFormat_uint16_t.id());
|
||||
context.getTypeManager().registerEnumerationEntry(OVP_TypeId_BinaryFormat, "IEEE_FLOAT_32", OVP_TypeId_BinaryFormat_float.id());
|
||||
|
||||
OVP_Declare_New(CBoxAlgorithmBrainampFileWriterGipsaDesc)
|
||||
// @END GIPSA
|
||||
|
||||
OVP_Declare_End()
|
||||
|
||||
} // namespace Tools
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
Reference in New Issue
Block a user