@@ -38,6 +38,34 @@ function vtkConcentricCylinderSource(publicAPI, model) {
38
38
publicAPI . setRadius = ( index , radius ) => { model . radius [ index ] = radius ; publicAPI . modified ( ) ; } ;
39
39
publicAPI . setCellField = ( index , field ) => { model . cellFields [ index ] = field ; publicAPI . modified ( ) ; } ;
40
40
41
+
42
+ publicAPI . removeMask = ( ) => {
43
+ model . mask = null ;
44
+ publicAPI . modified ( ) ;
45
+ } ;
46
+
47
+ publicAPI . setMaskLayer = ( index , hidden ) => {
48
+ let changeDetected = false ;
49
+
50
+ if ( ! model . mask && hidden ) {
51
+ changeDetected = true ;
52
+ model . mask = [ ] ;
53
+ }
54
+
55
+ if ( model . mask ) {
56
+ if ( ! model . mask [ index ] !== ! hidden ) {
57
+ changeDetected = true ;
58
+ }
59
+ model . mask [ index ] = hidden ;
60
+ }
61
+
62
+ if ( changeDetected ) {
63
+ publicAPI . modified ( ) ;
64
+ }
65
+ } ;
66
+
67
+ publicAPI . getMaskLayer = index => ( ( index === undefined ) ? model . mask : model . mask [ index ] ) ;
68
+
41
69
function requestData ( inData , outData ) {
42
70
if ( model . deleted || ! model . radius . length ) {
43
71
return ;
@@ -52,8 +80,66 @@ function vtkConcentricCylinderSource(publicAPI, model) {
52
80
const angle = 2 * Math . PI / model . resolution ;
53
81
const zRef = model . height / 2.0 ;
54
82
const numberOfPoints = model . resolution * nbLayers * 2 ;
55
- const cellArraySize = ( 2 * ( model . resolution + 1 ) ) + ( 5 * model . resolution ) + ( ( nbLayers - 1 ) * model . resolution * 20 ) ;
56
- const nbCells = 2 + model . resolution + ( ( nbLayers - 1 ) * 4 * model . resolution ) ;
83
+
84
+ // Compute cell count
85
+ let cellArraySize = 0 ;
86
+ let nbCells = 0 ;
87
+
88
+ if ( ! model . skipInnerFaces && ! model . mask ) {
89
+ // We keep everything
90
+ cellArraySize = ( 2 * ( model . resolution + 1 ) ) + ( 5 * model . resolution ) + ( ( nbLayers - 1 ) * model . resolution * 20 ) ;
91
+ nbCells = 2 + model . resolution + ( ( nbLayers - 1 ) * 4 * model . resolution ) ;
92
+ } else if ( ! model . skipInnerFaces && model . mask ) {
93
+ // We skip some cylinders
94
+ // Handle core
95
+ if ( ! model . mask [ 0 ] ) {
96
+ cellArraySize += ( 2 * ( model . resolution + 1 ) ) + ( 5 * model . resolution ) ;
97
+ nbCells += 2 + model . resolution ;
98
+ }
99
+ // Handle inside cylinders
100
+ for ( let layer = 1 ; layer < nbLayers ; layer ++ ) {
101
+ if ( ! model . mask [ layer ] ) {
102
+ // Add inside cylinder count
103
+ cellArraySize += model . resolution * 20 ;
104
+ nbCells += 4 * model . resolution ;
105
+ }
106
+ }
107
+ } else {
108
+ // We skip cylinders and internal faces
109
+ if ( ! model . skipInnerFaces || ! model . mask || ! model . mask [ 0 ] ) {
110
+ // core handling
111
+ cellArraySize += ( 2 * ( model . resolution + 1 ) ) ;
112
+ nbCells += 2 ;
113
+ if ( model . radius . length === 1 || ! model . skipInnerFaces || ( model . mask && model . mask [ 1 ] ) ) {
114
+ // add side faces
115
+ cellArraySize += 5 * model . resolution ;
116
+ nbCells += model . resolution ;
117
+ }
118
+ }
119
+
120
+ // Handle inside cylinders
121
+ for ( let layer = 1 ; layer < nbLayers ; layer ++ ) {
122
+ if ( ! model . skipInnerFaces || ! model . mask || ! model . mask [ layer ] ) {
123
+ const lastLayer = ( nbLayers - 1 === layer ) ;
124
+
125
+ // Add inside cylinder
126
+ cellArraySize += model . resolution * 10 ;
127
+ nbCells += model . resolution * 2 ; // top + bottom
128
+
129
+ // Do we add innerFaces
130
+ if ( ! model . skipInnerFaces || ( model . mask && model . mask [ layer - 1 ] ) ) {
131
+ cellArraySize += model . resolution * 5 ;
132
+ nbCells += model . resolution ;
133
+ }
134
+
135
+ // Do we add outterFaces
136
+ if ( lastLayer || ! model . skipInnerFaces || ( model . mask && model . mask [ layer + 1 ] ) ) {
137
+ cellArraySize += model . resolution * 5 ;
138
+ nbCells += model . resolution ;
139
+ }
140
+ }
141
+ }
142
+ }
57
143
58
144
// Points
59
145
let pointIdx = 0 ;
@@ -90,34 +176,47 @@ function vtkConcentricCylinderSource(publicAPI, model) {
90
176
// Create cells for the core
91
177
let currentField = model . cellFields [ 0 ] ;
92
178
93
- // Core: Top disk
94
- field [ fieldLocation ++ ] = currentField ;
95
- polys [ cellLocation ++ ] = model . resolution ;
96
- for ( let i = 0 ; i < model . resolution ; i ++ ) {
97
- polys [ cellLocation ++ ] = i ;
98
- }
99
-
100
- // Core: Bottom disk
101
- field [ fieldLocation ++ ] = currentField ;
102
- polys [ cellLocation ++ ] = model . resolution ;
103
- for ( let i = 0 ; i < model . resolution ; i ++ ) {
104
- polys [ cellLocation ++ ] = ( 2 * model . resolution ) - i - 1 ;
105
- }
106
-
107
- // Core: sides
108
- for ( let i = 0 ; i < model . resolution ; i ++ ) {
109
- polys [ cellLocation ++ ] = 4 ;
110
- polys [ cellLocation ++ ] = ( i + 1 ) % model . resolution ;
111
- polys [ cellLocation ++ ] = i ;
112
- polys [ cellLocation ++ ] = i + model . resolution ;
113
- polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution ;
179
+ // Core: filtering
180
+ if ( ! model . mask || ! model . mask [ 0 ] ) {
181
+ // Core: Top disk
182
+ field [ fieldLocation ++ ] = currentField ;
183
+ polys [ cellLocation ++ ] = model . resolution ;
184
+ for ( let i = 0 ; i < model . resolution ; i ++ ) {
185
+ polys [ cellLocation ++ ] = i ;
186
+ }
114
187
188
+ // Core: Bottom disk
115
189
field [ fieldLocation ++ ] = currentField ;
190
+ polys [ cellLocation ++ ] = model . resolution ;
191
+ for ( let i = 0 ; i < model . resolution ; i ++ ) {
192
+ polys [ cellLocation ++ ] = ( 2 * model . resolution ) - i - 1 ;
193
+ }
194
+
195
+ // Core: sides
196
+ if ( ! model . skipInnerFaces || ( model . mask && model . mask [ 1 ] ) || nbLayers === 1 ) {
197
+ for ( let i = 0 ; i < model . resolution ; i ++ ) {
198
+ polys [ cellLocation ++ ] = 4 ;
199
+ polys [ cellLocation ++ ] = ( i + 1 ) % model . resolution ;
200
+ polys [ cellLocation ++ ] = i ;
201
+ polys [ cellLocation ++ ] = i + model . resolution ;
202
+ polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution ;
203
+
204
+ field [ fieldLocation ++ ] = currentField ;
205
+ }
206
+ }
116
207
}
117
208
118
209
// Create cells for the layers
119
210
for ( let layer = 1 ; layer < nbLayers ; layer ++ ) {
211
+ // Skip layer if masked
212
+ if ( model . mask && model . mask [ layer ] ) {
213
+ /* eslint-disable no-continue */
214
+ continue ;
215
+ /* eslint-enable no-continue */
216
+ }
217
+
120
218
const offset = model . resolution * 2 * ( layer - 1 ) ;
219
+ const lastLayer = ( nbLayers - 1 === layer ) ;
121
220
currentField = model . cellFields [ layer ] ;
122
221
123
222
// Create top
@@ -143,25 +242,29 @@ function vtkConcentricCylinderSource(publicAPI, model) {
143
242
}
144
243
145
244
// Create inner
146
- for ( let i = 0 ; i < model . resolution ; i ++ ) {
147
- polys [ cellLocation ++ ] = 4 ;
148
- polys [ cellLocation ++ ] = i + offset ;
149
- polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + offset ;
150
- polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution + offset ;
151
- polys [ cellLocation ++ ] = i + model . resolution + offset ;
152
-
153
- field [ fieldLocation ++ ] = currentField ;
245
+ if ( ! model . skipInnerFaces || ( model . mask && model . mask [ layer - 1 ] ) ) {
246
+ for ( let i = 0 ; i < model . resolution ; i ++ ) {
247
+ polys [ cellLocation ++ ] = 4 ;
248
+ polys [ cellLocation ++ ] = i + offset ;
249
+ polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + offset ;
250
+ polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution + offset ;
251
+ polys [ cellLocation ++ ] = i + model . resolution + offset ;
252
+
253
+ field [ fieldLocation ++ ] = currentField ;
254
+ }
154
255
}
155
256
156
257
// Create outter
157
- for ( let i = 0 ; i < model . resolution ; i ++ ) {
158
- polys [ cellLocation ++ ] = 4 ;
159
- polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + offset + ( 2 * model . resolution ) ;
160
- polys [ cellLocation ++ ] = i + offset + ( 2 * model . resolution ) ;
161
- polys [ cellLocation ++ ] = i + model . resolution + offset + ( 2 * model . resolution ) ;
162
- polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution + offset + ( 2 * model . resolution ) ;
163
-
164
- field [ fieldLocation ++ ] = currentField ;
258
+ if ( ! model . skipInnerFaces || lastLayer || ( model . mask && ( model . mask [ layer + 1 ] || lastLayer ) ) ) {
259
+ for ( let i = 0 ; i < model . resolution ; i ++ ) {
260
+ polys [ cellLocation ++ ] = 4 ;
261
+ polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + offset + ( 2 * model . resolution ) ;
262
+ polys [ cellLocation ++ ] = i + offset + ( 2 * model . resolution ) ;
263
+ polys [ cellLocation ++ ] = i + model . resolution + offset + ( 2 * model . resolution ) ;
264
+ polys [ cellLocation ++ ] = ( ( i + 1 ) % model . resolution ) + model . resolution + offset + ( 2 * model . resolution ) ;
265
+
266
+ field [ fieldLocation ++ ] = currentField ;
267
+ }
165
268
}
166
269
}
167
270
@@ -196,6 +299,8 @@ const DEFAULT_VALUES = {
196
299
resolution : 6 ,
197
300
center : [ 0 , 0 , 0 ] ,
198
301
direction : [ 0.0 , 0.0 , 1.0 ] ,
302
+ skipInnerFaces : true ,
303
+ mask : null , // If present, array to know if a layer should be skipped(=true)
199
304
pointType : 'Float32Array' ,
200
305
} ;
201
306
@@ -209,6 +314,7 @@ export function extend(publicAPI, model, initialValues = {}) {
209
314
macro . setGet ( publicAPI , model , [
210
315
'height' ,
211
316
'resolution' ,
317
+ 'skipInnerFaces' ,
212
318
] ) ;
213
319
macro . setGetArray ( publicAPI , model , [
214
320
'center' ,
0 commit comments