diff --git a/src/applications/mne_scan/plugins/CMakeLists.txt b/src/applications/mne_scan/plugins/CMakeLists.txt index 775c74dbf69..bbf8418204b 100644 --- a/src/applications/mne_scan/plugins/CMakeLists.txt +++ b/src/applications/mne_scan/plugins/CMakeLists.txt @@ -17,6 +17,7 @@ add_subdirectory(fiffsimulator) add_subdirectory(ftbuffer) add_subdirectory(babymeg) add_subdirectory(natus) +add_subdirectory(randomdata) # Algorithm Plugin add_subdirectory(rtcmne) @@ -27,6 +28,7 @@ add_subdirectory(neuronalconnectivity) add_subdirectory(writetofile) add_subdirectory(hpi) add_subdirectory(rtfwd) +add_subdirectory(timefrequency) option(WITH_BRAINFLOW "Build brainflow plugin" OFF) option(WITH_LSL "Build LSL plugin" OFF) diff --git a/src/applications/mne_scan/plugins/randomdata/CMakeLists.txt b/src/applications/mne_scan/plugins/randomdata/CMakeLists.txt new file mode 100644 index 00000000000..a76a716e702 --- /dev/null +++ b/src/applications/mne_scan/plugins/randomdata/CMakeLists.txt @@ -0,0 +1,73 @@ +cmake_minimum_required(VERSION 3.14) +project(scan_randomdata LANGUAGES CXX) + +#Handle qt uic, moc, rrc automatically +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Widgets Network Concurrent) + +set(SOURCES + randomdata.cpp + randomdata_global.cpp +) + +set(HEADERS + randomdata.h + randomdata_global.h +) + +set(FILE_TO_UPDATE randomdata_global.cpp) + +set(SOURCE_PATHS ${SOURCES}) +list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +set(FFTW_LIBS "") + +if(USE_FFTW) + if (WIN32) + set(FFTW_LIBS + ${FFTW_DIR_LIBS}/libfftw3-3.dll + ${FFTW_DIR_LIBS}/libfftw3f-3.dll + ${FFTW_DIR_LIBS}/libfftwf3l-3.dll + ) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) + elseif(UNIX AND NOT APPLE) + set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) + endif() +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC ../) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + # mne_fs + # mne_mne + # mne_fwd + # mne_inverse + # mne_rtprocessing + # mne_connectivity + # mne_events + scDisp + scShared + scMeas + ${FFTW_LIBS}) + +target_compile_definitions(${PROJECT_NAME} PRIVATE SCAN_RANDOMDATA_PLUGIN MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}") + +if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${PROJECT_NAME} PRIVATE STATICBUILD QT_STATICPLUGIN) +endif() diff --git a/src/applications/mne_scan/plugins/randomdata/randomdata.cpp b/src/applications/mne_scan/plugins/randomdata/randomdata.cpp new file mode 100644 index 00000000000..7d19cb89500 --- /dev/null +++ b/src/applications/mne_scan/plugins/randomdata/randomdata.cpp @@ -0,0 +1,304 @@ +//============================================================================================================= +/** + * @file randomdata.cpp + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors + * may be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Contains the definition of the RandomData class. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include + +#include "randomdata/randomdata.h" + +#include +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include +#include +#include +#include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +namespace RANDOMDATAPLUGIN { + +//============================================================================================================= + +// QSharedPointer createFiffInfo(int numChassis, +// int numChannels) { +// QSharedPointer pFiffInfo; +// pFiffInfo->sfreq = 1000.0f; +// pFiffInfo->nchan = numChassis * numChannels; +// pFiffInfo->chs.clear(); +// +// for (int chan_i = 0; chan_i < pFiffInfo->nchan; ++chan_i) { +// FIFFLIB::FiffChInfo channel; +// channel.ch_name = QString("%1:%2").arg(numChannels, 2).arg(chan_i, 2); +// channel.kind = FIFFV_MEG_CH; +// channel.unit = FIFF_UNIT_T; +// channel.unit_mul = FIFF_UNITM_NONE; +// channel.chpos.coil_type = FIFFV_COIL_NONE; +// pFiffInfo->chs.append(channel); +// pFiffInfo->ch_names.append(channel.ch_name); +// } +// } + +// QSharedPointer +// createFiffInfo(std::vector> fl_chassis, float sfreq = 1000.f) { +// QSharedPointer pFiffInfo; +// pFiffInfo->sfreq = sfreq; +// pFiffInfo->chs.clear(); +// +// int total_channels = 0; +// int chassis_num = 0; +// for (auto &chassis : fl_chassis) { +// for (auto &sensor : chassis) { +// FIFFLIB::FiffChInfo channel; +// channel.ch_name = QString("%1:%2").arg(chassis_num, 2).arg(sensor, 2); +// channel.kind = FIFFV_MEG_CH; +// channel.unit = FIFF_UNIT_T; +// channel.unit_mul = FIFF_UNITM_NONE; +// channel.chpos.coil_type = FIFFV_COIL_NONE; +// pFiffInfo->chs.append(channel); +// pFiffInfo->ch_names.append(channel.ch_name); +// ++total_channels; +// } +// } +// pFiffInfo->nchan = total_channels; +// +// return pFiffInfo; +// } +// +// QSharedPointer +// createFiffInfo(int numChassis, int numChannels, float sfreq = 1000.f) { +// std::vector> fl; +// for (int i = 0; i < numChassis; ++i) { +// std::vector ch(numChannels); +// std::iota(ch.begin(), ch.end(), 1); +// fl.push_back(std::move(ch)); +// } +// return createFiffInfo(fl, sfreq); +// } + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +RandomData::RandomData() +: m_pFiffInfo(QSharedPointer(new FIFFLIB::FiffInfo())) +{ + m_pRTMSA_RandomData = SCSHAREDLIB::PluginOutputData< + SCMEASLIB::RealTimeMultiSampleArray>::create(this, "RandomData Out", + "RandomDataPlguin output"); + m_pRTMSA_RandomData->measurementData()->setName(this->getName()); + m_outputConnectors.append(m_pRTMSA_RandomData); +} + +//============================================================================================================= + +RandomData::~RandomData() +{ + if(this->isRunning()) { + RandomData::stop(); + } +} + +//============================================================================================================= + +QSharedPointer RandomData::clone() const +{ + QSharedPointer pRandomDataClone(new RandomData()); + return pRandomDataClone; +} + +//============================================================================================================= + +void RandomData::init() +{ + m_pFiffInfo->sfreq = 1000.0f; + m_pFiffInfo->nchan = 32; + m_pFiffInfo->chs.clear(); + + for (int chan_i = 0; chan_i < m_pFiffInfo->nchan; ++chan_i) { + FIFFLIB::FiffChInfo channel; + channel.ch_name = "Ch. " + QString::number(chan_i); + channel.kind = FIFFV_MEG_CH; + channel.unit = FIFF_UNIT_T; + channel.unit_mul = FIFF_UNITM_NONE; + channel.chpos.coil_type = FIFFV_COIL_NONE; + m_pFiffInfo->chs.append(channel); + m_pFiffInfo->ch_names.append(channel.ch_name); + } + + m_pRTMSA_RandomData->measurementData()->initFromFiffInfo( + m_pFiffInfo); // if(m_pCircularBuffer->pop(matData)) { + m_pRTMSA_RandomData->measurementData()->setMultiArraySize(1); + m_pRTMSA_RandomData->measurementData()->setVisibility(true); + + matData.resize(m_pFiffInfo->nchan, 200); + + qDebug() << " ^^^^^^^^^^^^^^^^^^^^ Init Random Data (....again)"; +} + +//============================================================================================================= + +void RandomData::unload() +{ +} + +//============================================================================================================= + +bool RandomData::start() +{ + // Init circular buffer to transmit data from the producer to this thread + // if(!m_pCircularBuffer) { + // m_pCircularBuffer = QSharedPointer(new + // CircularBuffer_Matrix_double(10)); + // } + // + // //Setup fiff info before setting up the RMTSA because we need it to init + // the RTMSA setUpFiffInfo(); + // + // //Set the channel size of the RMTSA - this needs to be done here and NOT in + // the init() function because the user can change the number of channels + // during runtime + // m_pRMTSA_Natus->measurementData()->initFromFiffInfo(m_pFiffInfo); + // m_pRMTSA_Natus->measurementData()->setMultiArraySize(1); + // + QThread::start(); + // + // // Start the producer + // m_pNatusProducer = + // QSharedPointer::create(m_iSamplesPerBlock, + // m_iNumberChannels); m_pNatusProducer->moveToThread(&m_pProducerThread); + // connect(m_pNatusProducer.data(), &NatusProducer::newDataAvailable, + // this, &RandomData::onNewDataAvailable, Qt::DirectConnection); + // m_pProducerThread.start(); + + return true; +} + +//============================================================================================================= + +bool RandomData::stop() +{ + requestInterruption(); + wait(500); + m_pRTMSA_RandomData->measurementData()->clear(); + + return true; +} + +//============================================================================================================= + +SCSHAREDLIB::AbstractPlugin::PluginType RandomData::getType() const +{ + return SCSHAREDLIB::AbstractPlugin::PluginType::_ISensor; +} + +//============================================================================================================= + +QString RandomData::getName() const +{ + return "Random Data"; +} + +//============================================================================================================= + +QWidget* RandomData::setupWidget() +{ + + // guiWidget = std::make_unique(); + + // NatusSetup* widget = new NatusSetup(this);//widget is later destroyed by + // CentralWidget - so it has to be created everytime new + + // init properties dialog + // widget->initGui(); + + // auto *frame = new QWidget(); + // frame->setLayout(new QHBoxLayout()); + // + // auto *flWidget = new DISPLIB::RandomDataView(2, 16); + // + // frame->layout()->addWidget(flWidget); + // flWidget->setBlinkState(0, 2, true); + // flWidget->setBlinkState(1, 5, true); + + return new QLabel("Random data Baby!"); +} + +//============================================================================================================= + +void RandomData::run() { + + for (;;) { + // gather the data + + matData = Eigen::MatrixXd::Random(m_pFiffInfo->nchan, 200); + matData *= 4e-12; + + msleep(200); + + if (isInterruptionRequested()) + break; + m_pRTMSA_RandomData->measurementData()->setValue(matData); + } +} + +//============================================================================================================= + +QString RandomData::getBuildInfo() { + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); +} + +} // namespace RANDOMDATAPLUGIN + diff --git a/src/applications/mne_scan/plugins/randomdata/randomdata.h b/src/applications/mne_scan/plugins/randomdata/randomdata.h new file mode 100644 index 00000000000..73d9c044815 --- /dev/null +++ b/src/applications/mne_scan/plugins/randomdata/randomdata.h @@ -0,0 +1,141 @@ +//============================================================================================================= +/** + * @file randomdata.h + * @author Juan GarciaPrieto ; + * Gabriel B Motta ; + * @since 0.1.0 + * @date February, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Contains the declaration of the Random data plugin class. + * + */ + +#ifndef RANDOMDATA_H +#define RANDOMDATA_H //============================================================================================================= INCLUDES ============================================================================================================= + +#include "randomdata/randomdata_global.h" +// #include "randomdata/randomdata_plugin_gui.h" + +#include +// #include +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// FORWARD DECLARATION +//============================================================================================================= + +namespace SCMEASLIB { +class RealTimeMultiSampleArray; +} + +namespace FIFFLIB { +class FiffInfo; +} + + +//============================================================================================================= +// DEFINE NAMESPACE RANDOMDATAPLUGIN +//============================================================================================================= + +namespace RANDOMDATAPLUGIN { + +//============================================================================================================= +// RANDOMDATAPLUGIN FORWARD DECLARATIONS +//============================================================================================================= + +//============================================================================================================= +/** + * The RandomData class provides a EEG connector for generating random data. + * + * @brief The RandomData class. + */ +class RANDOMDATASHARED_EXPORT RandomData : public SCSHAREDLIB::AbstractSensor { + Q_OBJECT + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "randomdata.json") //New Qt5 Plugin system replaces Q_EXPORT_PLUGIN2 macro + // Use the Q_INTERFACES() macro to tell Qt's meta-object system about the interfaces + Q_INTERFACES(SCSHAREDLIB::AbstractSensor) + + public: + //========================================================================================================= + /** + * Constructs RandomData. + */ + RandomData(); + + //========================================================================================================= + /** + * Destroys RandomData. + */ + ~RandomData(); + + //========================================================================================================= + /** + * Virtual Interface + * */ + virtual QSharedPointer clone() const; + virtual void init(); + virtual void unload(); + virtual bool start(); + virtual bool stop(); + virtual AbstractPlugin::PluginType getType() const; + virtual QString getName() const; + virtual QWidget* setupWidget(); + virtual QString getBuildInfo(); + + protected: + //========================================================================================================= + /** + * the starting point for the thread. after calling start(), the newly created thread calls this function. + * returning from this method will end the execution of the thread. + * pure virtual method inherited by qthread. + */ + virtual void run(); + + // std::unique_ptr guiWidget; + + QSharedPointer> m_pRTMSA_RandomData; + QSharedPointer m_pFiffInfo; + Eigen::MatrixXd matData; + +}; // namespace RANDOMDATAPLUGIN + +} + +#endif // RANDOMDATA_H diff --git a/src/applications/mne_scan/plugins/randomdata/randomdata.json b/src/applications/mne_scan/plugins/randomdata/randomdata.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/applications/mne_scan/plugins/randomdata/randomdata_global.cpp b/src/applications/mne_scan/plugins/randomdata/randomdata_global.cpp new file mode 100644 index 00000000000..d009cc09065 --- /dev/null +++ b/src/applications/mne_scan/plugins/randomdata/randomdata_global.cpp @@ -0,0 +1,55 @@ +//============================================================================================================= +/** + * @file randomdata_global.cpp + * @author Juan G Prieto ; + * Gabriel B Motta ; + * @since 0.1.9 + * @date September, 2021 + * + * @section LICENSE + * + * Copyright (C) 2021, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief randomdata plugin global definitions. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "randomdata_global.h" + +//============================================================================================================= +// DEFINE METHODS +//============================================================================================================= + +const char* RANDOMDATAPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} + +//============================================================================================================= + +const char* RANDOMDATAPLUGIN::buildHash(){ return UTILSLIB::gitHash();} + +//============================================================================================================= + +const char* RANDOMDATAPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} + diff --git a/src/applications/mne_scan/plugins/randomdata/randomdata_global.h b/src/applications/mne_scan/plugins/randomdata/randomdata_global.h new file mode 100644 index 00000000000..ed025965d3f --- /dev/null +++ b/src/applications/mne_scan/plugins/randomdata/randomdata_global.h @@ -0,0 +1,81 @@ +//============================================================================================================= +/** + * @file randomdata_global.h + * @author Lorenz Esch + * @since 0.1.0 + * @date June, 2018 + * + * @section LICENSE + * + * Copyright (C) 2018, Lorenz Esch. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Contains the Random Data plugin library export/import macros. + * + */ + +#ifndef RANDOMDATA_GLOBAL_H +#define RANDOMDATA_GLOBAL_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// PREPROCESSOR DEFINES +//============================================================================================================= + +#if defined(SCAN_RANDOMDATA_PLUGIN) +# define RANDOMDATASHARED_EXPORT Q_DECL_EXPORT /**< Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library. */ +#else +# define RANDOMDATASHARED_EXPORT Q_DECL_IMPORT /**< Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library. */ +#endif + +namespace RANDOMDATAPLUGIN { + +//============================================================================================================= +/** + * Returns build date and time. + */ +RANDOMDATASHARED_EXPORT const char* buildDateTime(); + +//============================================================================================================= +/** + * Returns abbreviated build git hash. + */ +RANDOMDATASHARED_EXPORT const char* buildHash(); + +//============================================================================================================= +/** + * Returns full build git hash. + */ +RANDOMDATASHARED_EXPORT const char* buildHashLong(); +} // namespace RANDOMDATAPLUGIN + +#endif // RANDOMDATA_GLOBAL_H diff --git a/src/applications/mne_scan/plugins/timefrequency/CMakeLists.txt b/src/applications/mne_scan/plugins/timefrequency/CMakeLists.txt new file mode 100644 index 00000000000..e02a4df92a5 --- /dev/null +++ b/src/applications/mne_scan/plugins/timefrequency/CMakeLists.txt @@ -0,0 +1,80 @@ +cmake_minimum_required(VERSION 3.14) +project(scan_timefrequency LANGUAGES CXX) + +#Handle qt uic, moc, rrc automatically +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS + Core Widgets Network Concurrent) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED + COMPONENTS Core Widgets Network Concurrent) + +set(SOURCES + timefrequency.cpp + timefrequency_global.cpp +) + +set(HEADERS + timefrequency_global.h + timefrequency.h +) + +set(FILE_TO_UPDATE timefrequency_global.cpp) + +set(SOURCE_PATHS ${SOURCES}) +list(TRANSFORM SOURCE_PATHS PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/") +set_source_files_properties(${FILE_TO_UPDATE} PROPERTIES OBJECT_DEPENDS "${SOURCE_PATHS}") + +add_library(${PROJECT_NAME} ${SOURCES} ${HEADERS}) + +set(FFTW_LIBS "") + +if(USE_FFTW) + if (WIN32) + set(FFTW_LIBS + ${FFTW_DIR_LIBS}/libfftw3-3.dll + ${FFTW_DIR_LIBS}/libfftw3f-3.dll + ${FFTW_DIR_LIBS}/libfftwf3l-3.dll + ) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}) + elseif(UNIX AND NOT APPLE) + set(FFTW_LIBS ${FFTW_DIR_LIBS}/lib/libfftw3.so) + target_include_directories(${PROJECT_NAME} PRIVATE ${FFTW_DIR_INCLUDE}/api) + endif() +endif() + +target_include_directories(${PROJECT_NAME} PUBLIC ../) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt${QT_VERSION_MAJOR}::Core + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Network + Qt${QT_VERSION_MAJOR}::Concurrent + eigen + mne_disp + mne_utils + mne_fiff + # mne_fs + # mne_mne + # mne_fwd + # mne_inverse + # mne_rtprocessing + # mne_connectivity + # mne_events + scDisp + scShared + scMeas + ${FFTW_LIBS}) + +target_compile_definitions(${PROJECT_NAME} PRIVATE + SCAN_TIMEFREQUENCY_PLUGIN + MNE_GIT_HASH_SHORT="${MNE_GIT_HASH_SHORT}" + MNE_GIT_HASH_LONG="${MNE_GIT_HASH_LONG}" +) + +if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${PROJECT_NAME} PRIVATE + STATICBUILD QT_STATICPLUGIN) +endif() diff --git a/src/applications/mne_scan/plugins/timefrequency/timefrequency.cpp b/src/applications/mne_scan/plugins/timefrequency/timefrequency.cpp new file mode 100644 index 00000000000..58a0ff42023 --- /dev/null +++ b/src/applications/mne_scan/plugins/timefrequency/timefrequency.cpp @@ -0,0 +1,189 @@ +//============================================================================================================= +/** + * @file timefrequency.cpp + * @author Juan Garcia-Prieto ; + * @since 0.1.0 + * @date March, 2023 + * + * @section LICENSE + * + * Copyright (C) 2016, Christoph Dinh, Gabriel B Motta, Lorenz Esch. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Definition of the TimeFrequency class. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "timefrequency/timefrequency.h" + +#include + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include +#include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + +//============================================================================================================= +// USED NAMESPACES +//============================================================================================================= + +//============================================================================================================= +// DEFINE MEMBER METHODS +//============================================================================================================= + +namespace TIMEFREQUENCYPLUGIN { + +TimeFrequency::TimeFrequency() +: m_pRTMSA_In(Q_NULLPTR), + m_pRTMSA_Out(Q_NULLPTR) +{ + qDebug() << "[TimeFrequency::TimeFrequency] Creating Plugin Object."; +} + +//============================================================================================================= + +TimeFrequency::~TimeFrequency() +{ + if(this->isRunning()) { + TimeFrequency::stop(); + } +} + +//============================================================================================================= + +QSharedPointer TimeFrequency::clone() const +{ + QSharedPointer pTimeFrequencyClone(new TimeFrequency); + return pTimeFrequencyClone; +} + +//============================================================================================================= + +void TimeFrequency::init() +{ + // Input + m_pRTMSA_In = SCSHAREDLIB::PluginInputData< + SCMEASLIB::RealTimeMultiSampleArray>:: + create(this, "TimeFrequencyIn", "TimeFrequency in data"); + connect(m_pRTMSA_In.data(), &SCSHAREDLIB::PluginInputConnector::notify, + this, &TimeFrequency::update, Qt::DirectConnection); + m_inputConnectors.append(m_pRTMSA_In); + + // Output + m_pRTMSA_Out = SCSHAREDLIB::PluginOutputData< + SCMEASLIB::RealTimeMultiSampleArray>:: + create(this, "TimeFrequencyOut", "TimeFrequencyPluginOutputdata"); + m_pRTMSA_Out->measurementData()->setName(this->getName()); + m_outputConnectors.append(m_pRTMSA_Out); +} + +//============================================================================================================= + +void TimeFrequency::unload() +{ + +} + +//============================================================================================================= + +bool TimeFrequency::start() +{ + //Start thread as soon as we have received the first data block. See update(). + return true; +} + +//============================================================================================================= + +bool TimeFrequency::stop() +{ + requestInterruption(); + + wait(500); + + return true; +} + +//============================================================================================================= + +SCSHAREDLIB::AbstractPlugin::PluginType TimeFrequency::getType() const +{ + return _IAlgorithm; +} + +//============================================================================================================= + +QString TimeFrequency::getName() const +{ + return "TimeFrequency"; +} + +//============================================================================================================= + +QWidget* TimeFrequency::setupWidget() +{ + return new QLabel("Time Frequency Baby"); +} + +//============================================================================================================= +void TimeFrequency::update(QSharedPointer pMeasurement) +{ + qDebug() << "new data!"; +} + +void TimeFrequency::run() +{ + + // Init + Eigen::MatrixXd matData; + // matData. + while (true) + { + msleep(500); + if(isInterruptionRequested()) + break; + qDebug() << "run!!"; + + // m_pRTMSA_Out->measurementData()->setValue(matData); + } +} + +//============================================================================================================= + +QString TimeFrequency::getBuildInfo() +{ + return QString(buildDateTime()) + QString(" - ") + QString(buildHash()); +} + +} // namespace TIMEFREQUENCYPLUGIN + diff --git a/src/applications/mne_scan/plugins/timefrequency/timefrequency.h b/src/applications/mne_scan/plugins/timefrequency/timefrequency.h new file mode 100644 index 00000000000..797cda20f1e --- /dev/null +++ b/src/applications/mne_scan/plugins/timefrequency/timefrequency.h @@ -0,0 +1,135 @@ +//============================================================================================================= +/** + * @file timefrequency.h + * @author Juan Garcia-Prieto ; + * @since 0.1.0 + * @date March, 2023 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan Garcia-Prieto. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Contains the declaration of the TimeFrequency plugin class. + * + */ + +#ifndef TIMEFREQUENCY_H +#define TIMEFREQUENCY_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "timefrequency_global.h" +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include +#include +#include + +//============================================================================================================= +// EIGEN INCLUDES +//============================================================================================================= + + +//============================================================================================================= +// FORWARD DECLARATIONS +//============================================================================================================= + +namespace SCMEASLIB { +class RealTimeMultiSampleArray; +} + +namespace FIFFLIB { +class FiffInfo; +} + +//============================================================================================================= +// DEFINE NAMESPACE TIMEFREQUENCYPLUGIN +//============================================================================================================= + +namespace TIMEFREQUENCYPLUGIN { + +//============================================================================================================= +// TIMEFREQUENCYPLUGIN FORWARD DECLARATIONS +//============================================================================================================= + +//============================================================================================================= +/** + * DECLARE CLASS TimeFrequency + * @brief The TimeFrequency class provides a tools to compute and show time-frequency maps. */ +class TIMEFREQUENCYSHARED_EXPORT TimeFrequency : public SCSHAREDLIB::AbstractAlgorithm +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "scsharedlib/1.0" FILE "timefrequency.json") + Q_INTERFACES(SCSHAREDLIB::AbstractAlgorithm) + + public: + //========================================================================================================= + /** + * Constructs a TimeFrequency. + */ + TimeFrequency(); + + //========================================================================================================= + /** + * Destroys the TimeFrequency. + */ + ~TimeFrequency(); + + //========================================================================================================= + /** + * AbstractAlgorithm functions + */ + virtual QSharedPointer clone() const; + virtual void init(); + virtual void unload(); + virtual bool start(); + virtual bool stop(); + virtual AbstractPlugin::PluginType getType() const; + virtual QString getName() const; + virtual QWidget* setupWidget(); + virtual QString getBuildInfo(); + protected: + virtual void run(); + //========================================================================================================= + + public: + //========================================================================================================= + void update(QSharedPointer pMeasurement); + /** + * Other methods can go here... + */ + + private: + QSharedPointer > m_pRTMSA_In; /**< The RealTimeMultiSampleArray of the TimeFrequency input.*/ + QSharedPointer > m_pRTMSA_Out; /**< The RealTimeMultiSampleArray to provide time-frequency data to other plugins.*/ + //QSharedPointer m_pFiffInfo; /**< Fiff measurement info.*/ +}; + +} // namespace TIMEFREQUENCYPLUGIN + +#endif // TIMEFREQUENCY_PLUGIN_MNESCAN diff --git a/src/applications/mne_scan/plugins/timefrequency/timefrequency.json b/src/applications/mne_scan/plugins/timefrequency/timefrequency.json new file mode 100644 index 00000000000..e69de29bb2d diff --git a/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.cpp b/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.cpp new file mode 100644 index 00000000000..4a97f66117f --- /dev/null +++ b/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.cpp @@ -0,0 +1,55 @@ +//============================================================================================================= +/** + * @file timefrequency_global.cpp + * @author Juan G Prieto ; + * Gabriel B Motta ; + * @since 0.1.9 + * @date September, 2021 + * + * @section LICENSE + * + * Copyright (C) 2023, Juan G Prieto, Gabriel B Motta. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief timefrequency plugin global definitions. + * + */ + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include "timefrequency_global.h" + +//============================================================================================================= +// DEFINE METHODS +//============================================================================================================= + +const char* TIMEFREQUENCYPLUGIN::buildDateTime(){ return UTILSLIB::dateTimeNow();} + +//============================================================================================================= + +const char* TIMEFREQUENCYPLUGIN::buildHash(){ return UTILSLIB::gitHash();} + +//============================================================================================================= + +const char* TIMEFREQUENCYPLUGIN::buildHashLong(){ return UTILSLIB::gitHashLong();} + diff --git a/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.h b/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.h new file mode 100644 index 00000000000..b44538d88ec --- /dev/null +++ b/src/applications/mne_scan/plugins/timefrequency/timefrequency_global.h @@ -0,0 +1,84 @@ +//============================================================================================================= +/** + @file timefrequency_global.h + * @author Christoph Dinh ; + * Lorenz Esch + * @since 0.1.0 + * @date February, 2016 + * + * @section LICENSE + * + * Copyright (C) 2016, Christoph Dinh, Lorenz Esch. All rights reserved. + * + * 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. + * * Neither the name of MNE-CPP authors nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "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 THE COPYRIGHT OWNER OR CONTRIBUTORS 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. + * + * + * @brief Contains the TimeFrequency library export/import macros. + * + */ + +#ifndef TIMEFREQUENCY_GLOBAL_H +#define TIMEFREQUENCY_GLOBAL_H + +//============================================================================================================= +// INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// QT INCLUDES +//============================================================================================================= + +#include + +//============================================================================================================= +// PREPROCESSOR DEFINES +//============================================================================================================= + +#if defined(SCAN_TIMEFREQUENCY_PLUGIN) +# define TIMEFREQUENCYSHARED_EXPORT Q_DECL_EXPORT /**< Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library. */ +#else +# define TIMEFREQUENCYSHARED_EXPORT Q_DECL_IMPORT /**< Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library. */ +#endif + +namespace TIMEFREQUENCYPLUGIN { + +//============================================================================================================= +/** + * Returns build date and time. + */ +TIMEFREQUENCYSHARED_EXPORT const char* buildDateTime(); + +//============================================================================================================= +/** + * Returns abbreviated build git hash. + */ +TIMEFREQUENCYSHARED_EXPORT const char* buildHash(); + +//============================================================================================================= +/** + * Returns full build git hash. + */ +TIMEFREQUENCYSHARED_EXPORT const char* buildHashLong(); + +} // namespace TIMEFREQUENCYPLUGIN + +#endif // TIMEFREQUENCY_GLOBAL_H +