Skip to content

Commit d9d2a39

Browse files
authored
Merge pull request #2255 from psavery/gradient-opacity-multivolume-only
Force gradient opacity for multi-volumes only
2 parents 3ffc0a4 + 9e07ab8 commit d9d2a39

3 files changed

Lines changed: 32 additions & 2 deletions

File tree

tomviz/modules/ModuleVolume.cxx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ vtkStandardNewMacro(SmartVolumeMapper)
6262
{
6363
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must be
6464
// set or the shader will fail to compile.
65+
// (likely fixed in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
6566
m_gradientOpacity->AddPoint(0.0, 1.0);
6667
connect(&HistogramManager::instance(), &HistogramManager::histogram2DReady,
6768
this, [=](vtkSmartPointer<vtkImageData> image,
@@ -81,6 +82,12 @@ vtkStandardNewMacro(SmartVolumeMapper)
8182
this->updateColorMap();
8283
emit this->renderNeeded();
8384
});
85+
86+
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
87+
// be set or the shader will fail to compile.
88+
// (likely fixed in https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
89+
connect(&VolumeManager::instance(), &VolumeManager::usingMultiVolumeChanged,
90+
this, &ModuleVolume::updateColorMap);
8491
}
8592

8693
ModuleVolume::~ModuleVolume()
@@ -371,9 +378,20 @@ void ModuleVolume::updateColorMap()
371378
int propertyMode = vtkVolumeProperty::TF_1D;
372379
const Module::TransferMode mode = getTransferMode();
373380
switch (mode) {
374-
case (Module::SCALAR):
375-
m_volumeProperty->SetGradientOpacity(m_gradientOpacity);
381+
case (Module::SCALAR): {
382+
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
383+
// be set or the shader will fail to compile.
384+
// (likely fixed in
385+
// https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
386+
bool usingMultiVolume =
387+
VolumeManager::instance().usingMultiVolume(this->view());
388+
if (usingMultiVolume) {
389+
m_volumeProperty->SetGradientOpacity(m_gradientOpacity);
390+
} else {
391+
m_volumeProperty->SetGradientOpacity(nullptr);
392+
}
376393
break;
394+
}
377395
case (Module::GRADIENT_1D):
378396
m_volumeProperty->SetGradientOpacity(gradientOpacityMap());
379397
break;

tomviz/modules/VolumeManager.cxx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void VolumeManager::onModuleAdded(Module* module)
9090
viewVolumes->auxProperty->SetScalarOpacity(viewVolumes->auxOpacity);
9191
// NOTE: Due to a bug in vtkMultiVolume, a gradient opacity function must
9292
// be set or the shader will fail to compile.
93+
// (likely fixed in
94+
// https://gitlab.kitware.com/vtk/vtk/-/merge_requests/8909)
9395
viewVolumes->auxProperty->SetGradientOpacity(
9496
viewVolumes->auxGradientOpacity);
9597
viewVolumes->auxVolume->SetProperty(viewVolumes->auxProperty);
@@ -243,6 +245,15 @@ bool VolumeManager::allowMultiVolume(vtkSMViewProxy* view) const
243245
return this->d->views[view]->usingMultiVolume;
244246
}
245247

248+
bool VolumeManager::usingMultiVolume(vtkSMViewProxy* view) const
249+
{
250+
if (!this->d->views.contains(view)) {
251+
return false;
252+
}
253+
254+
return this->d->views[view]->usingMultiVolume;
255+
}
256+
246257
int VolumeManager::volumeCount(vtkSMViewProxy* view) const
247258
{
248259
if (!this->d->views.contains(view)) {

tomviz/modules/VolumeManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class VolumeManager : public QObject
3030
static VolumeManager& instance();
3131
void allowMultiVolume(bool allow, vtkSMViewProxy* view);
3232
bool allowMultiVolume(vtkSMViewProxy* view) const;
33+
bool usingMultiVolume(vtkSMViewProxy* view) const;
3334
int volumeCount(vtkSMViewProxy* view) const;
3435

3536
signals:

0 commit comments

Comments
 (0)