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

Improve WidgetInterface API #9

Merged
merged 9 commits into from
Apr 10, 2018
Prev Previous commit
Next Next commit
fix several cases where slicenr_change api was not yet updated
instead of calling cleanup for specific widgets, base class now has cleanup API, and Mainwindow calls it in generic block
  • Loading branch information
Bryn Lloyd committed Apr 10, 2018
commit 1836dc09d643e8a523e5b07989482175b00f79a3
78 changes: 38 additions & 40 deletions Plugins/BiasCorrection/BiasCorrection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CommandIterationUpdate : public itk::Command

public:
void SetProgressObject(QProgressDialog* progress,
const std::vector<unsigned int>& num_iterations)
const std::vector<unsigned int>& num_iterations)
{
m_NumberOfIterations = num_iterations;
m_Progress = progress;
Expand All @@ -52,7 +52,7 @@ class CommandIterationUpdate : public itk::Command
}

void Execute(const itk::Object* object,
const itk::EventObject& event) ITK_OVERRIDE
const itk::EventObject& event) ITK_OVERRIDE
{
const TFilter* filter = dynamic_cast<const TFilter*>(object);

Expand All @@ -64,9 +64,9 @@ class CommandIterationUpdate : public itk::Command
double current_level = filter->GetCurrentLevel();
double current_iteration = filter->GetElapsedIterations();
int percent = static_cast<int>(
(current_level +
current_iteration / m_NumberOfIterations.at(current_level)) *
100.0 / m_NumberOfIterations.size());
(current_level +
current_iteration / m_NumberOfIterations.at(current_level)) *
100.0 / m_NumberOfIterations.size());
m_Progress->setValue(std::min(percent, 100));

if (m_Progress->wasCanceled())
Expand All @@ -83,7 +83,7 @@ class CommandIterationUpdate : public itk::Command

template<typename ImageType>
typename ImageType::Pointer AllocImage(
const typename itk::ImageBase<ImageType::ImageDimension>* exemplar)
const typename itk::ImageBase<ImageType::ImageDimension>* exemplar)
{
typename ImageType::Pointer rval = ImageType::New();
// it may be the case that the output image might have a different
Expand All @@ -110,17 +110,17 @@ inline QString Format(const char* tooltip)
} // namespace

BiasCorrectionWidget::BiasCorrectionWidget(iseg::SliceHandlerInterface* hand3D,
QWidget* parent, const char* name,
Qt::WindowFlags wFlags)
: WidgetInterface(parent, name, wFlags), handler3D(hand3D),
m_CurrentFilter(nullptr)
QWidget* parent, const char* name,
Qt::WindowFlags wFlags)
: WidgetInterface(parent, name, wFlags), handler3D(hand3D),
m_CurrentFilter(nullptr)
{
setToolTip(Format(
"Correct non-uniformity (especially in MRI) using the N4 Bias Correction "
"algorithm by "
"<br>"
"Tustison et al., 'N4ITK: Improved N3 Bias Correction', IEEE "
"Transactions on Medical Imaging, 29(6) : 1310 - 1320, June 2010"));
"Correct non-uniformity (especially in MRI) using the N4 Bias Correction "
"algorithm by "
"<br>"
"Tustison et al., 'N4ITK: Improved N3 Bias Correction', IEEE "
"Transactions on Medical Imaging, 29(6) : 1310 - 1320, June 2010"));

activeslice = handler3D->get_activeslice();

Expand All @@ -147,8 +147,6 @@ BiasCorrectionWidget::BiasCorrectionWidget(iseg::SliceHandlerInterface* hand3D,
vbox1->setMinimumWidth(std::max(300, vbox1->sizeHint().width()));

QObject::connect(bias_exec, SIGNAL(clicked()), this, SLOT(do_work()));

return;
}

