diff --git a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.cpp b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.cpp index f1fa9eefb0..dd7bd6ad49 100644 --- a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.cpp +++ b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.cpp @@ -1,178 +1,180 @@ /*=================================================================== 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 "PhotoacousticArtifact.h" #include #include #include #include #include #include //#include //#include // Helper function to create a fully set up instance of our // AwesomeImageInteractor, based on the state machine specified in Paint.xml // as well as its configuration in PaintConfig.xml. Both files are compiled // into our MyAwesomeLib module as resources. //static AwesomeImageInteractor::Pointer CreateAwesomeImageInteractor() //{ // auto myAwesomeLib = us::ModuleRegistry::GetModule("MyAwesomeLib"); // // auto interactor = AwesomeImageInteractor::New(); // interactor->LoadStateMachine("Paint.xml", myAwesomeLib); // interactor->SetEventConfig("PaintConfig.xml", myAwesomeLib); // // return interactor; //} // Don't forget to initialize the VIEW_ID. const std::string PhotoacousticArtifact::VIEW_ID = "photoacousticproject.views.photoacoustic.artifacts"; void PhotoacousticArtifact::CreateQtPartControl(QWidget* parent) { // Setting up the UI is a true pleasure when using .ui files, isn't it? m_Controls.setupUi(parent); // Wire up the UI widgets with our functionality. - connect(m_Controls.processImageButton, SIGNAL(clicked()), this, SLOT(ProcessSelectedImage())); + connect(m_Controls.applyFilterPushButton, SIGNAL(clicked()), this, SLOT(ProcessSelectedImage())); } void PhotoacousticArtifact::SetFocus() { - m_Controls.processImageButton->setFocus(); + //m_Controls.processImageButton->setFocus(); } void PhotoacousticArtifact::OnSelectionChanged(berry::IWorkbenchPart::Pointer, const QList& dataNodes) { for (const auto& dataNode : dataNodes) { // Write robust code. Always check pointers before using them. If the // data node pointer is null, the second half of our condition isn't // even evaluated and we're safe (C++ short-circuit evaluation). if (dataNode.IsNotNull() && dynamic_cast(dataNode->GetData()) != nullptr) { m_Controls.selectImageLabel->setVisible(false); return; } } + //m_Controls.horizontalLayout->activate(); j + // Nothing is selected or the selection doesn't contain an image. - m_Controls.selectImageLabel->setVisible(true); + //m_Controls.selectImageLabel->setVisible(true); } void PhotoacousticArtifact::ProcessSelectedImage() { // Before we even think about processing something, we need to make sure // that we have valid input. Don't be sloppy, this is a main reason // for application crashes if neglected. mitk::PhotoacousticArtifact* filter = new mitk::PhotoacousticArtifact(); auto selectedDataNodes = this->GetDataManagerSelection(); if (selectedDataNodes.empty()) return; auto firstSelectedDataNode = selectedDataNodes.front(); if (firstSelectedDataNode.IsNull()) { QMessageBox::information(nullptr, "Photoacoustic Artifact", "Please load and select an image before starting image processing."); return; } auto data = firstSelectedDataNode->GetData(); // Something is selected, but does it contain data? if (data != nullptr) { // We don't use the auto keyword here, which would evaluate to a native // image pointer. Instead, we want a smart pointer in order to ensure that // the image isn't deleted somewhere else while we're using it. mitk::Image::Pointer image = dynamic_cast(data); // Something is selected and it contains data, but is it an image? if (image.IsNotNull()) { auto imageName = firstSelectedDataNode->GetName(); - auto offset = m_Controls.offsetSpinBox->value(); + auto offset = m_Controls.chooseThresholdSpinBox->value(); MITK_INFO << "Process image \"" << imageName << "\" ..."; // We're finally using the AwesomeImageFilter from our AwesomeLib module. //auto filter = AwesomeImageFilter::New(); //filter->SetInput(image); //filter->SetOffset(offset); //filter->Update(); //mitk::Image::Pointer processedImage = filter->GetOutput(); //if (processedImage.IsNull() || !processedImage->IsInitialized()) //return; MITK_INFO << " done"; // Stuff the resulting image into a data node, set some properties, // and add it to the data storage, which will eventually display the // image in the application. auto processedImageDataNode = mitk::DataNode::New(); //processedImageDataNode->SetData(processedImage); - QString name = QString("%1 (Offset: %2)").arg(imageName.c_str()).arg(offset); - processedImageDataNode->SetName(name.toStdString()); + //QString name = QString("%1 (Offset: %2)").arg(imageName.c_str()).arg(offset); + //processedImageDataNode->SetName(name.toStdString()); // We don't really need to copy the level window, but if we wouldn't // do it, the new level window would be initialized to display the image // with optimal contrast in order to capture the whole range of pixel // values. This is also true for the input image as long as one didn't // modify its level window manually. Thus, the images would appear // identical unless you compare the level window widget for both images. mitk::LevelWindow levelWindow; if (firstSelectedDataNode->GetLevelWindow(levelWindow)) processedImageDataNode->SetLevelWindow(levelWindow); // We also attach our AwesomeImageInteractor, which allows us to paint // on the resulting images by using the mouse as long as the CTRL key // is pressed. //auto interactor = CreateAwesomeImageInteractor(); //if (interactor.IsNotNull()) // interactor->SetDataNode(processedImageDataNode); this->GetDataStorage()->Add(processedImageDataNode); } } // Now it's your turn. This class/method has lots of room for improvements, // for example: // // - What happens when multiple items are selected but the first one isn't // an image? - There isn't any feedback for the user at all. // - What's the front item of a selection? Does it depend on the order // of selection or the position in the Data Manager? - Isn't it // better to process all selected images? Don't forget to adjust the // titles of the UI widgets. // - In addition to the the displayed label, it's probably a good idea to // enable or disable the button depending on the selection. } diff --git a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.h b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.h index 916da8e3f5..f369e1707a 100644 --- a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.h +++ b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifact.h @@ -1,69 +1,69 @@ /*=================================================================== 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 PhotoacousticArtifact_h #define PhotoacousticArtifact_h #include #include // There's an item "PhotoacousticArtifactViewControls.ui" in the UI_FILES list in // files.cmake. The Qt UI Compiler will parse this file and generate a // header file prefixed with "ui_", which is located in the build directory. // Use Qt Creator to view and edit .ui files. The generated header file // provides a class that contains all of the UI widgets. #include // All views in MITK derive from QmitkAbstractView. You have to override // at least the two methods CreateQtPartControl() and SetFocus(). class PhotoacousticArtifact : public QmitkAbstractView { // As QmitkAbstractView derives from QObject and we want to use the Qt // signal and slot mechanism, we must not forget the Q_OBJECT macro. // This header file also has to be listed in MOC_H_FILES in files.cmake, // in order that the Qt Meta-Object Compiler can find and process this // class declaration. Q_OBJECT - + public: // This is a tricky one and will give you some headache later on in // your debug sessions if it has been forgotten. Also, don't forget // to initialize it in the implementation file. static const std::string VIEW_ID; // In this method we initialize the GUI components and connect the // associated signals and slots. void CreateQtPartControl(QWidget* parent) override; -private slots: + private slots: void ProcessSelectedImage(); private: // Typically a one-liner. Set the focus to the default widget. void SetFocus() override; // This method is conveniently called whenever the selection of Data Manager // items changes. void OnSelectionChanged( berry::IWorkbenchPart::Pointer source, const QList& dataNodes) override; // Generated from the associated UI file, it encapsulates all the widgets // of our view. Ui::PhotoacousticArtifactViewControls m_Controls; }; #endif diff --git a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifactViewControls.ui b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifactViewControls.ui index bab44d293a..81ffd320fc 100644 --- a/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifactViewControls.ui +++ b/Plugins/org.mitk.gui.qt.photoacousticartifacts/src/internal/PhotoacousticArtifactViewControls.ui @@ -1,87 +1,82 @@ PhotoacousticArtifactViewControls - + 0 0 220 160 Photoacoustic Artifacts QLabel { color: rgb(255, 0, 0) } Please select an image. - - - - 0 - - - - - Offset - - - - - - - - 0 - 0 - - - - 9999 - - - - - + + + + + + 101 + 16777215 + + + + Choose threshold: + + + + + + + + 202 + 16777215 + + + + + - - - Process selected image - + - Add Offset + Apply Filter Qt::Vertical QSizePolicy::Expanding 20 220