diff --git a/Modules/US/USModel/mitkUSProbe.cpp b/Modules/US/USModel/mitkUSProbe.cpp index 15a89c87c9..d1d0f7abe5 100644 --- a/Modules/US/USModel/mitkUSProbe.cpp +++ b/Modules/US/USModel/mitkUSProbe.cpp @@ -1,83 +1,88 @@ /*=================================================================== 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 "mitkUSProbe.h" #include mitk::USProbe::USProbe() : itk::Object() { } mitk::USProbe::USProbe(std::string identifier) : m_Name(identifier) { } mitk::USProbe::~USProbe() { } bool mitk::USProbe::IsEqualToProbe(mitk::USProbe::Pointer probe) { if (m_Name.compare(probe->GetName()) == 0) return true; else return false; } void mitk::USProbe::SetDepthAndSpacing(int depth, mitk::Vector3D spacing) { m_DepthsAndSpacings.insert(std::pair(depth, spacing)); } std::map mitk::USProbe::GetDepthsAndSpacing() { return m_DepthsAndSpacings; } void mitk::USProbe::SetDepth(int depth) { mitk::Vector3D defaultSpacing; defaultSpacing[0] = 1; defaultSpacing[1] = 1; defaultSpacing[2] = 0; m_DepthsAndSpacings.insert(std::pair(depth, defaultSpacing)); } +void mitk::USProbe::RemoveDepth(int depthToRemove) +{ + m_DepthsAndSpacings.erase(depthToRemove); +} + void mitk::USProbe::SetSpacingForGivenDepth(int givenDepth, Vector3D spacing) { m_DepthsAndSpacings[givenDepth][0] = spacing[0]; m_DepthsAndSpacings[givenDepth][1] = spacing[1]; m_DepthsAndSpacings[givenDepth][2] = spacing[2]; } mitk::Vector3D mitk::USProbe::GetSpacingForGivenDepth(int givenDepth) { mitk::Vector3D spacing; std::map::iterator it = m_DepthsAndSpacings.find(givenDepth); if (it != m_DepthsAndSpacings.end()) //check if given depth really exists { spacing[0] = it->second[0]; spacing[1] = it->second[1]; spacing[2] = it->second[2]; } else { //spacing does not exist, so set default spacing (1,1,0) spacing[0] = 1; spacing[1] = 1; spacing[2] = 0; } return spacing; } diff --git a/Modules/US/USModel/mitkUSProbe.h b/Modules/US/USModel/mitkUSProbe.h index 04b2b898b0..c5b6624b98 100644 --- a/Modules/US/USModel/mitkUSProbe.h +++ b/Modules/US/USModel/mitkUSProbe.h @@ -1,91 +1,96 @@ /*=================================================================== 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 MITKUSProbe_H_HEADER_INCLUDED_ #define MITKUSProbe_H_HEADER_INCLUDED_ #include #include #include #include #include namespace mitk { /**Documentation * \brief Right now, the US Probe is only a fancy name for a string. Later, it could handle probe specific parameters * like the current frequency etc. It is able to compare itself to other probes for device managment though. * * \ingroup US */ //Be sure to check the isEqualTo() method if you expand this class to see if it needs work! class MITKUS_EXPORT USProbe : public itk::Object { public: mitkClassMacroItkParent(USProbe, itk::Object); itkFactorylessNewMacro(Self) itkCloneMacro(Self) mitkNewMacro1Param(Self, std::string); /** * \brief Compares this probe to another probe and returns true if they are equal in terms of name AND NAME ONLY * be sure to sufficiently extend this method along with further capabilities probes. */ bool IsEqualToProbe(mitk::USProbe::Pointer probe); /** * \brief Sets a scanning depth of the probe and the associated spacing */ void SetDepthAndSpacing(int depth, Vector3D spacing); /** * \brief Gets all scanning depths and the associates spacings of the probe as an std::map with depth as key (represented by an int) and *spacing as value (represented by a Vector3D) */ std::map GetDepthsAndSpacing(); /** * \brief Sets a scanning depth of the probe with the default spacing (1,1,0). Exact spacing needs to be calibrated. */ void SetDepth(int depth); + /** + * \brief Removes the given depth of the probe, if it exists + */ + void RemoveDepth(int depthToRemove); + /** * \ brief Sets the spacing associated to the given depth of the probe. Spacing needs to be calibrated. */ void SetSpacingForGivenDepth(int givenDepth, Vector3D spacing); /** * \brief Returns the spacing that is associated to the given depth of the probe. *If spacing was not calibrated or if depth does not exist for this probe the default spacing (1,1,0) is returned. */ Vector3D GetSpacingForGivenDepth(int givenDepth); //## getter and setter ## itkGetMacro(Name, std::string); itkSetMacro(Name, std::string); protected: USProbe(); USProbe(std::string identifier); virtual ~USProbe(); std::string m_Name; // Map containing the depths and the associated spacings as an std::vector with depth as key and spacing as value std::map m_DepthsAndSpacings; }; } // namespace mitk #endif diff --git a/Modules/US/USModel/mitkUSVideoDevice.cpp b/Modules/US/USModel/mitkUSVideoDevice.cpp index 9646e3a584..ab9429d22a 100644 --- a/Modules/US/USModel/mitkUSVideoDevice.cpp +++ b/Modules/US/USModel/mitkUSVideoDevice.cpp @@ -1,182 +1,195 @@ /*=================================================================== 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 "mitkUSVideoDevice.h" #include "mitkUSVideoDeviceCustomControls.h" mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model) { Init(); m_SourceIsFile = false; m_DeviceID = videoDeviceNumber; m_FilePath = ""; } mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model) : mitk::USDevice(manufacturer, model) { Init(); m_SourceIsFile = true; m_FilePath = videoFilePath; } mitk::USVideoDevice::USVideoDevice(int videoDeviceNumber, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata) { Init(); m_SourceIsFile = false; m_DeviceID = videoDeviceNumber; m_FilePath = ""; } mitk::USVideoDevice::USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata) : mitk::USDevice(metadata) { Init(); m_SourceIsFile = true; m_FilePath = videoFilePath; } mitk::USVideoDevice::~USVideoDevice() { //m_Source->UnRegister(); m_Source = 0; } void mitk::USVideoDevice::Init() { m_Source = mitk::USImageVideoSource::New(); m_ControlInterfaceCustom = mitk::USVideoDeviceCustomControls::New(this); //this->SetNumberOfInputs(1); this->SetNumberOfIndexedOutputs(1); // mitk::USImage::Pointer output = mitk::USImage::New(); // output->Initialize(); this->SetNthOutput(0, this->MakeOutput(0)); } std::string mitk::USVideoDevice::GetDeviceClass() { return mitk::USVideoDevice::GetDeviceClassStatic(); } std::string mitk::USVideoDevice::GetDeviceClassStatic() { return "org.mitk.modules.us.USVideoDevice"; } mitk::USAbstractControlInterface::Pointer mitk::USVideoDevice::GetControlInterfaceCustom() { return m_ControlInterfaceCustom.GetPointer(); } bool mitk::USVideoDevice::OnInitialization() { // nothing to do at initialization of video device return true; } bool mitk::USVideoDevice::OnConnection() { if (m_SourceIsFile){ m_Source->SetVideoFileInput(m_FilePath); } else { m_Source->SetCameraInput(m_DeviceID); } //SetSourceCropArea(); return true; } bool mitk::USVideoDevice::OnDisconnection() { if (m_DeviceState == State_Activated) this->Deactivate(); m_Source->ReleaseInput(); return true; } bool mitk::USVideoDevice::OnActivation() { // make sure that video device is ready before aquiring images if (!m_Source->GetIsReady()) { MITK_WARN("mitkUSDevice")("mitkUSVideoDevice") << "Could not activate us video device. Check if video grabber is configured correctly."; return false; } MITK_INFO << "Activated UsVideoDevice!"; return true; } bool mitk::USVideoDevice::OnDeactivation() { // happens automatically when m_Active is set to false return true; } void mitk::USVideoDevice::UnregisterOnService() { if (m_DeviceState == State_Activated) { this->Deactivate(); } if (m_DeviceState == State_Connected) { this->Disconnect(); } mitk::USDevice::UnregisterOnService(); } mitk::USImageSource::Pointer mitk::USVideoDevice::GetUSImageSource() { return m_Source.GetPointer(); } std::vector mitk::USVideoDevice::GetAllProbes() { if (m_Probes.empty()) { MITK_INFO << "No probes exist for this USVideDevice. Empty vector is returned"; } return m_Probes; } mitk::USProbe::Pointer mitk::USVideoDevice::GetCurrentProbe() { if (m_CurrentProbe.IsNotNull()) { return m_CurrentProbe; } else { return 0; } } mitk::USProbe::Pointer mitk::USVideoDevice::GetProbeByName(std::string name) { for (std::vector::iterator it = m_Probes.begin(); it != m_Probes.end(); it++) { if (name.compare((*it)->GetName()) == 0) return (*it); } MITK_INFO << "No probe with given name " << name << " was found."; return 0; //no matching probe was found so 0 is returned } +void mitk::USVideoDevice::RemoveProbeByName(std::string name) +{ + for (std::vector::iterator it = m_Probes.begin(); it != m_Probes.end(); it++) + { + if (name.compare((*it)->GetName()) == 0) + { + m_Probes.erase(it); + return; + } + } + MITK_INFO << "No Probe with given name " << name << " was found"; +} + void mitk::USVideoDevice::AddNewProbe(mitk::USProbe::Pointer probe) { m_Probes.push_back(probe); } bool mitk::USVideoDevice::GetIsSourceFile() { return m_SourceIsFile; } diff --git a/Modules/US/USModel/mitkUSVideoDevice.h b/Modules/US/USModel/mitkUSVideoDevice.h index 66ca274e6b..840f624b4d 100644 --- a/Modules/US/USModel/mitkUSVideoDevice.h +++ b/Modules/US/USModel/mitkUSVideoDevice.h @@ -1,220 +1,225 @@ /*=================================================================== 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 MITKUSVideoDevice_H_HEADER_INCLUDED_ #define MITKUSVideoDevice_H_HEADER_INCLUDED_ #include #include #include "mitkUSDevice.h" #include "mitkUSImageVideoSource.h" #include "mitkUSProbe.h" #include namespace itk { template class SmartPointer; } namespace mitk { class USVideoDeviceCustomControls; class USAbstractControlInterface; /** * \brief A mitk::USVideoDevice is the common class for video only devices. * They capture video input either from a file or from a device and * transform the output into an mitk::USImage with attached metadata. * This simple implementation does only capture and display 2d images without * registration for example. * * \ingroup US */ class MITKUS_EXPORT USVideoDevice : public mitk::USDevice { public: mitkClassMacro(USVideoDevice, mitk::USDevice); // To open a device (DeviceID, Manufacturer, Model) mitkNewMacro3Param(Self, int, std::string, std::string); // To open A VideoFile (Path, Manufacturer, Model) mitkNewMacro3Param(Self, std::string, std::string, std::string); // To open a device (DeviceID, Metadata) mitkNewMacro2Param(Self, int, mitk::USImageMetadata::Pointer); // To open A VideoFile (Path, Metadata) mitkNewMacro2Param(Self, std::string, mitk::USImageMetadata::Pointer); /** * \return the qualified name of this class (as returned by GetDeviceClassStatic()) */ virtual std::string GetDeviceClass() override; /** * This methode is necessary instead of a static member attribute to avoid * "static initialization order fiasco" when an instance of this class is * used in a module activator. * * \return the qualified name of this class */ static std::string GetDeviceClassStatic(); /** * Getter for the custom control interface which was created during the * construction process of mitk::USVideoDevice. * * \return custom control interface of the video device */ virtual itk::SmartPointer GetControlInterfaceCustom() override; /** * \brief Remove this device from the micro service. * This method is public for mitk::USVideoDevice, because this devices * can be completly removed. This is not possible for API devices, which * should be available while their sub module is loaded. */ void UnregisterOnService(); /** * \return mitk::USImageSource connected to this device */ virtual USImageSource::Pointer GetUSImageSource() override; /** * \brief Return all probes for this USVideoDevice or an empty vector it no probes were set * Returns a std::vector of all probes that exist for this USVideoDevice if there were probes set while creating or modifying this USVideoDevice. * Otherwise it returns an empty vector. Therefore always check if vector is filled, before using it! */ std::vector GetAllProbes(); /** * \brief Return current active probe for this USVideoDevice * Returns a pointer to the probe that is currently in use. If there were probes set while creating or modifying this USVideoDevice. * Returns null otherwise */ mitk::USProbe::Pointer GetCurrentProbe(); /** \brief adds a new probe to the device */ void AddNewProbe(mitk::USProbe::Pointer probe); /** * \brief get the probe by its name * Returns a pointer to the probe identified by the given name. If no probe of given name exists for this Device 0 is returned. */ mitk::USProbe::Pointer GetProbeByName(std::string name); + /** + * \brief Removes the Probe with the given name + */ + void RemoveProbeByName(std::string name); + /** \brief True, if this Device plays back a file, false if it recieves data from a device */ bool GetIsSourceFile(); itkGetMacro(Image, mitk::Image::Pointer); itkGetMacro(DeviceID, int); itkGetMacro(FilePath, std::string); protected: /** * \brief Creates a new device that will deliver USImages taken from a video device. * under windows, try -1 for device number, which will grab the first available one * (Open CV functionality) */ USVideoDevice(int videoDeviceNumber, std::string manufacturer, std::string model); /** * \brief Creates a new device that will deliver USImages taken from a video file. */ USVideoDevice(std::string videoFilePath, std::string manufacturer, std::string model); /** * \brief Creates a new device that will deliver USImages taken from a video device. * under windows, try -1 for device number, which will grab the first available one * (Open CV functionality) */ USVideoDevice(int videoDeviceNumber, mitk::USImageMetadata::Pointer metadata); /** * \brief Creates a new device that will deliver USImages taken from a video file. */ USVideoDevice(std::string videoFilePath, mitk::USImageMetadata::Pointer metadata); virtual ~USVideoDevice(); /** * \brief Initializes common properties for all constructors. */ void Init(); /** * \brief Is called during the initialization process. * Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnInitialization() override; /** * \brief Is called during the connection process. * Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnConnection() override; /** * \brief Is called during the disconnection process. * Returns true if successful and false if unsuccessful. Additionally, you may throw an exception to clarify what went wrong. */ virtual bool OnDisconnection() override; /** * \brief Is called during the activation process. After this method is finsihed, the device should be generating images */ virtual bool OnActivation() override; /** * \brief Is called during the deactivation process. After a call to this method the device should still be connected, but not producing images anymore. */ virtual bool OnDeactivation() override; /** * \brief The image source that we use to aquire data */ mitk::USImageVideoSource::Pointer m_Source; /** * \brief True, if this source plays back a file, false if it recieves data from a device */ bool m_SourceIsFile; /** * \brief The device id to connect to. Undefined, if m_SourceIsFile == true; */ int m_DeviceID; /** * \brief The Filepath id to connect to. Undefined, if m_SourceIsFile == false; */ std::string m_FilePath; /** * \brief custom control interface for us video device */ itk::SmartPointer m_ControlInterfaceCustom; /** * \brief probes for this USVideoDevice */ std::vector < mitk::USProbe::Pointer > m_Probes; /** \brief probe that is currently in use */ mitk::USProbe::Pointer m_CurrentProbe; }; } // namespace mitk #endif // MITKUSVideoDevice_H_HEADER_INCLUDED_ diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp index c3b89f1228..08303d6c71 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.cpp @@ -1,227 +1,236 @@ /*=================================================================== 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. ===================================================================*/ //#define _USE_MATH_DEFINES #include #include #include #include #include "mitkUSVideoDevice.h" const std::string QmitkUSDeviceManagerWidget::VIEW_ID = "org.mitk.views.QmitkUSDeviceManagerWidget"; QmitkUSDeviceManagerWidget::QmitkUSDeviceManagerWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); } QmitkUSDeviceManagerWidget::~QmitkUSDeviceManagerWidget() {} //////////////////// INITIALIZATION ///////////////////// void QmitkUSDeviceManagerWidget::CreateQtPartControl(QWidget* parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkUSDeviceManagerWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); m_Controls->m_ConnectedDevices->SetAutomaticallySelectFirstEntry(true); } // Initializations std::string empty = ""; m_Controls->m_ConnectedDevices->Initialize( mitk::USDevice::GetPropertyKeys().US_PROPKEY_LABEL, empty); } void QmitkUSDeviceManagerWidget::CreateConnections() { if (m_Controls) { connect(m_Controls->m_BtnActivate, SIGNAL(clicked()), this, SLOT(OnClickedActivateDevice())); // connect( m_Controls->m_BtnDisconnect, SIGNAL( clicked() ), this, // SLOT(OnClickedDisconnectDevice()) ); connect(m_Controls->m_BtnRemove, SIGNAL(clicked()), this, SLOT(OnClickedRemoveDevice())); connect(m_Controls->m_BtnNewDevice, SIGNAL(clicked()), this, SLOT(OnClickedNewDevice())); connect(m_Controls->m_ConnectedDevices, SIGNAL(ServiceSelectionChanged(us::ServiceReferenceU)), this, SLOT(OnDeviceSelectionChanged(us::ServiceReferenceU))); + connect(m_Controls->m_BtnEdit, SIGNAL(clicked()), this, + SLOT(OnClickedEditDevice())); } } ///////////// Methods & Slots Handling Direct Interaction ///////////////// void QmitkUSDeviceManagerWidget::OnClickedActivateDevice() { mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedService(); if (device.IsNull()) { return; } if (device->GetIsActive()) { device->Deactivate(); device->Disconnect(); } else { QApplication::setOverrideCursor(Qt::WaitCursor); if (device->GetDeviceState() < mitk::USDevice::State_Connected) { device->Connect(); } if (device->GetIsConnected()) { device->Activate(); } QApplication::restoreOverrideCursor(); if (!device->GetIsActive()) { QMessageBox::warning( this, "Activation failed", "Could not activate device. Check logging for details."); } else { emit DeviceActivated(); } } // Manually reevaluate Button logic OnDeviceSelectionChanged( m_Controls->m_ConnectedDevices->GetSelectedServiceReference()); } void QmitkUSDeviceManagerWidget::OnClickedDisconnectDevice() { mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedService(); if (device.IsNull()) { return; } if (device->GetIsConnected()) { device->Disconnect(); } else { if (!device->Connect()) { QMessageBox::warning( this, "Connecting failed", "Could not connect to device. Check logging for details."); } } } void QmitkUSDeviceManagerWidget::OnClickedRemoveDevice() { mitk::USDevice::Pointer device = m_Controls->m_ConnectedDevices->GetSelectedService(); if (device.IsNull()) { return; } if (device->GetDeviceClass() == "org.mitk.modules.us.USVideoDevice") { if (device->GetIsActive()) { device->Deactivate(); } if (device->GetIsConnected()) { device->Disconnect(); } dynamic_cast(device.GetPointer()) ->UnregisterOnService(); } } void QmitkUSDeviceManagerWidget::OnClickedNewDevice() { emit NewDeviceButtonClicked(); } +void QmitkUSDeviceManagerWidget::OnClickedEditDevice() +{ + mitk::USDevice::Pointer device = + m_Controls->m_ConnectedDevices->GetSelectedService(); + emit EditDeviceButtonClicked(device); +} + void QmitkUSDeviceManagerWidget::OnDeviceSelectionChanged( us::ServiceReferenceU reference) { if (!reference) { m_Controls->m_BtnActivate->setEnabled(false); m_Controls->m_BtnRemove->setEnabled(false); return; } std::string isConnected = reference.GetProperty( mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISCONNECTED) .ToString(); std::string isActive = reference.GetProperty( mitk::USDevice::GetPropertyKeys().US_PROPKEY_ISACTIVE) .ToString(); if (isActive.compare("false") == 0) { m_Controls->m_BtnActivate->setEnabled(true); m_Controls->m_BtnActivate->setText("Activate"); } else { m_Controls->m_BtnActivate->setEnabled(true); m_Controls->m_BtnActivate->setText("Deactivate"); } std::string deviceClass = reference.GetProperty(mitk::USDevice::GetPropertyKeys().US_PROPKEY_CLASS) .ToString(); m_Controls->m_BtnRemove->setEnabled(deviceClass == "org.mitk.modules.us.USVideoDevice"); m_Controls->m_BtnEdit->setEnabled((deviceClass == "org.mitk.modules.us.USVideoDevice") && (isActive.compare("false") == 0)); } void QmitkUSDeviceManagerWidget::DisconnectAllDevices() { // at the moment disconnects ALL devices. Maybe we only want to disconnect the // devices handled by this widget? us::ModuleContext* thisContext = us::GetModuleContext(); std::vector > services = thisContext->GetServiceReferences(); for (std::vector >::iterator it = services.begin(); it != services.end(); ++it) { mitk::USDevice* currentDevice = thisContext->GetService(*it); currentDevice->Disconnect(); } MITK_INFO << "Disconnected ALL US devises!"; } diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h index 5b97b605fd..ccda656c99 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidget.h @@ -1,90 +1,93 @@ /*=================================================================== 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 _QmitkUSDeviceManagerWidget_H_INCLUDED #define _QmitkUSDeviceManagerWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSDeviceManagerWidgetControls.h" #include "mitkUSDevice.h" #include //QT headers #include #include /** * @brief This Widget is used to manage available Ultrasound Devices. * * It allows activation, deactivation and disconnection of connected devices. * * @ingroup USUI */ class MITKUSUI_EXPORT QmitkUSDeviceManagerWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkUSDeviceManagerWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSDeviceManagerWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); /* @brief Disconnects all devices immediately. */ virtual void DisconnectAllDevices(); signals: void NewDeviceButtonClicked(); + void EditDeviceButtonClicked(mitk::USDevice::Pointer); /* This signal is emitted if a device is activated. */ void DeviceActivated(); public slots: protected slots : /* \brief Called, when the button "Activate Device" was clicked. */ void OnClickedActivateDevice(); /* \brief Called, when the button "Disconnect Device" was clicked. */ void OnClickedDisconnectDevice(); void OnClickedRemoveDevice(); void OnClickedNewDevice(); + void OnClickedEditDevice(); + /* \brief Called, when the selection in the devicelist changes. */ void OnDeviceSelectionChanged(us::ServiceReferenceU reference); protected: Ui::QmitkUSDeviceManagerWidgetControls* m_Controls; ///< member holding the UI elements of this widget private: }; #endif // _QmitkUSDeviceManagerWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui index 4e429dae10..cd0767938d 100644 --- a/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui +++ b/Modules/USUI/Qmitk/QmitkUSDeviceManagerWidgetControls.ui @@ -1,90 +1,90 @@ QmitkUSDeviceManagerWidgetControls 0 0 405 234 0 0 QmitkUSDeviceManagerWidget - - - - false - - - Activate - - - false Remove :/USUI/minus.png:/USUI/minus.png New Video Device :/USUI/plus.png:/USUI/plus.png - + false Edit Video Device + + + + false + + + Activate + + + QmitkServiceListWidget QWidget
QmitkServiceListWidget.h
1
diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp index 468c3c306a..682fc00a2c 100644 --- a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.cpp @@ -1,246 +1,405 @@ /*=================================================================== 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. ===================================================================*/ //#define _USE_MATH_DEFINES #include // QT headers #include // mitk headers // itk headers const std::string QmitkUSNewVideoDeviceWidget::VIEW_ID = "org.mitk.views.QmitkUSNewVideoDeviceWidget"; QmitkUSNewVideoDeviceWidget::QmitkUSNewVideoDeviceWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); } QmitkUSNewVideoDeviceWidget::~QmitkUSNewVideoDeviceWidget() {} //////////////////// INITIALIZATION ///////////////////// void QmitkUSNewVideoDeviceWidget::CreateQtPartControl(QWidget* parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkUSNewVideoDeviceWidgetControls; m_Controls->setupUi(parent); this->CreateConnections(); } } void QmitkUSNewVideoDeviceWidget::CreateConnections() { if (m_Controls) { - connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, - SLOT(OnClickedDone())); + // connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, + // SLOT(OnClickedDone())); connect(m_Controls->m_BtnCancel, SIGNAL(clicked()), this, SLOT(OnClickedCancel())); connect(m_Controls->m_RadioDeviceSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection())); connect(m_Controls->m_RadioFileSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection())); connect(m_Controls->m_RadioOIGTLClientSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection())); connect(m_Controls->m_RadioOIGTLServerSource, SIGNAL(clicked()), this, SLOT(OnDeviceTypeSelection())); connect(m_Controls->m_OpenFileButton, SIGNAL(clicked()), this, SLOT(OnOpenFileButtonClicked())); + + //Connect buttons and functions for editing of probes + connect(m_Controls->m_BtnRemoveProbe, SIGNAL(clicked()), this, SLOT(OnClickedRemoveProbe())); + connect(m_Controls->m_BtnRemoveDepth, SIGNAL(clicked()), this, SLOT(OnClickedRemoveDepth())); + connect(m_Controls->m_BtnAddDepths, SIGNAL(clicked()), this, SLOT(OnClickedAddDepths())); + connect(m_Controls->m_Probes, SIGNAL(currentTextChanged(const QString &)), this, SLOT(OnProbeChanged(const QString &))); } } ///////////// Methods & Slots Handling Direct Interaction ///////////////// void QmitkUSNewVideoDeviceWidget::OnClickedDone() { m_Active = false; // Create Device mitk::USVideoDevice::Pointer newDevice; if (m_Controls->m_RadioDeviceSource->isChecked()) { newDevice = mitk::USVideoDevice::New( m_Controls->m_DeviceSelector->value(), m_Controls->m_Manufacturer->text().toStdString(), m_Controls->m_Model->text().toStdString()); newDevice->SetComment(m_Controls->m_Comment->text().toStdString()); } else if (m_Controls->m_RadioFileSource->isChecked()) { newDevice = mitk::USVideoDevice::New( m_Controls->m_FilePathSelector->text().toStdString(), m_Controls->m_Manufacturer->text().toStdString(), m_Controls->m_Model->text().toStdString()); newDevice->SetComment(m_Controls->m_Comment->text().toStdString()); } else if (m_Controls->m_RadioOIGTLClientSource->isChecked()) { std::string host = m_Controls->m_OIGTLClientHost->text().toStdString(); int port = m_Controls->m_OIGTLClientPort->value(); // Create a new USIGTLDevice. The last parameter tells the device that it should be a client. mitk::USIGTLDevice::Pointer device = mitk::USIGTLDevice::New(m_Controls->m_Manufacturer->text().toStdString(), m_Controls->m_Model->text().toStdString(), host, port, false); device->Initialize(); emit Finished(); // The rest of this method does stuff that is specific to USVideoDevices, // which we don't need. So we return directly. return; } else { std::string host = m_Controls->m_OIGTLServerHost->text().toStdString(); int port = m_Controls->m_OIGTLServerPort->value(); // Create a new USIGTLDevice. The last parameter tells the device that it should be a server. mitk::USIGTLDevice::Pointer device = mitk::USIGTLDevice::New(m_Controls->m_Manufacturer->text().toStdString(), m_Controls->m_Model->text().toStdString(), host, port, true); device->Initialize(); emit Finished(); // The rest of this method does stuff that is specific to USVideoDevices, // which we don't need. So we return directly. return; } // get USImageVideoSource from new device mitk::USImageVideoSource::Pointer imageSource = dynamic_cast( newDevice->GetUSImageSource().GetPointer()); if (!imageSource) { MITK_ERROR << "There is no USImageVideoSource at the current device."; mitkThrow() << "There is no USImageVideoSource at the current device."; } // Set Video Options imageSource->SetColorOutput(!m_Controls->m_CheckGreyscale->isChecked()); // If Resolution override is activated, apply it if (m_Controls->m_CheckResolutionOverride->isChecked()) { int width = m_Controls->m_ResolutionWidth->value(); int height = m_Controls->m_ResolutionHeight->value(); imageSource->OverrideResolution(width, height); imageSource->SetResolutionOverride(true); } if (!m_Controls->m_ProbesInformation->text().isEmpty()) //there are informations about the probes of the device, so create the probes { - QString probesInformation = m_Controls->m_ProbesInformation->text(); - QStringList probes = probesInformation.split(';'); //split the different probes - for (int i = 0; i < probes.size(); i++) - { - QStringList depths = probes.at(i).split(','); //now for every probe split the probe name and the different depths - mitk::USProbe::Pointer probe = mitk::USProbe::New(); - probe->SetName(depths.at(0).toStdString()); //first element is the probe name - for (int i = 1; i < depths.size(); ++i) //all the other elements are the depths for the specific probe so add them to the probe - { - probe->SetDepth(depths.at(i).toInt()); - } - newDevice->AddNewProbe(probe); - } + AddProbesToDevice(newDevice); } else //no information about the probes of the device, so set default value { mitk::USProbe::Pointer probe = mitk::USProbe::New("default"); probe->SetDepth(0); newDevice->AddNewProbe(probe); } newDevice->Initialize(); + CleanUpAfterCreatingNewDevice(); + + emit Finished(); +} + +void QmitkUSNewVideoDeviceWidget::OnClickedFinishedEditing() +{ + m_Active = false; + m_TargetDevice->SetManufacturer(m_Controls->m_Manufacturer->text().toStdString()); + m_TargetDevice->SetName(m_Controls->m_Model->text().toStdString()); + m_TargetDevice->SetComment(m_Controls->m_Comment->text().toStdString()); + + if (!m_Controls->m_ProbesInformation->text().isEmpty()){ //there is information about probes to add, so add them + AddProbesToDevice(m_TargetDevice); + } + mitk::USImageVideoSource::Pointer imageSource = + dynamic_cast( + m_TargetDevice->GetUSImageSource().GetPointer()); + if (!imageSource) + { + MITK_ERROR << "There is no USImageVideoSource at the current device."; + mitkThrow() << "There is no USImageVideoSource at the current device."; + } + + // Set Video Options + imageSource->SetColorOutput(!m_Controls->m_CheckGreyscale->isChecked()); + + // If Resolution override is activated, apply it + if (m_Controls->m_CheckResolutionOverride->isChecked()) + { + int width = m_Controls->m_ResolutionWidth->value(); + int height = m_Controls->m_ResolutionHeight->value(); + imageSource->OverrideResolution(width, height); + imageSource->SetResolutionOverride(true); + } + CleanUpAfterEditingOfDevice(); + MITK_INFO << "Finished Editing"; emit Finished(); } void QmitkUSNewVideoDeviceWidget::OnClickedCancel() { m_TargetDevice = 0; m_Active = false; + CleanUpAfterCreatingNewDevice(); + CleanUpAfterEditingOfDevice(); emit Finished(); } void QmitkUSNewVideoDeviceWidget::OnDeviceTypeSelection() { m_Controls->m_FilePathSelector->setEnabled( m_Controls->m_RadioFileSource->isChecked()); m_Controls->m_DeviceSelector->setEnabled( m_Controls->m_RadioDeviceSource->isChecked()); m_Controls->m_OIGTLClientHost->setEnabled( m_Controls->m_RadioOIGTLClientSource->isChecked()); m_Controls->m_OIGTLClientPort->setEnabled( m_Controls->m_RadioOIGTLClientSource->isChecked()); m_Controls->m_OIGTLServerHost->setEnabled( m_Controls->m_RadioOIGTLServerSource->isChecked()); m_Controls->m_OIGTLServerPort->setEnabled( m_Controls->m_RadioOIGTLServerSource->isChecked()); } void QmitkUSNewVideoDeviceWidget::OnOpenFileButtonClicked() { QString fileName = QFileDialog::getOpenFileName(NULL, "Open Video File"); if (fileName.isNull()) { return; } // user pressed cancel m_Controls->m_FilePathSelector->setText(fileName); m_Controls->m_RadioFileSource->setChecked(true); this->OnDeviceTypeSelection(); } ///////////////// Methods & Slots Handling Logic ////////////////////////// void QmitkUSNewVideoDeviceWidget::EditDevice(mitk::USDevice::Pointer device) { // If no VideoDevice is given, throw an exception if (device->GetDeviceClass().compare("org.mitk.modules.us.USVideoDevice") != 0) { // TODO Alert if bad path mitkThrow() << "NewVideoDeviceWidget recieved an incompatible device type " "to edit. Type was: " << device->GetDeviceClass(); } m_TargetDevice = static_cast(device.GetPointer()); m_Active = true; + + ChangeUIEditingUSVideoDevice(); } void QmitkUSNewVideoDeviceWidget::CreateNewDevice() { + //When new device is created there are no probes to edit, therefore disable the Groupbox + m_Controls->m_GroupBoxEditProbes->setEnabled(false); + + //Toggle functionality of Btn_Done + connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone())); + m_Controls->m_BtnDone->setText("Add Video Device"); + + //Fill Metadata with default information + m_Controls->m_Manufacturer->setText("Unknown Manufacturer"); + m_Controls->m_Model->setText("Unknown Model"); + m_Controls->m_Comment->setText("None"); + m_TargetDevice = 0; m_Active = true; } /////////////////////// HOUSEHOLDING CODE /////////////////////////////// QListWidgetItem* QmitkUSNewVideoDeviceWidget::ConstructItemFromDevice( mitk::USDevice::Pointer device) { QListWidgetItem* result = new QListWidgetItem; std::string text = device->GetDeviceManufacturer() + "|" + device->GetDeviceModel(); result->setText(text.c_str()); return result; } + +void QmitkUSNewVideoDeviceWidget::ChangeUIEditingUSVideoDevice() +{ + //deactivate the group box containing Videosource options because they should not be changed + m_Controls->m_GroupBoxVideoSource->setEnabled(false); + + //activate the groupbox contaning the options to edit the probes of the device and fill it with information + m_Controls->m_GroupBoxEditProbes->setEnabled(true); + std::vector probes = m_TargetDevice->GetAllProbes(); + for (std::vector::iterator it = probes.begin(); it != probes.end(); it++) + { + std::string probeName = (*it)->GetName(); + m_Controls->m_Probes->addItem(QString::fromUtf8(probeName.data(), probeName.size())); + } + OnProbeChanged(m_Controls->m_Probes->currentText()); + + //Toggle functionality of Btn_Done + m_Controls->m_BtnDone->setText("Save Changes"); + connect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedFinishedEditing())); + + //Fill Metadata with Information provided by the Device selected to edit + m_Controls->m_Manufacturer->setText(m_TargetDevice->GetManufacturer().c_str()); + m_Controls->m_Model->setText(m_TargetDevice->GetName().c_str()); + m_Controls->m_Comment->setText(m_TargetDevice->GetComment().c_str()); +} + +void QmitkUSNewVideoDeviceWidget::OnClickedAddDepths() +{ + if (!m_Controls->m_Probes->currentText().isEmpty()) + { + std::string probename = m_Controls->m_Probes->currentText().toStdString(); + mitk::USProbe::Pointer currentProbe = m_TargetDevice->GetProbeByName(probename); + QString depths = m_Controls->m_AddDepths->text(); + QStringList singleDepths = depths.split(','); + for (int i = 0; i < singleDepths.size(); i++) + { + currentProbe->SetDepth(singleDepths.at(i).toInt()); + } + m_Controls->m_AddDepths->clear(); + OnProbeChanged(m_Controls->m_Probes->currentText()); + } +} + +void QmitkUSNewVideoDeviceWidget::OnClickedRemoveDepth() +{ + if (!m_Controls->m_Probes->currentText().isEmpty() && !m_Controls->m_Depths->currentText().isEmpty()) + { + std::string probename = m_Controls->m_Probes->currentText().toStdString(); + int indexOfDepthToRemove = m_Controls->m_Depths->currentIndex(); + mitk::USProbe::Pointer currentProbe = m_TargetDevice->GetProbeByName(probename); + currentProbe->RemoveDepth(m_Controls->m_Depths->currentText().toInt()); + m_Controls->m_Depths->removeItem(indexOfDepthToRemove); + } +} + +void QmitkUSNewVideoDeviceWidget::OnClickedRemoveProbe() +{ + if (!m_Controls->m_Probes->currentText().isEmpty()) + { + std::string probename = m_Controls->m_Probes->currentText().toStdString(); + int indexOfProbeToRemove = m_Controls->m_Probes->currentIndex(); + m_TargetDevice->RemoveProbeByName(probename); + m_Controls->m_Probes->removeItem(indexOfProbeToRemove); + } +} + +void QmitkUSNewVideoDeviceWidget::OnProbeChanged(const QString & probename) +{ + if (!probename.isEmpty()) + { + std::string name = probename.toStdString(); + mitk::USProbe::Pointer probe = m_TargetDevice->GetProbeByName(name); + std::map depths = probe->GetDepthsAndSpacing(); + m_Controls->m_Depths->clear(); + for (std::map::iterator it = depths.begin(); it != depths.end(); it++) + { + m_Controls->m_Depths->addItem(QString::number(it->first)); + } + } +} + +void QmitkUSNewVideoDeviceWidget::CleanUpAfterCreatingNewDevice() +{ + disconnect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedDone())); + m_Controls->m_ProbesInformation->clear(); +} + +void QmitkUSNewVideoDeviceWidget::CleanUpAfterEditingOfDevice() +{ + disconnect(m_Controls->m_BtnDone, SIGNAL(clicked()), this, SLOT(OnClickedFinishedEditing())); + m_Controls->m_Probes->clear(); + m_Controls->m_Depths->clear(); + m_Controls->m_AddDepths->clear(); + m_Controls->m_ProbesInformation->clear(); +} + +void QmitkUSNewVideoDeviceWidget::AddProbesToDevice(mitk::USVideoDevice::Pointer device) +{ + QString probesInformation = m_Controls->m_ProbesInformation->text(); + QStringList probes = probesInformation.split(';'); //split the different probes + for (int i = 0; i < probes.size(); i++) + { + QStringList depths = probes.at(i).split(','); //now for every probe split the probe name and the different depths + mitk::USProbe::Pointer probe = mitk::USProbe::New(); + probe->SetName(depths.at(0).toStdString()); //first element is the probe name + for (int i = 1; i < depths.size(); i++) //all the other elements are the depths for the specific probe so add them to the probe + { + probe->SetDepth(depths.at(i).toInt()); + } + device->AddNewProbe(probe); + } +} diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h index bc64b76aa5..4f116f96cd 100644 --- a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidget.h @@ -1,112 +1,130 @@ /*=================================================================== 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 _QmitkUSNewVideoDeviceWidget_H_INCLUDED #define _QmitkUSNewVideoDeviceWidget_H_INCLUDED #include "MitkUSUIExports.h" #include "ui_QmitkUSNewVideoDeviceWidgetControls.h" #include "mitkUSVideoDevice.h" #include "mitkUSIGTLDevice.h" //QT headers #include #include //mitk header /** * @brief This Widget enables the USer to create and connect Video Devices. * * @ingroup USUI */ class MITKUSUI_EXPORT QmitkUSNewVideoDeviceWidget :public QWidget { //this is needed for all Qt objects that should have a MOC object (everything that derives from QObject) Q_OBJECT public: static const std::string VIEW_ID; QmitkUSNewVideoDeviceWidget(QWidget* p = 0, Qt::WindowFlags f1 = 0); virtual ~QmitkUSNewVideoDeviceWidget(); /* @brief This method is part of the widget an needs not to be called seperately. */ virtual void CreateQtPartControl(QWidget *parent); /* @brief This method is part of the widget an needs not to be called seperately. (Creation of the connections of main and control widget.)*/ virtual void CreateConnections(); signals: void Finished(); public slots: /* \brief Activates the widget and displays the given device's Data to edit. */ void EditDevice(mitk::USDevice::Pointer device); /* \brief Activates the widget with fields empty. */ void CreateNewDevice(); protected slots: /* \brief Called, when the the user clicks the "Done" button (Labeled either "Add Device" or "Edit Device", depending on the situation. */ void OnClickedDone(); + void OnClickedFinishedEditing(); + /* \brief Called, when the button "Cancel" was clicked */ void OnClickedCancel(); /* \brief Called, when the Use selects one of the Radiobuttons */ void OnDeviceTypeSelection(); void OnOpenFileButtonClicked(); + void OnClickedRemoveProbe(); + + void OnClickedRemoveDepth(); + + void OnClickedAddDepths(); + + void OnProbeChanged(const QString & probename); + protected: Ui::QmitkUSNewVideoDeviceWidgetControls* m_Controls; ///< member holding the UI elements of this widget /* \brief Constructs a ListItem from the given device for display in the list of active devices */ QListWidgetItem* ConstructItemFromDevice(mitk::USDevice::Pointer device); + void ChangeUIEditingUSVideoDevice(); + + void CleanUpAfterEditingOfDevice(); + + void CleanUpAfterCreatingNewDevice(); + + void AddProbesToDevice(mitk::USVideoDevice::Pointer device); + /* \brief Displays whether this widget is active or not. It gets activated by either sending a Signal to * the "CreateNewDevice" Slot or to the "EditDevice" Slot. If the user finishes editing the device, a * "EditingComplete" Signal is sent, and the widget is set to inactive again. Clicking Cancel also * deactivates it. */ bool m_Active; /** * \brief This is the device to edit. It is either the device transmitted in the "EditDevice" signal, or a new one * if the "CreateNewDevice slot was called. */ mitk::USVideoDevice::Pointer m_TargetDevice; }; #endif // _QmitkUSNewVideoDeviceWidget_H_INCLUDED diff --git a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui index 3209a986aa..82f3aeb080 100644 --- a/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui +++ b/Modules/USUI/Qmitk/QmitkUSNewVideoDeviceWidgetControls.ui @@ -1,435 +1,569 @@ - QmitkUSNewVideoDeviceWidgetControls - - - - 0 - 0 - 330 - 679 - - - + QmitkUSNewVideoDeviceWidgetControls + + + + 0 + 0 + 330 + 837 + + + + + 0 + 0 + + + + QmitkUSNewVideoDeviceWidget + + + + QFormLayout::AllNonFixedFieldsGrow + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Metadata: + + + + + + Comment + + + + + + + + 50 + false + true + + + + Device Information: + + + + + + + Manufacturer + + + + + + + Unknown Manufacturer + + + + + + + Model + + + + + + + Unknown Model + + + + + + + None + + + + + + + + + + Video Source: + + + + + + From Device: + + + true + + + + + + + 0 + + + 10 + + + 0 + + + + + + + From File: + + + + + + + + + false + + + + + + + + + + ... + + + + + + + + + OIGTL Server + + + + + + + + + false + + + localhost + + + + + + + false + + + 1 + + + 65535 + + + 18944 + + + + + + + + + OIGTL Client + + + + + + + + + false + + + localhost + + + + + + + false + + + 1 + + + 65535 + + + 18944 + + + + + + + + + + + + Video Options: + + + + + + Greyscale Image (Significantly faster) + + + true + + + + + + + + + + + + Add Video Device + + + + :/USUI/accept.png:/USUI/accept.png + + + + + + + Cancel + + + + :/USUI/restart.png:/USUI/restart.png + + + + + + + + + + 0 + 0 + + + - 0 - 0 + 50 + 130 - - - QmitkUSNewVideoDeviceWidget - - - - QFormLayout::AllNonFixedFieldsGrow + + + Add Probes + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 10 + 100 + 281 + 21 + - - 0 + + + + + 10 + 20 + 311 + 71 + - - 0 + + Enter the names of the probes of the VideoDevice and, +separated by commas, its scanning depths. +If you want to add several probes separate the probes +and their informations by semicolons +E.g. ACV,100,120,150;BDW,90,100;CSV,120,150,180 + - - 0 + + Qt::PlainText - - 0 + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop - - - - Metadata: - - - - - - Comment - - - - - - - - 50 - false - true - - - - Device Information: - - - - - - - Manufacturer - - - - - - - Unknown Manufacturer - - - - - - - Model - - - - - - - Unknown Model - - - - - - - None - - - - - + + false + + + 0 + + + + + + + + Override: + + + + + + Width: + + - - - - Video Source: - - - - - - From Device: - - - true - - - - - - - 0 - - - 10 - - - 0 - - - - - - - From File: - - - - - - - - - false - - - - - - - - - - ... - - - - - - - - - OIGTL Server - - - - - - - - - false - - - localhost - - - - - - - false - - - 1 - - - 65535 - - - 18944 - - - - - - - - - OIGTL Client - - - - - - - - - false - - - localhost - - - - - - - false - - - 1 - - - 65535 - - - 18944 - - - - - - - + + + + + 0 + 0 + + + + 10 + + + 2048 + + + 10 + + + 480 + + - - - - Video Options: - - - - - - Greyscale Image (Significantly faster) - - - true - - - - - + + + + Height: + + - - - - - - Add Video Device - - - - :/USUI/accept.png:/USUI/accept.png - - - - - - - - Cancel - - - - :/USUI/restart.png:/USUI/restart.png - - - - - + + + + Enable Resolution Override + + - - - - - 0 - 0 - - - - - 50 - 130 - - - - Probes - - - - - 10 - 100 - 301 - 21 - - - - - - - 10 - 20 - 311 - 71 - - - - - Enter the names of the probes of the VideoDevice and, - separated by commas, its scanning depths. - If you want to add several probes separate the probes - and their informations by semicolons. - E.g. ACV,100,120,150;BDW,90,100;CSV,120,150,180 - - - - Qt::PlainText - - - + + + + + 0 + 0 + + + + 10 + + + 2048 + + + 10 + + + 640 + + - - - - Override: - - - - - - Width: - - - - - - - - 0 - 0 - - - - 10 - - - 2048 - - - 10 - - - 480 - - - - - - - Height: - - - - - - - Enable Resolution Override - - - - - - - - 0 - 0 - - - - 10 - - - 2048 - - - 10 - - - 640 - - - - - - - If you encounter problems with devices (e.g. Images of uniform color and error messages in the log window), then try to set the resolution externally using the device's driver panel and then enter the same resolution here. - - - true - - - - - + + + + If you encounter problems with devices (e.g. Images of uniform color and error messages in the log window), then try to set the resolution externally using the device's driver panel and then enter the same resolution here. + + + true + + - - - - - m_Manufacturer - m_Model - m_Comment - m_RadioDeviceSource - m_DeviceSelector - m_RadioFileSource - m_CheckResolutionOverride - - - - - + + + + + + + false + + + + 0 + 180 + + + + Edit Probes + + + + + 10 + 40 + 69 + 22 + + + + + + + 10 + 90 + 69 + 22 + + + + + + + 10 + 150 + 71 + 20 + + + + + + + 10 + 20 + 47 + 13 + + + + Probes + + + + + + 10 + 70 + 171 + 16 + + + + Scanning Depths for chosen Probe + + + + + + 10 + 120 + 291 + 31 + + + + Enter Scanning Depths you want to add to chosen Probe. +Seperate them by commas. E.g. 120,150,180 + + + + + + 120 + 90 + 111 + 23 + + + + Remove this Depth + + + + + + 120 + 150 + 111 + 23 + + + + Add Depths + + + + + + 120 + 40 + 111 + 23 + + + + Remove this Probe + + + + + + + + + m_Manufacturer + m_Model + m_Comment + m_RadioDeviceSource + m_DeviceSelector + m_RadioFileSource + m_CheckResolutionOverride + + + + + 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 9bf833281c..25cbd1abec 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.cpp @@ -1,490 +1,500 @@ /*=================================================================== 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_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())); + connect(m_Controls.m_DeviceManagerWidget, SIGNAL(EditDeviceButtonClicked(mitk::USDevice::Pointer)), this, SLOT(OnClickedEditDevice())); //Change Widget Visibilities + connect(m_Controls.m_DeviceManagerWidget, SIGNAL(EditDeviceButtonClicked(mitk::USDevice::Pointer)), this->m_Controls.m_NewVideoDeviceWidget, SLOT(EditDevice(mitk::USDevice::Pointer))); // 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::OnClickedEditDevice() +{ + m_Controls.m_NewVideoDeviceWidget->setVisible(true); + m_Controls.m_DeviceManagerWidget->setVisible(false); + m_Controls.m_WidgetActiveDevices->setVisible(false); + m_Controls.m_Headline->setText("Edit Video Device:"); +} + 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_FPS2d < lowestFPS)) { lowestFPS = m_FPS2d; } if (m_Controls.m_Update3DView->isChecked() && (m_FPS3d < lowestFPS)) { lowestFPS = m_FPS3d; } m_Controls.m_FramerateLabel->setText("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() + ")")); } } 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); } diff --git a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h index bdaec7fefd..7275eb4796 100644 --- a/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h +++ b/Plugins/org.mitk.gui.qt.ultrasound/src/internal/UltrasoundSupport.h @@ -1,149 +1,150 @@ /*=================================================================== 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 UltrasoundSupport_h #define UltrasoundSupport_h #include #include #include "ui_UltrasoundSupportControls.h" #include "QmitkUSAbstractCustomWidget.h" #include "QmitkUSControlsBModeWidget.h" #include "QmitkUSControlsDopplerWidget.h" #include "QmitkUSControlsProbesWidget.h" #include #include /*! \brief UltrasoundSupport This plugin provides functionality to manage Ultrasound devices, create video devices and to view device images. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class UltrasoundSupport : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT - public: +public: - virtual void SetFocus() override; + virtual void SetFocus() override; - static const std::string VIEW_ID; + static const std::string VIEW_ID; - virtual void CreateQtPartControl(QWidget *parent) override; + virtual void CreateQtPartControl(QWidget *parent) override; - UltrasoundSupport(); - virtual ~UltrasoundSupport(); + UltrasoundSupport(); + virtual ~UltrasoundSupport(); public slots: - /* - * \brief This is called when the newDeviceWidget is closed - */ - void OnNewDeviceWidgetDone(); + /* + * \brief This is called when the newDeviceWidget is closed + */ + void OnNewDeviceWidgetDone(); protected slots: - void OnClickedAddNewDevice(); + void OnClickedAddNewDevice(); - void OnChangedFramerateLimit(); + void OnChangedFramerateLimit(); - /* - *\brief Called, when the selection in the list of the active devices changes. - */ - void OnChangedActiveDevice(); + void OnClickedEditDevice(); - void OnClickedFreezeButton(); + /* + *\brief Called, when the selection in the list of the active devices changes. + */ + void OnChangedActiveDevice(); - void OnDeciveServiceEvent(const ctkServiceEvent event); + void OnClickedFreezeButton(); - /* - * \brief This is the main imaging loop that updates the image and is called regularily during the imaging process - */ - void UpdateImage(); + void OnDeciveServiceEvent(const ctkServiceEvent event); - void RenderImage2d(); + /* + * \brief This is the main imaging loop that updates the image and is called regularily during the imaging process + */ + void UpdateImage(); - void RenderImage3d(); + void RenderImage2d(); - void StartTimers(); + void RenderImage3d(); - void StopTimers(); + void StartTimers(); - protected: + void StopTimers(); - void CreateControlWidgets(); - void RemoveControlWidgets(); +protected: - /** The device that is currently used to aquire images */ - mitk::USDevice::Pointer m_Device; + void CreateControlWidgets(); + void RemoveControlWidgets(); + /** The device that is currently used to aquire images */ + mitk::USDevice::Pointer m_Device; - void SetTimerIntervals(int intervalPipeline, int interval2D, int interval3D); - /** This timer triggers periodic updates to the pipeline */ - QTimer* m_UpdateTimer; - QTimer* m_RenderingTimer2d; - QTimer* m_RenderingTimer3d; + void SetTimerIntervals(int intervalPipeline, int interval2D, int interval3D); + /** This timer triggers periodic updates to the pipeline */ + QTimer* m_UpdateTimer; + QTimer* m_RenderingTimer2d; + QTimer* m_RenderingTimer3d; - /** These clocks are used to compute the framerate in the methods DisplayImage(),RenderImage2d() and RenderImage3d(). */ - QTime m_Clock; - QTime m_Clock2d; - QTime m_Clock3d; + /** These clocks are used to compute the framerate in the methods DisplayImage(),RenderImage2d() and RenderImage3d(). */ + QTime m_Clock; + QTime m_Clock2d; + QTime m_Clock3d; - /** A counter to comute the framerate. */ - int m_FrameCounterPipeline; - int m_FrameCounter2d; - int m_FrameCounter3d; - int m_FPSPipeline, m_FPS2d, m_FPS3d; + /** A counter to comute the framerate. */ + int m_FrameCounterPipeline; + int m_FrameCounter2d; + int m_FrameCounter3d; + int m_FPSPipeline, m_FPS2d, m_FPS3d; - /** Stores the properties of some QWidgets (and the tool storage file name) to QSettings.*/ - void StoreUISettings(); + /** Stores the properties of some QWidgets (and the tool storage file name) to QSettings.*/ + void StoreUISettings(); - /** Loads the properties of some QWidgets (and the tool storage file name) from QSettings.*/ - void LoadUISettings(); + /** Loads the properties of some QWidgets (and the tool storage file name) from QSettings.*/ + void LoadUISettings(); - /** The node that we feed images into.*/ - mitk::DataNode::Pointer m_Node; + /** The node that we feed images into.*/ + mitk::DataNode::Pointer m_Node; - /** The image that is hold by the node above.*/ - mitk::Image::Pointer m_Image; + /** The image that is hold by the node above.*/ + mitk::Image::Pointer m_Image; - /** The old geometry of m_Image. It is needed to check if the geometry changed (e.g. because - * the zoom factor was modified) and the image needs to be reinitialized. */ - mitk::SlicedGeometry3D::Pointer m_OldGeometry; + /** The old geometry of m_Image. It is needed to check if the geometry changed (e.g. because + * the zoom factor was modified) and the image needs to be reinitialized. */ + mitk::SlicedGeometry3D::Pointer m_OldGeometry; - Ui::UltrasoundSupportControls m_Controls; + Ui::UltrasoundSupportControls m_Controls; - QmitkUSAbstractCustomWidget* m_ControlCustomWidget; - QmitkUSControlsBModeWidget* m_ControlBModeWidget; - QmitkUSControlsDopplerWidget* m_ControlDopplerWidget; - QmitkUSControlsProbesWidget* m_ControlProbesWidget; + QmitkUSAbstractCustomWidget* m_ControlCustomWidget; + QmitkUSControlsBModeWidget* m_ControlBModeWidget; + QmitkUSControlsDopplerWidget* m_ControlDopplerWidget; + QmitkUSControlsProbesWidget* m_ControlProbesWidget; - QList m_CustomWidgetServiceReference; + QList m_CustomWidgetServiceReference; - bool m_ImageAlreadySetToNode; - unsigned int m_CurrentImageWidth; - unsigned int m_CurrentImageHeight; - double m_CurrentDynamicRange; + bool m_ImageAlreadySetToNode; + unsigned int m_CurrentImageWidth; + unsigned int m_CurrentImageHeight; + double m_CurrentDynamicRange; }; #endif // UltrasoundSupport_h