void BiasCorrectionWidget::do_work()
Expand All @@ -170,9 +168,9 @@ void BiasCorrectionWidget::do_work()
try
{
auto output = DoBiasCorrection<InputImageType::Pointer>(
input, ITK_NULLPTR,
std::vector<unsigned int>(num_levels, num_iterations), shrink_factor,
conv_threshold);
input, ITK_NULLPTR,
std::vector<unsigned int>(num_levels, num_iterations), shrink_factor,
conv_threshold);

if (output)
{
Expand Down Expand Up @@ -205,14 +203,14 @@ QSize BiasCorrectionWidget::sizeHint() const { return vbox1->sizeHint(); }

BiasCorrectionWidget::~BiasCorrectionWidget() { delete vbox1; }

void BiasCorrectionWidget::slicenr_changed()
void BiasCorrectionWidget::on_slicenr_changed()
{
activeslice = handler3D->get_activeslice();
}

void BiasCorrectionWidget::init()
{
slicenr_changed();
on_slicenr_changed();
hideparams_changed();
}

Expand All @@ -233,9 +231,9 @@ QIcon BiasCorrectionWidget::GetIcon(QDir picdir)

template<typename ImagePointer>
ImagePointer BiasCorrectionWidget::DoBiasCorrection(
ImagePointer inputImage, ImagePointer maskImage,
const std::vector<unsigned int>& numIters, int shrinkFactor,
double convergenceThreshold)
ImagePointer inputImage, ImagePointer maskImage,
const std::vector<unsigned int>& numIters, int shrinkFactor,
double convergenceThreshold)
{
bool verbose = false;

Expand All @@ -244,13 +242,13 @@ ImagePointer BiasCorrectionWidget::DoBiasCorrection(
static const int ImageDimension = ImageType::ImageDimension;

typedef itk::N4BiasFieldCorrectionImageFilter<ImageType, MaskImageType,
ImageType>
CorrecterType;
ImageType>
CorrecterType;
typename CorrecterType::Pointer correcter = CorrecterType::New();
m_CurrentFilter = correcter;

QProgressDialog progress("Performing bias correction...", "Cancel", 0, 101,
this);
this);
progress.setWindowModality(Qt::WindowModal);
progress.setModal(true);
progress.show();
Expand All @@ -267,22 +265,22 @@ ImagePointer BiasCorrectionWidget::DoBiasCorrection(
if (verbose)
{
std::cout << "Mask not read. Using the entire image as the mask."
<< std::endl
<< std::endl;
<< std::endl
<< std::endl;
}
maskImage = MaskImageType::New();
maskImage->CopyInformation(inputImage);
maskImage->SetRegions(inputImage->GetRequestedRegion());
maskImage->Allocate(false);
maskImage->FillBuffer(
itk::NumericTraits<typename MaskImageType::PixelType>::OneValue());
itk::NumericTraits<typename MaskImageType::PixelType>::OneValue());
}

