4
4
import 'babel-polyfill' ;
5
5
import 'vtk.js/Sources/favicon' ;
6
6
7
- import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper' ;
8
- import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor' ;
9
- import vtkColorMaps from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps' ;
10
- import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction' ;
11
- import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow' ;
12
- import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
13
- import vtkURLExtract from 'vtk.js/Sources/Common/Core/URLExtract' ;
14
- import vtkXMLPolyDataReader from 'vtk.js/Sources/IO/XML/XMLPolyDataReader' ;
15
- import { ColorMode , ScalarMode } from 'vtk.js/Sources/Rendering/Core/Mapper/Constants' ;
7
+ import HttpDataAccessHelper from 'vtk.js/Sources/IO/Core/DataAccessHelper/HttpDataAccessHelper' ;
8
+ import vtkActor from 'vtk.js/Sources/Rendering/Core/Actor' ;
9
+ import vtkColorMaps from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction/ColorMaps' ;
10
+ import vtkColorTransferFunction from 'vtk.js/Sources/Rendering/Core/ColorTransferFunction' ;
11
+ import vtkFullScreenRenderWindow from 'vtk.js/Sources/Rendering/Misc/FullScreenRenderWindow' ;
12
+ import vtkMapper from 'vtk.js/Sources/Rendering/Core/Mapper' ;
13
+ import vtkURLExtract from 'vtk.js/Sources/Common/Core/URLExtract' ;
14
+ import vtkXMLPolyDataReader from 'vtk.js/Sources/IO/XML/XMLPolyDataReader' ;
15
+ import {
16
+ ColorMode ,
17
+ ScalarMode ,
18
+ } from 'vtk.js/Sources/Rendering/Core/Mapper/Constants' ;
16
19
17
20
import style from './GeometryViewer.mcss' ;
18
21
import icon from '../../../Documentation/content/icon/favicon-96x96.png' ;
@@ -29,12 +32,12 @@ const userParams = vtkURLExtract.extractURLParameters();
29
32
30
33
// Background handling
31
34
if ( userParams . background ) {
32
- background = userParams . background . split ( ',' ) . map ( s => Number ( s ) ) ;
35
+ background = userParams . background . split ( ',' ) . map ( ( s ) => Number ( s ) ) ;
33
36
}
34
37
const selectorClass =
35
- ( background . length === 3 && background . reduce ( ( a , b ) => a + b , 0 ) < 1.5 )
36
- ? style . dark
37
- : style . light ;
38
+ background . length === 3 && background . reduce ( ( a , b ) => a + b , 0 ) < 1.5
39
+ ? style . dark
40
+ : style . light ;
38
41
39
42
// name
40
43
const defaultName = userParams . name || '' ;
@@ -47,12 +50,14 @@ const field = userParams.field || '';
47
50
48
51
// camera
49
52
function updateCamera ( camera ) {
50
- [ 'zoom' , 'pitch' , 'elevation' , 'yaw' , 'azimuth' , 'roll' , 'dolly' ] . forEach ( ( key ) => {
51
- if ( userParams [ key ] ) {
52
- camera [ key ] ( userParams [ key ] ) ;
53
+ [ 'zoom' , 'pitch' , 'elevation' , 'yaw' , 'azimuth' , 'roll' , 'dolly' ] . forEach (
54
+ ( key ) => {
55
+ if ( userParams [ key ] ) {
56
+ camera [ key ] ( userParams [ key ] ) ;
57
+ }
58
+ renderWindow . render ( ) ;
53
59
}
54
- renderWindow . render ( ) ;
55
- } ) ;
60
+ ) ;
56
61
}
57
62
58
63
function preventDefaults ( e ) {
@@ -115,15 +120,31 @@ function createPipeline(fileName, fileContents) {
115
120
// Create UI
116
121
const presetSelector = document . createElement ( 'select' ) ;
117
122
presetSelector . setAttribute ( 'class' , selectorClass ) ;
118
- presetSelector . innerHTML = vtkColorMaps
119
- . rgbPresetNames
120
- . map ( name => `<option value="${ name } " ${ lutName === name ? 'selected="selected"' : '' } >${ name } </option>` )
123
+ presetSelector . innerHTML = vtkColorMaps . rgbPresetNames
124
+ . map (
125
+ ( name ) =>
126
+ `<option value="${ name } " ${
127
+ lutName === name ? 'selected="selected"' : ''
128
+ } >${ name } </option>`
129
+ )
121
130
. join ( '' ) ;
122
131
123
132
const representationSelector = document . createElement ( 'select' ) ;
124
133
representationSelector . setAttribute ( 'class' , selectorClass ) ;
125
- representationSelector . innerHTML = [ 'Hidden' , 'Points' , 'Wireframe' , 'Surface' , 'Surface with Edge' ]
126
- . map ( ( name , idx ) => `<option value="${ idx === 0 ? 0 : 1 } :${ idx < 4 ? idx - 1 : 2 } :${ idx === 4 ? 1 : 0 } ">${ name } </option>` ) . join ( '' ) ;
134
+ representationSelector . innerHTML = [
135
+ 'Hidden' ,
136
+ 'Points' ,
137
+ 'Wireframe' ,
138
+ 'Surface' ,
139
+ 'Surface with Edge' ,
140
+ ]
141
+ . map (
142
+ ( name , idx ) =>
143
+ `<option value="${ idx === 0 ? 0 : 1 } :${ idx < 4 ? idx - 1 : 2 } :${
144
+ idx === 4 ? 1 : 0
145
+ } ">${ name } </option>`
146
+ )
147
+ . join ( '' ) ;
127
148
representationSelector . value = '1:2:0' ;
128
149
129
150
const colorBySelector = document . createElement ( 'select' ) ;
@@ -188,7 +209,11 @@ function createPipeline(fileName, fileContents) {
188
209
// --------------------------------------------------------------------
189
210
190
211
function updateRepresentation ( event ) {
191
- const [ visibility , representation , edgeVisibility ] = event . target . value . split ( ':' ) . map ( Number ) ;
212
+ const [
213
+ visibility ,
214
+ representation ,
215
+ edgeVisibility ,
216
+ ] = event . target . value . split ( ':' ) . map ( Number ) ;
192
217
actor . getProperty ( ) . set ( { representation, edgeVisibility } ) ;
193
218
actor . setVisibility ( ! ! visibility ) ;
194
219
renderWindow . render ( ) ;
@@ -212,25 +237,48 @@ function createPipeline(fileName, fileContents) {
212
237
// --------------------------------------------------------------------
213
238
214
239
const colorByOptions = [ { value : ':' , label : 'Solid color' } ] . concat (
215
- source . getPointData ( ) . getArrays ( ) . map ( a => ( { label : `(p) ${ a . getName ( ) } ` , value : `PointData:${ a . getName ( ) } ` } ) ) ,
216
- source . getCellData ( ) . getArrays ( ) . map ( a => ( { label : `(c) ${ a . getName ( ) } ` , value : `CellData:${ a . getName ( ) } ` } ) ) ) ;
240
+ source
241
+ . getPointData ( )
242
+ . getArrays ( )
243
+ . map ( ( a ) => ( {
244
+ label : `(p) ${ a . getName ( ) } ` ,
245
+ value : `PointData:${ a . getName ( ) } ` ,
246
+ } ) ) ,
247
+ source
248
+ . getCellData ( )
249
+ . getArrays ( )
250
+ . map ( ( a ) => ( {
251
+ label : `(c) ${ a . getName ( ) } ` ,
252
+ value : `CellData:${ a . getName ( ) } ` ,
253
+ } ) )
254
+ ) ;
217
255
colorBySelector . innerHTML = colorByOptions
218
- . map ( ( { label, value } ) => `<option value="${ value } " ${ field === value ? 'selected="selected"' : '' } >${ label } </option>` )
256
+ . map (
257
+ ( { label, value } ) =>
258
+ `<option value="${ value } " ${
259
+ field === value ? 'selected="selected"' : ''
260
+ } >${ label } </option>`
261
+ )
219
262
. join ( '' ) ;
220
263
221
264
function updateColorBy ( event ) {
222
265
const [ location , colorByArrayName ] = event . target . value . split ( ':' ) ;
223
- const interpolateScalarsBeforeMapping = ( location === 'PointData' ) ;
266
+ const interpolateScalarsBeforeMapping = location === 'PointData' ;
224
267
let colorMode = ColorMode . DEFAULT ;
225
268
let scalarMode = ScalarMode . DEFAULT ;
226
- const scalarVisibility = ( location . length > 0 ) ;
269
+ const scalarVisibility = location . length > 0 ;
227
270
if ( scalarVisibility ) {
228
- const activeArray = source [ `get${ location } ` ] ( ) . getArrayByName ( colorByArrayName ) ;
271
+ const activeArray = source [ `get${ location } ` ] ( ) . getArrayByName (
272
+ colorByArrayName
273
+ ) ;
229
274
const newDataRange = activeArray . getRange ( ) ;
230
275
dataRange [ 0 ] = newDataRange [ 0 ] ;
231
276
dataRange [ 1 ] = newDataRange [ 1 ] ;
232
277
colorMode = ColorMode . MAP_SCALARS ;
233
- scalarMode = ( location === 'PointData' ) ? ScalarMode . USE_POINT_FIELD_DATA : ScalarMode . USE_CELL_FIELD_DATA ;
278
+ scalarMode =
279
+ location === 'PointData'
280
+ ? ScalarMode . USE_POINT_FIELD_DATA
281
+ : ScalarMode . USE_CELL_FIELD_DATA ;
234
282
235
283
const numberOfComponents = activeArray . getNumberOfComponents ( ) ;
236
284
if ( numberOfComponents > 1 ) {
@@ -244,7 +292,9 @@ function createPipeline(fileName, fileContents) {
244
292
while ( compOpts . length <= numberOfComponents ) {
245
293
compOpts . push ( `Component ${ compOpts . length } ` ) ;
246
294
}
247
- componentSelector . innerHTML = compOpts . map ( ( t , index ) => `<option value="${ index - 1 } ">${ t } </option>` ) . join ( '' ) ;
295
+ componentSelector . innerHTML = compOpts
296
+ . map ( ( t , index ) => `<option value="${ index - 1 } ">${ t } </option>` )
297
+ . join ( '' ) ;
248
298
} else {
249
299
componentSelector . style . display = 'none' ;
250
300
}
@@ -294,7 +344,14 @@ function createPipeline(fileName, fileContents) {
294
344
renderer . resetCamera ( ) ;
295
345
renderWindow . render ( ) ;
296
346
297
- global . pipeline [ fileName ] = { actor, mapper, source, lookupTable, renderer, renderWindow } ;
347
+ global . pipeline [ fileName ] = {
348
+ actor,
349
+ mapper,
350
+ source,
351
+ lookupTable,
352
+ renderer,
353
+ renderWindow,
354
+ } ;
298
355
}
299
356
300
357
// ----------------------------------------------------------------------------
@@ -326,11 +383,15 @@ export function load(container, options) {
326
383
container . appendChild ( progressContainer ) ;
327
384
328
385
const progressCallback = ( progressEvent ) => {
329
- const percent = Math . floor ( 100 * progressEvent . loaded / progressEvent . total ) ;
386
+ const percent = Math . floor (
387
+ 100 * progressEvent . loaded / progressEvent . total
388
+ ) ;
330
389
progressContainer . innerHTML = `Loading ${ percent } %` ;
331
390
} ;
332
391
333
- HttpDataAccessHelper . fetchBinary ( options . fileURL , { progressCallback } ) . then ( ( binary ) => {
392
+ HttpDataAccessHelper . fetchBinary ( options . fileURL , {
393
+ progressCallback,
394
+ } ) . then ( ( binary ) => {
334
395
container . removeChild ( progressContainer ) ;
335
396
createViewer ( container ) ;
336
397
createPipeline ( defaultName , binary ) ;
@@ -354,7 +415,9 @@ export function initLocalFileLoader(container) {
354
415
}
355
416
356
417
const fileContainer = document . createElement ( 'div' ) ;
357
- fileContainer . innerHTML = `<div class="${ style . bigFileDrop } "/><input type="file" multiple accept=".vtp" style="display: none;"/>` ;
418
+ fileContainer . innerHTML = `<div class="${
419
+ style . bigFileDrop
420
+ } "/><input type="file" multiple accept=".vtp" style="display: none;"/>`;
358
421
myContainer . appendChild ( fileContainer ) ;
359
422
360
423
const fileInput = fileContainer . querySelector ( 'input' ) ;
@@ -371,11 +434,10 @@ export function initLocalFileLoader(container) {
371
434
372
435
fileInput . addEventListener ( 'change' , handleFile ) ;
373
436
fileContainer . addEventListener ( 'drop' , handleFile ) ;
374
- fileContainer . addEventListener ( 'click' , e => fileInput . click ( ) ) ;
437
+ fileContainer . addEventListener ( 'click' , ( e ) => fileInput . click ( ) ) ;
375
438
fileContainer . addEventListener ( 'dragover' , preventDefaults ) ;
376
439
}
377
440
378
-
379
441
// Look at URL an see if we should load a file
380
442
// ?fileURL=https://data.kitware.com/api/v1/item/59cdbb588d777f31ac63de08/download
381
443
if ( userParams . url || userParams . fileURL ) {
0 commit comments