Skip to content

Commit

Permalink
Set region done from checkbox, grey out in visualizations if done
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Nov 7, 2019
1 parent 37fa3d4 commit 3f2cacf
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 21 deletions.
6 changes: 5 additions & 1 deletion MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ MainWindow::MainWindow() {
regionTable->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
regionTableContainer->layout()->addWidget(regionTable);

connect(regionTable, SIGNAL(removeRegion(int)), this, SLOT(on_removeRegion(int)));
QObject::connect(regionTable, &RegionTable::regionDone, this, &MainWindow::on_regionDone);
QObject::connect(regionTable, &RegionTable::removeRegion, this, &MainWindow::on_removeRegion);

qApp->installEventFilter(this);
}
Expand Down Expand Up @@ -200,6 +201,9 @@ void MainWindow::on_actionExit_triggered() {
qApp->exit();
}

void MainWindow::on_regionDone(int label, bool done) {
visualizationContainer->SetRegionDone((unsigned short)label, done);
}
void MainWindow::on_removeRegion(int label) {
visualizationContainer->RemoveRegion((unsigned short)label);
}
Expand Down
1 change: 1 addition & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public slots:
virtual void on_actionExit_triggered();

// Region table events
virtual void on_regionDone(int label, bool done);
virtual void on_removeRegion(int label);

protected:
Expand Down
10 changes: 10 additions & 0 deletions Region.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <algorithm>

