Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[InteractiveSegmentation] Decouple progress bar & more #146

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Modules/CaPTkInteractiveSegmentation/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
mitk_create_module(
INCLUDE_DIRS PUBLIC include third_party/jsoncpp/include
PACKAGE_DEPENDS ITK Qt5|Core+Widgets PRIVATE yaml-cpp
PACKAGE_DEPENDS ITK Qt5|Core PRIVATE yaml-cpp
DEPENDS PUBLIC MitkCore MitkMultilabel #MitkCaPTkCommon
)

add_subdirectory(cmdapps)
10 changes: 0 additions & 10 deletions Modules/CaPTkInteractiveSegmentation/cmdapps/CMakeLists.txt

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@
// that you want to be part of the public interface of your module.
#include <MitkCaPTkInteractiveSegmentationExports.h>

#include "CaPTkInteractiveSegmentationAdapter.h"
#include "GeodesicTrainingSegmentation.h"

#include "mitkImage.h"
#include "mitkLabelSetImage.h"
#include "mitkDataStorage.h"

#include <QObject>
#include <QFuture>
#include <QFutureWatcher>
#include <QProgressBar>

/** \class CaPTkInteractiveSegmentation
* \brief Singleton class that runs the interactive segmentation
* algorithm and adds the result to the data storage
*/
class MITKCAPTKINTERACTIVESEGMENTATION_EXPORT CaPTkInteractiveSegmentation /*final*/ :
class MITKCAPTKINTERACTIVESEGMENTATION_EXPORT CaPTkInteractiveSegmentation :
public QObject
{
Q_OBJECT

public:
CaPTkInteractiveSegmentation(
mitk::DataStorage::Pointer dataStorage,
QObject *parent = 0);
CaPTkInteractiveSegmentation(QObject *parent = 0);

~CaPTkInteractiveSegmentation() {}

Expand All @@ -40,16 +33,26 @@ class MITKCAPTKINTERACTIVESEGMENTATION_EXPORT CaPTkInteractiveSegmentation /*fin
* algorithm finishes, OnAlgorithmFinished() is called.
*
* @param images a list of the co-registered input images
* @param labels label image that contains the user drawn seeds
* @param seeds labels image that contains the user drawn seeds
*/
void Run(std::vector<mitk::Image::Pointer>& images,
mitk::LabelSetImage::Pointer& seeds);

// void Run(Json::Value& task_json, Json::Value& cohort_json);
signals:
/** \brief This gets emitted when the async execution finishes */
void finished(bool ok, std::string errorMessage, mitk::LabelSetImage::Pointer result);

void progressUpdate(int progress);

// void Run(std::string task_json_path, std::string cohort_json_path);
protected slots:
/** \brief This function runs in the main thread when
* the algorithm is finished to add the result to the data storage
*/
void OnAlgorithmFinished();

void SetProgressBar(QProgressBar* progressBar);
void OnProgressUpdateInternalReceived(int progress);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between the 2 update methods?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of connecting the ProgressUpdate(int) signal, with the QProgressBar's setValue(int) slot, we connect it with OnProgressUpdateInternalReceived(int), which then emits the signal. This re-emitted signal gets connected with the progress bar in the plugin.

That intermediate stage happens because the initial ProgressUpdate(int) signal doesn't belong to the class captk::InteractiveSegmentation, but a class it uses, so we can't connect it directly.


protected:

/** \struct Result
* \brief result of the execution of the algorithm
Expand All @@ -59,20 +62,11 @@ class MITKCAPTKINTERACTIVESEGMENTATION_EXPORT CaPTkInteractiveSegmentation /*fin
*/
typedef struct Result
{
mitk::LabelSetImage::Pointer seeds;
mitk::LabelSetImage::Pointer segmentation;
bool ok = true;
std::string errorMessage = "";
} Result;

public slots:
/** \brief This function runs in the main thread when
* the algorithm is finished to add the result to the data storage
*/
void OnAlgorithmFinished();

protected:

/** \brief Runs the algorithm after the operations in Run
*
* This can serve as a background thread. When the
Expand All @@ -84,25 +78,10 @@ public slots:
*/
Result RunThread(std::vector<mitk::Image::Pointer>& images,
mitk::LabelSetImage::Pointer& seeds);

/** \brief Used to give the appropriate name to the output segmentation.
*
* The first one is called "Segmentation". Subsequent ones "Segmentation-2" etc
*/
std::string FindNextAvailableSegmentationName();

/** \brief Helper function to identify if a string is a number
*
*/
bool IsNumber(const std::string& s);

bool m_IsRunning = false;
QFutureWatcher<Result> m_Watcher;
QFuture<Result> m_FutureResult;

mitk::DataStorage::Pointer m_DataStorage;

QProgressBar* m_ProgressBar;
};

#endif // ! CaPTkInteractiveSegmentation_h
Loading