[vtkusers] Subclassing vtk.js objects

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon Aug 6 16:42:21 EDT 2018


This is how I would do it. (BTW, the issue tracker of vtk.js would allow
better formatting)

(function(){  // <==== Change

function vtkMyInteractorStyleImage(publicAPI, model) {
  // Set our className
  model.classHierarchy.push('vtkMyInteractorStyleImage');
}


const DEFAULT_VALUES = {
  windowLevelStartPosition: [0, 0],
  windowLevelCurrentPosition: [0, 0],
  lastSlicePosition: 0,
  windowLevelInitial: [1.0, 0.5],
  currentImageProperty: 0,
  currentImageNumber: -1,
  interactionMode: 'IMAGE2D',
  xViewRightVector: [0, 1, 0],
  xViewUpVector: [0, 0, -1],
  yViewRightVector: [1, 0, 0],
  yViewUpVector: [0, 0, -1],
  zViewRightVector: [1, 0, 0],
  zViewUpVector: [0, 1, 0],
};

//
----------------------------------------------------------------------------

function extend(publicAPI, model, initialValues = {}) {
  Object.assign(model, DEFAULT_VALUES, initialValues);

  // Inheritance
  vtk.Interaction.Style.vtkInteractorStyleImage.extend(publicAPI, model,
initialValues); // <==== Change

  // Create get-set macros
  vtk.macro.setGet(publicAPI, model, ['interactionMode']); // <==== Change

  // For more macro methods, see "Sources/macro.js"

  // Object specific methods
  vtkMyInteractorStyleImage(publicAPI, model);
}


//
----------------------------------------------------------------------------

const newInstance = vtk.macro.newInstance(extend,
'vtkMyInteractorStyleImage'); // <==== Change

//
----------------------------------------------------------------------------

const vtkMyInteractorStyleImage = Object.assign({ newInstance, extend });
// <==== Change

// Expose your class to the outside...
window.vtkMyInteractorStyleImage = vtkMyInteractorStyleImage; // <====
Change

})(); // <==== Change

On Mon, Aug 6, 2018 at 2:29 PM Richard Frank via vtkusers <
vtkusers at public.kitware.com> wrote:

>
>
> I’m trying to subclass a vtk.js object in an script as here:
>
>
>
> https://kitware.github.io/vtk-js/docs/intro_vtk_as_external_script.html
>
>
>
>
>
>
>
> Here’s a codepen example of what I’m trying to do: subclass
> vtkInteractorStyleImage with vtkMyInteractorStyleImage
> as a simple test.
>
> https://codepen.io/RickFrank/pen/jpvqJe
>
>
>
> I can’t seem to do this outside of a npm style project.
>
>
>
> Is this a limitation of VTK.js?
>
>
>
>
>
> Thanks
>
>
>
> Rick Frank
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Search the list archives at: http://markmail.org/search/?q=vtkusers
>
> Follow this link to subscribe/unsubscribe:
> https://public.kitware.com/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/vtkusers/attachments/20180806/1aedfea7/attachment.html>


More information about the vtkusers mailing list