diff --git a/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkSurfaceModifier.cpp b/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkSurfaceModifier.cpp index 4b075faf56..938f522944 100644 --- a/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkSurfaceModifier.cpp +++ b/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkSurfaceModifier.cpp @@ -1,245 +1,245 @@ /*=================================================================== 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. ===================================================================*/ // mitk headers #include "mitkSurfaceModifier.h" #include "mitkSurfaceToPointSetFilter.h" // vtk headers #include #include #include #include mitk::SurfaceModifier::SurfaceModifier() { m_myRandomGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); } mitk::SurfaceModifier::~SurfaceModifier() { } mitk::Point3D mitk::SurfaceModifier::PerturbePointAlongAxis(mitk::Point3D point, mitk::Vector3D axis, double variance) { if (m_myRandomGenerator.IsNull()) m_myRandomGenerator = itk::Statistics::MersenneTwisterRandomVariateGenerator::New(); mitk::Point3D returnValue; // normalize axis mitk::Vector3D normalizedAxis = axis; normalizedAxis.Normalize(); // create noise double noise = m_myRandomGenerator->GetNormalVariate(0.0, variance); // std::cout <GetNormalVariate(0.0, varianceX); returnValue[1] = point[1] + m_myRandomGenerator->GetNormalVariate(0.0, varianceY); returnValue[2] = point[2] + m_myRandomGenerator->GetNormalVariate(0.0, varianceZ); return returnValue; } bool mitk::SurfaceModifier::TransformSurface(mitk::Surface::Pointer surface, itk::Matrix TransformationR, itk::Vector TransformationT) { // apply transformation vtkSmartPointer points = vtkSmartPointer::New(); points->ShallowCopy(surface->GetVtkPolyData()->GetPoints()); for (unsigned int i = 0; i < points->GetNumberOfPoints(); i++) { double p[3]; points->GetPoint(i, p); mitk::Point3D point; point[0] = p[0]; point[1] = p[1]; point[2] = p[2]; point = TransformPoint(point, TransformationR, TransformationT); p[0] = point[0]; p[1] = point[1]; p[2] = point[2]; points->SetPoint(i, p); } surface->GetVtkPolyData()->SetPoints(points); return true; } bool mitk::SurfaceModifier::TransformSurfaceCoGCoordinates(mitk::Surface::Pointer surface, itk::Matrix TransformationR, itk::Vector TransformationT, itk::Matrix &OverallTransformationR, itk::Vector &OverallTransformationT) { // initialize return values OverallTransformationR.SetIdentity(); OverallTransformationT.Fill(0); // move surface to center of gravity and store transformation itk::Matrix TransformRToCenter; itk::Vector TransformTToCenter; MoveSurfaceToCenter(surface, TransformRToCenter, TransformTToCenter); OverallTransformationR = TransformRToCenter; OverallTransformationT = TransformTToCenter; // apply transformation TransformSurface(surface, TransformationR, TransformationT); OverallTransformationR = TransformationR * OverallTransformationR; OverallTransformationT = (TransformationR * OverallTransformationT) + TransformationT; // move surface back to original position (build inverse transformation andy apply it) TransformRToCenter = TransformRToCenter.GetInverse(); TransformTToCenter = (TransformRToCenter * TransformTToCenter) * -1.; TransformSurface(surface, TransformRToCenter, TransformTToCenter); OverallTransformationR = TransformRToCenter * OverallTransformationR; OverallTransformationT = (TransformRToCenter * OverallTransformationT) + TransformTToCenter; return true; } mitk::Point3D mitk::SurfaceModifier::TransformPoint(mitk::Point3D point, itk::Matrix TransformationR, itk::Vector TransformationT) { mitk::Point3D returnValue = TransformationR * point + TransformationT; return returnValue; } bool mitk::SurfaceModifier::AddOutlierToSurface( mitk::Surface::Pointer surface, double varianceX, double varianceY, double varianceZ, double outlierChance) { vtkSmartPointer points = vtkSmartPointer::New(); points->ShallowCopy(surface->GetVtkPolyData()->GetPoints()); for (unsigned int i = 0; i < points->GetNumberOfPoints(); i++) { double p[3]; points->GetPoint(i, p); mitk::Point3D point; point[0] = p[0]; point[1] = p[1]; point[2] = p[2]; if ((outlierChance - vtkMath::Random(0, 1)) > 0) point = PerturbePoint(point, varianceX, varianceY, varianceZ); p[0] = point[0]; p[1] = point[1]; p[2] = point[2]; points->SetPoint(i, p); } surface->GetVtkPolyData()->SetPoints(points); return true; } bool mitk::SurfaceModifier::PerturbeSurface( - mitk::Surface::Pointer surface, double varianceX, double varianceY, double varianceZ, double maxNoiseVectorLenght) + mitk::Surface::Pointer surface, double varianceX, double varianceY, double varianceZ, double maxNoiseVectorLength) { vtkSmartPointer points = vtkSmartPointer::New(); points->ShallowCopy(surface->GetVtkPolyData()->GetPoints()); for (unsigned int i = 0; i < points->GetNumberOfPoints(); i++) { double p[3]; points->GetPoint(i, p); mitk::Point3D point; point[0] = p[0]; point[1] = p[1]; point[2] = p[2]; - point = PerturbePoint(point, varianceX, varianceY, varianceZ, maxNoiseVectorLenght); + point = PerturbePoint(point, varianceX, varianceY, varianceZ); p[0] = point[0]; p[1] = point[1]; p[2] = point[2]; points->SetPoint(i, p); } surface->GetVtkPolyData()->SetPoints(points); return true; } bool mitk::SurfaceModifier::MoveSurfaceToCenter(mitk::Surface::Pointer surface) { itk::Matrix dummyR; itk::Vector dummyT; return MoveSurfaceToCenter(surface, dummyR, dummyT); } bool mitk::SurfaceModifier::MoveSurfaceToCenter(mitk::Surface::Pointer surface, itk::Matrix &TransformR, itk::Vector &TransformT) { // get center of cravity mitk::Point3D CoG = GetCenterOfGravity(surface); // initialize transforms TransformR.SetIdentity(); TransformT.Fill(0); TransformT[0] = -CoG[0]; TransformT[1] = -CoG[1]; TransformT[2] = -CoG[2]; // apply transform return TransformSurface(surface, TransformR, TransformT); } mitk::Point3D mitk::SurfaceModifier::GetCenterOfGravity(mitk::Surface::Pointer surface) { // convert surface to point set mitk::SurfaceToPointSetFilter::Pointer myConverter = mitk::SurfaceToPointSetFilter::New(); myConverter->SetInput(surface); myConverter->Update(); mitk::PointSet::Pointer pointSet = myConverter->GetOutput(); // calculate center of gravity mitk::Point3D cog; cog.Fill(0); for (int i = 0; i < pointSet->GetSize(); i++) { cog[0] += pointSet->GetPoint(i)[0]; cog[1] += pointSet->GetPoint(i)[1]; cog[2] += pointSet->GetPoint(i)[2]; } cog[0] /= pointSet->GetSize(); cog[1] /= pointSet->GetSize(); cog[2] /= pointSet->GetSize(); return cog; } mitk::Surface::Pointer mitk::SurfaceModifier::DeepCopy(mitk::Surface::Pointer originalSurface) { mitk::Surface::Pointer clonedSurface = mitk::Surface::New(); vtkSmartPointer clonedPolyData = vtkSmartPointer::New(); clonedPolyData->DeepCopy(originalSurface->GetVtkPolyData()); clonedSurface->SetVtkPolyData(clonedPolyData); return clonedSurface; } diff --git a/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkTargetPointsCalculator.h b/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkTargetPointsCalculator.h index 503550fa84..84904df251 100644 --- a/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkTargetPointsCalculator.h +++ b/Examples/Plugins/org.mitk.example.gui.imaging/src/internal/surfaceutilities/mitkTargetPointsCalculator.h @@ -1,100 +1,99 @@ /*=================================================================== 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 MITKTARGETPOINTSCALCULATOR_H_HEADER_INCLUDED_ #define MITKTARGETPOINTSCALCULATOR_H_HEADER_INCLUDED_ // mitk headers #include "mitkCommon.h" #include "mitkImage.h" #include "mitkPointSet.h" #include "mitkSurface.h" // itk headers #include "itkObject.h" #include namespace mitk { /** * @brief This class offers methods to automatically calculate target points inside a (closed) surface. */ class TargetPointsCalculator : public itk::Object { public: mitkClassMacroItkParent(TargetPointsCalculator, itk::Object); itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** @brief identifier for target point calculation method */ enum TargetPointCalculationMethod { EvenlyDistributedTargetPoints, OneTargetPointInCenterOfGravity }; /** @brief Sets the method for the target point calculation. Default value is EvenlyDistributedTargetPoints. */ void SetTargetPointCalculationMethod(TargetPointCalculationMethod method); /** @brief Sets the inter point distance (in mm), which is a parameter for the evenly distributed target points. * This parameter is only used if the method is set to EvenlyDistributedTargetPoints. Default value is 20. */ void SetInterPointDistance(int d); - using Superclass::SetInput; /** @brief Sets the input surface. This parameter must be set before calculation is started. */ void SetInput(mitk::Surface::Pointer input); /** @brief Calculates the target points. * @return Returns true if calculation was successful. False if not, you can get an error message in this case. */ bool DoCalculate(); /** @return Returns the calculated target points. Returns null if no target points are calculated yet. */ mitk::PointSet::Pointer GetOutput(); /** @return Returns the last error message. Returns an empty string if there was no error yet. */ std::string GetErrorMessage(); protected: TargetPointsCalculator(); ~TargetPointsCalculator(); typedef itk::Image ImageType; int m_InterPointDistance; mitk::PointSet::Pointer m_Output; mitk::Surface::Pointer m_Input; std::string m_ErrorMessage; TargetPointCalculationMethod m_Method; mitk::Image::Pointer CreateBinaryImage(); mitk::PointSet::Pointer CreateTargetPoints(mitk::Image::Pointer binaryImage); bool isInside(ImageType::Pointer currentImageAsitkImage, mitk::Point3D p); int RoundUpToGatter(int i, int gatter); int RoundUpToCentimeters(int i); mitk::PointSet::Pointer CreateTargetPointInCOG(mitk::Surface::Pointer surface); }; } #endif diff --git a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp index dfda03fffe..97db4353ce 100644 --- a/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp +++ b/Plugins/org.mitk.gui.qt.tubegraph/src/internal/QmitkTubeGraphDeleteLabelGroupDialog.cpp @@ -1,92 +1,92 @@ /*=================================================================== 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 "QmitkTubeGraphDeleteLabelGroupDialog.h" #include #include #include #include #include QmitkTubeGraphDeleteLabelGroupDialog::QmitkTubeGraphDeleteLabelGroupDialog(QWidget* parent) :QDialog(parent) { QDialog::setFixedSize(400, 400); auto layout = new QVBoxLayout(this); layout->setMargin(5); layout->setSpacing(5); descriptionLabel = new QLabel("Which Label Group should be removed?", this); layout->addWidget(descriptionLabel); labelGroupListWidget = new QListWidget(this); labelGroupListWidget->setSelectionMode(QAbstractItemView::MultiSelection); layout->addWidget(labelGroupListWidget); auto buttonLayout = new QHBoxLayout(); deleteButton = new QPushButton("Delete", this); buttonLayout->addWidget(deleteButton); connect( deleteButton, SIGNAL(clicked()), this, SLOT(OnDeleteLabelGroupClicked()) ); cancleButton = new QPushButton("Cancle", this); buttonLayout->addWidget(cancleButton); connect( cancleButton, SIGNAL(clicked()), this, SLOT(reject()) ); layout->addLayout(buttonLayout); deleteButton->setFocus(); } QmitkTubeGraphDeleteLabelGroupDialog::~QmitkTubeGraphDeleteLabelGroupDialog() { delete descriptionLabel; delete labelGroupListWidget; delete deleteButton; delete cancleButton; } void QmitkTubeGraphDeleteLabelGroupDialog::OnDeleteLabelGroupClicked() { //get selected items and save it in vector m_LabelGroupList.clear(); for (int i =0; i < labelGroupListWidget->count(); i++) { QListWidgetItem* newItem= labelGroupListWidget->item(i); if(newItem->isSelected()) //For all checked items { m_LabelGroupList.push_back(newItem->text()); } } this->accept(); } QStringList QmitkTubeGraphDeleteLabelGroupDialog::GetSelectedLabelGroups() { return m_LabelGroupList; } void QmitkTubeGraphDeleteLabelGroupDialog::SetLabelGroups(const QStringList &labelGroups) { - for (QStringList::iterator iterator = labelGroups.begin(); iterator != labelGroups.end(); iterator++) - labelGroupListWidget->addItem(*iterator); + for (const auto &labelGroup : labelGroups) + labelGroupListWidget->addItem(labelGroup); } 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 834fedd635..3862f7413f 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())); 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() != nullptr) && (!mitk::Equal(m_OldGeometry.GetPointer(), curOutput->GetGeometry(), 0.0001, false)) ) { mitk::IRenderWindowPart* renderWindow = this->GetRenderWindowPart(); if ((renderWindow != nullptr) && (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() != static_cast(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 for (auto device : this->m_Controls.m_ActiveVideoDevices->GetAllServices()) { - if (device.IsNotNull() && device->GetIsActive()) + if (device != nullptr && 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); }