Skip to content

Commit f51b1ad

Browse files
authored
Merge branch 'master' into harmonize-manipulator-use-in-widgets
2 parents 3e2a76c + e10a87a commit f51b1ad

File tree

32 files changed

+775
-411
lines changed

32 files changed

+775
-411
lines changed

Sources/Common/Core/CellArray/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,12 @@ function extractCellSizes(cellArray) {
1818
}
1919

2020
function getNumberOfCells(cellArray) {
21-
return extractCellSizes(cellArray).length;
21+
let cellId = 0;
22+
for (let cellArrayIndex = 0; cellArrayIndex < cellArray.length; ) {
23+
cellArrayIndex += cellArray[cellArrayIndex] + 1;
24+
cellId++;
25+
}
26+
return cellId;
2227
}
2328

2429
// ----------------------------------------------------------------------------
@@ -43,8 +48,11 @@ function vtkCellArray(publicAPI, model) {
4348
return model.numberOfCells;
4449
}
4550

46-
model.cellSizes = extractCellSizes(model.values);
47-
model.numberOfCells = model.cellSizes.length;
51+
if (model.cellSizes) {
52+
model.numberOfCells = model.cellSizes.length;
53+
} else {
54+
model.numberOfCells = getNumberOfCells(model.values);
55+
}
4856
return model.numberOfCells;
4957
};
5058

