Skip to content

Commit

Permalink
Add gradient opacity tranfer function and toggle for auto adjust samp…
Browse files Browse the repository at this point in the history
…le distance
  • Loading branch information
davidborland committed Jun 8, 2021
1 parent 5f7b544 commit ffd9d9f
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 162 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ set(UI_RESOURCES
# Create executable
qt5_wrap_ui(UISrcs ${UI_FILES} )
# CMAKE_AUTOMOC is ON so the MOC headers will be automatically wrapped.
add_executable(Segmentor MACOSX_BUNDLE WIN32 ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
#add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
#add_executable(Segmentor MACOSX_BUNDLE WIN32 ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
add_executable(Segmentor MACOSX_BUNDLE ${CXX_FILES} ${UISrcs} ${QT_WRAP} ${UI_RESOURCES})
qt5_use_modules(Segmentor Core Gui)
target_link_libraries(Segmentor ${VTK_LIBRARIES})
install(TARGETS Segmentor
Expand Down
38 changes: 19 additions & 19 deletions qt/MainWindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,20 @@ MainWindow::MainWindow() {
brushRadiusSpinBox->setToolTip("Adjust brush radius (left / right arrow)");

// Overlay opacity shortcut
QShortcut* overlayUp = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right), this);
QShortcut* overlayDown = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left), this);
QShortcut* overlayOpacityUp = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Right), this);
QShortcut* overlayOpacityDown = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_Left), this);

QObject::connect(overlayUp, &QShortcut::activated, this, &MainWindow::on_overlayUp);
QObject::connect(overlayDown, &QShortcut::activated, this, &MainWindow::on_overlayDown);
QObject::connect(this, &MainWindow::overlayChanged, settingsDialog, &SettingsDialog::on_overlayChanged);
QObject::connect(overlayOpacityUp, &QShortcut::activated, this, &MainWindow::on_overlayOpacityUp);
QObject::connect(overlayOpacityDown, &QShortcut::activated, this, &MainWindow::on_overlayOpacityDown);
QObject::connect(this, &MainWindow::overlayOpacityChanged, settingsDialog, &SettingsDialog::on_overlayOpacityChanged);

// Region opacity shortcut
QShortcut* opacityUp = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Right), this);
QShortcut* opacityDown = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Left), this);
// Surface opacity shortcut
QShortcut* surfaceOpacityUp = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Right), this);
QShortcut* surfaceOpacityDown = new QShortcut(QKeySequence(Qt::SHIFT + Qt::Key_Left), this);

QObject::connect(opacityUp, &QShortcut::activated, this, &MainWindow::on_opacityUp);
QObject::connect(opacityDown, &QShortcut::activated, this, &MainWindow::on_opacityDown);
QObject::connect(this, &MainWindow::opacityChanged, settingsDialog, &SettingsDialog::on_opacityChanged);
QObject::connect(surfaceOpacityUp, &QShortcut::activated, this, &MainWindow::on_surfaceOpacityUp);
QObject::connect(surfaceOpacityDown, &QShortcut::activated, this, &MainWindow::on_surfaceOpacityDown);
QObject::connect(this, &MainWindow::surfaceOpacityChanged, settingsDialog, &SettingsDialog::on_surfaceOpacityChanged);

// 2D/3D toggle
QShortcut* toggleView = new QShortcut(QKeySequence("t"), this);
Expand Down Expand Up @@ -861,40 +861,40 @@ void MainWindow::on_regionColor(int label, QColor color) {
visualizationContainer->SetRegionColor((unsigned short)label, color.redF(), color.greenF(), color.blueF());
}

