All files / Sources/Widgets/Manipulators/PickerManipulator index.js

68.42% Statements 13/19
20% Branches 1/5
75% Functions 3/4
68.42% Lines 13/19

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                    1x   1x                                       1x   1x 1x 1x 1x   1x   1x               1x   1x   1x         1x          
import macro from 'vtk.js/Sources/macros';
import vtkCellPicker from 'vtk.js/Sources/Rendering/Core/CellPicker';
import vtkAbstractManipulator from 'vtk.js/Sources/Widgets/Manipulators/AbstractManipulator';
 
// ----------------------------------------------------------------------------
// vtkPickerManipulator methods
// ----------------------------------------------------------------------------
 
function vtkPickerManipulator(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkPickerManipulator');
 
  publicAPI.handleEvent = (callData) => {
    const { position, pokedRenderer } = callData;
 
    model.picker.pick([position.x, position.y, 0.0], pokedRenderer);
    if (model.picker.getPickedPositions().length > 0) {
      model.position = model.picker.getPickedPositions()[0];
    } else {
      model.position = null;
    }
    return {
      worldCoords: model.position,
    };
  };
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
function defaultValues(initialValues) {
  if (!initialValues.picker) {
    // Default picker
    const picker = vtkCellPicker.newInstance();
    picker.initializePickList();
    picker.setPickFromList(true);
    picker.setTolerance(0);
 
    initialValues.picker = picker;
  }
  return {
    ...initialValues,
  };
}
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  vtkAbstractManipulator.extend(publicAPI, model, defaultValues(initialValues));
 
  macro.setGet(publicAPI, model, ['picker']);
 
  vtkPickerManipulator(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkPickerManipulator');
 
// ----------------------------------------------------------------------------
 
export default { extend, newInstance };