Sources/IO/XML/XMLImageDataReader/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ function vtkXMLImageDataReader(publicAPI, model) {
2020
.getAttribute('Spacing')
2121
.split(' ')
2222
.map((t) => Number(t));
23+
const direction = imageDataElem
24+
.getAttribute('Direction')
25+
?.split(' ')
26+
.map((t) => Number(t));
2327
const pieces = imageDataElem.getElementsByTagName('Piece');
2428
const nbPieces = pieces.length;
2529

@@ -30,7 +34,12 @@ function vtkXMLImageDataReader(publicAPI, model) {
3034
.getAttribute('Extent')
3135
.split(' ')
3236
.map((t) => Number(t));
33-
const imageData = vtkImageData.newInstance({ origin, spacing, extent });
37+
const imageData = vtkImageData.newInstance({
38+
origin,
39+
spacing,
40+
direction,
41+
extent,
42+
});
3443

3544
// Fill data
3645
vtkXMLReader.processFieldData(
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import test from 'tape-catch';
2+
import vtkXMLImageDataReader from '../index';
3+
import vtkMath from '../../../../Common/Core/Math';
4+
5+
test('Test XML data is read correctly', (t) => {
6+
const expectedOrigin = [10, 20, 30];
7+
const expectedSpacing = [0.5, 1.5, 2.0];
8+
const expectedDirection = [-1, 0, 0, 0, 1, 0, 0, 0, -1];
9+
10+
const fileContent = `
11+
<?xml version="1.0"?>
12+
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
13+
<ImageData WholeExtent="0 -1 0 -1 0 -1" Origin="10 20 30" Spacing="0.5 1.5 2.0" Direction="-1 0 0 0 1 0 0 0 -1">
14+
<Piece Extent="0 -1 0 -1 0 -1" >
15+
<PointData>
16+
</PointData>
17+
<CellData>
18+
</CellData>
19+
</Piece>
20+
</ImageData>
21+
<AppendedData encoding="base64">
22+
_
23+
</AppendedData>
24+
</VTKFile>
25+
`;
26+
27+
const enc = new TextEncoder();
28+
const arrayBuffer = enc.encode(fileContent);
29+
30+
const reader = vtkXMLImageDataReader.newInstance();
31+
32+
reader.parseAsArrayBuffer(arrayBuffer);
33+
const imageData = reader.getOutputData();
34+
35+
t.ok(
36+
vtkMath.areEquals(imageData.getOrigin(), expectedOrigin),
37+
'Make sure the origin is correct.'
38+
);
39+
40+
t.ok(
41+
vtkMath.areEquals(imageData.getSpacing(), expectedSpacing),
42+
'Make sure the spacing is correct.'
43+
);
44+
45+
t.ok(
46+
vtkMath.areEquals(imageData.getDirection(), expectedDirection),
47+
'Make sure the direction is correct.'
48+
);
49+
50+
t.end();
51+
});
52+
53+
test('Test XML data is read when Direction attribute not present', (t) => {
54+
const expectedOrigin = [10, 20, 30];
55+
const expectedSpacing = [1, 2, 3];
56+
57+
const fileContent = `
58+
<?xml version="1.0"?>
59+
<VTKFile type="ImageData" version="0.1" byte_order="LittleEndian" header_type="UInt32" compressor="vtkZLibDataCompressor">
60+
<ImageData WholeExtent="0 -1 0 -1 0 -1" Origin="10 20 30" Spacing="1 2 3">
61+
<Piece Extent="0 -1 0 -1 0 -1" >
62+
<PointData>
63+
</PointData>
64+
<CellData>
65+
</CellData>
66+
</Piece>
67+
</ImageData>
68+
<AppendedData encoding="base64">
69+
_
70+
</AppendedData>
71+
</VTKFile>
72+
`;
73+
74+
const enc = new TextEncoder();
75+
const arrayBuffer = enc.encode(fileContent);
76+
77+
const reader = vtkXMLImageDataReader.newInstance();
78+
79+
reader.parseAsArrayBuffer(arrayBuffer);
80+
const imageData = reader.getOutputData();
81+
82+
t.ok(
83+
vtkMath.areEquals(imageData.getOrigin(), expectedOrigin),
84+
'Make sure the origin is correct.'
85+
);
86+
87+
t.ok(
88+
vtkMath.areEquals(imageData.getSpacing(), expectedSpacing),
89+
'Make sure the spacing is correct.'
90+
);
91+
92+
t.end();
93+
});

Sources/IO/XML/XMLImageDataWriter/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function vtkXMLImageDataWriter(publicAPI, model) {
2323
WholeExtent: dataObject.getExtent().join(' '),
2424
Origin: dataObject.getOrigin().join(' '),
2525
Spacing: dataObject.getSpacing().join(' '),
26+
Direction: dataObject.getDirection().join(' '),
2627
});
2728

2829
const piece = imageData.ele('Piece', {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import test from 'tape-catch';
2+
import vtkImageDataWriter from '../index';
3+
import vtkImageData from '../../../../Common/DataModel/ImageData';
4+
5+
test('Test XML writer file content', (t) => {
6+
const expectedSubstring =
7+
'<ImageData WholeExtent="0 -1 0 -1 0 -1" Origin="10 20 30" Spacing="1 2 3" Direction="-1 0 0 0 1 0 0 0 -1">';
8+
9+
const imageData = vtkImageData.newInstance();
10+
imageData.setOrigin([10, 20, 30]);
11+
imageData.setSpacing([1, 2, 3]);
12+
imageData.setDirection([-1, 0, 0, 0, 1, 0, 0, 0, -1]);
13+
14+
const writer = vtkImageDataWriter.newInstance();
15+
const fileContents = writer.write(imageData);
16+
17+
t.ok(
18+
fileContents.includes(expectedSubstring),
19+
'Make sure the XML file generated is correct.'
20+
);
21+
22+
t.end();
23+
});

Sources/Interaction/Manipulators/MouseCameraAxisRotateManipulator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function vtkMouseCameraAxisRotateManipulator(publicAPI, model) {
4747
const dx = model.previousPosition.x - position.x;
4848
const dy = model.previousPosition.y - position.y;
4949

50-
const size = interactor.getView().getSize();
50+
const size = interactor.getView().getViewportSize(renderer);
5151

5252
// Azimuth
5353
mat4.rotate(

Sources/Interaction/Manipulators/MouseCameraTrackballMultiRotateManipulator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function vtkMouseCameraTrackballMultiRotateManipulator(publicAPI, model) {
2626
let currentManipulator = null;
2727

2828
publicAPI.onButtonDown = (interactor, renderer, position) => {
29-
const viewSize = interactor.getView().getSize();
29+
const viewSize = interactor.getView().getViewportSize(renderer);
3030
const viewCenter = [0.5 * viewSize[0], 0.5 * viewSize[1]];
3131
const rotateRadius = 0.9 * max(viewCenter[0], viewCenter[1]);
3232
const dist2 =

Sources/Interaction/Manipulators/MouseCameraTrackballPanManipulator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ function vtkMouseCameraTrackballPanManipulator(publicAPI, model) {
3939
vtkMath.cross(vpn, up, right);
4040

4141
// These are different because y is flipped.
42-
const height = interactor.getView().getSize()[1];
42+
const height = interactor.getView().getViewportSize(renderer)[1];
4343
let dx = (pos.x - lastPos.x) / height;
4444
let dy = (lastPos.y - pos.y) / height;
4545

Sources/Interaction/Manipulators/MouseCameraTrackballRotateManipulator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function vtkMouseCameraTrackballRotateManipulator(publicAPI, model) {
4646
const dx = model.previousPosition.x - position.x;
4747
const dy = model.previousPosition.y - position.y;
4848

49-
const size = interactor.getView().getSize();
49+
const size = interactor.getView().getViewportSize(renderer);
5050

5151
// Azimuth
5252
const viewUp = camera.getViewUp();

Sources/Interaction/Manipulators/MouseCameraTrackballZoomManipulator/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function vtkMouseCameraTrackballZoomManipulator(publicAPI, model) {
1212

1313
publicAPI.onButtonDown = (interactor, renderer, position) => {
1414
model.previousPosition = position;
15-
const size = interactor.getView().getSize();
15+
const size = interactor.getView().getViewportSize(renderer);
1616

1717
const camera = renderer.getActiveCamera();
1818
const direction = model.flipDirection ? -1 : 1;

0 commit comments

Comments
 (0)