UNPKG

react-vtk-js

Version:

React based declarative vtk.js visualization pipeline

2 lines (1 loc) 2.94 kB
import e from"../node_modules/@babel/runtime/helpers/esm/toConsumableArray.js";import t from"../node_modules/@babel/runtime/helpers/esm/classCallCheck.js";import r from"../node_modules/@babel/runtime/helpers/esm/createClass.js";import n from"../node_modules/@babel/runtime/helpers/esm/inherits.js";import o from"../node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js";import i from"../node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js";import s,{Component as a}from"react";import l from"prop-types";import{ViewContext as u,RepresentationContext as c}from"./View.js";import p from"../node_modules/@kitware/vtk.js/Interaction/UI/VolumeController.js";function m(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=i(e);if(t){var s=i(this).constructor;r=Reflect.construct(n,arguments,s)}else r=n.apply(this,arguments);return o(this,r)}}var f=function(o){n(l,a);var i=m(l);function l(e){var r;t(this,l),(r=i.call(this,e)).subscriptions=[],r.containerRef=s.createRef();var n=e.size,o=e.rescaleColorMap;return r.controller=p.newInstance({size:n,rescaleColorMap:o}),r}return r(l,[{key:"render",value:function(){var e=this;return s.createElement(u.Consumer,null,(function(t){return s.createElement(c.Consumer,null,(function(r){return e.view=t,e.representation=r,s.createElement("div",{ref:e.containerRef})}))}))}},{key:"componentDidMount",value:function(){this.init()}},{key:"componentDidUpdate",value:function(t,r,n){var o;(o=this.controller).setSize.apply(o,e(this.props.size)),this.controller.render()}},{key:"componentWillUnmount",value:function(){for(;this.subscriptions.length;)this.subscriptions.pop().unsubscribe();this.controller.setContainer(null),this.controller.delete(),this.controller=null}},{key:"init",value:function(){var e=this,t=this.containerRef.current,r=this.view,n=r.renderWindow,o=r.props,i=this.representation.volume,s=o.background[0]+o.background[1]+o.background[2]<1.5;if(i&&i.getMapper()&&i.getMapper().getInputData()){var a=i.getMapper().getInputData();this.controller.setContainer(t),this.controller.setupContent(n,i,s),this.controller.render(),this.view.resetCamera(),this.view.renderView(),this.subscriptions.push(a.onModified((function(){return e.onDataChange()}),-1))}else setTimeout((function(){return e.init()}),100)}},{key:"onDataChange",value:function(){var e=this.controller.getWidget();if(this.representation&&this.representation.volume){var t=this.representation.volume.getMapper().getInputData(),r=t.getPointData().getScalars()||t.getPointData().getArrays()[0];e.setDataArray(r.getData())}}}]),l}();f.defaultProps={size:[400,150],rescaleColorMap:!0},f.propTypes={id:l.string,size:l.arrayOf(l.number),rescaleColorMap:l.bool};export{f as default};