All files / Sources/Proxy/Representations/GlyphRepresentationProxy index.js

31.57% Statements 12/38
0% Branches 0/5
33.33% Functions 2/6
33.33% Lines 12/36

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                                        1x   1x                                                                                                           1x               1x 1x 1x             1x         1x     1x     1x 1x             1x                
import macro from 'vtk.js/Sources/macros';
import vtk from 'vtk.js/Sources/vtk';
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
import vtkProperty from 'vtk.js/Sources/Rendering/Core/Property';
import vtkGlyph3DMapper from 'vtk.js/Sources/Rendering/Core/Glyph3DMapper';
import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray';
import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData';
import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction';
 
import vtkAbstractRepresentationProxy from 'vtk.js/Sources/Proxy/Core/AbstractRepresentationProxy';
 
// For Glyph creation using the vtk factory
import 'vtk.js/Sources/Filters/Sources';
 
// ----------------------------------------------------------------------------
// vtkGlyphRepresentationProxy methods
// ----------------------------------------------------------------------------
 
function vtkGlyphRepresentationProxy(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkGlyphRepresentationProxy');
 
  model.property = vtkProperty.newInstance();
 
  function processJSON(description) {
    model.actors.length = 0;
 
    // Handle colors
    const lookupTable = vtkColorTransferFunction.newInstance();
    lookupTable.applyColorMap({ RGBPoints: description.rgbPoints });
 
    // Handle glyph
    model.glyph = {};
    let count = description.glyph.length;
    while (count--) {
      const glyph = description.glyph[count];
      model.glyph[glyph.id] = vtk(glyph);
    }
 
    // Handle mapping
    count = description.mapping.length;
    while (count--) {
      const sourceDesc = description.mapping[count];
      const glyph = model.glyph[sourceDesc.glyphId];
      const source = vtkPolyData.newInstance();
      source.getPoints().setData(Float32Array.from(sourceDesc.coordinates), 3);
      if (sourceDesc.scale) {
        source.getPointData().addArray(
          vtkDataArray.newInstance({
            name: 'scaling',
            values: Float32Array.from(sourceDesc.scale),
            numberOfComponents: 3,
          })
        );
      }
      const mapper = vtkGlyph3DMapper.newInstance({
        useLookupTableScalarRange: true,
        lookupTable,
        orient: false,
        scaling: !!sourceDesc.scale,
        scaleArray: 'scaling',
        scaleMode: vtkGlyph3DMapper.ScaleModes.SCALE_BY_COMPONENTS,
      });
      const actor = vtkActor.newInstance();
      if (model.property) {
        actor.setProperty(model.property);
      }
 
      actor.setMapper(mapper);
      mapper.setInputData(source, 0);
      mapper.setInputConnection(glyph.getOutputPort(), 1);
 
      model.actors.push(actor);
    }
  }
 
  model.sourceDependencies.push({ setInputData: processJSON });
 
  // Add actors
  // model.actors.push(model.sphereActor);
  // model.actors.push(model.stickActor);
 
  // API ----------------------------------------------------------------------
 
  publicAPI.setColorBy = () => {};
  publicAPI.getColorBy = () => [];
  publicAPI.listDataArrays = () => [];
}
 
// ----------------------------------------------------------------------------
// Object factory
// ----------------------------------------------------------------------------
 
const DEFAULT_VALUES = {};
 
// ----------------------------------------------------------------------------
 
export function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);
 
  // Object methods
  vtkAbstractRepresentationProxy.extend(publicAPI, model, initialValues);
 
  // Object specific methods
  vtkGlyphRepresentationProxy(publicAPI, model);
  macro.proxyPropertyMapping(publicAPI, model, {
    edgeVisibility: { modelKey: 'property', property: 'edgeVisibility' },
  });
}
 
// ----------------------------------------------------------------------------
 
export const newInstance = macro.newInstance(
  extend,
  'vtkGlyphRepresentationProxy'
);
 
// ----------------------------------------------------------------------------
 
export default { newInstance, extend };