Skip to content

Commit

Permalink
Merge branch 'master' into reslice-cursor-rotation-handle-position
Browse files Browse the repository at this point in the history
  • Loading branch information
finetjul authored Jul 12, 2021
2 parents 7254377 + 9962dd8 commit 9606404
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 74 deletions.
2 changes: 1 addition & 1 deletion Sources/Common/Core/ImageHelper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function imageToImageData(
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.scale(flipX ? -1 : 1, flipY ? -1 : 1);
ctx.rotate((rotate * Math.PI) / 180);
ctx.drawImage(image, -image.width / 2, -image.width / 2);
ctx.drawImage(image, -image.width / 2, -image.height / 2);

return canvasToImageData(canvas);
}
Expand Down
45 changes: 0 additions & 45 deletions Sources/IO/XML/XMLPolyDataReader/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import macro from 'vtk.js/Sources/macro';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkXMLReader from 'vtk.js/Sources/IO/XML/XMLReader';

Expand Down Expand Up @@ -60,28 +59,6 @@ function handleCells(
return size;
}

// ----------------------------------------------------------------------------

function handleFieldDataArray(
dataArrayElem,
compressor,
byteOrder,
headerType,
binaryBuffer
) {
const size = Number(dataArrayElem.getAttribute('NumberOfTuples'));
return vtkDataArray.newInstance(
vtkXMLReader.processDataArray(
size,
dataArrayElem,
compressor,
byteOrder,
headerType,
binaryBuffer
)
);
}

// ----------------------------------------------------------------------------
// vtkXMLPolyDataReader methods
// ----------------------------------------------------------------------------
Expand All @@ -92,26 +69,9 @@ function vtkXMLPolyDataReader(publicAPI, model) {

publicAPI.parseXML = (rootElem, type, compressor, byteOrder, headerType) => {
const datasetElem = rootElem.getElementsByTagName(model.dataType)[0];
const fieldDataElem = datasetElem.getElementsByTagName('FieldData')[0];
const pieces = datasetElem.getElementsByTagName('Piece');
const nbPieces = pieces.length;

// field data
let fieldDataArrays = [];
if (fieldDataElem) {
fieldDataArrays = [
...fieldDataElem.getElementsByTagName('DataArray'),
].map((daElem) =>
handleFieldDataArray(
daElem,
compressor,
byteOrder,
headerType,
model.binaryBuffer
)
);
}

for (let outputIndex = 0; outputIndex < nbPieces; outputIndex++) {
// Create dataset
const polydata = vtkPolyData.newInstance();
Expand Down Expand Up @@ -162,11 +122,6 @@ function vtkXMLPolyDataReader(publicAPI, model) {
model.binaryBuffer
);

const fieldData = polydata.getFieldData();
for (let i = 0; i < fieldDataArrays.length; i++) {
fieldData.addArray(fieldDataArrays[i]);
}

// Add new output
model.output[outputIndex] = polydata;
}
Expand Down
43 changes: 43 additions & 0 deletions Sources/IO/XML/XMLReader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,28 @@ function processFieldData(
}
}

// ----------------------------------------------------------------------------
function handleFieldDataArrays(
fieldDataElem,
compressor,
byteOrder,
headerType,
binaryBuffer
) {
return [...fieldDataElem.getElementsByTagName('DataArray')].map((daElem) =>
vtkDataArray.newInstance(
processDataArray(
Number(daElem.getAttribute('NumberOfTuples')),
daElem,
compressor,
byteOrder,
headerType,
binaryBuffer
)
)
);
}

// ----------------------------------------------------------------------------
// vtkXMLReader methods
// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -513,6 +535,27 @@ function vtkXMLReader(publicAPI, model) {
}

publicAPI.parseXML(rootElem, type, compressor, byteOrder, headerType);

const datasetElem = rootElem.getElementsByTagName(type)[0];
const fieldDataElem = datasetElem.getElementsByTagName('FieldData')[0];

if (fieldDataElem) {
const fieldDataArrays = handleFieldDataArrays(
fieldDataElem,
compressor,
byteOrder,
headerType,
model.binaryBuffer
);

for (let i = 0; i < model.output.length; i++) {
const fieldData = model.output[i].getFieldData();
for (let j = 0; j < fieldDataArrays.length; j++) {
fieldData.addArray(fieldDataArrays[j]);
}
}
}

