Skip to content

Commit 66b8f52

Browse files
authored
(VC) Add ability to swap segmentation algorithms (#15)
* Rename chain seg base class * (VC) Add ability to swap segmentation algorithms * cleanup
1 parent 45b730c commit 66b8f52

File tree

6 files changed

+192
-148
lines changed

6 files changed

+192
-148
lines changed

apps/VC/CWindow.cpp

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
#include "vc/core/util/Iteration.hpp"
1414
#include "vc/core/util/Logging.hpp"
1515
#include "vc/meshing/OrderedPointSetMesher.hpp"
16+
#include "vc/segmentation/LocalResliceParticleSim.hpp"
1617

1718
namespace vc = volcart;
19+
namespace vcs = volcart::segmentation;
1820
using namespace ChaoVis;
1921
using qga = QGuiApplication;
2022

@@ -216,10 +218,17 @@ void CWindow::CreateWidgets(void)
216218
SLOT(OnPathItemClicked(QListWidgetItem*)));
217219

218220
// segmentation methods
219-
QComboBox* aSegMethodsComboBox =
220-
this->findChild<QComboBox*>("cmbSegMethods");
221+
auto* aSegMethodsComboBox = this->findChild<QComboBox*>("cmbSegMethods");
221222
aSegMethodsComboBox->addItem(tr("Local Reslice Particle Simulation"));
223+
connect(
224+
aSegMethodsComboBox, SIGNAL(currentIndexChanged(int)), this,
225+
SLOT(OnChangeSegAlgo(int)));
226+
227+
// ADD NEW SEGMENTATION ALGORITHM NAMES HERE
228+
// aSegMethodsComboBox->addItem(tr("My custom algorithm"));
222229

230+
// LRPS segmentation parameters
231+
// all of these are contained in the this->ui.lrpsParams
223232
fEdtAlpha = this->findChild<QLineEdit*>("edtAlphaVal");
224233
fEdtBeta = this->findChild<QLineEdit*>("edtBetaVal");
225234
fEdtDelta = this->findChild<QLineEdit*>("edtDeltaVal");
@@ -259,6 +268,9 @@ void CWindow::CreateWidgets(void)
259268
fEdtEndIndex, SIGNAL(editingFinished()), this,
260269
SLOT(OnEdtEndingSliceValChange()));
261270

