Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(picker): opacity test for volume picking #3044

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading