@@ -4,43 +4,67 @@ import curry from 'curry'
4
4
import setupDicomForm from './dicomForm'
5
5
import parseDicomFiles from './parseDicomFiles'
6
6
7
- const outputFileInformation = curry ( async function outputFileInformation ( outputTextArea , event ) {
8
- outputTextArea . textContent = "Parsing..."
7
+ function replacer ( key , value ) {
8
+ if ( ! ! value && value . byteLength !== undefined ) {
9
+ return String ( value . slice ( 0 , 6 ) ) + '...'
10
+ }
11
+ return value
12
+ }
9
13
14
+ const outputFileInformation = curry ( async function outputFileInformation ( outputTextArea , event ) {
10
15
// Get files
11
16
const dataTransfer = event . dataTransfer
12
17
const files = event . target . files || dataTransfer . files
13
18
14
19
// Parse DICOM metadata
20
+ outputTextArea . textContent = "-- Parsing + organising all files using javascript... "
21
+ let start = window . performance . now ( )
15
22
const { patients, failures } = await parseDicomFiles ( files , true )
23
+ let end = window . performance . now ( )
24
+ let time = end - start
25
+ console . log ( `-- Javascript parsing + organising: ${ time } ` )
26
+ outputTextArea . textContent += `${ time } \n`
16
27
17
- // Select DICOM serie
18
- outputTextArea . textContent = "Please select serie..."
28
+ // Select DICOM series
19
29
setupDicomForm ( patients , async ( serie ) => {
20
- console . time ( 'customRead:' )
30
+ // Read image data with javascript code
31
+ outputTextArea . textContent += `-- Loading image data using javascript... `
32
+ start = window . performance . now ( )
21
33
const image1 = serie . getImageData ( )
22
- console . log ( image1 )
23
- console . warn ( image1 . data . length )
24
- console . timeEnd ( 'customRead:' )
25
- outputTextArea . textContent = "Loading..."
34
+ end = window . performance . now ( )
35
+ time = end - start
36
+ console . log ( `-- Loading image data using javascript: ${ time } ` )
37
+ outputTextArea . textContent += `${ time } \n`
38
+ outputTextArea . textContent += JSON . stringify ( image1 , replacer , 4 )
39
+ outputTextArea . textContent += '\n'
26
40
27
- // Read DICOM serie
28
- console . time ( 'itkRead:' )
41
+ // Read image data with itk
42
+ outputTextArea . textContent += `-- Parsing selected series files + loading image data using itk... `
43
+ start = window . performance . now ( )
29
44
const files = Object . values ( serie . images ) . map ( ( image ) => image . file )
30
45
const { image, webWorker } = await readImageDICOMFileSeries ( null , files )
31
46
webWorker . terminate ( )
32
- console . log ( image )
33
- console . warn ( image . data . length )
34
- console . timeEnd ( 'itkRead:' )
35
-
36
- // Display
37
- function replacer ( key , value ) {
38
- if ( ! ! value && value . byteLength !== undefined ) {
39
- return String ( value . slice ( 0 , 6 ) ) + '...'
47
+ end = window . performance . now ( )
48
+ console . log ( `-- Parsing selected series files + loading image data using itk: ${ time } ` )
49
+ outputTextArea . textContent += `${ time } \n`
50
+ outputTextArea . textContent += JSON . stringify ( image , replacer , 4 )
51
+ outputTextArea . textContent += '\n'
52
+
53
+ // Compare
54
+ outputTextArea . textContent += "-- Comparing pixel data..."
55
+ if ( image1 . data . length !== image . data . length ) {
56
+ let msg = 'Pixel data size differ 𐄂'
57
+ outputTextArea . textContent += ` ${ msg } \n`
58
+ throw Error ( msg )
59
+ }
60
+ for ( let i = 0 ; i < image . data . length ; i ++ ) {
61
+ if ( image1 . data [ i ] !== image . data [ i ] ) {
62
+ let msg = `Element ${ i } differs 𐄂`
63
+ outputTextArea . textContent += ` ${ msg } \n`
64
+ throw Error ( msg )
40
65
}
41
- return value
42
66
}
43
- outputTextArea . textContent = JSON . stringify ( image , replacer , 4 )
67
+ outputTextArea . textContent += ' they match ✓'
44
68
} )
45
69
} )
46
70
0 commit comments