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

test(testImageLabelOutline): add slicing mode test #9

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
33 changes: 23 additions & 10 deletions Sources/Rendering/Core/ImageMapper/test/testImageLabelOutline.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs';

import vtkImageMapper from 'vtk.js/Sources/Rendering/Core/ImageMapper';
import vtkImageSlice from 'vtk.js/Sources/Rendering/Core/ImageSlice';
import { SlicingMode } from 'vtk.js/Sources/Rendering/Core/ImageMapper/Constants';
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer';
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow';
import vtkImageData from 'vtk.js/Sources/Common/DataModel/ImageData';
Expand All @@ -13,7 +14,7 @@ import vtkPiecewiseFunction from 'vtk.js/Sources/Common/DataModel/PiecewiseFunct

import baseline from './testImageLabelOutline.png';

test('Test ImageMapper', (t) => {
test.only('Test ImageMapper', (t) => {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to remove

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤣👍️

const gc = testUtils.createGarbageCollector(t);
t.ok('rendering', 'vtkImageMapper testImage');

Expand All @@ -37,6 +38,9 @@ test('Test ImageMapper', (t) => {
const BACKGROUND = 0;
const LOW_VALUE = 80;
const HIGH_VALUE = 160;
const SLICE = 5;
const SLICING_MODE = SlicingMode.I;
const CAMERA_POS = [10, 0, 0];

function createLabelPipeline(backgroundImageData) {
const labelMapData = gc.registerResource(
Expand Down Expand Up @@ -79,6 +83,9 @@ test('Test ImageMapper', (t) => {
ofun: gc.registerResource(vtkPiecewiseFunction.newInstance()),
};

labelMap.mapper.setSlicingMode(SLICING_MODE);
labelMap.mapper.setSlice(SLICE);

// Labelmap pipeline
labelMap.mapper.setInputData(labelMapData);
labelMap.actor.setMapper(labelMap.mapper);
Expand Down Expand Up @@ -129,7 +136,7 @@ test('Test ImageMapper', (t) => {
// Create a one slice vtkImageData that has four quadrants of different values

const imageData = gc.registerResource(vtkImageData.newInstance());
const dims = [10, 10, 1];
const dims = [10, 10, 10];
imageData.setSpacing(1, 1, 1);
imageData.setOrigin(0.1, 0.1, 0.1);
imageData.setDirection(1, 0, 0, 0, 1, 0, 0, 0, 1);
Expand All @@ -140,14 +147,16 @@ test('Test ImageMapper', (t) => {
const values = new Uint8Array(dims[0] * dims[1] * dims[2]);

let i = 0;
for (let y = 0; y < dims[1]; y++) {
for (let x = 0; x < dims[0]; x++, i++) {
if ((x < 3 && y < 3) || (x > 7 && y > 7)) {
values[i] = BACKGROUND;
} else if (x > 4 && x < 6 && y > 4 && y < 7) {
values[i] = LOW_VALUE;
} else {
values[i] = HIGH_VALUE;
for (let z = 0; z < dims[2]; z++) {
for (let y = 0; y < dims[1]; y++) {
for (let x = 0; x < dims[0]; x++, i++) {
if (x > 3 && x < 6 && y > 3 && y < 6) {
values[i] = LOW_VALUE;
} else if (x > 1 && x < 8 && y > 1 && y < 8) {
values[i] = HIGH_VALUE;
} else {
values[i] = BACKGROUND;
}
}
}
}
Expand All @@ -170,11 +179,15 @@ test('Test ImageMapper', (t) => {
const actor = gc.registerResource(vtkImageSlice.newInstance());
const mapper = gc.registerResource(vtkImageMapper.newInstance());
mapper.setInputData(data);
mapper.setSlicingMode(SLICING_MODE);
mapper.setSlice(SLICE);
actor.setMapper(mapper);
actor.getProperty().setInterpolationTypeToNearest();

renderer.addActor(actor);
renderer.addActor(labelMap.actor);

renderer.getActiveCamera().setPosition(...CAMERA_POS);
renderer.resetCamera();
renderer.resetCameraClippingRange();
renderWindow.render();
Expand Down
Loading