Skip to content

Commit

Permalink
fix(picker): opacity test for volume picking
Browse files Browse the repository at this point in the history
  • Loading branch information
bourdaisj committed Mar 25, 2024
1 parent 7b8b101 commit 723c19a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 8 deletions.
8 changes: 5 additions & 3 deletions Sources/Rendering/Core/Picker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,14 @@ function vtkPicker(publicAPI, model) {
// Note that only vtkProp3D's can be picked by vtkPicker.
props.forEach((prop) => {
const mapper = prop.getMapper();
const propIsNotFullyTranslucent =
prop.getProperty?.()?.getOpacity() > 0.0;

const propIsFullyTranslucent =
prop.getProperty?.().getOpacity?.() === 0.0;

const pickable =
prop.getNestedPickable() &&
prop.getNestedVisibility() &&
propIsNotFullyTranslucent;
!propIsFullyTranslucent;

if (!pickable) {
// prop cannot be picked
Expand Down
44 changes: 39 additions & 5 deletions Sources/Rendering/Core/Picker/test/testPicker.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import test from 'tape';
import testUtils from 'vtk.js/Sources/Testing/testUtils';

import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs';
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow';
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
import vtkPicker from 'vtk.js/Sources/Rendering/Core/Picker';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkPicker from 'vtk.js/Sources/Rendering/Core/Picker';
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow';
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
import vtkRTAnalyticSource from 'vtk.js/Sources/Filters/Sources/RTAnalyticSource';
import vtkVolume from 'vtk.js/Sources/Rendering/Core/Volume';
import vtkVolumeMapper from 'vtk.js/Sources/Rendering/Core/VolumeMapper';
import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs';
import 'vtk.js/Sources/Rendering/Profiles/Volume';

function setupRenderingComponents(gc) {
const container = document.querySelector('body');
Expand Down Expand Up @@ -138,6 +142,36 @@ test.onlyIfWebGL('vtkPicker.pick3DPoint - multiple actors', (t) => {
gc.releaseResources();
});

test.onlyIfWebGL('vtkPicker.pick - volume', (t) => {
const gc = testUtils.createGarbageCollector(t);
const renderer = setupRenderingComponents(gc);

const source = vtkRTAnalyticSource.newInstance();
const size = 50;
source.setWholeExtent([0, size, 0, size, 0, size]);
source.update();

const volumeMapper = vtkVolumeMapper.newInstance();
volumeMapper.setInputConnection(source.getOutputPort());
const volume = vtkVolume.newInstance();
volume.setMapper(volumeMapper);
renderer.addVolume(volume);

const picker = vtkPicker.newInstance();

picker.setPickFromList(1);
picker.initializePickList();
picker.addPickList(volume);

picker.pick([200, 200, 1.0], renderer);

const pickedActors = picker.getActors();
t.equal(pickedActors.length, 1);
t.ok(pickedActors[0] === volume);

gc.releaseResources();
});

test('Test vtkPicker instance', (t) => {
t.ok(vtkPicker, 'Make sure the class definition exists');
const instance = vtkPicker.newInstance();
Expand Down

0 comments on commit 723c19a

Please sign in to comment.