271+
// INSERT OTHER SEGMENTATION PARAMETER WIDGETS HERE
272+
// this->ui.segParamsStack->addWidget(new QLabel("Parameter widgets here"));
273+
262274
// start segmentation button
263275
QPushButton* aBtnStartSeg = this->findChild<QPushButton*>("btnStartSeg");
264276
connect(
@@ -570,29 +582,39 @@ void CWindow::DoSegmentation(void)
570582
{
571583
statusBar->clearMessage();
572584

573-
// REVISIT - do we need to get the latest value from the widgets since we
574-
// constantly get the values?
575-
if (!SetUpSegParams()) {
585+
// Make sure our seg params structure has the current values
586+
if (not SetUpSegParams()) {
576587
QMessageBox::information(
577588
this, tr("Info"), tr("Invalid parameter for segmentation"));
578589
return;
579590
}
580591

581-
// 2) do segmentation from the starting slice
582-
vc::segmentation::LocalResliceSegmentation segmenter;
583-
segmenter.setChain(fStartingPath);
584-
segmenter.setVolume(currentVolume);
585-
segmenter.setMaterialThickness(fVpkg->materialThickness());
586-
segmenter.setTargetZIndex(fSegParams.targetIndex);
587-
segmenter.setOptimizationIterations(fSegParams.fNumIters);
588-
segmenter.setResliceSize(fSegParams.fWindowWidth);
589-
segmenter.setAlpha(fSegParams.fAlpha);
590-
segmenter.setK1(fSegParams.fK1);
591-
segmenter.setK2(fSegParams.fK2);
592-
segmenter.setBeta(fSegParams.fBeta);
593-
segmenter.setDelta(fSegParams.fDelta);
594-
segmenter.setDistanceWeightFactor(fSegParams.fPeakDistanceWeight);
595-
segmenter.setConsiderPrevious(fSegParams.fIncludeMiddle);
592+
// Setup LRPS
593+
auto segIdx = this->ui.cmbSegMethods->currentIndex();
594+
Segmenter::Pointer segmenter;
595+
if (segIdx == 0) {
596+
auto lrps = vcs::LocalResliceSegmentation::New();
597+
lrps->setMaterialThickness(fVpkg->materialThickness());
598+
lrps->setTargetZIndex(fSegParams.targetIndex);
599+
lrps->setOptimizationIterations(fSegParams.fNumIters);
600+
lrps->setResliceSize(fSegParams.fWindowWidth);
601+
lrps->setAlpha(fSegParams.fAlpha);
602+
lrps->setK1(fSegParams.fK1);
603+
lrps->setK2(fSegParams.fK2);
604+
lrps->setBeta(fSegParams.fBeta);
605+
lrps->setDelta(fSegParams.fDelta);
606+
lrps->setDistanceWeightFactor(fSegParams.fPeakDistanceWeight);
607+
lrps->setConsiderPrevious(fSegParams.fIncludeMiddle);
608+
segmenter = lrps;
609+
}
610+
// ADD OTHER SEGMENTER SETUP HERE. MATCH THE IDX TO THE IDX IN THE
611+
// DROPDOWN LIST
612+
613+
// set common parameters
614+
segmenter->setChain(fStartingPath);
615+
segmenter->setVolume(currentVolume);
616+
617+
// setup
596618
submitSegmentation(segmenter);
597619
setWidgetsEnabled(false);
598620
worker_progress_.show();
@@ -1036,6 +1058,11 @@ void CWindow::ToggleSegmentationTool(void)
10361058
UpdateView();
10371059
}
10381060

1061+
void CWindow::OnChangeSegAlgo(int index)
1062+
{
1063+
this->ui.segParamsStack->setCurrentIndex(index);
1064+
}
1065+
10391066
// Handle gravity value change
10401067
void CWindow::OnEdtAlphaValChange()
10411068
{

apps/VC/CWindow.hpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include "ui_VCMain.h"
1818

1919
#include "vc/core/types/VolumePkg.hpp"
20-
#include "vc/segmentation/LocalResliceParticleSim.hpp"
20+
#include "vc/segmentation/ChainSegmentationAlgorithm.hpp"
2121

2222
// Volpkg version required by this app
2323
static constexpr int VOLPKG_SUPPORTED_VERSION = 6;
@@ -43,6 +43,8 @@ class CWindow : public QMainWindow
4343
}; // idle
4444
enum SaveResponse : bool { Cancelled, Continue };
4545

46+
// Structure for segmentation parameters
47+
// Declare parameters for new algos here and update SetUpSegParams()
4648
using SSegParams = struct SSegParams_tag {
4749
int fNumIters;
4850
double fAlpha;
@@ -56,10 +58,10 @@ class CWindow : public QMainWindow
5658
int targetIndex;
5759
};
5860

59-
using Segmenter = volcart::segmentation::LocalResliceSegmentation;
61+
using Segmenter = volcart::segmentation::ChainSegmentationAlgorithm;
6062

6163
signals:
62-
void submitSegmentation(Segmenter s);
64+
void submitSegmentation(Segmenter::Pointer s);
6365

6466
public slots:
6567
void onSegmentationFinished(Segmenter::PointSet ps);
@@ -121,6 +123,8 @@ private slots:
121123
void TogglePenTool(void);
122124
void ToggleSegmentationTool(void);
123125

126+
void OnChangeSegAlgo(int index);
127+
124128
void OnEdtAlphaValChange();
125129
void OnEdtBetaValChange();
126130
void OnEdtDeltaValChange();
@@ -227,31 +231,29 @@ class VolPkgBackend : public QObject
227231
{
228232
Q_OBJECT
229233
public:
234+
using Segmenter = volcart::segmentation::ChainSegmentationAlgorithm;
235+
230236
explicit VolPkgBackend(QObject* parent = nullptr) : QObject(parent) {}
231237

232238
signals:
233239
void segmentationStarted(size_t);
234-
void segmentationFinished(CWindow::Segmenter::PointSet ps);
240+
void segmentationFinished(Segmenter::PointSet ps);
235241
void segmentationFailed(std::string);
236242
void progressUpdated(size_t);
237243

238244
public slots:
239-
void startSegmentation(CWindow::Segmenter s)
245+
void startSegmentation(Segmenter::Pointer segmenter)
240246
{
241-
segmenter = std::move(s);
242-
segmenter.progressUpdated.connect(
247+
segmenter->progressUpdated.connect(
243248
[=](size_t p) { progressUpdated(p); });
244-
segmentationStarted(segmenter.progressIterations());
249+
segmentationStarted(segmenter->progressIterations());
245250
try {
246-
auto result = segmenter.compute();
251+
auto result = segmenter->compute();
247252
segmentationFinished(result);
248253
} catch (const std::exception& e) {
249254
segmentationFailed(e.what());
250255
}
251256
}
252-
253-
public:
254-
CWindow::Segmenter segmenter;
255257
};
256258

257259
} // namespace ChaoVis

0 commit comments

Comments
 (0)