11import 'vtk.js/Sources/favicon' ;
22
3- import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow ' ;
3+ import Constants from 'vtk.js/Sources/Filters/General/TubeFilter/Constants ' ;
44import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor' ;
5- // import vtkPointSource from 'vtk.js/Sources/Filters/Sources/PointSource ';
6- // import vtkOutlineFilter from 'vtk.js/Sources/Filters/General/OutlineFilter ';
5+ import vtkDataArray from 'vtk.js/Sources/Common/Core/DataArray ' ;
6+ import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow ' ;
77import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
88import vtkMath from 'vtk.js/Sources/Common/Core/Math' ;
9- import vtkTubeFilter from 'vtk.js/Sources/Filters/General/TubeFilter' ;
109import vtkPoints from 'vtk.js/Sources/Common/Core/Points' ;
1110import vtkPolyData from 'vtk.js/Sources/Common/DataModel/PolyData' ;
12- import { VtkPointPrecision } from 'vtk.js/Sources/Filters/General/Constants ' ;
11+ import vtkTubeFilter from 'vtk.js/Sources/Filters/General/TubeFilter ' ;
1312import { VtkDataTypes } from 'vtk.js/Sources/Common/Core/DataArray/Constants' ;
13+ import { VtkPointPrecision } from 'vtk.js/Sources/Filters/General/Constants' ;
1414
1515import controlPanel from './controlPanel.html' ;
1616
17+ const { VtkVaryRadius } = Constants ;
18+
1719// ----------------------------------------------------------------------------
1820// Standard rendering code setup
1921// ----------------------------------------------------------------------------
@@ -43,8 +45,8 @@ function addRepresentation(name, filter, props = {}) {
4345 global [ `${ name } Mapper` ] = mapper ;
4446}
4547
46- vtkMath . randomSeed ( 1 ) ;
47- const numSegments = 2 ;
48+ vtkMath . randomSeed ( 15222 ) ;
49+ const numSegments = 3 ;
4850
4951function initializePolyData ( dType ) {
5052 let pointType = VtkDataTypes . FLOAT ;
@@ -56,43 +58,45 @@ function initializePolyData(dType) {
5658 const polyData = vtkPolyData . newInstance ( ) ;
5759 const points = vtkPoints . newInstance ( { dataType : pointType } ) ;
5860 points . setNumberOfPoints ( numSegments + 1 ) ;
59- // const pointData = points.getData( );
61+ const pointData = new Float32Array ( 3 * ( numSegments + 1 ) ) ;
6062 const verts = new Uint32Array ( 2 * ( numSegments + 1 ) ) ;
6163 const lines = new Uint32Array ( numSegments + 2 ) ;
6264 lines [ 0 ] = numSegments + 1 ;
65+ const scalarsData = new Float32Array ( numSegments + 1 ) ;
66+ const scalars = vtkDataArray . newInstance (
67+ { name : 'Scalars' , values : scalarsData } ) ;
6368
64- const pointData = [ 0 , 0 , 0 , - 0.13 , - 0.51 , 0 , - 0.41 , - 0.48 , 0 ] ;
65- points . setData ( pointData ) ;
6669 for ( let i = 0 ; i < ( numSegments + 1 ) ; ++ i ) {
67- // for (let j = 0; j < 3; ++j) {
68- // pointData[(3 * i) + j] = Math.random();
69- // }
70+ for ( let j = 0 ; j < 3 ; ++ j ) {
71+ pointData [ ( 3 * i ) + j ] = vtkMath . random ( ) ;
72+ }
73+ scalarsData [ i ] = i * 0.1 ;
7074 verts [ i ] = 1 ;
7175 verts [ i + 1 ] = i ;
7276 lines [ i + 1 ] = i ;
7377 }
7478
79+ points . setData ( pointData ) ;
7580 polyData . setPoints ( points ) ;
76- // polyData.getVerts().setData(verts);
81+ polyData . getVerts ( ) . setData ( verts ) ;
7782 polyData . getLines ( ) . setData ( lines ) ;
83+ polyData . getPointData ( ) . setScalars ( scalars ) ;
7884 return polyData ;
7985}
8086
8187// ----------------------------------------------------------------------------
8288
8389
84- // const pointSource = vtkPointSource.newInstance({ numberOfPoints: 25, radius: 0.25 });
8590const polyData = initializePolyData ( VtkPointPrecision . DOUBLE ) ;
8691const tubeFilter = vtkTubeFilter . newInstance ( ) ;
87- tubeFilter . setCapping ( true ) ;
88- tubeFilter . setNumberOfSides ( 30 ) ;
89- tubeFilter . setRadius ( 0.083 ) ;
90- tubeFilter . setRadiusFactor ( 10 ) ;
92+ tubeFilter . setCapping ( false ) ;
93+ tubeFilter . setNumberOfSides ( 50 ) ;
94+ tubeFilter . setRadius ( 0.1 ) ;
9195
9296tubeFilter . setInputData ( polyData ) ;
97+ tubeFilter . setInputArrayToProcess ( 0 , 'Scalars' , 'PointData' , 'Scalars' ) ;
9398
9499addRepresentation ( 'polyData' , polyData , { } ) ;
95- // addRepresentation('pointSource', pointSource, { pointSize: 5 });
96100addRepresentation ( 'tubeFilter' , tubeFilter , { } ) ;
97101
98102renderer . resetCamera ( ) ;
@@ -104,13 +108,31 @@ renderWindow.render();
104108
105109fullScreenRenderer . addController ( controlPanel ) ;
106110
107- // ['numberOfPoints', 'radius'].forEach((propertyName) => {
108- // document.querySelector(`.${propertyName}`).addEventListener('input', (e) => {
109- // const value = Number(e.target.value);
110- // pointSource.set({ [propertyName]: value });
111- // renderWindow.render();
112- // });
113- // });
111+ [ 'numberOfSides' , 'radius' , 'onRatio' ] . forEach ( ( propertyName ) => {
112+ document . querySelector ( `.${ propertyName } ` ) . addEventListener ( 'input' , ( e ) => {
113+ const value = Number ( e . target . value ) ;
114+ tubeFilter . set ( { [ propertyName ] : value } ) ;
115+ renderWindow . render ( ) ;
116+ } ) ;
117+ } ) ;
118+
119+ document . querySelector ( '.varyRadius' ) . addEventListener ( 'change' , ( e ) => {
120+ const value = e . target . value ;
121+ tubeFilter . set ( { varyRadius : VtkVaryRadius [ value ] } ) ;
122+ renderWindow . render ( ) ;
123+ } ) ;
124+
125+ document . querySelector ( '.capping' ) . addEventListener ( 'change' , ( e ) => {
126+ const capping = ! ! ( e . target . checked ) ;
127+ tubeFilter . set ( { capping } ) ;
128+ renderWindow . render ( ) ;
129+ } ) ;
130+
131+ document . querySelector ( '.tubing' ) . addEventListener ( 'change' , ( e ) => {
132+ const tubing = ! ! ( e . target . checked ) ;
133+ global . tubeFilterActor . setVisibility ( tubing ) ;
134+ renderWindow . render ( ) ;
135+ } ) ;
114136
115137// // ----- Console play ground -----
116138// global.pointSource = pointSource;
0 commit comments