Region::Region(vtkImageData* inputData, unsigned short regionLabel, double regionColor[3]) {
done = false;

// Input data info
data = inputData;
unsigned short* scalars = static_cast<unsigned short*>(data->GetScalarPointer());
Expand Down Expand Up @@ -120,6 +122,10 @@ void Region::UpdateExtent() {
voi->SetVOI(padExtent);
}

void Region::SetDone(bool isDone) {
done = isDone;
}

unsigned short Region::GetLabel() {
return label;
}
Expand All @@ -145,4 +151,8 @@ int Region::GetNumVoxels() {

const int* Region::GetExtent() {
return extent;
}

bool Region::GetDone() {
return done;
}
3 changes: 3 additions & 0 deletions Region.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@ class Region {

void SetExtent(int newExtent[6]);
void UpdateExtent(int x, int y, int z);
void SetDone(bool done);

unsigned short GetLabel();
const double* GetColor();
int GetNumVoxels();
const int* GetExtent();
bool GetDone();

protected:
unsigned short label;
double color[3];
int extent[6];
bool done;

vtkSmartPointer<vtkImageData> data;
vtkSmartPointer<vtkExtractVOI> voi;
Expand Down
24 changes: 13 additions & 11 deletions RegionTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QStyle>
#include <QPushButton>
#include <QSignalMapper>
#include <QCheckBox>

#include "Region.h"

Expand All @@ -21,8 +22,6 @@ RegionTable::RegionTable(QWidget* parent)
verticalHeader()->setVisible(false);

setSizeAdjustPolicy(QAbstractScrollArea::AdjustToContents);

removeMapper = new QSignalMapper(this);
}

void RegionTable::Update(const std::vector<Region*>& regions) {
Expand All @@ -36,9 +35,10 @@ void RegionTable::Update(const std::vector<Region*>& regions) {

for (int i = 0; i < numRegions; i++) {
Region* region = regions[i];
int label = (int)region->GetLabel();

// Id
QTableWidgetItem* idItem = new QTableWidgetItem(QString::number(region->GetLabel()));
QTableWidgetItem* idItem = new QTableWidgetItem(QString::number(label));
idItem->setTextAlignment(Qt::AlignCenter);

// Color
Expand All @@ -52,24 +52,26 @@ void RegionTable::Update(const std::vector<Region*>& regions) {
sizeItem->setTextAlignment(Qt::AlignCenter);

// Checkbox
//QCheckbox* checkBox = new QCheckBox();
QTableWidgetItem* checkItem = new QTableWidgetItem();
checkItem->setCheckState(Qt::Unchecked);
QCheckBox* checkBox = new QCheckBox(this);
checkBox->setChecked(region->GetDone());
checkBox->setStyleSheet("margin-left:10%;margin-right:5%;");
QObject::connect(checkBox, &QCheckBox::stateChanged, [this, label](int state) {
regionDone(label, state);
});

// Remove button
QPushButton* removeButton = new QPushButton(this);
removeButton->setIcon(removeIcon);
connect(removeButton, SIGNAL(clicked()), removeMapper, SLOT(map()));
removeMapper->setMapping(removeButton, (int)region->GetLabel());
QObject::connect(removeButton, &QPushButton::clicked, [this, label]() {
removeRegion(label);
});

setItem(i, 0, idItem);
setItem(i, 1, colorItem);
setItem(i, 2, sizeItem);
setItem(i, 3, checkItem);
setCellWidget(i, 3, checkBox);
setCellWidget(i, 4, removeButton);
}

connect(removeMapper, SIGNAL(mapped(int)), this, SIGNAL(removeRegion(int)));

resizeColumnsToContents();
}
4 changes: 1 addition & 3 deletions RegionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ class RegionTable : public QTableWidget {
void Update(const std::vector<Region*>& regions);

signals:
void regionDone(int label, bool done);
void removeRegion(int label);

protected:
QSignalMapper * removeMapper;
};

#endif
42 changes: 39 additions & 3 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,28 @@ void VisualizationContainer::GrowRegion(int x, int y, int z) {
Render();
}

void VisualizationContainer::SetRegionDone(unsigned short label, bool done) {
Region* region = GetRegion(label);

if (!region) return;

region->SetDone(done);

if (done) {
// Set to grey
labelColors->SetTableValue(label, 0.5, 0.5, 0.5);
labelColors->Build();
}
else {
// Set to color map
UpdateColors(label);
}

volumePipeline->SetSurfaceDone(label, done);

Render();
}

void VisualizationContainer::RemoveRegion(unsigned short label) {
int index = GetRegionIndex(label);

Expand All @@ -602,7 +624,7 @@ void VisualizationContainer::RemoveRegion(unsigned short label) {
}

regions.erase(regions.begin() + index);
volumePipeline->RemoveSurface(index);
volumePipeline->RemoveSurface(label);
qtWindow->UpdateRegionTable(regions);

labels->Modified();
Expand Down Expand Up @@ -652,12 +674,20 @@ void VisualizationContainer::UpdateColors(unsigned short label) {
{ 177,89,40 }
};

for (int i = 0; i < numColors; i++) {
for (int j = 0; j < 3; j++) {
colors[i][j] /= 255.0;
}
}

if (label >= labelColors->GetNumberOfTableValues()) {
labelColors->SetNumberOfTableValues(label + 1);
labelColors->SetRange(0, label);
double* c = colors[(label - 1) % numColors];
labelColors->SetTableValue(label, c[0], c[1], c[2]);
}

double* c = colors[(label - 1) % numColors];
labelColors->SetTableValue(label, c[0], c[1], c[2]);
labelColors->Build();
}

void VisualizationContainer::UpdateColors() {
Expand Down Expand Up @@ -706,6 +736,12 @@ int VisualizationContainer::GetRegionIndex(unsigned short label) {
return -1;
}

Region* VisualizationContainer::GetRegion(unsigned short label) {
int index = GetRegionIndex(label);

return index == -1 ? nullptr : regions[index];
}

void VisualizationContainer::RemoveRegions() {
for (int i = 0; i < (int)regions.size(); i++) {
delete regions[i];
Expand Down
2 changes: 2 additions & 0 deletions VisualizationContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class VisualizationContainer {

void GrowRegion(int x, int y, int z);
void RemoveRegion(unsigned short label);
void SetRegionDone(unsigned short label, bool done);

void Render();

Expand Down Expand Up @@ -83,6 +84,7 @@ class VisualizationContainer {
unsigned short GetNewLabel();

int GetRegionIndex(unsigned short label);
Region* GetRegion(unsigned short label);
void RemoveRegions();
void ExtractRegions();

Expand Down
27 changes: 25 additions & 2 deletions VolumePipeline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,31 @@ void VolumePipeline::AddSurface(Region* region) {
surfaces.push_back(surface);
}

void VolumePipeline::RemoveSurface(int index) {
surfaces.erase(surfaces.begin() + index);
void VolumePipeline::RemoveSurface(unsigned short label) {
for (int i = 0; i < (int)surfaces.size(); i++) {
if (surfaces[i]->GetRegion()->GetLabel() == label) {
surfaces.erase(surfaces.begin() + i);
return;
}
}
}

void VolumePipeline::SetSurfaceDone(unsigned short label, bool done) {
for (int i = 0; i < (int)surfaces.size(); i++) {
Region* region = surfaces[i]->GetRegion();

if (region->GetLabel() == label) {
if (region->GetDone()) {
surfaces[i]->GetActor()->GetProperty()->SetColor(0.5, 0.5, 0.5);
}
else {
const double* color = region->GetColor();
surfaces[i]->GetActor()->GetProperty()->SetColor(color[0], color[1], color[2]);
}

return;
}
}
}

void VolumePipeline::SetCurrentLabel(unsigned short label) {
Expand Down
3 changes: 2 additions & 1 deletion VolumePipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class VolumePipeline {
void SetRegions(vtkImageData* data, std::vector<Region*> regions);

void AddSurface(Region* region);
void RemoveSurface(int index);
void RemoveSurface(unsigned short label);
void SetSurfaceDone(unsigned short label, bool done);

void SetShowProbe(bool visibility);
void SetProbePosition(double x, double y, double z);
Expand Down

0 comments on commit 3f2cacf

Please sign in to comment.