/**
* convergence options
*/
typename CorrecterType::VariableSizeArrayType maximumNumberOfIterations(
numIters.size());
numIters.size());
for (unsigned int d = 0; d < numIters.size(); d++)
{
maximumNumberOfIterations[d] = numIters[d];
Expand Down Expand Up @@ -361,9 +359,9 @@ ImagePointer BiasCorrectionWidget::DoBiasCorrection(
* corrected image.
*/
typedef itk::BSplineControlPointImageFilter<
typename CorrecterType::BiasFieldControlPointLatticeType,
typename CorrecterType::ScalarImageType>
BSplinerType;
typename CorrecterType::BiasFieldControlPointLatticeType,
typename CorrecterType::ScalarImageType>
BSplinerType;
typename BSplinerType::Pointer bspliner = BSplinerType::New();
bspliner->SetInput(correcter->GetLogBiasFieldControlPointLattice());
bspliner->SetSplineOrder(correcter->GetSplineOrder());
Expand All @@ -376,9 +374,9 @@ ImagePointer BiasCorrectionWidget::DoBiasCorrection(
typename ImageType::Pointer logField = AllocImage<ImageType>(inputImage);

itk::ImageRegionIterator<typename CorrecterType::ScalarImageType> ItB(
bspliner->GetOutput(), bspliner->GetOutput()->GetLargestPossibleRegion());
bspliner->GetOutput(), bspliner->GetOutput()->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> ItF(logField,
logField->GetLargestPossibleRegion());
logField->GetLargestPossibleRegion());
for (ItB.GoToBegin(), ItF.GoToBegin(); !ItB.IsAtEnd(); ++ItB, ++ItF)
{
ItF.Set(ItB.Get()[0]);
Expand All @@ -398,13 +396,13 @@ ImagePointer BiasCorrectionWidget::DoBiasCorrection(
if (isMaskImageSpecified)
{
itk::ImageRegionIteratorWithIndex<ImageType> ItD(
divider->GetOutput(), divider->GetOutput()->GetLargestPossibleRegion());
divider->GetOutput(), divider->GetOutput()->GetLargestPossibleRegion());
itk::ImageRegionIterator<ImageType> ItI(
inputImage, inputImage->GetLargestPossibleRegion());
inputImage, inputImage->GetLargestPossibleRegion());
for (ItD.GoToBegin(), ItI.GoToBegin(); !ItD.IsAtEnd(); ++ItD, ++ItI)
{
if (maskImage->GetPixel(ItD.GetIndex()) ==
itk::NumericTraits<typename MaskImageType::PixelType>::ZeroValue())
itk::NumericTraits<typename MaskImageType::PixelType>::ZeroValue())
{
ItD.Set(ItI.Get());
}
Expand Down
14 changes: 6 additions & 8 deletions Plugins/BiasCorrection/BiasCorrection.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BiasCorrectionWidget : public iseg::WidgetInterface
Q_OBJECT
public:
BiasCorrectionWidget(iseg::SliceHandlerInterface* hand3D, QWidget* parent = 0,
const char* name = 0, Qt::WindowFlags wFlags = 0);
const char* name = 0, Qt::WindowFlags wFlags = 0);
~BiasCorrectionWidget();

QSize sizeHint() const override;
Expand All @@ -41,12 +41,13 @@ class BiasCorrectionWidget : public iseg::WidgetInterface

protected:
template<typename ImagePointer>
ImagePointer
DoBiasCorrection(ImagePointer inputImage, ImagePointer maskImage,
const std::vector<unsigned int>& numIters,
int shrinkFactor, double convergenceThreshold);
ImagePointer DoBiasCorrection(ImagePointer inputImage, ImagePointer maskImage,
const std::vector<unsigned int>& numIters,
int shrinkFactor, double convergenceThreshold);

private:
void on_slicenr_changed() override;

iseg::SliceHandlerInterface* handler3D;
unsigned short activeslice;
Q3VBox* vbox1;
Expand All @@ -64,9 +65,6 @@ class BiasCorrectionWidget : public iseg::WidgetInterface

itk::ProcessObject* m_CurrentFilter;

public slots:
void slicenr_changed();

private slots:
void do_work();
void cancel();
Expand Down
16 changes: 8 additions & 8 deletions Plugins/ConfidenceConnected/Confidence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
#include <sstream>

ConfidenceWidget::ConfidenceWidget(iseg::SliceHandlerInterface* hand3D, QWidget* parent,
const char* name, Qt::WindowFlags wFlags)
: WidgetInterface(parent, name, wFlags), handler3D(hand3D)
const char* name, Qt::WindowFlags wFlags)
: WidgetInterface(parent, name, wFlags), handler3D(hand3D)
{
activeslice = handler3D->get_activeslice();

usp = NULL;

vbox1 = new Q3VBox(this);
bias_header = new QLabel("ConfidenceConnected Algorithm:(Pick with OLC "
"Foreground 1 pixel to start) ",
vbox1);
"Foreground 1 pixel to start) ",
vbox1);
hbox2 = new Q3HBox(vbox1);
hbox3 = new Q3HBox(vbox1);
hbox4 = new Q3HBox(vbox1);
Expand Down Expand Up @@ -71,11 +71,11 @@ void ConfidenceWidget::do_work()
typedef TMask TOutput;

typedef itk::CurvatureFlowImageFilter<TInput, TInput>
CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType;
CurvatureFlowImageFilterType::Pointer smoothing;
smoothing = CurvatureFlowImageFilterType::New();
typedef itk::ConfidenceConnectedImageFilter<TInput, TOutput>
ConnectedFilterType;
ConnectedFilterType;
ConnectedFilterType::Pointer confidenceConnected;
confidenceConnected = ConnectedFilterType::New();

Expand Down Expand Up @@ -111,14 +111,14 @@ ConfidenceWidget::~ConfidenceWidget()
free(usp);
}

void ConfidenceWidget::slicenr_changed()
void ConfidenceWidget::on_slicenr_changed()
{
activeslice = handler3D->get_activeslice();
}

void ConfidenceWidget::init()
{
slicenr_changed();
on_slicenr_changed();
hideparams_changed();
}

Expand Down
52 changes: 22 additions & 30 deletions Plugins/ConfidenceConnected/Confidence.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class ConfidenceWidget : public iseg::WidgetInterface
{
Q_OBJECT
public:
ConfidenceWidget(iseg::SliceHandlerInterface *hand3D, QWidget *parent = 0,
const char *name = 0, Qt::WindowFlags wFlags = 0);
ConfidenceWidget(iseg::SliceHandlerInterface* hand3D, QWidget* parent = 0,
const char* name = 0, Qt::WindowFlags wFlags = 0);
~ConfidenceWidget();
void init() override;
void newloaded() override;
Expand All @@ -32,37 +32,29 @@ class ConfidenceWidget : public iseg::WidgetInterface
QIcon GetIcon(QDir picdir) override { return QIcon(picdir.absFilePath(QString("Confidence.png"))); }

protected:
virtual void on_tissuenr_changed(int i) override { std::cerr << "tissue " << i << std::endl; }
virtual void on_slicenr_changed() override { std::cerr << "slice changed " << std::endl; }

virtual void on_mouse_clicked(iseg::Point p) override { std::cerr << "on_mouse_clicked" << std::endl; }
virtual void on_mouse_released(iseg::Point p) override { std::cerr << "on_mouse_released" << std::endl; }
virtual void on_mouse_moved(iseg::Point p) override { std::cerr << "on_mouse_moved" << std::endl; }
void on_slicenr_changed() override;

private:
unsigned int *usp;
iseg::SliceHandlerInterface *handler3D;
unsigned int* usp;
iseg::SliceHandlerInterface* handler3D;
unsigned short activeslice;
Q3VBox *vbox1;
QLabel *bias_header;
QPushButton *bias_exec;
Q3HBox *hbox2;
Q3HBox *hbox3;
Q3HBox *hbox4;
Q3HBox *hbox5;
QLabel *txt_h2;
QLabel *txt_h3;
QLabel *txt_h4;
QLabel *txt_h5;
QSpinBox *sl_h2;
QSpinBox *sl_h3;
QSpinBox *sl_h4;
QSpinBox *sl_h5;
QSpinBox *sl_h6;
QSpinBox *sl_h7;

public slots:
void slicenr_changed();
Q3VBox* vbox1;
QLabel* bias_header;
QPushButton* bias_exec;
Q3HBox* hbox2;
Q3HBox* hbox3;
Q3HBox* hbox4;
Q3HBox* hbox5;
QLabel* txt_h2;
QLabel* txt_h3;
QLabel* txt_h4;
QLabel* txt_h5;
QSpinBox* sl_h2;
QSpinBox* sl_h3;
QSpinBox* sl_h4;
QSpinBox* sl_h5;
QSpinBox* sl_h6;
QSpinBox* sl_h7;

private slots:
void do_work();
Expand Down
Loading