I had a hard time to use imageReslice. Basically the only thing required here is ResliceAxes. I checked the instruction but doesn’t seem to work well for me. so I checked the source code vtk.js\Sources\Widgets\Widgets3D\ResliceCursorWidget\index.js, could someone help me to understand section 6 of the code, especially the code

`vec4.transformMat4(originXYZW, planeOrigin, newResliceAxes); mat4.transpose(newResliceAxes, newResliceAxes); vec4.transformMat4(newOriginXYZW, originXYZW, newResliceAxes);`

why planeOrigin needs to be transformed by newResliceAxes? isn’t the planeSource alreay transformed and bounded? why newOriginXYZW needs to be computed this way? why newResliceAxes needs to be transposed? what’s the correct way to set ResliceAxes? does it matter to use [p1-o, p2-o,normal, center] or [p2-o, p1-o,-normal, center] ?

Thanks!

publicAPI.updateReslicePlane = function (imageReslice, viewType) {

// 1. Calculate appropriate pixel spacing for the reslicing

var spacing = model.widgetState.getImage().getSpacing();

// 2. Compute original (i.e. before rotation) plane (i.e. origin, p1, p2) centered on cursor center.

var planeSource = computeReslicePlaneOrigin(viewType);

var _model$widgetState$ge = model.widgetState.getPlanes()[viewType], normal = _model$widgetState$ge.normal, viewUp = _model$widgetState$ge.viewUp;

// 3. transform planeSource to fit the correct normal, viewUp and center

transformPlane(planeSource, model.widgetState.getCenter(), normal, viewUp); // Clip to bounds

// 4. bound plane so o,p1,p2 are image bounded

var boundedOrigin = _toConsumableArray(planeSource.getOrigin());

var boundedP1 = _toConsumableArray(planeSource.getPoint1());

var boundedP2 = _toConsumableArray(planeSource.getPoint2());

boundPlane(model.widgetState.getImage().getBounds(), boundedOrigin, boundedP1, boundedP2);

planeSource.setOrigin.apply(planeSource, _toConsumableArray(boundedOrigin));

planeSource.setPoint1.apply(planeSource, _toConsumableArray(boundedP1));

planeSource.setPoint2.apply(planeSource, _toConsumableArray(boundedP2));

var o = planeSource.getOrigin();

var p1 = planeSource.getPoint1();

var p2 = planeSource.getPoint2();

// 5. compute plane size and spacing

var planeAxis1 = [];

subtract(p1, o, planeAxis1);

var planeAxis2 = [];

subtract(p2, o, planeAxis2); // The x,y dimensions of the plane

var planeSizeX = normalize(planeAxis1);

var planeSizeY = normalize(planeAxis2);

var spacingX = Math.abs(planeAxis1[0] * spacing[0]) + Math.abs(planeAxis1[1] * spacing[1]) + Math.abs(planeAxis1[2] * spacing[2]);

var spacingY = Math.abs(planeAxis2[0] * spacing[0]) + Math.abs(planeAxis2[1] * spacing[1]) + Math.abs(planeAxis2[2] * spacing[2]);

// 6. set newResliceAxes

var newResliceAxes = mat4.identity(new Float64Array(16));

for (var i = 0; i < 3; i++) {

newResliceAxes[4 * i + 0] = planeAxis1[i];

newResliceAxes[4 * i + 1] = planeAxis2[i];

newResliceAxes[4 * i + 2] = normal[i];

}

var planeOrigin = [o[0],o[1],o[2],1.0]);

var originXYZW = [];

var newOriginXYZW = [];

vec4.transformMat4(originXYZW, planeOrigin, newResliceAxes);

mat4.transpose(newResliceAxes, newResliceAxes);

vec4.transformMat4(newOriginXYZW, originXYZW, newResliceAxes);

newResliceAxes[4 * 3 + 0] = newOriginXYZW[0];

newResliceAxes[4 * 3 + 1] = newOriginXYZW[1];

newResliceAxes[4 * 3 + 2] = newOriginXYZW[2];

var modified = imageReslice.setResliceAxes(newResliceAxes);

// Compute a new set of resliced extents