Skip to content

Commit

Permalink
test(vtkView2DProxy): add a test with a vtkImageSlice
Browse files Browse the repository at this point in the history
  • Loading branch information
bruyeret authored and finetjul committed Oct 17, 2023
1 parent e09614c commit 91c456a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions Sources/Proxy/Core/View2DProxy/test/testView2DProxy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import test from 'tape-catch';
import testUtils from 'vtk.js/Sources/Testing/testUtils';

// Load the rendering pieces we want to use (for both WebGL and WebGPU)
import 'vtk.js/Sources/Rendering/Profiles/All';

import vtkImageMapper from 'vtk.js/Sources/Rendering/Core/ImageMapper';
import vtkImageReslice from 'vtk.js/Sources/Imaging/Core/ImageReslice';
import vtkImageSlice from 'vtk.js/Sources/Rendering/Core/ImageSlice';
import vtkRTAnalyticSource from 'vtk.js/Sources/Filters/Sources/RTAnalyticSource';
import vtkView2DProxy from 'vtk.js/Sources/Proxy/Core/View2DProxy';

import baseline from './viewProxy2D.png';

test.onlyIfWebGL(
'Test vtkProxy2D Rendering with vtkImageSlice representation',
(t) => {
const gc = testUtils.createGarbageCollector(t);
t.ok('rendering', 'vtkView2DProxy Rendering');

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

const image = source.getOutputData();
const spacing = 0.7;
image.setSpacing([spacing, spacing, spacing]);

const reslice = gc.registerResource(vtkImageReslice.newInstance());
reslice.setInputData(image);

const mapper = gc.registerResource(vtkImageMapper.newInstance());
mapper.setInputConnection(reslice.getOutputPort());

const actor = gc.registerResource(vtkImageSlice.newInstance());
actor.setMapper(mapper);

const viewProxy = gc.registerResource(
vtkView2DProxy.newInstance({
useParallelRendering: true,
axis: undefined,
fitProps: true,
})
);
viewProxy.addRepresentation(actor);

const container = gc.registerDOMElement(document.createElement('div'));
document.body.appendChild(container);

viewProxy.setContainer(container);
viewProxy.resize();
viewProxy.resetCamera();

const glWindow = viewProxy.getRenderer().getRenderWindow().getViews()[0];
glWindow.setSize(400, 400);
glWindow.captureNextImage().then((capturedImage) => {
testUtils.compareImages(
capturedImage,
[baseline],
'Proxy/Core/View2DProxy/testView2DProxy',
t,
5,
gc.releaseResources
);
});
glWindow.render();
}
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 91c456a

Please sign in to comment.