Skip to content

Commit

Permalink
fix(ImageCroppingRegionsWidget): Use Orientation constant
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Jan 10, 2018
1 parent 600f1c7 commit 8ec8ce4
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
const Orientation = {
YZ: 0,
XZ: 1,
XY: 2,
};

const Events = ['PlanesPositionChanged'];

export default { Orientation, Events };
export default { Events };
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import vtkWidgetRepresentation from 'vtk.js/Sources/Interaction/Widgets/WidgetRe
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import Constants from 'vtk.js/Sources/Interaction/Widgets/ImageCroppingRegionsRepresentation/Constants';
import WidgetConstants from 'vtk.js/Sources/Interaction/Widgets/ImageCroppingRegionsWidget/Constants';

const { vtkErrorMacro } = macro;
const { Orientation, Events } = Constants;
const { Events } = Constants;
const { Orientation } = WidgetConstants;

// ----------------------------------------------------------------------------
// vtkImageCroppingRegionsRepresentation methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const WidgetState = {
MOVE_RIGHT_TOP: 8,
};

const Orientation = {
YZ: 0,
XZ: 1,
XY: 2,
};

const CropWidgetEvents = ['CroppingPlanesPositionChanged'];

export default { WidgetState, CropWidgetEvents };
export default { WidgetState, CropWidgetEvents, Orientation };
26 changes: 13 additions & 13 deletions Sources/Interaction/Widgets/ImageCroppingRegionsWidget/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import vtkImageCroppingRegionsRepresentation from 'vtk.js/Sources/Interaction/Wi
import Constants from 'vtk.js/Sources/Interaction/Widgets/ImageCroppingRegionsWidget/Constants';

const { vtkErrorMacro, VOID, EVENT_ABORT } = macro;
const { WidgetState, CropWidgetEvents } = Constants;
const { WidgetState, CropWidgetEvents, Orientation } = Constants;

const events = [
'MouseMove',
Expand Down Expand Up @@ -203,18 +203,18 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
let camUp2D;

switch (model.sliceOrientation) {
case 0: // YZ
case Orientation.YZ:
ax1 = [planes[2], planes[3]]; // Y crop bounds
ax2 = [planes[4], planes[5]]; // Z crop bounds
camUp2D = [camUp[1], camUp[2]];
break;
case 1: // ZX
case Orientation.XZ: // ZX
ax1 = [planes[0], planes[1]]; // X crop bounds
ax2 = [planes[4], planes[5]]; // Z crop bounds
// reverse camUp to be -Z, then X
camUp2D = [-camUp[2], camUp[0]];
break;
case 2: // XY
case Orientation.XY:
ax1 = [planes[0], planes[1]]; // X crop bounds
ax2 = [planes[2], planes[3]]; // Y crop bounds
camUp2D = [camUp[0], camUp[1]];
Expand Down Expand Up @@ -257,7 +257,7 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
let top;

switch (model.sliceOrientation) {
case 0: // YZ
case Orientation.YZ:
[left, bottom] = view.worldToDisplay(
model.slice,
leftBottom[0],
Expand All @@ -271,7 +271,7 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
model.currentRenderer
);
break;
case 1: // ZX
case Orientation.XZ: // ZX
[left, bottom] = view.worldToDisplay(
leftBottom[0],
model.slice,
Expand All @@ -285,7 +285,7 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
model.currentRenderer
);
break;
case 2: // XY
case Orientation.XY:
[left, bottom] = view.worldToDisplay(
leftBottom[0],
leftBottom[1],
Expand Down Expand Up @@ -356,15 +356,15 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
let camUp2D;

switch (model.sliceOrientation) {
case 0: // YZ
case Orientation.YZ:
ax1 = [planes[2], planes[3]]; // Y crop pos
ax2 = [planes[4], planes[5]]; // Z crop pos
bounds1 = [bounds[2], bounds[3]];
bounds2 = [bounds[4], bounds[5]];
camUp2D = [camUp[1], camUp[2]];
newPos = [newPos[1], newPos[2]];
break;
case 1: // ZX
case Orientation.XZ: // ZX
ax1 = [planes[4], planes[5]]; // Z crop pos
ax2 = [planes[0], planes[1]]; // X crop pos
bounds1 = [bounds[4], bounds[5]];
Expand All @@ -373,7 +373,7 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {
camUp2D = [camUp[2], camUp[0]];
newPos = [newPos[2], newPos[0]];
break;
case 2: // XY
case Orientation.XY:
ax1 = [planes[0], planes[1]]; // X crop pos
ax2 = [planes[2], planes[3]]; // Y crop pos
bounds1 = [bounds[0], bounds[1]];
Expand Down Expand Up @@ -485,15 +485,15 @@ function vtkImageCroppingRegionsWidget(publicAPI, model) {

// assign new plane values
switch (model.sliceOrientation) {
case 0: // YZ
case Orientation.YZ:
[planes[2], planes[3]] = ax1;
[planes[4], planes[5]] = ax2;
break;
case 1: // ZX
case Orientation.XZ: // ZX
[planes[0], planes[1]] = ax2;
[planes[4], planes[5]] = ax1;
break;
case 2: // XY
case Orientation.XY:
[planes[0], planes[1]] = ax1;
[planes[2], planes[3]] = ax2;
break;
Expand Down

0 comments on commit 8ec8ce4

Please sign in to comment.