@@ -8,7 +8,13 @@ import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor';
8
8
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
9
9
import vtkPlaneSource from 'vtk.js/Sources/Filters/Sources/PlaneSource' ;
10
10
import vtkSphereSource from 'vtk.js/Sources/Filters/Sources/SphereSource' ;
11
- import { FieldAssociations } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants' ;
11
+ import vtkConeSource from 'vtk.js/Sources/Filters/Sources/ConeSource' ;
12
+ import vtkCalculator from 'vtk.js/Sources/Filters/General/Calculator' ;
13
+ import { AttributeTypes } from 'vtk.js/Sources/Common/DataModel/DataSetAttributes/Constants' ;
14
+ import {
15
+ FieldDataTypes ,
16
+ FieldAssociations ,
17
+ } from 'vtk.js/Sources/Common/DataModel/DataSet/Constants' ;
12
18
13
19
test ( 'Test HardwareSelector' , ( tapeContext ) => {
14
20
const gc = testUtils . createGarbageCollector ( tapeContext ) ;
@@ -60,9 +66,39 @@ test('Test HardwareSelector', (tapeContext) => {
60
66
actor3 . getProperty ( ) . setEdgeVisibility ( true ) ;
61
67
actor3 . getProperty ( ) . setEdgeColor ( 1.0 , 0.5 , 0.5 ) ;
62
68
actor3 . getProperty ( ) . setDiffuseColor ( 0.5 , 1.0 , 0.5 ) ;
69
+ actor3 . getProperty ( ) . setOpacity ( 0.8 ) ;
63
70
actor3 . setPosition ( 1.0 , 1.0 , 1.0 ) ;
64
-
65
71
renderer . addActor ( actor3 ) ;
72
+ const ConeSource = gc . registerResource ( vtkConeSource . newInstance ( ) ) ;
73
+ const filter = vtkCalculator . newInstance ( ) ;
74
+
75
+ filter . setInputConnection ( ConeSource . getOutputPort ( ) ) ;
76
+ filter . setFormula ( {
77
+ getArrays : ( inputDataSets ) => ( {
78
+ input : [ ] ,
79
+ output : [
80
+ {
81
+ location : FieldDataTypes . CELL ,
82
+ name : 'Random' ,
83
+ dataType : 'Float32Array' ,
84
+ attribute : AttributeTypes . SCALARS ,
85
+ } ,
86
+ ] ,
87
+ } ) ,
88
+ evaluate : ( arraysIn , arraysOut ) => {
89
+ const [ scalars ] = arraysOut . map ( ( d ) => d . getData ( ) ) ;
90
+ for ( let i = 0 ; i < scalars . length ; i ++ ) {
91
+ scalars [ i ] = Math . random ( ) ;
92
+ }
93
+ } ,
94
+ } ) ;
95
+ const mapper4 = gc . registerResource ( vtkMapper . newInstance ( ) ) ;
96
+ mapper4 . setInputConnection ( filter . getOutputPort ( ) ) ;
97
+ const actor4 = gc . registerResource ( vtkActor . newInstance ( ) ) ;
98
+ actor4 . setMapper ( mapper4 ) ;
99
+ actor4 . getProperty ( ) . setOpacity ( 0.5 ) ;
100
+ actor4 . setPosition ( 1.0 , 1.0 , 1.25 ) ;
101
+ renderer . addActor ( actor4 ) ;
66
102
67
103
// now create something to view it, in this case webgl
68
104
const glwindow = gc . registerResource ( renderWindow . newAPISpecificView ( ) ) ;
@@ -80,14 +116,15 @@ test('Test HardwareSelector', (tapeContext) => {
80
116
sel . selectAsync ( renderer , 200 , 200 , 300 , 300 ) . then ( ( res ) => {
81
117
// res[1] should be at 1.0, 1.0, 1.5 in world coords
82
118
const allGood =
83
- res . length === 2 &&
84
- res [ 0 ] . getProperties ( ) . prop === actor &&
85
- res [ 1 ] . getProperties ( ) . prop === actor3 &&
86
- Math . abs ( res [ 1 ] . getProperties ( ) . worldPosition [ 0 ] - 1.0 ) < 0.02 &&
87
- Math . abs ( res [ 1 ] . getProperties ( ) . worldPosition [ 1 ] - 1.0 ) < 0.02 &&
88
- Math . abs ( res [ 1 ] . getProperties ( ) . worldPosition [ 2 ] - 1.5 ) < 0.02 ;
89
-
90
- tapeContext . ok ( res . length === 2 , 'Two props selected' ) ;
119
+ res . length === 3 &&
120
+ res [ 0 ] . getProperties ( ) . prop === actor4 &&
121
+ res [ 1 ] . getProperties ( ) . prop === actor &&
122
+ res [ 2 ] . getProperties ( ) . prop === actor3 &&
123
+ Math . abs ( res [ 2 ] . getProperties ( ) . worldPosition [ 0 ] - 1.0 ) < 0.02 &&
124
+ Math . abs ( res [ 2 ] . getProperties ( ) . worldPosition [ 1 ] - 1.0 ) < 0.02 &&
125
+ Math . abs ( res [ 2 ] . getProperties ( ) . worldPosition [ 2 ] - 1.5 ) < 0.02 ;
126
+
127
+ tapeContext . ok ( res . length === 3 , 'Three props selected' ) ;
91
128
tapeContext . ok ( allGood , 'Correct props were selected' ) ;
92
129
} )
93
130
) ;
0 commit comments