All files / Sources/Widgets/Widgets3D/InteractiveOrientationWidget index.js

50% Statements 10/20
0% Branches 0/12
60% Functions 3/5
50% Lines 9/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156                                    1x       1x                 1x                     1x                                                                                                                                                                             1x                 1x   1x   1x         1x                
import macro from 'vtk.js/Sources/macros';
import vtkAbstractWidgetFactory from 'vtk.js/Sources/Widgets/Core/AbstractWidgetFactory';
import vtkConvexFaceContextRepresentation from 'vtk.js/Sources/Widgets/Representations/ConvexFaceContextRepresentation';
 
import widgetBehavior from 'vtk.js/Sources/Widgets/Widgets3D/InteractiveOrientationWidget/behavior';
import {
  INITIAL_POINTS,
  generateState,
} from 'vtk.js/Sources/Widgets/Widgets3D/InteractiveOrientationWidget/state';
 
import { Behavior } from 'vtk.js/Sources/Widgets/Representations/WidgetRepresentation/Constants';
import { ViewTypes } from 'vtk.js/Sources/Widgets/Core/WidgetManager/Constants';
 
// ----------------------------------------------------------------------------
// Factory
// ----------------------------------------------------------------------------
 
function vtkInteractiveOrientationWidget(publicAPI, model) {
  model.classHierarchy.push('vtkInteractiveOrientationWidget');
 
  // --- Widget Requirement ---------------------------------------------------
 
  model.methodsToLink = [
    'closePolyLine',
    'activeScaleFactor',
    'activeColor',
    'useActiveColor',
    'glyphResolution',
    'defaultScale',
  ];
 
  publicAPI.setBounds = (bounds) => {
    const handles = model.widgetState.getStatesWithLabel('handles');
    for (let i = 0; i < handles.length; i++) {
      const xyz = INITIAL_POINTS[i];
      const x = xyz[0] > 0 ? bounds[1] : bounds[0];
      const y = xyz[1] > 0 ? bounds[3] : bounds[2];
      const z = xyz[2] > 0 ? bounds[5] : bounds[4];
      handles[i].setOrigin(x, y, z);
    }
  };
 
  publicAPI.getRepresentationsForViewType = (viewType) => {
    switch (viewType) {
      case ViewTypes.DEFAULT:
      case ViewTypes.GEOMETRY:
      case ViewTypes.SLICE:
      case ViewTypes.VOLUME:
      default:
        return [
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['---', '--+', '-++', '-+-'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 1',
            },
          },
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['---', '+--', '+-+', '--+'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 2',
            },
          },
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['+--', '++-', '+++', '+-+'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 3',
            },
          },
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['++-', '-+-', '-++', '+++'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 4',
            },
          },
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['-++', '--+', '+-+', '+++'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 5',
            },
          },
          {
            builder: vtkConvexFaceContextRepresentation,
            labels: ['-+-', '++-', '+--', '---'],
            initialValues: {
              behavior: Behavior.HANDLE,
              pickable: true,
              activeScaleFactor: 1.2,
              activeColor: 1,
              useActiveColor: true,
              name: 'Face 6',
            },
          },
        ];
    }
  };
}
 
// ----------------------------------------------------------------------------
 
const defaultValues = (initialValues) => ({
  behavior: widgetBehavior,
  widgetState: generateState(),
  ...initialValues,
});
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, defaultValues(initialValues));
 
  vtkAbstractWidgetFactory.extend(publicAPI, model, initialValues);
 
  vtkInteractiveOrientationWidget(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(
  extend,
  'vtkInteractiveOrientationWidget'
);
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };