Skip to content

Commit

Permalink
Add highlighting of current region to region table
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Nov 20, 2019
1 parent a9e68f9 commit a6ca8ea
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
4 changes: 4 additions & 0 deletions MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void MainWindow::UpdateRegionTable(RegionCollection* regions) {
regionTable->Update(regions);
}

void MainWindow::HighlightRegionTable(unsigned short label) {
regionTable->Highlight(label);
}

void MainWindow::on_actionOpen_Image_File_triggered() {
// Open a file dialog to read the file
QString fileName = QFileDialog::getOpenFileName(this,
Expand Down
1 change: 1 addition & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class MainWindow : public QMainWindow, private Ui::MainWindow {
virtual ~MainWindow();

void UpdateRegionTable(RegionCollection* regions);
void HighlightRegionTable(unsigned short label);

public slots:
// Use Qt's auto-connect magic to tie GUI widgets to slots,
Expand Down
24 changes: 24 additions & 0 deletions RegionTable.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,19 @@ void RegionTable::Update(RegionCollection* regions) {
// Id
QTableWidgetItem* idItem = new QTableWidgetItem(QString::number(label));
idItem->setTextAlignment(Qt::AlignCenter);
idItem->setFlags(Qt::ItemIsSelectable);

// Color
const double* col = region->GetColor();
QColor color(col[0] * 255, col[1] * 255, col[2] * 255);
QTableWidgetItem* colorItem = new QTableWidgetItem("");
colorItem->setBackgroundColor(color);
colorItem->setFlags(Qt::ItemIsSelectable);

// Size
QTableWidgetItem* sizeItem = new QTableWidgetItem(QString::number(region->GetNumVoxels()));
sizeItem->setTextAlignment(Qt::AlignCenter);
sizeItem->setFlags(Qt::ItemIsSelectable);

// Checkbox
QCheckBox* checkBox = new QCheckBox(this);
Expand All @@ -76,4 +79,25 @@ void RegionTable::Update(RegionCollection* regions) {
}

resizeColumnsToContents();

Highlight(0);
}

void RegionTable::Highlight(unsigned short label) {
QString labelString = QString::number(label);

for (int i = 0; i < rowCount(); i++) {
QTableWidgetItem* ti = item(i, 0);

if (ti->text() == labelString) {
ti->setBackgroundColor(QColor("#1d91c0"));
ti->setTextColor(QColor("white"));

scrollToItem(ti);
}
else {
ti->setBackgroundColor(QColor("white"));
ti->setTextColor(QColor("black"));
}
}
}
1 change: 1 addition & 0 deletions RegionTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class RegionTable : public QTableWidget {
RegionTable(QWidget* parent = 0);

void Update(RegionCollection* regions);
void Highlight(unsigned short label);

signals:
void regionDone(int label, bool done);
Expand Down
11 changes: 0 additions & 11 deletions SliceView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,6 @@ void SliceView::SetInteractionMode(enum InteractionMode mode) {
style->SetMode(mode);
}

void SliceView::SetCurrentLabel(unsigned short label) {
if (label > 0) {
double color[3];
labelSlice->GetProperty()->GetLookupTable()->GetColor(label, color);
probe->GetProperty()->SetColor(color);
}
else {
probe->GetProperty()->SetColor(1, 1, 1);
}
}

void SliceView::ToggleLabelSlice() {
labelSlice->SetVisibility(!labelSlice->GetVisibility());
Render();
Expand Down
2 changes: 0 additions & 2 deletions SliceView.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ class SliceView {
void SetInteractionMode(enum InteractionMode mode);

void SetCurrentRegion(Region* region);

void SetCurrentLabel(unsigned short label);

void ToggleLabelSlice();

Expand Down
9 changes: 2 additions & 7 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -369,14 +369,9 @@ void VisualizationContainer::ErasePoint(double x, double y, double z) {
void VisualizationContainer::SetCurrentRegion(Region* region) {
currentRegion = region;
volumeView->SetCurrentRegion(currentRegion);
sliceView->SetCurrentRegion(currentRegion);
sliceView->SetCurrentRegion(currentRegion);

if (currentRegion) {
sliceView->SetCurrentLabel(currentRegion->GetLabel());
}
else {
sliceView->SetCurrentLabel(0);
}
qtWindow->HighlightRegionTable(region ? region->GetLabel() : 0);
}

void VisualizationContainer::RelabelCurrentRegion() {
Expand Down

0 comments on commit a6ca8ea

Please sign in to comment.