diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h index 13c0587375..04f6f78019 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/MitkRegionIterator.h @@ -1,133 +1,127 @@ /*=================================================================== 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 MitkRegionIterator_h #define MitkRegionIterator_h template class MitkRegionIterator { private: ImageType* m_Image; int m_Radius; float m_Spacing_x, m_Spacing_y, m_Spacing_z; public: MitkRegionIterator(ImageType* image, int radius) - :m_Image(image), - m_Radius(radius) + : m_Image(image) + , m_Radius(radius) {} void SetRadius(int radius) { m_Radius = radius; } void SetSpacing(float x, float y, float z) { m_Spacing_x = x; m_Spacing_y = y; m_Spacing_z = z; } int GetMeanPixelValueForRegion(IndexType seedIndex) { int mean = 0; int sum = 0; int count = 0; int radius_x = m_Radius / m_Spacing_x; int radius_y = m_Radius / m_Spacing_y; int radius_z = m_Radius / m_Spacing_z; - //x-Direction - for (int i = -radius_x; i <= radius_x; i++) + // x-Direction + for (int i = -radius_x; i <= radius_x; ++i) { IndexType localSeedIndex; localSeedIndex[0] = seedIndex[0] + i; - //y-Direction - for (int j = -radius_y; j <= radius_y; j++) + // y-Direction + for (int j = -radius_y; j <= radius_y; ++j) { localSeedIndex[1] = seedIndex[1] + j; - //z-Direction - for (int k = -radius_z; k <= radius_z; k++) + // z-Direction + for (int k = -radius_z; k <= radius_z; ++k) { localSeedIndex[2] = seedIndex[2] + k; - //MITK_INFO << m_Image->GetPixel(localSeedIndex); sum += m_Image->GetPixel(localSeedIndex); count++; } } } + mean = sum / count; return mean; } int GetThresholdByStdDivMethod(IndexType seedIndex) { - int thresholdRange = 0; - double* pixelValueVector = new double[1000]; - int count = 0; - double sum = 0; + std::vector pixelValueVector; int radius_x = m_Radius / m_Spacing_x; int radius_y = m_Radius / m_Spacing_y; int radius_z = m_Radius / m_Spacing_z; - //x-Direction - for (int i = -radius_x; i <= radius_x; i++) + IndexType localSeedIndex; + ImageType::PixelType currentValue; + + // x-Direction + for (int i = -radius_x; i <= radius_x; ++i) { - IndexType localSeedIndex; localSeedIndex[0] = seedIndex[0] + i; - //y-Direction - for (int j = -radius_y; j <= radius_y; j++) + // y-Direction + for (int j = -radius_y; j <= radius_y; ++j) { localSeedIndex[1] = seedIndex[1] + j; - //z-Direction - for (int k = -radius_z; k <= radius_z; k++) + // z-Direction + for (int k = -radius_z; k <= radius_z; ++k) { localSeedIndex[2] = seedIndex[2] + k; - int currentValue = m_Image->GetPixel(localSeedIndex); - sum += currentValue; - pixelValueVector[count++] = currentValue; - //MITK_INFO << m_Image->GetPixel(localSeedIndex); + currentValue = m_Image->GetPixel(localSeedIndex); + pixelValueVector.push_back(currentValue); } } } - int mean = sum / count; - int quadraticSum = 0; + auto sum = std::accumulate(pixelValueVector.begin(), pixelValueVector.end(), 0.0); + auto mean = sum / pixelValueVector.size(); + double quadraticSum = 0.0; - for (int i = 0; i < count; i++) + for (auto pixelValue : pixelValueVector) { - double helper = (pixelValueVector[i] - mean)*(pixelValueVector[i] - mean); + auto helper = (pixelValue - mean) * (pixelValue - mean); quadraticSum += helper; } - double SD = std::sqrt(quadraticSum / count); - - thresholdRange = SD; - return thresholdRange; + return std::sqrt(quadraticSum / pixelValueVector.size()); } - }; #endif //MitkRegionIterator_h \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.cpp b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.cpp index d9fab8a05b..72a2724c0d 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.cpp +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.cpp @@ -1,249 +1,207 @@ -#include "QmitkRegionGrowingThread.h" +/*=================================================================== -#include "MitkRegionIterator.h" +The Medical Imaging Interaction Toolkit (MITK) -// Blueberry -//#include -//#include -// -// Qmitk -//#include "QmitkRegionGrowingView.h" +Copyright (c) German Cancer Research Center, +Division of Medical and Biological Informatics. +All rights reserved. -//! [cpp-includes] -// Qmitk -//#include "QmitkPointListWidget.h" -//#include "QmitkRenderWindow.h" +This software is distributed WITHOUT ANY WARRANTY; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR +A PARTICULAR PURPOSE. -// MITK -//#include "mitkColorProperty.h" -//#include "mitkITKImageImport.h" -#include "mitkImageAccessByItk.h" -#include "mitkImageCast.h" -//#include "mitkProperties.h" -#include "itkMaskImageFilter.h" -#include "itkRegionOfInterestImageFilter.h" -//#include "itkNeighborhoodConnectedImageFilter.h" +See LICENSE.txt or http://www.mitk.org for details. +===================================================================*/ -#include +#include "QmitkRegionGrowingThread.h" #include "MitkRegionIterator.h" +// MITK +#include +#include +#include + +// itk +#include +#include +#include + QmitkRegionGrowingThread::QmitkRegionGrowingThread() - : m_ThresholdMethod(ThresholdMethod::easy), - m_Image(NULL) + : m_ThresholdMethod(ThresholdMethod::easy) + , m_Image(nullptr) + , m_PointSet(nullptr) { - m_PointSet = mitk::PointSet::New(); - + // nothing here } -QmitkRegionGrowingThread::~QmitkRegionGrowingThread() +void QmitkRegionGrowingThread::run() { + // actually perform region growing. Here we have both an image and some seed points + AccessByItk_1(m_Image, ItkImageProcessing, m_Image->GetGeometry()) } void QmitkRegionGrowingThread::SetImage(mitk::Image *image) { m_Image = image; } +void QmitkRegionGrowingThread::ResetResults() +{ + m_RegionGrowingResultVector.clear(); +} + QmitkRegionGrowingThread::ThresholdMethod QmitkRegionGrowingThread::GetThresholdMethod() { return m_ThresholdMethod; } void QmitkRegionGrowingThread::SetThresholdMethod(QmitkRegionGrowingThread::ThresholdMethod thresholdMethod) { m_ThresholdMethod = thresholdMethod; } -void QmitkRegionGrowingThread::run() -{ - // actually perform region growing. Here we have both an image and some seed points - AccessByItk_1(m_Image, ItkImageProcessing, m_Image->GetGeometry()) // some magic to call the correctly templated function -} - mitk::PointSet::Pointer QmitkRegionGrowingThread::GetPointSet() { return m_PointSet; } void QmitkRegionGrowingThread::SetPointSet(mitk::PointSet::Pointer pointSet) { m_PointSet = pointSet; } QVector QmitkRegionGrowingThread::GetRegionGrowingResultVector() { return m_RegionGrowingResultVector; } -//! [cpp-itkimageaccess] template void QmitkRegionGrowingThread::ItkImageProcessing(itk::Image *itkImage, mitk::BaseGeometry *imageGeometry) { typedef itk::Image InputImageType; - //typedef typename InputImageType::IndexType IndexType; typedef typename InputImageType::RegionType RegionType; typedef typename InputImageType::RegionType::IndexType IndexType; typedef typename InputImageType::RegionType::SizeType SizeType; // instantiate an ITK region growing filter, set its parameters typedef itk::ConnectedThresholdImageFilter RegionGrowingFilterType; typename RegionGrowingFilterType::Pointer regionGrower = RegionGrowingFilterType::New(); // determine a thresholding interval IndexType seedIndex; mitk::PointSet::PointsContainer *points = m_PointSet->GetPointSet()->GetPoints(); int iteration = 0; //m_Controls->progressBar->setMaximum(points->Size()); for (mitk::PointSet::PointsConstIterator pointsIterator = points->Begin(); pointsIterator != points->End(); ++pointsIterator) { //m_Controls->progressBar->setValue((int)iteration++); - emit updateProgressBar((int)iteration++); + emit UpdateProgressBar(iteration++); // first test if this point is inside the image at all if (!imageGeometry->IsInside(pointsIterator.Value())) { continue; } - TPixel min(std::numeric_limits::max()); - TPixel max(std::numeric_limits::min()); - - - //if (m_Controls->checkBoxCustomRange->isChecked()) - //{ - //max = m_Controls->spinBoxMax->value(); - //min = m_Controls->spinBoxMin->value(); - //} - // convert world coordinates to image indices imageGeometry->WorldToIndex(pointsIterator.Value(), seedIndex); //================================================= MitkRegionIterator mitkRegionIterator(itkImage, 1); int thresholdRange = 0; //================================================= // get the pixel value at this point TPixel currentPixelValue = itkImage->GetPixel(seedIndex); - //if (!m_Controls->checkBoxCustomRange->isChecked()) - //{ switch (m_ThresholdMethod) { case 0: - // adjust minimum and maximum values - if (currentPixelValue > max) - max = currentPixelValue; - - if (currentPixelValue < min) - min = currentPixelValue; thresholdRange = 130; break; - case 1: - // adjust minimum and maximum values - if (currentPixelValue > max) - max = currentPixelValue; - - if (currentPixelValue < min) - min = currentPixelValue; - //regionGrower->SetConnectivity(RegionGrowingFilterType::ConnectivityEnumType::FaceConnectivity); - mitkRegionIterator.SetRadius(4); mitkRegionIterator.SetSpacing( itkImage->GetSpacing()[0], itkImage->GetSpacing()[1], itkImage->GetSpacing()[2]); thresholdRange = mitkRegionIterator.GetThresholdByStdDivMethod(seedIndex); break; } - if (min < thresholdRange) + TPixel min = currentPixelValue - thresholdRange; + TPixel max = currentPixelValue + thresholdRange; + + // adjust pixel to be inside the image pixel type range + if (currentPixelValue < min) { - min = 0; + min = std::numeric_limits::min(); } - else + if (currentPixelValue > max) { - min -= thresholdRange; + max = std::numeric_limits::max(); } - max += thresholdRange; - //} - //m_Controls->spinBoxMin->setValue(min); - //m_Controls->spinBoxMax->setValue(max); - - MITK_INFO << "Values between min:" << min << " and max:" << max; + MITK_DEBUG << "Threshold range: " << thresholdRange; + MITK_DEBUG << "Values between min: " << min << " and max: " << max; regionGrower->SetInput(itkImage); - //not possible to set requested region for regiongrower. It is set to LargestPossibleRegion in Update() - //regionGrower->GetOutput()->SetRequestedRegion(region); - //regionGrower->GetOutput()->UpdateOutputInformation(); - // set thresholds and execute filter regionGrower->AddSeed(seedIndex); regionGrower->SetLower(min); regionGrower->SetUpper(max); regionGrower->SetConnectivity(RegionGrowingFilterType::FaceConnectivity); - regionGrower->Update(); int regionGrowingDiameter = 20; - //Define region for regiongrowing + // define region for region growing IndexType centerIndex = seedIndex; centerIndex[0] -= regionGrowingDiameter / 2; centerIndex[1] -= regionGrowingDiameter / 2; centerIndex[2] -= regionGrowingDiameter / 4; - //Set maximum region fpr regiongrowing + // set maximum region for region growing SizeType size; size.Fill(regionGrowingDiameter); size[0] = regionGrowingDiameter; size[1] = regionGrowingDiameter; size[2] = regionGrowingDiameter / 2; - RegionType region(centerIndex, size); + RegionType regionOfInterest(centerIndex, size); + regionOfInterest.Crop(itkImage->GetLargestPossibleRegion()); - region.Crop(itkImage->GetLargestPossibleRegion()); - - typedef itk::RegionOfInterestImageFilter< InputImageType, InputImageType > ROIFilterType; + typedef itk::RegionOfInterestImageFilter ROIFilterType; ROIFilterType::Pointer roiFilter = ROIFilterType::New(); - roiFilter->SetRegionOfInterest(region); + roiFilter->SetRegionOfInterest(regionOfInterest); roiFilter->SetInput(regionGrower->GetOutput()); roiFilter->Update(); - roiFilter->UpdateLargestPossibleRegion(); mitk::Image::Pointer resultImage; mitk::CastToMitkImage(roiFilter->GetOutput(), resultImage); mitk::DataNode::Pointer newNode = mitk::DataNode::New(); newNode->SetData(resultImage); // set some properties newNode->SetProperty("binary", mitk::BoolProperty::New(true)); newNode->SetProperty("name", mitk::StringProperty::New("dumb segmentation")); newNode->SetProperty("color", mitk::ColorProperty::New(1.0, 0.0, 0.0)); newNode->SetProperty("volumerendering", mitk::BoolProperty::New(true)); newNode->SetProperty("layer", mitk::IntProperty::New(1)); newNode->SetProperty("opacity", mitk::FloatProperty::New(0.5)); - newNode->SetProperty("globalObject_RWM", mitk::BoolProperty::New(true)); - - // add result to data tree - //this->GetDataStorage()->Add(newNode); - //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); m_RegionGrowingResultVector.append(newNode); regionGrower->ClearSeeds(); } - emit updateProgressBar((int)points->Size()); + emit UpdateProgressBar(static_cast(points->Size())); } -//! [cpp-itkimageaccess] diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.h b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.h index 1c3e298faf..2ac42f59cb 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.h +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingThread.h @@ -1,73 +1,74 @@ /*=================================================================== 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 QMITKREGIONGROWINGTHREAD_H_INCLUDED -#define QMITKREGIONGROWINGTHREAD_H_INCLUDED +#ifndef QMITKREGIONGROWINGTHREAD_H +#define QMITKREGIONGROWINGTHREAD_H -//QT headers -#include +#include +#include -#include "mitkPointSet.h" -#include "QmitkPointListWidget.h" +// QT +#include +#include +// itk #include - class QmitkRegionGrowingThread : public QThread { Q_OBJECT -signals: - void updateProgressBar(int value); +Q_SIGNALS: + + void UpdateProgressBar(int value); public: + QmitkRegionGrowingThread(); - ~QmitkRegionGrowingThread(); - //! [itkimageprocessing] /** \brief ITK image processing function This function is templated like an ITK image. The MITK-Macro AccessByItk determines the actual pixel type and dimensionality of a given MITK image and calls this function for further processing (in our case region growing) */ template void ItkImageProcessing(itk::Image *itkImage, mitk::BaseGeometry *imageGeometry); /* brief Method called once the thread is executed. */ void run() override; void SetImage(mitk::Image *image); + void ResetResults(); mitk::PointSet::Pointer GetPointSet(); void SetPointSet(mitk::PointSet::Pointer pointSet); - //! [members] - mitk::Image * m_Image; - /// \brief This is the actual seed point data object - mitk::PointSet::Pointer m_PointSet; - enum ThresholdMethod { easy, stddiv } m_ThresholdMethod; - + ThresholdMethod GetThresholdMethod(); void SetThresholdMethod(ThresholdMethod thresholdMethod); + QVector GetRegionGrowingResultVector(); + + mitk::Image* m_Image; + mitk::PointSet::Pointer m_PointSet; + QVector m_RegionGrowingResultVector; - QVector GetRegionGrowingResultVector(); }; -#endif //QMITKREGIONGROWINGTHREAD_H_INCLUDED \ No newline at end of file +#endif //QMITKREGIONGROWINGTHREAD_H diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.cpp b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.cpp index 87509c4527..f54c61f7af 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.cpp +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.cpp @@ -1,288 +1,285 @@ /*=================================================================== 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 gui qt regiongrowing plugin +#include "QmitkRegionGrowingView.h" +#include "MitkRegionIterator.h" + // Blueberry #include #include -// Qmitk -#include "QmitkRegionGrowingView.h" - -//! [cpp-includes] // Qmitk #include "QmitkPointListWidget.h" #include "QmitkRenderWindow.h" // MITK #include "mitkColorProperty.h" #include "mitkITKImageImport.h" #include "mitkProperties.h" // ITK #include "itksys/SystemTools.hxx" -//! [cpp-includes] - // Qt #include -#include "MitkRegionIterator.h" const std::string QmitkRegionGrowingView::VIEW_ID = "org.mitk.views.example.regiongrowing"; -QmitkRegionGrowingView::QmitkRegionGrowingView() : m_PointListWidget(NULL) +QmitkRegionGrowingView::QmitkRegionGrowingView() + : m_PointListWidget(nullptr) { m_RegionGrowingThread = new QmitkRegionGrowingThread(); } QmitkRegionGrowingView::~QmitkRegionGrowingView() { - while (this->m_RegionGrowingThread->isRunning()) // wait until thread has finished + if (!m_RegionGrowingThread->isFinished()) { - itksys::SystemTools::Delay(100); + m_RegionGrowingThread->terminate(); + m_RegionGrowingThread->wait(); } - delete this->m_RegionGrowingThread; + m_RegionGrowingThread->deleteLater(); } void QmitkRegionGrowingView::SetFocus() { m_Controls->buttonPerformImageProcessing->setFocus(); } void QmitkRegionGrowingView::CreateQtPartControl(QWidget *parent) { m_Controls = new Ui::QmitkRegionGrowingViewControls; // create GUI widgets from the Qt Designer's .ui file m_Controls->setupUi(parent); //add different methods for threshold determination m_Controls->comboBoxThresholdMethod->addItem("easy"); m_Controls->comboBoxThresholdMethod->addItem("stddiv"); this->connectSignals(); - //! [cpp-createqtpartcontrol] // create a QmitkPointListWidget and add it to the widget created from .ui file - m_PointListWidget = new QmitkPointListWidget(); + m_PointListWidget = new QmitkPointListWidget(parent); m_Controls->verticalLayout->addWidget(m_PointListWidget, 1); // retrieve a possibly existing IRenderWindowPart if (mitk::IRenderWindowPart *renderWindowPart = GetRenderWindowPart()) { // let the point set widget know about the render window part (crosshair updates) RenderWindowPartActivated(renderWindowPart); } this->setupPointSetNode(); m_Controls->buttonPerformImageProcessing->setEnabled(false); m_Controls->pushButtonAddPointList->setEnabled(false); m_Controls->progressBar->setMinimum(0); m_Controls->progressBar->setMaximum(0); m_Controls->progressBar->hide(); } void QmitkRegionGrowingView::connectSignals() { connect(m_Controls->buttonPerformImageProcessing, SIGNAL(clicked()), this, SLOT(OnStartRegionGrowing())); connect(m_Controls->checkBoxCustomRange, SIGNAL(clicked(bool)), this, SLOT(OnUseCustomRange(bool))); connect(m_Controls->pushButtonClearPointList, SIGNAL(clicked()), this, SLOT(OnClearPointSet())); connect(m_Controls->comboBoxThresholdMethod, SIGNAL(currentIndexChanged(int)), this, SLOT(OnSetThresholdMethod(int))); connect(m_Controls->pushButtonAddPointList, SIGNAL(clicked()), this, SLOT(OnAddPointSet())); - connect((QObject*) this->m_RegionGrowingThread, SIGNAL(finished()), this, SLOT(OnRegionGrowingThreadFinished()), Qt::QueuedConnection); - connect((QObject*) this->m_RegionGrowingThread, SIGNAL(updateProgressBar(int)), this, SLOT(OnUpdateProgressBar(int)), Qt::QueuedConnection); + connect((QObject*) m_RegionGrowingThread, SIGNAL(finished()), this, SLOT(OnRegionGrowingThreadFinished()), Qt::QueuedConnection); + connect((QObject*) m_RegionGrowingThread, SIGNAL(UpdateProgressBar(int)), this, SLOT(OnUpdateProgressBar(int)), Qt::QueuedConnection); } void QmitkRegionGrowingView::setupPointSetNode() { - mitk::DataNode::Pointer pointSetNode = this->GetDataStorage()->GetNamedNode("seed points for region growing"); + mitk::DataNode::Pointer pointSetNode = GetDataStorage()->GetNamedNode("seed points for region growing"); if (pointSetNode == nullptr) { // create a new DataNode containing a PointSet with some interaction pointSetNode = mitk::DataNode::New(); pointSetNode->SetData(mitk::PointSet::New()); pointSetNode->SetName("seed points for region growing"); pointSetNode->SetProperty("helper object", mitk::BoolProperty::New(true)); pointSetNode->SetProperty("layer", mitk::IntProperty::New(1024)); - pointSetNode->SetProperty("globalObject_RWM", mitk::BoolProperty::New(true)); // add the pointset to the data storage (for rendering and access by other modules) GetDataStorage()->Add(pointSetNode); } // tell the GUI widget about the point set m_PointListWidget->SetPointSetNode(pointSetNode); - //! [cpp-createqtpartcontrol] } void QmitkRegionGrowingView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/, const QList &nodes) { // iterate all selected objects, adjust warning visibility - foreach (mitk::DataNode::Pointer node, nodes) + for (const auto& node : nodes) { if (node.IsNotNull() && dynamic_cast(node->GetData()) && !m_RegionGrowingThread->isRunning()) { m_Controls->labelWarning->setVisible(false); m_Controls->buttonPerformImageProcessing->setEnabled(true); return; } else if (node.IsNotNull() && dynamic_cast(node->GetData())) { m_Controls->pushButtonAddPointList->setEnabled(true); return; } } m_Controls->labelWarning->setVisible(true); m_Controls->buttonPerformImageProcessing->setEnabled(false); m_Controls->pushButtonAddPointList->setEnabled(false); } void QmitkRegionGrowingView::RenderWindowPartActivated(mitk::IRenderWindowPart *renderWindowPart) { // let the point set widget know about the slice navigation controllers // in the active render window part (crosshair updates) - foreach (QmitkRenderWindow *renderWindow, renderWindowPart->GetQmitkRenderWindows().values()) + for (auto* renderWindow : renderWindowPart->GetQmitkRenderWindows().values()) { m_PointListWidget->AddSliceNavigationController(renderWindow->GetSliceNavigationController()); } } void QmitkRegionGrowingView::RenderWindowPartDeactivated(mitk::IRenderWindowPart *renderWindowPart) { - foreach (QmitkRenderWindow *renderWindow, renderWindowPart->GetQmitkRenderWindows().values()) + for (auto* renderWindow : renderWindowPart->GetQmitkRenderWindows().values()) { m_PointListWidget->RemoveSliceNavigationController(renderWindow->GetSliceNavigationController()); } } void QmitkRegionGrowingView::OnStartRegionGrowing() { m_Controls->buttonPerformImageProcessing->setEnabled(false); m_Controls->progressBar->show(); m_Controls->progressBar->setValue(0); mitk::PointSet::PointsContainer *points = m_PointListWidget->GetPointSet()->GetPointSet()->GetPoints(); m_Controls->progressBar->setMaximum(points->Size()); - QList nodes = this->GetDataManagerSelection(); + QList nodes = GetDataManagerSelection(); if (nodes.empty()) + { return; + } mitk::DataNode *node = nodes.front(); - if (!node) + if (nullptr == node) { // Nothing selected. Inform the user and return - QMessageBox::information(NULL, "Template", "Please load and select an image before starting image processing."); + QMessageBox::information(nullptr, "Template", "Please load and select an image before starting image processing."); return; } // a node itself is not very useful, we need its data item (the image) mitk::BaseData *data = node->GetData(); - if (data) + if (nullptr != data) { // test if this data item is an image or not (could also be a surface or something totally different) - mitk::Image *image = dynamic_cast(data); - if (image) + mitk::Image *image = dynamic_cast(data); + if (nullptr != image) { - //! [cpp-doimageprocessing] // So we have an image. Let's see if the user has set some seed points already if (m_PointListWidget->GetPointSet()->GetSize() == 0) { // no points there. Not good for region growing - QMessageBox::information(NULL, + QMessageBox::information(nullptr, "Region growing functionality", "Please set some seed points inside the image first.\n" "(hold Shift key and click left mouse button inside the image.)"); return; } m_RegionGrowingThread->SetImage(image); + m_RegionGrowingThread->ResetResults(); m_RegionGrowingThread->SetPointSet(m_PointListWidget->GetPointSet()); m_RegionGrowingThread->start(); } } } void QmitkRegionGrowingView::OnUseCustomRange(bool useCustomRange) { m_Controls->spinBoxMax->setEnabled(useCustomRange); m_Controls->spinBoxMin->setEnabled(useCustomRange); } void QmitkRegionGrowingView::OnAddPointSet() { - QList pointSetNodeList = this->GetDataManagerSelection(); + QList pointSetNodeList = GetDataManagerSelection(); mitk::DataNode::Pointer pointSetNode = pointSetNodeList.first(); - //mitk::DataNode::Pointer pointSetNode = this->GetDataStorage()->GetNamedNode("seed points for region growing"); // tell the GUI widget about the point set m_PointListWidget->SetPointSetNode(pointSetNode); } void QmitkRegionGrowingView::OnClearPointSet() { QMessageBox::StandardButton reply; reply = QMessageBox::question(nullptr, "Test", "Are you sure?", QMessageBox::Yes | QMessageBox::No, QMessageBox::No); - if (reply == QMessageBox::Yes) { + if (reply == QMessageBox::Yes) + { m_PointListWidget->GetPointSet()->Clear(); } - else { + else + { //Clearing point set canceled } } void QmitkRegionGrowingView::OnSetThresholdMethod(int index) { int currentIndex = m_Controls->comboBoxThresholdMethod->currentIndex(); switch (currentIndex) { case 0: m_RegionGrowingThread->SetThresholdMethod(QmitkRegionGrowingThread::ThresholdMethod::easy); break; - case 1: m_RegionGrowingThread->SetThresholdMethod(QmitkRegionGrowingThread::ThresholdMethod::stddiv); break; - default: m_RegionGrowingThread->SetThresholdMethod(QmitkRegionGrowingThread::ThresholdMethod::easy); break; } } void QmitkRegionGrowingView::OnUpdateProgressBar(int value) { m_Controls->progressBar->setValue(value); } void QmitkRegionGrowingView::OnRegionGrowingThreadFinished() { QVector regionGrowingResultVector = m_RegionGrowingThread->GetRegionGrowingResultVector(); - foreach(mitk::DataNode::Pointer regionGrowingResult, regionGrowingResultVector) + for (const auto& regionGrowingResult : regionGrowingResultVector) { // add result to data tree - this->GetDataStorage()->Add(regionGrowingResult); + GetDataStorage()->Add(regionGrowingResult); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } m_Controls->progressBar->hide(); m_Controls->buttonPerformImageProcessing->setEnabled(true); -} \ No newline at end of file +} diff --git a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.h b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.h index 4f584dbbd2..cacb37914f 100644 --- a/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.h +++ b/Plugins/org.mitk.gui.qt.regiongrowing/src/internal/QmitkRegionGrowingView.h @@ -1,95 +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. ===================================================================*/ #ifndef QmitkRegionGrowingView_h #define QmitkRegionGrowingView_h #include #include #include "ui_QmitkRegionGrowingViewControls.h" -//! [includes] #include "mitkIRenderWindowPartListener.h" #include #include "QmitkRegionGrowingThread.h" class QmitkPointListWidget; -//! [includes] /** \brief QmitkRegionGrowingView - - \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. - - \sa QmitkAbstractView - \ingroup ${plugin_target}_internal */ class QmitkRegionGrowingView : public QmitkAbstractView, public mitk::IRenderWindowPartListener { - // 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: + static const std::string VIEW_ID; QmitkRegionGrowingView(); ~QmitkRegionGrowingView(); -protected slots: +protected Q_SLOTS: /// \brief Called when the user clicks the GUI button void OnStartRegionGrowing(); void OnUseCustomRange(bool useCustomRange); void OnAddPointSet(); void OnClearPointSet(); void OnSetThresholdMethod(int index); protected: + virtual void CreateQtPartControl(QWidget *parent) override; virtual void SetFocus() override; virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source, const QList &nodes) override; - //! [render-window-part-listener] void RenderWindowPartActivated(mitk::IRenderWindowPart *renderWindowPart) override; void RenderWindowPartDeactivated(mitk::IRenderWindowPart *renderWindowPart) override; - //! [render-window-part-listener] Ui::QmitkRegionGrowingViewControls* m_Controls; -private slots: +private Q_SLOTS: + void OnUpdateProgressBar(int value); void OnRegionGrowingThreadFinished(); private: + void connectSignals(); void setupPointSetNode(); QmitkRegionGrowingThread* m_RegionGrowingThread; QmitkPointListWidget *m_PointListWidget; }; #endif // QmitkRegionGrowingView_h