Skip to content

Commit

Permalink
Add toolbar to control some visualization settings
Browse files Browse the repository at this point in the history
  • Loading branch information
davidborland committed Dec 12, 2019
1 parent efa10d1 commit ba2af57
Show file tree
Hide file tree
Showing 15 changed files with 1,077 additions and 22 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ include(${VTK_USE_FILE})
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
find_package(Qt5Widgets REQUIRED QUIET)
else()
find_package(Qt4 REQUIRED)
Expand All @@ -27,14 +28,13 @@ file(GLOB CXX_FILES *.cxx)
if(${VTK_VERSION} VERSION_GREATER "6" AND VTK_QT_VERSION VERSION_GREATER "4")
qt5_wrap_ui(UISrcs ${UI_FILES} )
# CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
add_executable(Segmentor MACOSX_BUNDLE
${CXX_FILES} ${UISrcs} ${QT_WRAP})
add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${QT_WRAP} Segmentor.qrc)
qt5_use_modules(Segmentor Core Gui)
target_link_libraries(Segmentor ${VTK_LIBRARIES})
else()
QT4_WRAP_UI(UISrcs ${UI_FILES})
QT4_WRAP_CPP(MOCSrcs ${QT_WRAP})
add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs})
add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${MOCSrcs} Segmentor.qrc)
target_link_libraries(Segmentor ${VTK_LIBRARIES})
endif()

Expand Down
65 changes: 59 additions & 6 deletions MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "RegionTable.h"
#include "RegionMetadataIO.h"
#include "InteractionEnums.h"
#include "SliceView.h"
#include "VolumeView.h"

