1
+ import _ from "lodash" ;
1
2
import {
2
3
calculateTextureSizeAndCountForLayer ,
3
4
computeDataTexturesSetup ,
@@ -25,6 +26,34 @@ const grayscaleElementClass = "uint8";
25
26
const volumeByteCount = 4 ;
26
27
const volumeElementClass = "uint32" ;
27
28
29
+ /*
30
+ * The current rendering logic in WK only allows
31
+ * as many layers as necessary. This is done to avoid
32
+ * that the shaders are compiled for N layers even though
33
+ * N layers will never be rendered at the same time (because
34
+ * only one segmentation layer can be rendered at a time).
35
+ * For that reason, testing the specs has to be done with a
36
+ * sufficiently large amount of layers. To achieve this,
37
+ * the helper function createLayers is used.
38
+ */
39
+
40
+ const createGrayscaleLayer = ( ) => ( {
41
+ byteCount : grayscaleByteCount ,
42
+ elementClass : grayscaleElementClass ,
43
+ category : "color" ,
44
+ } ) ;
45
+ const createVolumeLayer = ( ) => ( {
46
+ byteCount : volumeByteCount ,
47
+ elementClass : volumeElementClass ,
48
+ category : "segmentation" ,
49
+ } ) ;
50
+
51
+ function createLayers ( grayscaleCount : number , volumeCount : number ) {
52
+ const grayscaleLayers = _ . range ( 0 , grayscaleCount ) . map ( ( ) => createGrayscaleLayer ( ) ) ;
53
+ const volumeLayers = _ . range ( 0 , volumeCount ) . map ( ( ) => createVolumeLayer ( ) ) ;
54
+ return grayscaleLayers . concat ( volumeLayers ) ;
55
+ }
56
+
28
57
test ( "calculateTextureSizeAndCountForLayer: grayscale data + minSpecs" , ( t ) => {
29
58
const { textureSize, textureCount } = calculateTextureSizeAndCountForLayer (
30
59
minSpecs ,
@@ -90,24 +119,8 @@ test("calculateTextureSizeAndCountForLayer: color data + betterSpecs", (t) => {
90
119
t . is ( textureSize , midSpecs . supportedTextureSize ) ;
91
120
t . is ( textureCount , 1 ) ;
92
121
} ) ;
93
- const grayscaleLayer1 = {
94
- byteCount : grayscaleByteCount ,
95
- elementClass : grayscaleElementClass ,
96
- } ;
97
- const grayscaleLayer2 = {
98
- byteCount : grayscaleByteCount ,
99
- elementClass : grayscaleElementClass ,
100
- } ;
101
- const grayscaleLayer3 = {
102
- byteCount : grayscaleByteCount ,
103
- elementClass : grayscaleElementClass ,
104
- } ;
105
- const volumeLayer1 = {
106
- byteCount : volumeByteCount ,
107
- elementClass : volumeElementClass ,
108
- } ;
109
122
110
- type Layer = typeof grayscaleLayer1 ;
123
+ type Layer = ReturnType < typeof createGrayscaleLayer > ;
111
124
112
125
const getByteCount = ( layer : Layer ) => layer . byteCount ;
113
126
@@ -123,7 +136,7 @@ function computeDataTexturesSetupCurried(spec: typeof minSpecs, hasSegmentation:
123
136
return ( layers : Layer [ ] ) =>
124
137
computeDataTexturesSetup (
125
138
spec ,
126
- layers as { elementClass : ElementClass } [ ] ,
139
+ layers as { elementClass : ElementClass ; category : "color" | "segmentation" } [ ] ,
127
140
getByteCount as any ,
128
141
hasSegmentation ,
129
142
DEFAULT_REQUIRED_BUCKET_CAPACITY ,
@@ -137,59 +150,37 @@ test("Basic support (no segmentation): all specs", (t) => {
137
150
[ midSpecs , 15 ] ,
138
151
[ betterSpecs , 31 ] ,
139
152
] ;
153
+ const hundredGrayscaleLayers = createLayers ( 100 , 0 ) ;
140
154
for ( const [ spec , expectedLayerCount ] of specs ) {
141
155
const computeDataTexturesSetupPartial = computeDataTexturesSetupCurried ( spec , false ) ;
142
- testSupportFlags ( t , computeDataTexturesSetupPartial ( [ grayscaleLayer1 ] ) , expectedLayerCount ) ;
143
156
testSupportFlags (
144
157
t ,
145
- computeDataTexturesSetupPartial ( [ grayscaleLayer1 , grayscaleLayer2 ] ) ,
158
+ computeDataTexturesSetupPartial ( hundredGrayscaleLayers ) ,
146
159
expectedLayerCount ,
147
160
) ;
148
161
testSupportFlags (
149
162
t ,
150
- computeDataTexturesSetupPartial ( [ grayscaleLayer1 , grayscaleLayer2 , grayscaleLayer3 ] ) ,
163
+ computeDataTexturesSetupPartial ( hundredGrayscaleLayers ) ,
164
+ expectedLayerCount ,
165
+ ) ;
166
+ testSupportFlags (
167
+ t ,
168
+ computeDataTexturesSetupPartial ( hundredGrayscaleLayers ) ,
151
169
expectedLayerCount ,
152
170
) ;
153
171
}
154
172
} ) ;
155
173
156
174
test ( "Basic support + volume: min specs" , ( t ) => {
157
175
const computeDataTexturesSetupPartial = computeDataTexturesSetupCurried ( minSpecs , true ) ;
158
- testSupportFlags ( t , computeDataTexturesSetupPartial ( [ grayscaleLayer1 , grayscaleLayer2 ] ) , 4 ) ;
159
- testSupportFlags ( t , computeDataTexturesSetupPartial ( [ grayscaleLayer1 , volumeLayer1 ] ) , 1 ) ;
160
- testSupportFlags (
161
- t ,
162
- computeDataTexturesSetupPartial ( [ grayscaleLayer1 , grayscaleLayer2 , volumeLayer1 ] ) ,
163
- 1 ,
164
- ) ;
165
- testSupportFlags (
166
- t ,
167
- computeDataTexturesSetupPartial ( [
168
- grayscaleLayer1 ,
169
- grayscaleLayer2 ,
170
- grayscaleLayer3 ,
171
- volumeLayer1 ,
172
- ] ) ,
173
- 1 ,
174
- ) ;
176
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 10 , 0 ) ) , 4 ) ;
177
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 10 , 1 ) ) , 1 ) ;
178
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 10 , 1 ) ) , 1 ) ;
179
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 10 , 1 ) ) , 1 ) ;
175
180
} ) ;
176
181
177
182
test ( "Basic support + volume: mid specs" , ( t ) => {
178
183
const computeDataTexturesSetupPartial = computeDataTexturesSetupCurried ( midSpecs , true ) ;
179
- testSupportFlags ( t , computeDataTexturesSetupPartial ( [ grayscaleLayer1 , volumeLayer1 ] ) , 12 ) ;
180
- testSupportFlags (
181
- t ,
182
- computeDataTexturesSetupPartial ( [ grayscaleLayer1 , grayscaleLayer2 , volumeLayer1 ] ) ,
183
- 12 ,
184
- ) ;
185
- testSupportFlags (
186
- t ,
187
- computeDataTexturesSetupPartial ( [
188
- grayscaleLayer1 ,
189
- grayscaleLayer2 ,
190
- grayscaleLayer3 ,
191
- volumeLayer1 ,
192
- ] ) ,
193
- 12 ,
194
- ) ;
184
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 20 , 1 ) ) , 12 ) ;
185
+ testSupportFlags ( t , computeDataTexturesSetupPartial ( createLayers ( 5 , 1 ) ) , 6 ) ;
195
186
} ) ;
0 commit comments