Skip to content

Commit b9ab3c6

Browse files
author
Alexis Girault
committed
Add logs to profile example
1 parent dd03b20 commit b9ab3c6

File tree

1 file changed

+45
-21
lines changed

1 file changed

+45
-21
lines changed

examples/Dicom/src/index.js

+45-21
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,67 @@ import curry from 'curry'
44
import setupDicomForm from './dicomForm'
55
import parseDicomFiles from './parseDicomFiles'
66

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+
}
913

14+
const outputFileInformation = curry(async function outputFileInformation (outputTextArea, event) {
1015
// Get files
1116
const dataTransfer = event.dataTransfer
1217
const files = event.target.files || dataTransfer.files
1318

1419
// Parse DICOM metadata
20+
outputTextArea.textContent = "-- Parsing + organising all files using javascript... "
21+
let start = window.performance.now()
1522
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`
1627

17-
// Select DICOM serie
18-
outputTextArea.textContent = "Please select serie..."
28+
// Select DICOM series
1929
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()
2133
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'
2640

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()
2944
const files = Object.values(serie.images).map((image) => image.file)
3045
const { image, webWorker } = await readImageDICOMFileSeries(null, files)
3146
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)
4065
}
41-
return value
4266
}
43-
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
67+
outputTextArea.textContent += ' they match ✓'
4468
})
4569
})
4670

0 commit comments

Comments
 (0)