#include "vtkCallbackCommand.h"
#include "vtkSmartPointer.h"
Expand All @@ -29,9 +31,6 @@ MainWindow::MainWindow() {
defaultImageDirectoryKey = "default_image_directory";
defaultSegmentationDirectoryKey = "default_segmentation_directory";

// Create tool bar
CreateToolBar();

// Create render windows
vtkNew<vtkGenericOpenGLRenderWindow> renderWindowLeft;
qvtkWidgetLeft->SetRenderWindow(renderWindowLeft);
Expand All @@ -42,6 +41,9 @@ MainWindow::MainWindow() {
// Create visualization container
visualizationContainer = new VisualizationContainer(qvtkWidgetLeft->GetInteractor(), qvtkWidgetRight->GetInteractor(), this);

// Create tool bar
CreateToolBar();

// Create region table
regionTable = new RegionTable();
regionTable->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
Expand Down Expand Up @@ -321,14 +323,33 @@ void MainWindow::on_actionExit_triggered() {
}

void MainWindow::on_actionNavigation() {

visualizationContainer->SetInteractionMode(NavigationMode);
}

void MainWindow::on_actionEdit() {
visualizationContainer->SetInteractionMode(EditMode);
}

void MainWindow::on_actionOverlay(bool checked) {
visualizationContainer->GetSliceView()->ShowLabelSlice(checked);
}

void MainWindow::on_actionVoxels(bool checked) {
visualizationContainer->GetSliceView()->ShowVoxelOutlines(checked);
}

void MainWindow::on_actionOutline(bool checked) {
visualizationContainer->GetSliceView()->ShowRegionOutlines(checked);
}

void MainWindow::on_actionSmoothNormals(bool checked) {
visualizationContainer->GetVolumeView()->SetSmoothShading(checked);
}

void MainWindow::on_actionSmoothSurfaces(bool checked) {
visualizationContainer->GetVolumeView()->SetSmoothSurfaces(checked);
}

void MainWindow::on_regionDone(int label, bool done) {
visualizationContainer->SetRegionDone((unsigned short)label, done);
}
Expand Down Expand Up @@ -377,16 +398,48 @@ void MainWindow::CreateToolBar() {

QAction* actionNavigation = new QAction("N", interactionModeGroup);
actionNavigation->setCheckable(true);
actionNavigation->setChecked(true);
actionNavigation->setChecked(visualizationContainer->GetInteractionMode() == NavigationMode);

QAction* actionEdit = new QAction("E", interactionModeGroup);
actionNavigation->setCheckable(false);
actionEdit->setCheckable(true);

QAction* actionOverlay = new QAction(QIcon(":/icons/icon_overlay.svg"), "Show overlay", this);
actionOverlay->setCheckable(true);
actionOverlay->setChecked(visualizationContainer->GetSliceView()->GetShowLabelSlice());

QAction* actionVoxels = new QAction(QIcon(":/icons/icon_voxels.svg"), "Show voxels", this);
actionVoxels->setCheckable(true);
actionVoxels->setChecked(visualizationContainer->GetSliceView()->GetShowVoxelOutlines());

QAction* actionOutline = new QAction(QIcon(":/icons/icon_outline.svg"), "Show outlines", this);
actionOutline->setCheckable(true);
actionOutline->setChecked(visualizationContainer->GetSliceView()->GetShowRegionOutlines());

QAction* actionSmoothNormals = new QAction(QIcon(":/icons/icon_smooth_normals.svg"), "Smooth normals", this);
actionSmoothNormals->setCheckable(true);
actionSmoothNormals->setChecked(visualizationContainer->GetVolumeView()->GetSmoothShading());

QAction* actionSmoothSurfaces = new QAction(QIcon(":/icons/icon_smooth_surface.svg"), "Smooth surfaces", this);
actionSmoothSurfaces->setCheckable(true);
actionSmoothSurfaces->setChecked(visualizationContainer->GetVolumeView()->GetSmoothSurfaces());

toolBar->addAction(actionNavigation);
toolBar->addAction(actionEdit);
toolBar->addSeparator();
toolBar->addAction(actionOverlay);
toolBar->addAction(actionVoxels);
toolBar->addAction(actionOutline);
toolBar->addSeparator();
toolBar->addAction(actionSmoothNormals);
toolBar->addAction(actionSmoothSurfaces);

QObject::connect(actionNavigation, &QAction::triggered, this, &MainWindow::on_actionNavigation);
QObject::connect(actionEdit, &QAction::triggered, this, &MainWindow::on_actionEdit);
QObject::connect(actionOverlay, &QAction::triggered, this, &MainWindow::on_actionOverlay);
QObject::connect(actionVoxels, &QAction::triggered, this, &MainWindow::on_actionVoxels);
QObject::connect(actionOutline, &QAction::triggered, this, &MainWindow::on_actionOutline);
QObject::connect(actionSmoothNormals, &QAction::triggered, this, &MainWindow::on_actionSmoothNormals);
QObject::connect(actionSmoothSurfaces, &QAction::triggered, this, &MainWindow::on_actionSmoothSurfaces);

toolBarWidget->layout()->addWidget(toolBar);
}
5 changes: 5 additions & 0 deletions MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ public slots:
// Tool bar events
virtual void on_actionNavigation();
virtual void on_actionEdit();
virtual void on_actionOverlay(bool checked);
virtual void on_actionVoxels(bool checked);
virtual void on_actionOutline(bool checked);
virtual void on_actionSmoothNormals(bool checked);
virtual void on_actionSmoothSurfaces(bool checked);

// Region table events
virtual void on_regionDone(int label, bool done);
Expand Down
9 changes: 9 additions & 0 deletions Segmentor.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>icons/icon_overlay.svg</file>
<file>icons/icon_voxels.svg</file>
<file>icons/icon_outline.svg</file>
<file>icons/icon_smooth_surface.svg</file>
<file>icons/icon_smooth_normals.svg</file>
</qresource>
</RCC>
36 changes: 23 additions & 13 deletions SliceView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ SliceView::SliceView(vtkRenderWindowInteractor* interactor, vtkLookupTable* lut)
plane = vtkSmartPointer<vtkPlane>::New();

labelSlice = vtkSmartPointer<vtkImageSlice>::New();
labelSlice->VisibilityOn();

// Rendering
renderer = vtkSmartPointer<vtkRenderer>::New();
Expand Down Expand Up @@ -122,8 +121,8 @@ void SliceView::Reset() {

SetCurrentRegion(nullptr);

slice->VisibilityOff();
labelSlice->VisibilityOff();
//slice->VisibilityOff();
//labelSlice->VisibilityOff();
probe->VisibilityOff();
sliceLocation->UpdateData(nullptr);
interactionModeLabel->VisibilityOff();
Expand Down Expand Up @@ -222,11 +221,24 @@ void SliceView::SetInteractionMode(enum InteractionMode mode) {
style->SetMode(mode);
}

void SliceView::ToggleLabelSlice() {
labelSlice->SetVisibility(!labelSlice->GetVisibility());
bool SliceView::GetShowLabelSlice() {
return labelSlice->GetVisibility();
}

void SliceView::ShowLabelSlice(bool show) {
labelSlice->SetVisibility(show);

Render();
}

void SliceView::ToggleLabelSlice() {
ShowLabelSlice(!labelSlice->GetVisibility());
}

bool SliceView::GetShowVoxelOutlines() {
return showVoxelOutlines;
}

void SliceView::ShowVoxelOutlines(bool show) {
showVoxelOutlines = show;

Expand All @@ -239,6 +251,10 @@ void SliceView::ToggleVoxelOutlines() {
ShowVoxelOutlines(!showVoxelOutlines);
}

bool SliceView::GetShowRegionOutlines() {
return showRegionOutlines;
}

void SliceView::ShowRegionOutlines(bool show) {
showRegionOutlines = show;

Expand Down Expand Up @@ -334,9 +350,6 @@ void SliceView::CreateSlice() {
slice = vtkSmartPointer<vtkImageSlice>::New();
slice->SetMapper(mapper);
slice->SetProperty(property);
slice->VisibilityOff();

renderer->AddActor(slice);
}

void SliceView::UpdateSlice() {
Expand All @@ -348,7 +361,7 @@ void SliceView::UpdateSlice() {
slice->GetProperty()->SetColorWindow(maxValue - minValue);
slice->GetProperty()->SetColorLevel(minValue + (maxValue - minValue) / 2);

slice->VisibilityOn();
renderer->AddActor(slice);
}

void SliceView::CreateLabelSlice() {
Expand All @@ -372,15 +385,12 @@ void SliceView::CreateLabelSlice() {
// Slice
labelSlice->SetMapper(mapper);
labelSlice->SetProperty(property);
labelSlice->VisibilityOff();

labelSliceRenderer->AddActor(labelSlice);
}

void SliceView::UpdateLabelSlice() {
labelSlice->GetMapper()->SetInputDataObject(labels);

labelSlice->VisibilityOn();
labelSliceRenderer->AddActor(labelSlice);
}

void SliceView::FilterRegions() {
Expand Down
4 changes: 4 additions & 0 deletions SliceView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@ class SliceView {

void SetCurrentRegion(Region* region);

bool GetShowLabelSlice();
void ShowLabelSlice(bool show);
void ToggleLabelSlice();

bool GetShowVoxelOutlines();
void ShowVoxelOutlines(bool show);
void ToggleVoxelOutlines();

bool GetShowRegionOutlines();
void ShowRegionOutlines(bool show);
void ToggleRegionOutlines();

Expand Down
4 changes: 4 additions & 0 deletions VisualizationContainer.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ void VisualizationContainer::SegmentVolume() {
Render();
}

InteractionMode VisualizationContainer::GetInteractionMode() {
return interactionMode;
}

void VisualizationContainer::SetInteractionMode(InteractionMode mode) {
interactionMode = mode;

Expand Down
1 change: 1 addition & 0 deletions VisualizationContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class VisualizationContainer {
void SegmentVolume();
FileErrorCode SaveSegmentationData(const std::string& fileName);

InteractionMode GetInteractionMode();
void SetInteractionMode(InteractionMode mode);
void ToggleInteractionMode();

Expand Down
8 changes: 8 additions & 0 deletions VolumeView.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ void VolumeView::SetInteractionMode(enum InteractionMode mode) {
style->SetMode(mode);
}

bool VolumeView::GetSmoothSurfaces() {
return smoothSurfaces;
}

void VolumeView::SetSmoothSurfaces(bool smooth) {
smoothSurfaces = smooth;

Expand All @@ -173,6 +177,10 @@ void VolumeView::ToggleSmoothSurfaces() {
SetSmoothSurfaces(!smoothSurfaces);
}

bool VolumeView::GetSmoothShading() {
return smoothShading;
}

void VolumeView::SetSmoothShading(bool smooth) {
smoothShading = smooth;

Expand Down
2 changes: 2 additions & 0 deletions VolumeView.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ class VolumeView {

void SetCurrentRegion(Region* region);

bool GetSmoothSurfaces();
void SetSmoothSurfaces(bool smooth);
void ToggleSmoothSurfaces();

bool GetSmoothShading();
void SetSmoothShading(bool smooth);
void ToggleSmoothShading();

Expand Down
Loading

0 comments on commit ba2af57

Please sign in to comment.