void MainWindow::on_overlayDown() {
void MainWindow::on_overlayOpacityDown() {
SliceView* sliceView = visualizationContainer->GetSliceView();

double value = qMax(sliceView->GetOverlayOpacity() - 0.1, 0.0);

sliceView->SetOverlayOpacity(value);

emit overlayChanged(value);
emit overlayOpacityChanged(value);
}

void MainWindow::on_overlayUp() {
void MainWindow::on_overlayOpacityUp() {
SliceView* sliceView = visualizationContainer->GetSliceView();

double value = qMin(sliceView->GetOverlayOpacity() + 0.1, 1.0);

sliceView->SetOverlayOpacity(value);

emit overlayChanged(value);
emit overlayOpacityChanged(value);
}

void MainWindow::on_opacityDown() {
void MainWindow::on_surfaceOpacityDown() {
double value = qMax(visualizationContainer->GetVolumeView()->GetVisibleOpacity() - 0.1, 0.0);

visualizationContainer->SetVisibleOpacity(value);

emit opacityChanged(value);
emit surfaceOpacityChanged(value);
}

void MainWindow::on_opacityUp() {
void MainWindow::on_surfaceOpacityUp() {
double value = qMin(visualizationContainer->GetVolumeView()->GetVisibleOpacity() + 0.1, 1.0);

visualizationContainer->SetVisibleOpacity(value);

emit opacityChanged(value);
emit surfaceOpacityChanged(value);
}

void MainWindow::on_brushRadiusDown() {
Expand Down
12 changes: 6 additions & 6 deletions qt/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,18 @@ public slots:
virtual void on_regionColor(int label, QColor color);

// Shortcuts for settings
virtual void on_overlayDown();
virtual void on_overlayUp();
virtual void on_opacityDown();
virtual void on_opacityUp();
virtual void on_overlayOpacityDown();
virtual void on_overlayOpacityUp();
virtual void on_surfaceOpacityDown();
virtual void on_surfaceOpacityUp();
virtual void on_brushRadiusDown();
virtual void on_brushRadiusUp();

signals:

void windowLevelChanged(double window, double value);
void overlayChanged(double value);
void opacityChanged(double value);
void overlayOpacityChanged(double value);
void surfaceOpacityChanged(double value);

protected:
// The visualization container
Expand Down
42 changes: 25 additions & 17 deletions qt/SettingsDialog.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ void SettingsDialog::initializeSettings() {
levelSpinBox->setValue(sliceView->GetLevel());

// Overlay opacity
overlaySpinBox->setValue(sliceView->GetOverlayOpacity());
overlayOpacitySpinBox->setValue(sliceView->GetOverlayOpacity());

// Region opacity
opacitySpinBox->setValue(volumeView->GetVisibleOpacity());
// Surface opacity
surfaceOpacitySpinBox->setValue(volumeView->GetVisibleOpacity());
}

void SettingsDialog::on_windowSpinBox_valueChanged(double value) {
Expand All @@ -63,28 +63,28 @@ void SettingsDialog::on_levelSpinBox_valueChanged(double value) {
visualizationContainer->GetSliceView()->SetLevel(value);
}

void SettingsDialog::on_overlaySpinBox_valueChanged(double value) {
void SettingsDialog::on_overlayOpacitySpinBox_valueChanged(double value) {
visualizationContainer->GetSliceView()->SetOverlayOpacity(value);
}

void SettingsDialog::on_overlayUp() {
overlaySpinBox->stepUp();
void SettingsDialog::on_overlayOpacityUp() {
overlayOpacitySpinBox->stepUp();
}

void SettingsDialog::on_overlayDown() {
overlaySpinBox->stepDown();
void SettingsDialog::on_overlayOpacityDown() {
overlayOpacitySpinBox->stepDown();
}

void SettingsDialog::on_opacitySpinBox_valueChanged(double value) {
void SettingsDialog::on_surfaceOpacitySpinBox_valueChanged(double value) {
visualizationContainer->SetVisibleOpacity(value);
}

void SettingsDialog::on_opacityUp() {
opacitySpinBox->stepUp();
void SettingsDialog::on_surfaceOpacityUp() {
surfaceOpacitySpinBox->stepUp();
}

void SettingsDialog::on_opacityDown() {
opacitySpinBox->stepDown();
void SettingsDialog::on_surfaceOpacityDown() {
surfaceOpacitySpinBox->stepDown();
}

void SettingsDialog::on_voxelSizeSpinBox() {
Expand All @@ -100,10 +100,18 @@ void SettingsDialog::on_windowLevelChanged(double window, double level) {
levelSpinBox->setValue(level);
}

void SettingsDialog::on_overlayChanged(double value) {
overlaySpinBox->setValue(value);
void SettingsDialog::on_overlayOpacityChanged(double value) {
overlayOpacitySpinBox->setValue(value);
}

void SettingsDialog::on_opacityChanged(double value) {
opacitySpinBox->setValue(value);
void SettingsDialog::on_surfaceOpacityChanged(double value) {
surfaceOpacitySpinBox->setValue(value);
}

void SettingsDialog::on_gradientOpacityCheckBox_stateChanged(int state) {
visualizationContainer->GetVolumeView()->SetVolumeRenderingGradientOpacity(state != 0);
}

void SettingsDialog::on_autoAdjustSamplingCheckBox_stateChanged(int state) {
visualizationContainer->GetVolumeView()->SetVolumeRenderingAutoAdjustSampling(state != 0);
}
19 changes: 11 additions & 8 deletions qt/SettingsDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,22 @@ public slots:
virtual void on_windowSpinBox_valueChanged(double value);
virtual void on_levelSpinBox_valueChanged(double value);

virtual void on_overlaySpinBox_valueChanged(double value);
virtual void on_overlayUp();
virtual void on_overlayDown();
virtual void on_overlayOpacitySpinBox_valueChanged(double value);
virtual void on_overlayOpacityUp();
virtual void on_overlayOpacityDown();

virtual void on_opacitySpinBox_valueChanged(double value);
virtual void on_opacityUp();
virtual void on_opacityDown();
virtual void on_surfaceOpacitySpinBox_valueChanged(double value);
virtual void on_surfaceOpacityUp();
virtual void on_surfaceOpacityDown();

virtual void on_voxelSizeSpinBox();

virtual void on_windowLevelChanged(double window, double level);
virtual void on_overlayChanged(double value);
virtual void on_opacityChanged(double value);
virtual void on_overlayOpacityChanged(double value);
virtual void on_surfaceOpacityChanged(double value);

virtual void on_gradientOpacityCheckBox_stateChanged(int state);
virtual void on_autoAdjustSamplingCheckBox_stateChanged(int state);

protected:
VisualizationContainer* visualizationContainer;
Expand Down
Loading

0 comments on commit ffd9d9f

Please sign in to comment.