All files / Sources/Rendering/Core/Actor2D index.js

52.63% Statements 40/76
20% Branches 6/30
37.5% Functions 6/16
54.92% Lines 39/71

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 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178                        8x   8x   8x   2x         2x     2x   2x     8x                           8x   8x 126x 8x   126x         8x           8x             8x             8x     8x   8x                                         8x                             8x   2x       2x 2x             8x 8x             1x                     8x     8x   8x 8x 8x 8x 8x 8x     8x 8x     8x         1x          
import macro from 'vtk.js/Sources/macros';
import vtkCoordinate from 'vtk.js/Sources/Rendering/Core/Coordinate';
import vtkProp from 'vtk.js/Sources/Rendering/Core/Prop';
import vtkProperty2D from 'vtk.js/Sources/Rendering/Core/Property2D';
import { Coordinate } from 'vtk.js/Sources/Rendering/Core/Coordinate/Constants';
 
// ----------------------------------------------------------------------------
// vtkActor2D methods
// ----------------------------------------------------------------------------
 
function vtkActor2D(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkActor2D');
 
  publicAPI.getActors2D = () => publicAPI;
 
  publicAPI.getIsOpaque = () => {
    // make sure we have a property
    Iif (!model.property) {
      // force creation of a property
      publicAPI.getProperty();
    }
 
    let isOpaque = model.property.getOpacity() >= 1.0;
 
    // are we using an opaque texture, if any?
    isOpaque = isOpaque && (!model.texture || !model.texture.isTranslucent());
 
    return isOpaque;
  };
 
  publicAPI.hasTranslucentPolygonalGeometry = () => {
    if (model.mapper === null) {
      return false;
    }
    // make sure we have a property
    if (model.property === null) {
      // force creation of a property
      publicAPI.setProperty(publicAPI.makeProperty());
    }
 
    // is this actor opaque ?
    return !publicAPI.getIsOpaque();
  };
 
  publicAPI.makeProperty = vtkProperty2D.newInstance;
 
  publicAPI.getProperty = () => {
    if (model.property === null) {
      model.property = publicAPI.makeProperty();
    }
    return model.property;
  };
 
  //----------------------------------------------------------------------------
  // Set the Prop2D's position in display coordinates.
  publicAPI.setDisplayPosition = (XPos, YPos) => {
    model.positionCoordinate.setCoordinateSystem(Coordinate.DISPLAY);
    model.positionCoordinate.setValue(XPos, YPos, 0.0);
  };
 
  //----------------------------------------------------------------------------
  publicAPI.setWidth = (w) => {
    const pos = model.position2Coordinate.getValue();
    model.position2Coordinate.setCoordinateSystemToNormalizedViewport();
    model.position2Coordinate.setValue(w, pos[1]);
  };
 
  //----------------------------------------------------------------------------
  publicAPI.setHeight = (w) => {
    const pos = model.position2Coordinate.getValue();
    model.position2Coordinate.setCoordinateSystemToNormalizedViewport();
    model.position2Coordinate.setValue(pos[0], w);
  };
 
  //----------------------------------------------------------------------------
  publicAPI.getWidth = () => model.position2Coordinate.getValue()[0];
 
  //----------------------------------------------------------------------------
  publicAPI.getHeight = () => model.position2Coordinate.getValue()[1];
 
  publicAPI.getMTime = () => {
    let mt = model.mtime;
    if (model.property !== null) {
      const time = model.property.getMTime();
      mt = time > mt ? time : mt;
    }
 
    mt =
      model.positionCoordinate.getMTime() > mt
        ? model.positionCoordinate.getMTime()
        : mt;
    mt =
      model.positionCoordinate2.getMTime() > mt
        ? model.positionCoordinate2.getMTime()
        : mt;
 
    // TBD: Handle array of textures here.
 
    return mt;
  };
 
  publicAPI.getRedrawMTime = () => {
    let mt = model.mtime;
    if (model.mapper !== null) {
      let time = model.mapper.getMTime();
      mt = time > mt ? time : mt;
      if (model.mapper.getInput() !== null) {
        // FIXME !!! getInputAlgorithm / getInput
        model.mapper.getInputAlgorithm().update();
        time = model.mapper.getInput().getMTime();
        mt = time > mt ? time : mt;
      }
    }
    return mt;
  };
 
  publicAPI.getBounds = () => {
    // does our mapper support bounds
    Iif (typeof publicAPI.getMapper().getBounds === 'function') {
      model.useBounds = true;
      return publicAPI.getMapper().getBounds();
    }
    model.useBounds = false;
    return [];
  };
 
  // Description:
  // Return the actual vtkCoordinate reference that the mapper should use
  // to position the actor. This is used internally by the mappers and should
  // be overridden in specialized subclasses and otherwise ignored.
  publicAPI.getActualPositionCoordinate = () => model.positionCoordinate;
  publicAPI.getActualPositionCoordinate2 = () => model.positionCoordinate2;
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {
  mapper: null,
  property: null,
  layerNumber: 0,
  positionCoordinate: null,
  positionCoordinate2: null,
};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Inheritance
  vtkProp.extend(publicAPI, model, initialValues);
 
  model.positionCoordinate = vtkCoordinate.newInstance();
  model.positionCoordinate.setCoordinateSystemToViewport();
  model.positionCoordinate2 = vtkCoordinate.newInstance();
  model.positionCoordinate2.setCoordinateSystemToNormalizedViewport();
  model.positionCoordinate2.setValue(0.5, 0.5);
  model.positionCoordinate2.setReferenceCoordinate(model.positionCoordinate);
 
  // Build VTK API
  macro.set(publicAPI, model, ['property']);
  macro.setGet(publicAPI, model, ['mapper']);
 
  // Object methods
  vtkActor2D(publicAPI, model);
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(extend, 'vtkActor2D');
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };