Skip to content

Commit

Permalink
Merge pull request #2255 from psavery/gradient-opacity-multivolume-only
Browse files Browse the repository at this point in the history
Force gradient opacity for multi-volumes only
  • Loading branch information
cjh1 authored Jun 22, 2022
2 parents 3ffc0a4 + 9e07ab8 commit d9d2a39
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
22 changes: 20 additions & 2 deletions tomviz/modules/ModuleVolume.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ vtkStandardNewMacro(SmartVolumeMapper)
{
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must be
// set or the shader will fail to compile.
// (likely fixed in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
m_gradientOpacity->AddPoint(0.0, 1.0);
connect(&HistogramManager::instance(), &HistogramManager::histogram2DReady,
this, [=](vtkSmartPointer<vtkImageData> image,
Expand All @@ -81,6 +82,12 @@ vtkStandardNewMacro(SmartVolumeMapper)
this->updateColorMap();
emit this->renderNeeded();
});

// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
// be set or the shader will fail to compile.
// (likely fixed in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
connect(&VolumeManager::instance(), &VolumeManager::usingMultiVolumeChanged,
this, &ModuleVolume::updateColorMap);
}

ModuleVolume::~ModuleVolume()
Expand Down Expand Up @@ -371,9 +378,20 @@ void ModuleVolume::updateColorMap()
int propertyMode = vtkVolumeProperty::TF_1D;
const Module::TransferMode mode = getTransferMode();
switch (mode) {
case (Module::SCALAR):
m_volumeProperty->SetGradientOpacity(m_gradientOpacity);
case (Module::SCALAR): {
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
// be set or the shader will fail to compile.
// (likely fixed in
// https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
bool usingMultiVolume =
VolumeManager::instance().usingMultiVolume(this->view());
if (usingMultiVolume) {
m_volumeProperty->SetGradientOpacity(m_gradientOpacity);
} else {
m_volumeProperty->SetGradientOpacity(nullptr);
}
break;
}
case (Module::GRADIENT_1D):
m_volumeProperty->SetGradientOpacity(gradientOpacityMap());
break;
Expand Down
11 changes: 11 additions & 0 deletions tomviz/modules/VolumeManager.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ void VolumeManager::onModuleAdded(Module* module)
viewVolumes->auxProperty->SetScalarOpacity(viewVolumes->auxOpacity);
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
// be set or the shader will fail to compile.
// (likely fixed in
// https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
viewVolumes->auxProperty->SetGradientOpacity(
viewVolumes->auxGradientOpacity);
viewVolumes->auxVolume->SetProperty(viewVolumes->auxProperty);
Expand Down Expand Up @@ -243,6 +245,15 @@ bool VolumeManager::allowMultiVolume(vtkSMViewProxy* view) const
return this->d->views[view]->usingMultiVolume;
}

bool VolumeManager::usingMultiVolume(vtkSMViewProxy* view) const
{
if (!this->d->views.contains(view)) {
return false;
}

return this->d->views[view]->usingMultiVolume;
}

int VolumeManager::volumeCount(vtkSMViewProxy* view) const
{
if (!this->d->views.contains(view)) {
Expand Down
1 change: 1 addition & 0 deletions tomviz/modules/VolumeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class VolumeManager : public QObject
static VolumeManager& instance();
void allowMultiVolume(bool allow, vtkSMViewProxy* view);
bool allowMultiVolume(vtkSMViewProxy* view) const;
bool usingMultiVolume(vtkSMViewProxy* view) const;
int volumeCount(vtkSMViewProxy* view) const;

signals:
Expand Down

0 comments on commit d9d2a39

Please sign in to comment.