diff --git a/Modules/US/CMakeLists.txt b/Modules/US/CMakeLists.txt index b4459daf79..f64ded5999 100644 --- a/Modules/US/CMakeLists.txt +++ b/Modules/US/CMakeLists.txt @@ -1,16 +1,17 @@ MITK_CREATE_MODULE( SUBPROJECTS INCLUDE_DIRS USControlInterfaces USFilters USModel INTERNAL_INCLUDE_DIRS ${INCLUDE_DIRS_INTERNAL} PACKAGE_DEPENDS Poco DEPENDS MitkOpenCVVideoSupport MitkQtWidgetsExt MitkIGTBase MitkOpenIGTLink WARNINGS_AS_ERRORS ) ## create US config #CONFIGURE_FILE(mitkUSConfig.h.in ${PROJECT_BINARY_DIR}/mitkUSConfig.h @ONLY) ADD_SUBDIRECTORY(USHardwareTelemed) +ADD_SUBDIRECTORY(USHardwareFraunhofer) ADD_SUBDIRECTORY(USNavigation) ADD_SUBDIRECTORY(Testing) diff --git a/Modules/US/USHardwareFraunhofer/CMakeLists.txt b/Modules/US/USHardwareFraunhofer/CMakeLists.txt new file mode 100644 index 0000000000..91d2db2f3e --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/CMakeLists.txt @@ -0,0 +1,19 @@ +IF(WIN32) + +OPTION(MITK_USE_US_FRAUNHOFER_SDK "Enable support for Fraunhofer api devices" OFF) + +IF(MITK_USE_US_FRAUNHOFER_SDK) + +SET(MITK_US_FRAUNHOFER_SDK_PATH "" CACHE PATH "Path to Fraunhofer SDK header files.") + +MITK_CREATE_MODULE( + SUBPROJECTS + DEPENDS MitkUS + INCLUDE_DIRS "${MITK_US_FRAUNHOFER_SDK_PATH}" + INTERNAL_INCLUDE_DIRS ${INCLUDE_DIRS_INTERNAL} + AUTOLOAD_WITH MitkUS +) + +ENDIF(MITK_USE_US_FRAUNHOFER_SDK) + +ENDIF(WIN32) diff --git a/Modules/US/USHardwareFraunhofer/files.cmake b/Modules/US/USHardwareFraunhofer/files.cmake new file mode 100644 index 0000000000..384e160443 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/files.cmake @@ -0,0 +1,10 @@ +SET(CPP_FILES +mitkUSFraunhoferActivator.cpp +mitkUSFraunhoferDevice.cpp +mitkUSFraunhoferImageSource.cpp +mitkUSFraunhoferProbe.cpp +mitkUSFraunhoferSDKHeader.cpp +mitkUSFraunhoferBModeControls.cpp +mitkUSFraunhoferDopplerControls.cpp +mitkUSFraunhoferProbesControls.cpp +) diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.cpp new file mode 100644 index 0000000000..05a2553620 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.cpp @@ -0,0 +1,40 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferActivator.h" + +mitk::USFraunhoferActivator::USFraunhoferActivator() +{ + MITK_INFO << "USFraunhoferActivator created"; +} + +mitk::USFraunhoferActivator::~USFraunhoferActivator() +{ +} + +void mitk::USFraunhoferActivator::Load(us::ModuleContext* context) +{ + // create a new device + m_Device = mitk::USFraunhoferDevice::New("Fraunhofer", "Ultrasound System"); + m_Device->Initialize(); +} + +void mitk::USFraunhoferActivator::Unload(us::ModuleContext* context) +{ + // set smart pointer to null (device will be unregistered from + // micro service in it's destrcutor) + m_Device = 0; +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.h new file mode 100644 index 0000000000..298b336508 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferActivator.h @@ -0,0 +1,53 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef __mitkUSFraunhoferActivator_h +#define __mitkUSFraunhoferActivator_h + +#include "mitkUSFraunhoferDevice.h" + +// Microservices +#include +#include + +namespace mitk +{ + class USFraunhoferActivator : public us::ModuleActivator { + public: + + USFraunhoferActivator(); + virtual ~USFraunhoferActivator(); + + /** + * \brief Fraunhofer device is created and initialized on module load. + * Service registration is done during the initialization process. + */ + void Load(us::ModuleContext* context); + + /** + * \brief Device pointer is removed on module unload. + * Service deregistration is done in the device destructor. + */ + void Unload(us::ModuleContext* context); + + protected: + USFraunhoferDevice::Pointer m_Device; + }; +} // namespace mitk + +US_EXPORT_MODULE_ACTIVATOR(mitk::USFraunhoferActivator) + +#endif // __mitkUSFraunhoferActivator_h \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.cpp new file mode 100644 index 0000000000..c94c1ce4a6 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.cpp @@ -0,0 +1,193 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferBModeControls.h" +#include "mitkUSFraunhoferDevice.h" +#include + +#define Fraunhofer_FREQUENCY_FACTOR 1000000 + +mitk::USFraunhoferBModeControls::USFraunhoferBModeControls(itk::SmartPointer device) +: mitk::USControlInterfaceBMode(device.GetPointer()), + m_Active(false), m_PowerSteps(new double[3]), + m_GainSteps(new double[3]), m_RejectionSteps(new double[3]), + m_DynamicRangeSteps(new double[3]) +{ +} + +mitk::USFraunhoferBModeControls::~USFraunhoferBModeControls() +{ + //this->ReleaseControls(); + + delete[] m_PowerSteps; + delete[] m_GainSteps; + delete[] m_RejectionSteps; + delete[] m_DynamicRangeSteps; +} + + +/*void mitk::USFraunhoferBModeControls::ReinitializeControls() +{ + this->ReleaseControls(); + this->CreateControls(); +} +*/ +void mitk::USFraunhoferBModeControls::SetIsActive(bool active) +{ + if (active) + { + //this->CreateControls(); + m_Active = true; + } + else + { + //this->ReleaseControls(); + m_Active = false; + } +} + +bool mitk::USFraunhoferBModeControls::GetIsActive() +{ + return m_Active; +} + +double mitk::USFraunhoferBModeControls::GetScanningFrequency() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningFrequency(double value) +{ +} + +std::vector mitk::USFraunhoferBModeControls::GetScanningFrequencyValues() +{ + std::vector h; + h.push_back(3); + return h; +} + +double mitk::USFraunhoferBModeControls::GetScanningPower() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningPower(double value) +{ +} + +double mitk::USFraunhoferBModeControls::GetScanningPowerMin() +{ + return m_PowerSteps[0]; +} + +double mitk::USFraunhoferBModeControls::GetScanningPowerMax() +{ + return m_PowerSteps[1]; +} + +double mitk::USFraunhoferBModeControls::GetScanningPowerTick() +{ + return m_PowerSteps[2]; +} + +double mitk::USFraunhoferBModeControls::GetScanningDepth() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningDepth(double value) +{ +} + +std::vector mitk::USFraunhoferBModeControls::GetScanningDepthValues() +{ + std::vector h; + h.push_back(3); + return h; +} + +double mitk::USFraunhoferBModeControls::GetScanningGain() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningGain(double value) +{ +} + +double mitk::USFraunhoferBModeControls::GetScanningGainMin() +{ + return m_GainSteps[0]; +} + +double mitk::USFraunhoferBModeControls::GetScanningGainMax() +{ + return m_GainSteps[1]; +} + +double mitk::USFraunhoferBModeControls::GetScanningGainTick() +{ + return m_GainSteps[2]; +} + +double mitk::USFraunhoferBModeControls::GetScanningRejection() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningRejection(double value) +{ +} + +double mitk::USFraunhoferBModeControls::GetScanningRejectionMin() +{ + return m_RejectionSteps[0]; +} + +double mitk::USFraunhoferBModeControls::GetScanningRejectionMax() +{ + return m_RejectionSteps[1]; +} + +double mitk::USFraunhoferBModeControls::GetScanningRejectionTick() +{ + return m_RejectionSteps[2]; +} + +double mitk::USFraunhoferBModeControls::GetScanningDynamicRange() +{ + return 0; +} + +void mitk::USFraunhoferBModeControls::OnSetScanningDynamicRange(double value) +{ +} + +double mitk::USFraunhoferBModeControls::GetScanningDynamicRangeMin() +{ + return m_DynamicRangeSteps[0]; +} + +double mitk::USFraunhoferBModeControls::GetScanningDynamicRangeMax() +{ + return m_DynamicRangeSteps[1]; +} + +double mitk::USFraunhoferBModeControls::GetScanningDynamicRangeTick() +{ + return m_DynamicRangeSteps[2]; +} diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.h new file mode 100644 index 0000000000..2e1cb9b388 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferBModeControls.h @@ -0,0 +1,94 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferBModeControls_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferBModeControls_H_HEADER_INCLUDED_ + +#include "mitkUSFraunhoferSDKHeader.h" +#include "mitkUSControlInterfaceBMode.h" + +#include + +namespace mitk { + class USFraunhoferDevice; + + /** + * \brief Implementation of mitk::USControlInterfaceBMode for Fraunhofer ultrasound devices. + * See documentation of mitk::USControlInterfaceBMode for a description of the interface methods. + */ + class USFraunhoferBModeControls : public USControlInterfaceBMode + { + public: + mitkClassMacro(USFraunhoferBModeControls, USControlInterfaceBMode); + mitkNewMacro1Param(Self, itk::SmartPointer); + + /** + * Scan mode is set to b mode when this controls are activated. + * All necessary controls are created at the Fraunhofer API. + */ + virtual void SetIsActive( bool ); + + /** + * \return true if API controls are created and scan mode is set to b mode + */ + virtual bool GetIsActive( ); + + virtual double GetScanningFrequency( ); + virtual void OnSetScanningFrequency( double frequency ); + virtual std::vector GetScanningFrequencyValues( ); + + virtual double GetScanningPower( ); + virtual void OnSetScanningPower( double power ); + virtual double GetScanningPowerMin( ); + virtual double GetScanningPowerMax( ); + virtual double GetScanningPowerTick( ); + + virtual double GetScanningDepth( ); + virtual void OnSetScanningDepth( double ); + virtual std::vector GetScanningDepthValues( ); + + virtual double GetScanningGain( ); + virtual void OnSetScanningGain( double ); + virtual double GetScanningGainMin( ); + virtual double GetScanningGainMax( ); + virtual double GetScanningGainTick( ); + + virtual double GetScanningRejection( ); + virtual void OnSetScanningRejection( double ); + virtual double GetScanningRejectionMin( ); + virtual double GetScanningRejectionMax( ); + virtual double GetScanningRejectionTick( ); + + virtual double GetScanningDynamicRange( ); + virtual void OnSetScanningDynamicRange( double ); + virtual double GetScanningDynamicRangeMin( ); + virtual double GetScanningDynamicRangeMax( ); + virtual double GetScanningDynamicRangeTick( ); + + protected: + USFraunhoferBModeControls(itk::SmartPointer device); + virtual ~USFraunhoferBModeControls(); + + bool m_Active; + + double* m_PowerSteps; // array holding possible power values: [min, max, tick] + double* m_GainSteps; // array holding possible gains: [min, max, tick] + double* m_RejectionSteps; // array holding possible rejections: [min, max, tick] + double* m_DynamicRangeSteps; // array holding possible dynamic range values: [min, max, tick] + }; +} // namespace mitk + +#endif // MITKUSFraunhoferBModeControls_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.cpp new file mode 100644 index 0000000000..7ff1e9a8d4 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.cpp @@ -0,0 +1,101 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferDevice.h" + +//#include "mitkUSFraunhoferSDKHeader.h" + +mitk::USFraunhoferDevice::USFraunhoferDevice(std::string manufacturer, std::string model) +: mitk::USDevice(manufacturer, model){} + +mitk::USFraunhoferDevice::~USFraunhoferDevice() +{ +} + +std::string mitk::USFraunhoferDevice::GetDeviceClass() +{ + return "org.mitk.modules.us.USFraunhoferDevice"; +} + +mitk::USControlInterfaceBMode::Pointer mitk::USFraunhoferDevice::GetControlInterfaceBMode() +{ + return nullptr; +} + +mitk::USControlInterfaceProbes::Pointer mitk::USFraunhoferDevice::GetControlInterfaceProbes() +{ + return nullptr; +}; + +mitk::USControlInterfaceDoppler::Pointer mitk::USFraunhoferDevice::GetControlInterfaceDoppler() +{ + return nullptr; +}; + +bool mitk::USFraunhoferDevice::OnInitialization() +{ + + return true; +} + +bool mitk::USFraunhoferDevice::OnConnection() +{ + // create main Fraunhofer API COM library object + + return true; +} + +bool mitk::USFraunhoferDevice::OnDisconnection() +{ + // control objects cannot be active anymore + + ReleaseUsgControls(); + + return true; +} + +bool mitk::USFraunhoferDevice::OnActivation() +{ + // probe controls are available now + + return true; +} + +bool mitk::USFraunhoferDevice::OnDeactivation() +{ + this->StopScanning(); + return true; +} + +void mitk::USFraunhoferDevice::OnFreeze(bool freeze) +{ + +} + +mitk::USImageSource::Pointer mitk::USFraunhoferDevice::GetUSImageSource() +{ + return nullptr; +} + +void mitk::USFraunhoferDevice::ReleaseUsgControls() +{ + +} + +void mitk::USFraunhoferDevice::StopScanning() +{ + +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.h new file mode 100644 index 0000000000..d19ffa6044 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDevice.h @@ -0,0 +1,146 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferDevice_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferDevice_H_HEADER_INCLUDED_ + +#include "mitkUSDevice.h" +#include "mitkUSFraunhoferImageSource.h" +#include "mitkUSFraunhoferProbesControls.h" +#include "mitkUSFraunhoferBModeControls.h" +#include "mitkUSFraunhoferDopplerControls.h" + +#include "mitkUSFraunhoferSDKHeader.h" + +namespace mitk { + /** + * \brief Implementation of mitk::USDevice for Fraunhofer API devices. + * Connects to a Fraunhofer API device through its COM library interface. + * + * This class handles all API communications and creates interfaces for + * b mode, doppler and probes controls. + * Images given by the device are put into an object of + * mitk::USFraunhoferImageSource. + */ + class USFraunhoferDevice : public USDevice + { + public: + mitkClassMacro(USFraunhoferDevice, mitk::USDevice); + mitkNewMacro2Param(Self, std::string, std::string); + + /** + * \brief Returns the class of the device. + */ + virtual std::string GetDeviceClass(); + + virtual USControlInterfaceBMode::Pointer GetControlInterfaceBMode(); + virtual USControlInterfaceProbes::Pointer GetControlInterfaceProbes(); + virtual USControlInterfaceDoppler::Pointer GetControlInterfaceDoppler(); + + /** + * \brief Is called during the initialization process. + * There is nothing done on the initialization of a mik::USFraunhoferDevive object. + * + * \return always true + */ + virtual bool OnInitialization(); + + /** + * \brief Is called during the connection process. + * Connect to the Fraunhofer API. + * + * \return true if successfull, false if no device is connected to the pc + * \throws mitk::Exception if something goes wrong at the API calls + */ + virtual bool OnConnection(); + + /** + * \brief Is called during the disconnection process. + * Deactivate and remove all Fraunhofer API controls. A disconnect from the + * Fraunhofer API is not possible for which reason the hardware stays in connected + * state even after calling this method. + * + * \return always true + * \throws mitk::Exception if something goes wrong at the API calls + */ + virtual bool OnDisconnection(); + + /** + * \brief Is called during the activation process. + * After this method is finished, the device is generating images in b mode. + * Changing scanning mode is possible afterwards by using the appropriate + * control interfaces. + * + * \return always true + * \throws mitk::Exception if something goes wrong at the API calls + */ + virtual bool OnActivation(); + + /** + * \brief Is called during the deactivation process. + * After a call to this method the device is connected, but not producing images anymore. + * + * \return always true + * \throws mitk::Exception if something goes wrong at the API calls + */ + virtual bool OnDeactivation(); + + /** + * \brief Changes scan state of the device if freeze is toggeled in mitk::USDevice. + */ + virtual void OnFreeze(bool freeze); + + /** @return Returns the current image source of this device. */ + USImageSource::Pointer GetUSImageSource( ); + + protected: + /** + * Constructs a mitk::USFraunhoferDevice object by given manufacturer + * and model string. These strings are just for labeling the device + * in the micro service. + * + * Control interfaces and image source are available directly after + * construction. Registration at the micro service happens not before + * initialization method was called. + */ + USFraunhoferDevice(std::string manufacturer, std::string model); + virtual ~USFraunhoferDevice(); + + void ReleaseUsgControls( ); + + /** + * \brief Stop ultrasound scanning by Fraunhofer API call. + * + * \throw mitk::Exception if API call returned with an error + */ + void StopScanning( ); + + /*USFraunhoferProbesControls::Pointer m_ControlsProbes; + USFraunhoferBModeControls::Pointer m_ControlsBMode; + USFraunhoferDopplerControls::Pointer m_ControlsDoppler; + + USFraunhoferImageSource::Pointer m_ImageSource;*/ + + /** + * The Fraunhofer API expects callback functions to pass + * both status messages and the processed images to the user. + * The message callback is here, the data itself is given directly to the image source. + */ + void stringMessageCallback(char* message); + }; +} // namespace mitk + +#endif // MITKUSFraunhoferDevice_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.cpp new file mode 100644 index 0000000000..59d7ea77d2 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.cpp @@ -0,0 +1,38 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferDopplerControls.h" +#include "mitkUSFraunhoferDevice.h" +#include + +mitk::USFraunhoferDopplerControls::USFraunhoferDopplerControls(itk::SmartPointer device) + : mitk::USControlInterfaceDoppler(device.GetPointer()) +{ +} + +mitk::USFraunhoferDopplerControls::~USFraunhoferDopplerControls() +{ +} + +void mitk::USFraunhoferDopplerControls::SetIsActive(bool isActive) +{ + m_IsActive = isActive; +} + +bool mitk::USFraunhoferDopplerControls::GetIsActive() +{ + return m_IsActive; +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.h new file mode 100644 index 0000000000..860b63eea7 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferDopplerControls.h @@ -0,0 +1,50 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferDopplerControls_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferDopplerControls_H_HEADER_INCLUDED_ + +#include "mitkUSFraunhoferSDKHeader.h" +#include "mitkUSControlInterfaceDoppler.h" + +#include + +namespace mitk { + class USFraunhoferDevice; + /** + * \brief Implementation of mitk::USControlInterfaceDoppler for Fraunhofer ultrasound devices. + * See documentation of mitk::USControlInterfaceBMode for a description of the interface methods. + * + * This implementation does nothing, yet! + */ + class USFraunhoferDopplerControls : public USControlInterfaceDoppler + { + public: + mitkClassMacro(USFraunhoferDopplerControls, USControlInterfaceDoppler); + mitkNewMacro1Param(Self, itk::SmartPointer); + + virtual void SetIsActive(bool); + virtual bool GetIsActive(); + + protected: + USFraunhoferDopplerControls(itk::SmartPointer device); + virtual ~USFraunhoferDopplerControls(); + + bool m_IsActive; + }; +} + +#endif // MITKUSFraunhoferDopplerControls_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.cpp new file mode 100644 index 0000000000..cd9fce79bd --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.cpp @@ -0,0 +1,62 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferImageSource.h" +#include "mitkUSFraunhoferSDKHeader.h" +#include "mitkImageReadAccessor.h" + +mitk::USFraunhoferImageSource::USFraunhoferImageSource() + : m_Image(mitk::Image::New()) +{ + +} + +mitk::USFraunhoferImageSource::~USFraunhoferImageSource( ) +{ + +} + +void mitk::USFraunhoferImageSource::GetNextRawImage( mitk::Image::Pointer& image) +{ + if(image.IsNull()) { + image = mitk::Image::New(); + } + +} + +void newDataCallback( + short* rfDataChannelData, + int channelDataChannelsPerDataset, + int channelDataSamplesPerChannel, + int channelDataTotalDatasets, + + short* rfDataArrayBeamformed, + int beamformedLines, + int beamformedSamples, + int beamformedTotalDatasets, + + unsigned char* imageData, + int imageWidth, + int imageHeight, + int imageBytesPerPixel, + int imageSetsTotal, + + double timeStamp) +{ + if (imageData != nullptr) + { + } +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.h new file mode 100644 index 0000000000..6d79616666 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferImageSource.h @@ -0,0 +1,78 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferImageSource_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferImageSource_H_HEADER_INCLUDED_ + +#include "mitkUSImageSource.h" +#include "mitkUSFraunhoferSDKHeader.h" + +#include "itkFastMutexLock.h" + +namespace mitk { +/** + * \brief Implementation of mitk::USImageSource for Fraunhofer API devices. + * The method mitk::USImageSource::GetNextRawImage() is implemented for + * getting images from the Fraunhofer API. + * + * A method for connecting this ImageSource to the Fraunhofer API is + * implemented (mitk::USFraunhoferImageSource::CreateAndConnectConverterPlugin()). + * This method is available for being used by mitk::USFraunhoferDevice. + */ +class USFraunhoferImageSource : public USImageSource +{ +public: + mitkClassMacro(USFraunhoferImageSource, USImageSource); + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + /** + * Implementation of the superclass method. Returns the pointer + * to the mitk::Image filled by Fraunhofer API callback. + */ + virtual void GetNextRawImage( mitk::Image::Pointer& ); + + /** + * The API calls this function to pass the image data to the + * user; here the m_Image is updated + */ + void newDataCallback( + short* rfDataChannelData, + int channelDataChannelsPerDataset, + int channelDataSamplesPerChannel, + int channelDataTotalDatasets, + + short* rfDataArrayBeamformed, + int beamformedLines, + int beamformedSamples, + int beamformedTotalDatasets, + + unsigned char* imageData, + int imageWidth, + int imageHeight, + int imageBytesPerPixel, + int imageSetsTotal, + + double timeStamp); + +protected: + USFraunhoferImageSource( ); + virtual ~USFraunhoferImageSource( ); + mitk::Image::Pointer m_Image; +}; +} // namespace mitk + +#endif // MITKUSFraunhoferImageSource_H diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.cpp new file mode 100644 index 0000000000..e999dd8f9e --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.cpp @@ -0,0 +1,26 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferProbe.h" +#include "mitkUSFraunhoferSDKHeader.h" + +mitk::USFraunhoferProbe::USFraunhoferProbe() +{ +} + +mitk::USFraunhoferProbe::~USFraunhoferProbe() +{ +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.h new file mode 100644 index 0000000000..0dd9451903 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbe.h @@ -0,0 +1,55 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferProbe_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferProbe_H_HEADER_INCLUDED_ + +#include "mitkUSProbe.h" + +namespace Usgfw2Lib { + struct IProbe; + struct IUsgDataView; +} + +namespace mitk +{ + /** + * \brief Specialized mitk::USProbe for handling Fraunhofer API probe objects. + * It encapsulates a probe object from the Fraunhofer API. + * + * This class should only be instantiated by mitk::USFraunhoferProbesControls. + * Every other object can get instances of mitk::USFraunhoferProbe from there. + */ + class USFraunhoferProbe : public USProbe + { + public: + mitkClassMacro(USFraunhoferProbe, USProbe); + itkNewMacro(Self); + + protected: + /** + * Constructs mitk::USFraunhoferProbe object with given API objects. + * + * \param probe API probe object which should be represented by the constructed object + * \param dataView API data view object conected to this probe object + */ + USFraunhoferProbe(); + virtual ~USFraunhoferProbe(); + + }; +} // namespace mitk + +#endif // MITKUSFraunhoferProbe_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.cpp new file mode 100644 index 0000000000..185bffb224 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.cpp @@ -0,0 +1,90 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#include "mitkUSFraunhoferProbesControls.h" +#include "mitkUSFraunhoferDevice.h" +#include + +mitk::USFraunhoferProbesControls::USFraunhoferProbesControls(itk::SmartPointer device) + : mitk::USControlInterfaceProbes(device.GetPointer()), + m_IsActive(false), m_FraunhoferDevice(device) +{ +} + +mitk::USFraunhoferProbesControls::~USFraunhoferProbesControls() +{ +} + + +void mitk::USFraunhoferProbesControls::SetIsActive(bool isActive) +{ + m_IsActive = isActive; +} + +bool mitk::USFraunhoferProbesControls::GetIsActive() +{ + return m_IsActive; +} + +std::vector mitk::USFraunhoferProbesControls::GetProbeSet() +{ + // create a new vector of base class (USProbe) objects, because + // interface wants a vector of this type + std::vector usProbes(1, 0); + + return usProbes; +} + +void mitk::USFraunhoferProbesControls::OnSelectProbe(unsigned int index) +{ + +} + +void mitk::USFraunhoferProbesControls::OnSelectProbe(mitk::USProbe::Pointer probe) +{ +} + +mitk::USProbe::Pointer mitk::USFraunhoferProbesControls::GetSelectedProbe() +{ + + return nullptr; +} + +unsigned int mitk::USFraunhoferProbesControls::GetProbesCount() const +{ + return 0; +} + + +void mitk::USFraunhoferProbesControls::ProbeRemoved(unsigned int index) +{ + MITK_INFO << "Probe removed..."; +} + +void mitk::USFraunhoferProbesControls::ProbeAdded(unsigned int index) +{ + MITK_INFO << "Probe arrived..."; +} + +bool mitk::USFraunhoferProbesControls::CreateProbesCollection() +{ + return true; +} + +void mitk::USFraunhoferProbesControls::CreateProbesSet() +{ + +} \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.h new file mode 100644 index 0000000000..8ed3c9092c --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferProbesControls.h @@ -0,0 +1,85 @@ +/*=================================================================== + +The Medical Imaging Interaction Toolkit (MITK) + +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. + +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. + +See LICENSE.txt or http://www.mitk.org for details. + +===================================================================*/ + +#ifndef MITKUSFraunhoferProbesControls_H_HEADER_INCLUDED_ +#define MITKUSFraunhoferProbesControls_H_HEADER_INCLUDED_ + +#include "mitkUSFraunhoferSDKHeader.h" +#include "mitkUSFraunhoferProbe.h" +#include "mitkUSControlInterfaceProbes.h" + +#include + +namespace mitk { + class USFraunhoferDevice; + + /** + * \brief Implementation of mitk::USControlInterfaceProbes for Fraunhofer ultrasound devices. + * See documentation of mitk::USControlInterfaceProbes for a description of the interface methods. + */ + class USFraunhoferProbesControls : public USControlInterfaceProbes + { + public: + mitkClassMacro(USFraunhoferProbesControls, USControlInterfaceProbes); + mitkNewMacro1Param(Self, itk::SmartPointer); + + /** + * Probe informations are fetched on activation. On deactivation there is nothing done. + */ + virtual void SetIsActive(bool); + + virtual bool GetIsActive(); + + virtual std::vector GetProbeSet(); + virtual void OnSelectProbe(unsigned int index); + virtual void OnSelectProbe(USProbe::Pointer probe); + virtual USProbe::Pointer GetSelectedProbe(); + virtual unsigned int GetProbesCount() const; + + void ProbeRemoved(unsigned int index); + void ProbeAdded(unsigned int index); + + protected: + /** + * Constructs an empty object. + * Fraunhofer device has to be set after constructing by calling + * mitk::USFraunhoferProbesControls::SetFraunhoferDevice before the + * object can be used. + */ + USFraunhoferProbesControls(itk::SmartPointer device); + virtual ~USFraunhoferProbesControls(); + + /** + * Create collection object (Fraunhofer API) for the API device. + */ + bool CreateProbesCollection(); + + /** + * Create vector of mitk::USFraunhoferProbe objects from the + * Fraunhofer API probe collection. Hence + * mitk::USFraunhoferProbesControls::CreateProbesCollection has to + * be called before. + */ + void CreateProbesSet(); + + bool m_IsActive; + unsigned int m_SelectedProbeIndex; + std::vector m_ProbesSet; + itk::SmartPointer m_FraunhoferDevice; + }; +} + +#endif // MITKUSFraunhoferProbesControls_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferSDKHeader.cpp b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferSDKHeader.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferSDKHeader.h b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferSDKHeader.h new file mode 100644 index 0000000000..4f88b9c237 --- /dev/null +++ b/Modules/US/USHardwareFraunhofer/mitkUSFraunhoferSDKHeader.h @@ -0,0 +1,234 @@ +// Framework.IBMT.US.CWrapper.h : +// The DiPhAS C Wrapper that enables C++ programs and libraries to use the .NET DiPhAS components. +// It includes functions to initializes the beamformer, apply parameter sets to the beamformer +// operation and control the beamformer scanning state. +// It defines delegate functions for internal messages and data to be passed to outside Dll or application +// code +// +// Written by the IBMT Beamformer Team: support-diphas@ibmt.fraunhofer.de +// Copyright Fraunhofer IBMT + +#ifdef WIN32 +# define CWRAPPERAPI extern "C" __declspec(dllexport) +#else +# define CWRAPPERAPI +#endif + +#pragma once + +#include + +//namespace IBMT_US_DiPhAS +//{ + + // This is a function that will be called by the beamformer asynchronously to this program + // It passes status messages to the user + typedef void(__cdecl *StringMessageCallback)(const char* message); + + // This is a function that will be called by the beamformer asynchronously to this program + // It passes the pre-beamformed rf data, beamformed rf data and/or scanconverted image data to the user + // If multiple pre-beamformed rf datasets are used to generate a beamformed datasets all recorded data is included here + typedef void(__cdecl *NewDataCallback)( + short* rfDataChannelData, + int channelDatalinesPerDataset, + int channelDataSamplesPerLine, + int channelDataTotalDatasets, + + short* rfDataArrayBeamformed, + int beamformedLines, + int beamformedSamples, + int beamformedTotalDatasets, // for sequence mode (or interleaved) we will get multiple rf data sets at once depending on beamforming algorithms + + unsigned char* imageData, + int imageWidth, + int imageHeight, + int imagePixelFormat, + int imageSetsTotal, // for sequence mode (or interleaved) we will get multiple images at once depending on beamforming algorithms + double timeStamp); + + typedef enum + { + PlaneWaveCompound = 1, + SphericalReconstruction = 2, + DelayAndSumLineBased = 3, + VirtualPointSource = 4, + Interleaved_OA_US = 5 + } Beamforming; + + typedef struct + { + float usePhaseCoherence; + int SpeedOfSoundMeterPerSecond; + int angleSkipFactor; + } BeamformingParametersPlaneWaveCompound; + + typedef struct + { + int SpeedOfSoundMeterPerSecond; + int angleSkipFactor; + } BeamformingParametersInterleaved_OA_US; + + typedef struct + { + int startEvent; + int endEvent; + } SequenceNative; + + typedef struct + { + bool enabled; + int triggerWidthMicroseconds; + int delayTrigger2Microseconds; // -1 for no second trigger + int constantPulseRepetitionRateHz; + } TriggerSetupNative; + + // The scanmode structure is used to define a beamformer operation state + // It includes parameters for ultrasound excitation, echo reception and further processing. + // This struct can be created and parameterized by the user to define the operation mode. + typedef struct + { + // general info: + char* scanModeName; + + // used transducer paramters: + char* transducerName; + float transducerPitchMeter; + int transducerType; + int transducerFrequencyHz; + int transducerElementCount; + int transducerCurvedRadiusMeter; + + // transmit parameters: + float transmitPhaseLengthSeconds; + int voltageV; + int transmitEventsCount; + + // predefined transmit pattern: + float* transmitEventsDelays; + SequenceNative* transmitSequences; + int transmitSequenceCount; + int* transmitEventsMuxPosition; // [0;7] + int* BurstCountPerChannel; + int* BurstHalfwaveClockCountPerChannel; + bool* BurstUseNegativePolarityPerChannel; + + int BurstHalfwaveClockCountAllChannels; + + // custom transmit pattern: + char** transmitBitPattern; + + + // trigger setup: + TriggerSetupNative triggerSetup; + + // receive parameters: + float receivePhaseLengthSeconds; + unsigned char* tgcdB; + int accumulation; + int averagingCount; + + int averageSpeedOfSound; + + // specify which type of data to be transferred over the API: + bool transferChannelData; + bool transferBeamformedData; + bool transferImageData; + + // reconstruction parameters for rf data: + bool computeBeamforming; + int beamformingAlgorithm; // from the enum Beamforming + void* beamformingAlgorithmParameters; // for example BeamformingParametersPlaneWaveCompound + int reconstructionLines; + int reconstructionSamplesPerLine; + float reconstructedLinePitchMmOrAngleDegree; + + bool bandpassApply; + bool bandpassFrequencyLowHz; + bool bandpassFrequencyHighHz; + + + // reconstruction parameters for image data: + int imageWidth; + int imageHeight; + int imageBytesPerPixel; // 1: greyscale only, 4: RGBA 32bit color image data with alpha + float imageMultiplier; + int imageLeveling; + } ScanModeNative; + + // This struct contains information about internal datarates or beamformer parameters + // It can be requested by the API and the data should only be read by the user application. + typedef struct + { + float dataTransferRateMBit; + float reconstructedDatasetsPerSecond; + float systemPRF; + char** customInformation; + int customInformationCount; + } BeamformerStateInfoNative; + + // This struct contains data about the configuration and capabilities of the current + // beamformer installed. It can be requested by the API and the data should only be read + // by the user application. + typedef struct + { + int ClockRateTransmitterInHz; + int ExtraReceiveTimeMicroSeconds; + const char* HardwareInterface; + int MaxNumberOfTransmitEvents; + int MaxSampleRateInHz; + float MaxTxLengthMicroSeconds; + float MaxVoltageInV; + int MinTransmitterPauseInClocksBySwitchingPosNeg; + bool MultiplexerAvailable; + int NumberOfChannels; + unsigned int NumberOfChannelsPerFrontend; + unsigned int NumberOfFrontends; + int* PossibleAccumulations; + int PossibleAccumulationsCount; + int SamplesTransferIntervalSize; + } BeamformerCapabilitiesNative; + + // This function created the beamformer class and sets up the Platform Setup. + // The callback functions specified are used for further information and data transmission + // from the beamformer implementation to the user code. + // It is possible to get information strings, pre-beamformed channel data of transducer elements, + // beamformed data including postprocessing and the final image data after scan conversion of + // the beamformed data. + CWRAPPERAPI bool createBeamformer( + StringMessageCallback stringMessageCallback, + NewDataCallback newDataCallback); + + // This function established the communication to the beamformer and starts it initially + CWRAPPERAPI bool initBeamformer(); + + // This function configures the current scan mode according to the content of the + // passed "ScanModeNative" instance. This function blocks until the new scan mode is set. + CWRAPPERAPI bool setupScan(ScanModeNative scanMode); + + // the function requests the beamformer capabilities of the connected beamformer system. + // It returns an instance of the "BeamformerCapabilitiesNative" struct. + CWRAPPERAPI void getBeamformerCapabilities(BeamformerCapabilitiesNative* caps); + + // This function closes the hardware interface connection and frees all resources used + // during measurements. + CWRAPPERAPI void closeBeamformer(); + + // This function starts or stops the beamformer permanent scanning operation according + // to its previous state. Data will be send permanently to the user code using the delegate + // functions for each measurement until this function is called again to stop the operation again. + // For single measurement the function "makeSingleScan" can be used. + CWRAPPERAPI bool toggleFreeze(); + + // the function requests the current internal information for the set up operation + // mode and returns it in an instance of the "BeamformerStateInfoNative" struct. + CWRAPPERAPI void getSystemInfo(BeamformerStateInfoNative* infos); + + // a function to trigger a single sequence defined in the ScanMode that has to be + // set previously using "bool setupScan(ScanModeNative scanMode)". + // Data will be send over the delegate functions specified in "initBeamformer" once. + CWRAPPERAPI void makeSingleScan(); + + // Send costum commands directly to beamformer. + CWRAPPERAPI void CustomCommand(std::string command); + +//} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp index e51bb0bf11..196fa4988f 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,498 +1,498 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include //Mitk #include #include #include #include #include // Qmitk #include "UltrasoundSupport.h" // Qt #include #include #include // Ultrasound #include "mitkUSDevice.h" #include "QmitkUSAbstractCustomWidget.h" #include #include #include "usServiceReference.h" #include "internal/org_mitk_gui_qt_ultrasound_Activator.h" const std::string UltrasoundSupport::VIEW_ID = "org.mitk.views.ultrasoundsupport"; void UltrasoundSupport::SetFocus() { } void UltrasoundSupport::CreateQtPartControl( QWidget *parent ) { //initialize timers m_UpdateTimer = new QTimer(this); m_RenderingTimer2d = new QTimer(this); m_RenderingTimer3d = new QTimer(this); // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); //load persistence data before connecting slots (so no slots are called in this phase...) LoadUISettings(); //connect signals and slots... connect( m_Controls.m_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this, SLOT(OnClickedAddNewDevice()) ); // Change Widget Visibilities connect( m_Controls.m_DeviceManagerWidget, SIGNAL(NewDeviceButtonClicked()), this->m_Controls.m_NewVideoDeviceWidget, SLOT(CreateNewDevice()) ); // Init NewDeviceWidget connect( m_Controls.m_ActiveVideoDevices, SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(OnChangedActiveDevice()) ); connect( m_Controls.m_RunImageTimer, SIGNAL(clicked()), this, SLOT(OnChangedActiveDevice()) ); connect( m_Controls.m_ShowImageStream, SIGNAL(clicked()), this, SLOT(OnChangedActiveDevice()) ); connect( m_Controls.m_NewVideoDeviceWidget, SIGNAL(Finished()), this, SLOT(OnNewDeviceWidgetDone()) ); // After NewDeviceWidget finished editing connect( m_Controls.m_FrameRatePipeline, SIGNAL(valueChanged(int)), this, SLOT(OnChangedFramerateLimit()) ); connect( m_Controls.m_FrameRate2d, SIGNAL(valueChanged(int)), this, SLOT(OnChangedFramerateLimit()) ); connect( m_Controls.m_FrameRate3d, SIGNAL(valueChanged(int)), this, SLOT(OnChangedFramerateLimit()) ); connect( m_Controls.m_FreezeButton, SIGNAL(clicked()), this, SLOT(OnClickedFreezeButton()) ); connect( m_UpdateTimer, SIGNAL(timeout()), this, SLOT(UpdateImage())); connect( m_RenderingTimer2d, SIGNAL(timeout()), this, SLOT(RenderImage2d())); connect( m_RenderingTimer3d, SIGNAL(timeout()), this, SLOT(RenderImage3d())); connect( m_Controls.m_Update2DView, SIGNAL(clicked()), this, SLOT(StartTimers()) ); connect( m_Controls.m_Update3DView, SIGNAL(clicked()), this, SLOT(StartTimers()) ); // Initializations m_Controls.m_NewVideoDeviceWidget->setVisible(false); std::string filter = "(&(" + us::ServiceConstants::OBJECTCLASS() + "=" + "org.mitk.services.UltrasoundDevice)(" + mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE + "=true))"; m_Controls.m_ActiveVideoDevices->Initialize( mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL ,filter); m_Controls.m_ActiveVideoDevices->SetAutomaticallySelectFirstEntry(true); m_FrameCounterPipeline = 0; m_FrameCounter2d = 0; m_FrameCounter3d = 0; // Create Node for US Stream if (m_Node.IsNull()) { m_Node = mitk::DataNode::New(); m_Node->SetName("US Support Viewing Stream"); //create a dummy image (gray values 0..255) for correct initialization of level window, etc. mitk::Image::Pointer dummyImage = mitk::ImageGenerator::GenerateRandomImage(100, 100, 1, 1, 1, 1, 1, 255,0); m_Node->SetData(dummyImage); m_OldGeometry = dynamic_cast(dummyImage->GetGeometry()); } m_Controls.tabWidget->setTabEnabled(1, false); } void UltrasoundSupport::OnClickedAddNewDevice() { m_Controls.m_NewVideoDeviceWidget->setVisible(true); m_Controls.m_DeviceManagerWidget->setVisible(false); m_Controls.m_Headline->setText("Add New Video Device:"); m_Controls.m_WidgetActiveDevices->setVisible(false); } void UltrasoundSupport::UpdateImage() { //Update device m_Device->Modified(); m_Device->Update(); //Only update the view if the image is shown if(m_Controls.m_ShowImageStream->isChecked()) { //Update data node mitk::Image::Pointer curOutput = m_Device->GetOutput(); if(curOutput->IsEmpty()) { m_Node->SetName("No Data received yet ..."); //create a noise image for correct initialization of level window, etc. mitk::Image::Pointer randomImage = mitk::ImageGenerator::GenerateRandomImage(32, 32, 1, 1, 1, 1, 1, 255,0); m_Node->SetData(randomImage); curOutput->SetGeometry(randomImage->GetGeometry()); } else { m_Node->SetName("US Support Viewing Stream"); m_Node->SetData(curOutput); } // if the geometry changed: reinitialize the ultrasound image if((m_OldGeometry.IsNotNull()) && (curOutput->GetGeometry() != NULL) && (!mitk::Equal(m_OldGeometry.GetPointer(),curOutput->GetGeometry(),0.0001,false)) ) { mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); if ( (renderWindow != NULL) && (curOutput->GetTimeGeometry()->IsValid()) && (m_Controls.m_ShowImageStream->isChecked()) ) { renderWindow->GetRenderingManager()->InitializeViews( curOutput->GetGeometry(), mitk::RenderingManager::REQUEST_UPDATE_ALL, true ); renderWindow->GetRenderingManager()->RequestUpdateAll(); } m_CurrentImageWidth = curOutput->GetDimension(0); m_CurrentImageHeight = curOutput->GetDimension(1); m_OldGeometry = dynamic_cast(curOutput->GetGeometry()); } } //Update frame counter m_FrameCounterPipeline ++; if (m_FrameCounterPipeline >= 10) { //compute framerate of pipeline update int nMilliseconds = m_Clock.restart(); int fps = 10000.0f / (nMilliseconds ); m_FPSPipeline = fps; m_FrameCounterPipeline = 0; //display lowest framerate in UI int lowestFPS=m_FPSPipeline; if (m_Controls.m_Update2DView->isChecked() && (m_FPS2disChecked() && (m_FPS3dsetText("Current Framerate: "+ QString::number(lowestFPS) +" FPS"); } } void UltrasoundSupport::RenderImage2d() { this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_2DWINDOWS); m_FrameCounter2d ++; if (m_FrameCounter2d >= 10) { //compute framerate of 2d render window update int nMilliseconds = m_Clock2d.restart(); int fps = 10000.0f / (nMilliseconds ); m_FPS2d = fps; m_FrameCounter2d = 0; } } void UltrasoundSupport::RenderImage3d() { this->RequestRenderWindowUpdate(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); m_FrameCounter3d ++; if (m_FrameCounter3d >= 10) { //compute framerate of 2d render window update int nMilliseconds = m_Clock3d.restart(); int fps = 10000.0f / (nMilliseconds ); m_FPS3d = fps; m_FrameCounter3d = 0; } } void UltrasoundSupport::OnChangedFramerateLimit() { StopTimers(); int intervalPipeline = (1000 / m_Controls.m_FrameRatePipeline->value()); int interval2D = (1000 / m_Controls.m_FrameRate2d->value()); int interval3D = (1000 / m_Controls.m_FrameRate3d->value()); SetTimerIntervals(intervalPipeline,interval2D,interval3D); StartTimers(); } void UltrasoundSupport::OnClickedFreezeButton() { if ( m_Device.IsNull() ) { MITK_WARN("UltrasoundSupport") << "Freeze button clicked though no device is selected."; return; } if ( m_Device->GetIsFreezed() ) { m_Device->SetIsFreezed(false); m_Controls.m_FreezeButton->setText("Freeze"); } else { m_Device->SetIsFreezed(true); m_Controls.m_FreezeButton->setText("Start Viewing Again"); } } void UltrasoundSupport::OnChangedActiveDevice() { //clean up and stop timer StopTimers(); this->RemoveControlWidgets(); this->GetDataStorage()->Remove(m_Node); m_Node->ReleaseData(); //get current device, abort if it is invalid m_Device = m_Controls.m_ActiveVideoDevices->GetSelectedService(); if (m_Device.IsNull()) { m_Controls.tabWidget->setTabEnabled(1, false); return; } //create the widgets for this device and enable the widget tab this->CreateControlWidgets(); m_Controls.tabWidget->setTabEnabled(1, true); //show node if the option is enabled if(m_Controls.m_ShowImageStream->isChecked()) { this->GetDataStorage()->Add(m_Node); } //start timer if(m_Controls.m_RunImageTimer->isChecked()) { int intervalPipeline = (1000 / m_Controls.m_FrameRatePipeline->value()); int interval2D = (1000 / m_Controls.m_FrameRate2d->value()); int interval3D = (1000 / m_Controls.m_FrameRate3d->value()); SetTimerIntervals(intervalPipeline,interval2D,interval3D); StartTimers(); m_Controls.m_TimerWidget->setEnabled(true); } else { m_Controls.m_TimerWidget->setEnabled(false); } } void UltrasoundSupport::OnNewDeviceWidgetDone() { m_Controls.m_NewVideoDeviceWidget->setVisible(false); m_Controls.m_DeviceManagerWidget->setVisible(true); m_Controls.m_Headline->setText("Ultrasound Devices:"); m_Controls.m_WidgetActiveDevices->setVisible(true); } void UltrasoundSupport::CreateControlWidgets() { m_ControlProbesWidget = new QmitkUSControlsProbesWidget(m_Device->GetControlInterfaceProbes(), m_Controls.m_ToolBoxControlWidgets); m_Controls.probesWidgetContainer->addWidget(m_ControlProbesWidget); // create b mode widget for current device m_ControlBModeWidget = new QmitkUSControlsBModeWidget(m_Device->GetControlInterfaceBMode(), m_Controls.m_ToolBoxControlWidgets); m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlBModeWidget, "B Mode Controls"); if ( ! m_Device->GetControlInterfaceBMode() ) { m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); } // create doppler widget for current device m_ControlDopplerWidget = new QmitkUSControlsDopplerWidget(m_Device->GetControlInterfaceDoppler(), m_Controls.m_ToolBoxControlWidgets); m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlDopplerWidget, "Doppler Controls"); if ( ! m_Device->GetControlInterfaceDoppler() ) { m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); } ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); if ( pluginContext ) { std::string filter = "(ork.mitk.services.UltrasoundCustomWidget.deviceClass=" + m_Device->GetDeviceClass() + ")"; QString interfaceName = QString::fromStdString(us_service_interface_iid() ); m_CustomWidgetServiceReference = pluginContext->getServiceReferences(interfaceName, QString::fromStdString(filter)); if (m_CustomWidgetServiceReference.size() > 0) { m_ControlCustomWidget = pluginContext->getService (m_CustomWidgetServiceReference.at(0))->CloneForQt(m_Controls.tab2); m_ControlCustomWidget->SetDevice(m_Device); m_Controls.m_ToolBoxControlWidgets->addItem(m_ControlCustomWidget, "Custom Controls"); } else { m_Controls.m_ToolBoxControlWidgets->addItem(new QWidget(m_Controls.m_ToolBoxControlWidgets), "Custom Controls"); m_Controls.m_ToolBoxControlWidgets->setItemEnabled(m_Controls.m_ToolBoxControlWidgets->count()-1, false); } } // select first enabled control widget for ( int n = 0; n < m_Controls.m_ToolBoxControlWidgets->count(); ++n) { if ( m_Controls.m_ToolBoxControlWidgets->isItemEnabled(n) ) { m_Controls.m_ToolBoxControlWidgets->setCurrentIndex(n); break; } } } void UltrasoundSupport::RemoveControlWidgets() { if(!m_ControlProbesWidget) {return;} //widgets do not exist... nothing to do // remove all control widgets from the tool box widget while (m_Controls.m_ToolBoxControlWidgets->count() > 0) { m_Controls.m_ToolBoxControlWidgets->removeItem(0); } // remove probes widget (which is not part of the tool box widget) m_Controls.probesWidgetContainer->removeWidget(m_ControlProbesWidget); delete m_ControlProbesWidget; m_ControlProbesWidget = 0; delete m_ControlBModeWidget; m_ControlBModeWidget = 0; delete m_ControlDopplerWidget; m_ControlDopplerWidget = 0; // delete custom widget if it is present if ( m_ControlCustomWidget ) { ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); delete m_ControlCustomWidget; m_ControlCustomWidget = 0; if ( m_CustomWidgetServiceReference.size() > 0 ) { pluginContext->ungetService(m_CustomWidgetServiceReference.at(0)); } } } void UltrasoundSupport::OnDeciveServiceEvent(const ctkServiceEvent event) { if ( m_Device.IsNull() || event.getType() != us::ServiceEvent::MODIFIED ) { return; } ctkServiceReference service = event.getServiceReference(); if ( m_Device->GetManufacturer() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_MANUFACTURER)).toString().toStdString() && m_Device->GetName() != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_NAME)).toString().toStdString() ) { return; } if ( ! m_Device->GetIsActive() && m_UpdateTimer->isActive() ) { StopTimers(); } if ( m_CurrentDynamicRange != service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble() ) { m_CurrentDynamicRange = service.getProperty(QString::fromStdString(mitk::USDevice::GetPropertyKeys().US_PROPKEY_BMODE_DYNAMIC_RANGE)).toDouble(); // update level window for the current dynamic range mitk::LevelWindow levelWindow; m_Node->GetLevelWindow(levelWindow); levelWindow.SetAuto(m_Image, true, true); m_Node->SetLevelWindow(levelWindow); } } UltrasoundSupport::UltrasoundSupport() : m_ControlCustomWidget(0), m_ControlBModeWidget(0), m_ControlProbesWidget(0), m_ImageAlreadySetToNode(false), m_CurrentImageWidth(0), m_CurrentImageHeight(0) { ctkPluginContext* pluginContext = mitk::PluginActivator::GetContext(); if ( pluginContext ) { // to be notified about service event of an USDevice pluginContext->connectServiceListener(this, "OnDeciveServiceEvent", QString::fromStdString("(" + us::ServiceConstants::OBJECTCLASS() + "=" + us_service_interface_iid() + ")")); } - // HAAAA! + } UltrasoundSupport::~UltrasoundSupport() { try { StopTimers(); // Get all active devicesand deactivate them to prevent freeze std::vector devices = this->m_Controls.m_ActiveVideoDevices->GetAllServices(); for (int i = 0; i < devices.size(); i ++) { mitk::USDevice::Pointer device = devices[i]; if (device.IsNotNull() && device->GetIsActive()) { device->Deactivate(); device->Disconnect(); } } StoreUISettings(); } catch(std::exception &e) { MITK_ERROR << "Exception during call of destructor! Message: " << e.what(); } } void UltrasoundSupport::StoreUISettings() { QSettings settings; settings.beginGroup(QString::fromStdString(VIEW_ID)); settings.setValue("DisplayImage", QVariant(m_Controls.m_ShowImageStream->isChecked())); settings.setValue("RunImageTimer", QVariant(m_Controls.m_RunImageTimer->isChecked())); settings.setValue("Update2DView", QVariant(m_Controls.m_Update2DView->isChecked())); settings.setValue("Update3DView", QVariant(m_Controls.m_Update3DView->isChecked())); settings.setValue("UpdateRatePipeline", QVariant(m_Controls.m_FrameRatePipeline->value())); settings.setValue("UpdateRate2d", QVariant(m_Controls.m_FrameRate2d->value())); settings.setValue("UpdateRate3d", QVariant(m_Controls.m_FrameRate3d->value())); settings.endGroup(); } void UltrasoundSupport::LoadUISettings() { QSettings settings; settings.beginGroup(QString::fromStdString(VIEW_ID)); m_Controls.m_ShowImageStream->setChecked(settings.value("DisplayImage", true).toBool()); m_Controls.m_RunImageTimer->setChecked(settings.value("RunImageTimer", true).toBool()); m_Controls.m_Update2DView->setChecked(settings.value("Update2DView", true).toBool()); m_Controls.m_Update3DView->setChecked(settings.value("Update3DView", true).toBool()); m_Controls.m_FrameRatePipeline->setValue(settings.value("UpdateRatePipeline", 50).toInt()); m_Controls.m_FrameRate2d->setValue(settings.value("UpdateRate2d", 20).toInt()); m_Controls.m_FrameRate3d->setValue(settings.value("UpdateRate3d", 5).toInt()); settings.endGroup(); } void UltrasoundSupport::StartTimers() { m_UpdateTimer->start(); if (m_Controls.m_Update2DView->isChecked()) {m_RenderingTimer2d->start();} if (m_Controls.m_Update3DView->isChecked()) {m_RenderingTimer3d->start();} } void UltrasoundSupport::StopTimers() { m_UpdateTimer->stop(); m_RenderingTimer2d->stop(); m_RenderingTimer3d->stop(); } void UltrasoundSupport::SetTimerIntervals(int intervalPipeline, int interval2D, int interval3D) { m_UpdateTimer->setInterval(intervalPipeline); m_RenderingTimer2d->setInterval(interval2D); m_RenderingTimer3d->setInterval(interval3D); }