return true;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import macro from 'vtk.js/Sources/macro';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkHandleRepresentation from 'vtk.js/Sources/Widgets/Representations/HandleRepresentation';
import vtkContextRepresentation from 'vtk.js/Sources/Widgets/Representations/ContextRepresentation';
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkSpline3D from 'vtk.js/Sources/Common/DataModel/Spline3D';
Expand Down Expand Up @@ -155,7 +155,7 @@ const DEFAULT_VALUES = {
export function extend(publicAPI, model, initialValues = {}) {
Object.assign(model, DEFAULT_VALUES, initialValues);

vtkHandleRepresentation.extend(publicAPI, model, initialValues);
vtkContextRepresentation.extend(publicAPI, model, initialValues);
macro.get(publicAPI, model, ['mapper']);
macro.setGet(publicAPI, model, [
'resolution',
Expand Down
17 changes: 9 additions & 8 deletions Sources/Widgets/Widgets3D/SplineWidget/behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { vec3 } from 'gl-matrix';
export default function widgetBehavior(publicAPI, model) {
model.classHierarchy.push('vtkSplineWidgetProp');

model.keysDown = {};
model.moveHandle = model.widgetState.getMoveHandle();

// --------------------------------------------------------------------------
// Private methods
// --------------------------------------------------------------------------

const updateHandlesSize = () => {
if (model.handleSizeInPixels !== null) {
if (model.handleSizeInPixels != null) {
const scale =
model.handleSizeInPixels *
vec3.distance(
Expand Down Expand Up @@ -104,21 +107,19 @@ export default function widgetBehavior(publicAPI, model) {

// --------------------------------------------------------------------------

const superSetHandleSizeInPixels = publicAPI.setHandleSizeInPixels;
publicAPI.setHandleSizeInPixels = (size) => {
superSetHandleSizeInPixels(size);
model.factory.setHandleSizeInPixels(size);
updateHandlesSize();
};
publicAPI.setHandleSizeInPixels(model.handleSizeInPixels); // set initial value
publicAPI.setHandleSizeInPixels(model.factory.getHandleSizeInPixels()); // set initial value

// --------------------------------------------------------------------------

const superSetResolution = publicAPI.setResolution;
publicAPI.setResolution = (resolution) => {
superSetResolution(resolution);
model.representations[1].setResolution(model.resolution);
model.factory.setResolution(resolution);
model.representations[1].setResolution(resolution);
};
publicAPI.setResolution(model.resolution); // set initial value
publicAPI.setResolution(model.factory.getResolution()); // set initial value

// --------------------------------------------------------------------------

Expand Down
6 changes: 2 additions & 4 deletions Sources/Widgets/Widgets3D/SplineWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,18 @@ function vtkSplineWidget(publicAPI, model) {
// initialization
// --------------------------------------------------------------------------

model.moveHandle = model.widgetState.getMoveHandle();
// Default manipulator
model.manipulator = vtkPlanePointManipulator.newInstance();
}

// ----------------------------------------------------------------------------

const DEFAULT_VALUES = {
keysDown: {},
freehandMinDistance: 0.1,
allowFreehand: true,
resolution: 32,
resolution: 32, // propagates to SplineContextRepresentation
defaultCursor: 'pointer',
handleSizeInPixels: 10,
handleSizeInPixels: 10, // propagates to SplineContextRepresentation
};

// ----------------------------------------------------------------------------
Expand Down
12 changes: 6 additions & 6 deletions Sources/macro.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import vtk from './vtk';
import vtk, { vtkGlobal } from './vtk';
import ClassHierarchy from './Common/Core/ClassHierarchy';

let globalMTime = 0;
Expand Down Expand Up @@ -33,14 +33,14 @@ consoleMethods.forEach((methodName) => {
fakeConsole[methodName] = noOp;
});

global.console = console.hasOwnProperty('log') ? console : fakeConsole;
vtkGlobal.console = console.hasOwnProperty('log') ? console : fakeConsole;

const loggerFunctions = {
debug: noOp, // Don't print debug by default
error: global.console.error || noOp,
info: global.console.info || noOp,
log: global.console.log || noOp,
warn: global.console.warn || noOp,
error: vtkGlobal.console.error || noOp,
info: vtkGlobal.console.info || noOp,
log: vtkGlobal.console.log || noOp,
warn: vtkGlobal.console.warn || noOp,
};

export function setLoggerFunction(name, fn) {
Expand Down
12 changes: 8 additions & 4 deletions Sources/vtk.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import globalThisShim from 'globalthis';

export const vtkGlobal = globalThisShim(); // returns native globalThis if compliant

const factoryMapping = {
vtkObject: () => null,
};
Expand All @@ -10,15 +14,15 @@ export default function vtk(obj) {
return obj;
}
if (!obj.vtkClass) {
if (global.console && global.console.error) {
global.console.error('Invalid VTK object');
if (vtkGlobal.console && vtkGlobal.console.error) {
vtkGlobal.console.error('Invalid VTK object');
}
return null;
}
const constructor = factoryMapping[obj.vtkClass];
if (!constructor) {
if (global.console && global.console.error) {
global.console.error(
if (vtkGlobal.console && vtkGlobal.console.error) {
vtkGlobal.console.error(
`No vtk class found for Object of type ${obj.vtkClass}`
);
}
Expand Down
5 changes: 1 addition & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"commander": "6.2.1",
"d3-scale": "3.2.4",
"gl-matrix": "3.3.0",
"globalthis": "^1.0.2",
"jszip": "3.2.0",
"pako": "2.0.3",
"seedrandom": "3.0.5",
Expand Down

0 comments on commit 9606404

Please sign in to comment.