@@ -4,6 +4,7 @@ import testUtils from 'vtk.js/Sources/Testing/testUtils';
4
4
import 'vtk.js/Sources/Rendering/Misc/RenderingAPIs' ;
5
5
import vtkRenderWindow from 'vtk.js/Sources/Rendering/Core/RenderWindow' ;
6
6
import vtkRenderer from 'vtk.js/Sources/Rendering/Core/Renderer' ;
7
+ import vtkPolydata from 'vtk.js/Sources/Common/DataModel/PolyData' ;
7
8
import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor' ;
8
9
import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
9
10
import vtkPlaneSource from 'vtk.js/Sources/Filters/Sources/PlaneSource' ;
@@ -64,6 +65,25 @@ test.onlyIfWebGL('Test HardwareSelector Points', (tapeContext) => {
64
65
65
66
renderer . addActor ( actor3 ) ;
66
67
68
+ // Square polyline upper left --------------------------------
69
+ // Triangle polyline lower right -----------------------------
70
+ const mapper4 = gc . registerResource ( vtkMapper . newInstance ( ) ) ;
71
+ const polygon = gc . registerResource ( vtkPolydata . newInstance ( ) ) ;
72
+ const squarePoints = [ - 0.25 , 1.25 , 0 , 0 , 1.25 , 0 , 0 , 1 , 0 , - 0.25 , 1 , 0 ] ;
73
+ const trianglePoints = [ 1 , 0 , 0 , 1 , - 0.25 , 0 , 1.25 , - 0.125 , 0 ] ;
74
+ polygon
75
+ . getPoints ( )
76
+ . setData ( Float32Array . from ( [ ...squarePoints , ...trianglePoints ] ) , 3 ) ;
77
+ polygon
78
+ . getLines ( )
79
+ . setData ( Uint16Array . from ( [ 5 , 0 , 1 , 2 , 3 , 0 , 4 , 4 , 5 , 6 , 4 ] ) ) ;
80
+ mapper4 . setInputData ( polygon ) ;
81
+
82
+ const actor4 = gc . registerResource ( vtkActor . newInstance ( ) ) ;
83
+ actor4 . setMapper ( mapper4 ) ;
84
+
85
+ renderer . addActor ( actor4 ) ;
86
+
67
87
// now create something to view it, in this case webgl
68
88
const glwindow = gc . registerResource ( renderWindow . newAPISpecificView ( ) ) ;
69
89
glwindow . setContainer ( renderWindowContainer ) ;
@@ -78,43 +98,68 @@ test.onlyIfWebGL('Test HardwareSelector Points', (tapeContext) => {
78
98
const promises = [ ] ;
79
99
80
100
// Test picking points
101
+ // On a point of the plane
81
102
promises . push (
82
103
sel . selectAsync ( renderer , 210 , 199 , 211 , 200 ) . then ( ( res ) => {
83
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 3 ) ;
104
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 4 ) ;
84
105
tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 33 ) ;
85
106
} )
86
107
) ;
87
-
108
+ // On a point of the lower sphere
88
109
promises . push (
89
110
sel . selectAsync ( renderer , 145 , 140 , 146 , 141 ) . then ( ( res ) => {
90
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 4 ) ;
111
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 5 ) ;
91
112
tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 0 ) ;
92
113
} )
93
114
) ;
94
-
115
+ // On a point of the upper sphere covered by an edge
95
116
promises . push (
96
117
sel . selectAsync ( renderer , 294 , 264 , 295 , 265 ) . then ( ( res ) => {
97
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 5 ) ;
98
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 0 ) ;
118
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 6 ) ;
119
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 2 ) ;
99
120
} )
100
121
) ;
101
122
102
123
sel . setFieldAssociation ( FieldAssociations . FIELD_ASSOCIATION_CELLS ) ;
103
124
104
125
// Test picking cells
126
+ // In the middle of the plane
105
127
promises . push (
106
128
sel . selectAsync ( renderer , 200 , 200 , 201 , 201 ) . then ( ( res ) => {
107
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 3 ) ;
129
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 4 ) ;
108
130
tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 27 ) ;
109
131
} )
110
132
) ;
111
-
133
+ // On a point of the upper sphere covered by some edges
112
134
promises . push (
113
135
sel . selectAsync ( renderer , 265 , 265 , 266 , 266 ) . then ( ( res ) => {
114
- tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 5 ) ;
136
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 6 ) ;
137
+ const attribID = res [ 0 ] . getProperties ( ) . attributeID ;
138
+ tapeContext . ok ( attribID >= 0 && attribID <= 7 ) ;
139
+ } )
140
+ ) ;
141
+ // On an edge of the upper sphere
142
+ promises . push (
143
+ sel . selectAsync ( renderer , 250 , 265 , 250 , 265 ) . then ( ( res ) => {
144
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 6 ) ;
145
+ const attribID = res [ 0 ] . getProperties ( ) . attributeID ;
146
+ tapeContext . ok ( attribID === 3 || attribID === 4 ) ;
147
+ } )
148
+ ) ;
149
+ // On a edge of the polyline square
150
+ promises . push (
151
+ sel . selectAsync ( renderer , 133 , 278 , 133 , 278 ) . then ( ( res ) => {
152
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 7 ) ;
115
153
tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 0 ) ;
116
154
} )
117
155
) ;
156
+ // On an edge of the polyline triangle
157
+ promises . push (
158
+ sel . selectAsync ( renderer , 265 , 128 , 265 , 128 ) . then ( ( res ) => {
159
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . propID === 7 ) ;
160
+ tapeContext . ok ( res [ 0 ] . getProperties ( ) . attributeID === 1 ) ;
161
+ } )
162
+ ) ;
118
163
Promise . all ( promises ) . then ( ( ) => {
119
164
gc . releaseResources ( ) ;
120
165
} ) ;
0 commit comments