UNPKG

react-vtk-js

Version:

React based declarative vtk.js visualization pipeline

2 lines (1 loc) 5.47 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 s from"../node_modules/@babel/runtime/helpers/esm/inherits.js";import i from"../node_modules/@babel/runtime/helpers/esm/possibleConstructorReturn.js";import a from"../node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js";import o,{Component as n}from"react";import l from"prop-types";import{ViewContext as c,RepresentationContext as u,DownstreamContext as p}from"./View.js";import d from"../node_modules/@kitware/vtk.js/Rendering/Core/Actor.js";import h from"../node_modules/@kitware/vtk.js/Rendering/Core/Mapper.js";import b from"../node_modules/@kitware/vtk.js/Rendering/Core/ColorTransferFunction/ColorMaps.js";import m from"../node_modules/@kitware/vtk.js/Rendering/Core/ColorTransferFunction.js";import f from"../node_modules/@kitware/vtk.js/Rendering/Core/CubeAxesActor.js";import v from"../node_modules/@kitware/vtk.js/Rendering/Core/ScalarBarActor.js";function y(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,s=a(e);if(t){var o=a(this).constructor;r=Reflect.construct(s,arguments,o)}else r=s.apply(this,arguments);return i(this,r)}}var A=function(i){s(l,n);var a=y(l);function l(e){var r;t(this,l),(r=a.call(this,e)).validData=!1,r.currentVisibility=!0,r.actor=d.newInstance({visibility:!1,representationId:e.id}),r.lookupTable=m.newInstance(),r.mapper=h.newInstance({lookupTable:r.lookupTable,useLookupTableScalarRange:!0}),r.actor.setMapper(r.mapper),r.cubeAxes=f.newInstance({visibility:!1,dataBounds:[-1,1,-1,1,-1,1]}),r.cubeAxes.getActors().forEach((function(e){return(0,e.setVisibility)(!1)})),r.scalarBar=v.newInstance(),r.scalarBar.setScalarsToColors(r.lookupTable),r.scalarBar.setVisibility(!1);return r.subscriptions=[],r.subscriptions.push(r.mapper.onModified((function e(){if(r.mapper.getInputData()){1===r.subscriptions.length&&r.subscriptions.push(r.mapper.getInputData().onModified(e));var t=r.mapper.getInputData().getBounds();t[0]<t[1]&&(r.cubeAxes.setDataBounds(t),r.view&&r.view.renderView())}}))),r}return r(l,[{key:"render",value:function(){var e=this;return o.createElement(c.Consumer,null,(function(t){return e.view||(e.cubeAxes.setCamera(t.renderer.getActiveCamera()),t.renderer.addActor(e.scalarBar),t.renderer.addActor(e.cubeAxes),t.renderer.addActor(e.actor),e.view=t),o.createElement(u.Provider,{value:e},o.createElement(p.Provider,{value:e.mapper},o.createElement("div",{key:e.props.id,id:e.props.id},e.props.children)))}))}},{key:"componentDidMount",value:function(){this.update(this.props)}},{key:"componentDidUpdate",value:function(e,t,r){this.update(this.props,e)}},{key:"componentWillUnmount",value:function(){for(;this.subscriptions.length;)this.subscriptions.pop().unsubscribe();this.view&&this.view.renderer&&(this.view.renderer.removeActor(this.scalarBar),this.view.renderer.removeActor(this.cubeAxes),this.view.renderer.removeActor(this.actor)),this.scalarBar.delete(),this.scalarBar=null,this.cubeAxes.delete(),this.cubeAxes=null,this.actor.delete(),this.actor=null,this.mapper.delete(),this.mapper=null,this.lookupTable.delete(),this.lookupTable=null}},{key:"update",value:function(t,r){var s,i=this,a=t.cubeAxesStyle,o=t.showCubeAxes,n=t.actor,l=t.mapper,c=t.property,u=t.colorMapPreset,p=t.colorDataRange;if(!n||r&&n===r.actor||this.actor.set(n),!l||r&&l===r.mapper||this.mapper.set(l),!c||r&&c===r.property||this.actor.getProperty().set(c),u&&(!r||u!==r.colorMapPreset)){var d,h=b.getPresetByName(u);this.lookupTable.applyColorMap(h),(d=this.lookupTable).setMappingRange.apply(d,e(p)),this.lookupTable.updateRange()}!p||r&&p===r.colorDataRange||((s=this.lookupTable).setMappingRange.apply(s,e(p)),this.lookupTable.updateRange());!a||r&&a===r.cubeAxesStyle||this.cubeAxes.set(a),o!==this.cubeAxes.getVisibility()&&(this.cubeAxes.setVisibility(o&&this.validData),this.cubeAxes.getActors().forEach((function(e){return(0,e.setVisibility)(o&&i.validData)}))),this.scalarBar.setVisibility(t.showScalarBar&&this.validData),this.scalarBar.setAxisLabel(t.scalarBarTitle),this.scalarBar.set(t.scalarBarStyle||{}),n&&void 0!==n.visibility&&(this.currentVisibility=n.visibility,this.actor.setVisibility(this.currentVisibility&&this.validData)),this.dataChanged()}},{key:"dataAvailable",value:function(){var e=this;this.validData||(this.validData=!0,this.actor.setVisibility(this.currentVisibility),this.scalarBar.setVisibility(this.props.showScalarBar),this.cubeAxes.setVisibility(this.props.showCubeAxes),this.cubeAxes.getActors().forEach((function(t){return(0,t.setVisibility)(e.props.showCubeAxes)})),this.dataChanged())}},{key:"dataChanged",value:function(){this.view&&this.view.renderView()}}]),l}();A.defaultProps={colorMapPreset:"erdc_rainbow_bright",colorDataRange:[0,1],showCubeAxes:!1,showScalarBar:!1,scalarBarTitle:""},A.propTypes={id:l.string,actor:l.object,mapper:l.object,property:l.object,colorMapPreset:l.string,colorDataRange:l.arrayOf(l.number),showCubeAxes:l.bool,cubeAxesStyle:l.object,showScalarBar:l.bool,scalarBarTitle:l.string,scalarBarStyle:l.object,children:l.oneOfType([l.arrayOf(l.node),l.node])};export{A as default};