Skip to content

Commit 778fd3e

Browse files
committed
feat(UMDExample): Support loading meshes
1 parent 07f69e2 commit 778fd3e

File tree

6 files changed

+54
-8
lines changed

6 files changed

+54
-8
lines changed

examples/UMD/dist/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<title>itk.js UMD Example</title>
55
<meta charset="UTF-8" />
66
<link rel="stylesheet" href="styles.css">
7-
<script src="https://unpkg.com/itk@9.4.0/umd/itk.js"></script>
7+
<script src="https://unpkg.com/itk@9.5.0/umd/itk.js"></script>
88
</head>
99

1010
<body>
11-
<!-- Image selector -->
11+
<!-- Selector -->
1212
<div>
13-
<label>Select image:</label>
13+
<label>Select image or mesh:</label>
1414
<input name="inputFile" type="file">
1515
</div>
1616

examples/UMD/dist/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ function processFile(event) {
55
var dataTransfer = event.dataTransfer;
66
var files = event.target.files || dataTransfer.files;
77

8-
return itk.readImageFile(null, files[0]).then(function({ image, webWorker }) {
8+
return itk.readFile(null, files[0]).then(function({ image, mesh, webWorker }) {
99
webWorker.terminate();
10+
var imageOrMesh = image || mesh;
1011

1112
function replacer(key, value) {
1213
if (!!value && value.byteLength !== undefined) {
1314
return String(value.slice(0, 6)) + "...";
1415
}
1516
return value;
1617
}
17-
outputTextArea.textContent = JSON.stringify(image, replacer, 4);
18+
outputTextArea.textContent = JSON.stringify(imageOrMesh, replacer, 4);
1819
});
1920
}

examples/UMD/dist/styles.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ textarea {
88
position: absolute;
99
box-sizing: border-box;
1010
width: 100%;
11+
height: 80%;
1112
bottom: 0px;
1213
left: 0px;
1314
top: 50px;

examples/UMD/karma.conf.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = function init (config) {
1717
basePath: '',
1818
frameworks: ['tap'],
1919
files: [
20-
'https://unpkg.com/itk@9.4.0/umd/itk.js',
20+
'https://unpkg.com/itk@9.5.0/umd/itk.js',
2121
'./dist/index.js',
2222
'./test/index.js'
2323
],

examples/UMD/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
"url": "https://github.com/InsightSoftwareConsortium/itk-js/issues"
2323
},
2424
"homepage": "https://github.com/InsightSoftwareConsortium/itk-js#readme",
25-
"dependencies": {},
2625
"devDependencies": {
2726
"axios": "^0.18.0",
2827
"karma": "^2.0.0",

examples/UMD/test/index.js

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'tape'
22
import axios from 'axios'
33

4-
test('Loading an image file and displaying its contents', (t) => {
4+
test('Load an image file and display its contents', (t) => {
55
const expectedOutput = `{
66
"imageType": {
77
"dimension": 2,
@@ -44,6 +44,51 @@ test('Loading an image file and displaying its contents', (t) => {
4444
document.body.appendChild(outputTextArea)
4545
processFile(event)
4646
.then(function () {
47+
outputTextArea.remove(outputTextArea)
48+
t.equal(outputTextArea.textContent, expectedOutput, 'Text area matches expected output')
49+
t.end()
50+
})
51+
})
52+
})
53+
54+
55+
test('Load a mesh file and display its contents', (t) => {
56+
const expectedOutput = `{
57+
"meshType": {
58+
"dimension": 3,
59+
"pointComponentType": "float",
60+
"pointPixelComponentType": null,
61+
"pointPixelType": 1,
62+
"pointPixelComponents": 0,
63+
"cellComponentType": "uint32_t",
64+
"cellPixelComponentType": null,
65+
"cellPixelType": 1,
66+
"cellPixelComponents": 0
67+
},
68+
"name": "Mesh",
69+
"numberOfPoints": 2903,
70+
"points": "3.716360092163086,2.3433899879455566,0,4.126560211181641,0.6420270204544067,0...",
71+
"numberOfPointPixels": 0,
72+
"pointData": null,
73+
"numberOfCells": 3263,
74+
"cells": "4,4,250,251,210,252...",
75+
"numberOfCellPixels": 0,
76+
"cellData": null,
77+
"cellBufferSize": 18856,
78+
"numberofPointPixels": 0,
79+
"numberofCellPixels": 0
80+
}`
81+
const meshURL = 'https://data.kitware.com/api/v1/file/5c72abb18d777f072b610e69/download'
82+
return axios.get(meshURL, { responseType: 'blob' })
83+
.then((response) => {
84+
const testFile = new window.File([response.data], 'cow.vtk')
85+
// mock the event
86+
const event = { target: { files: [testFile] } }
87+
const outputTextArea = document.createElement('textarea')
88+
document.body.appendChild(outputTextArea)
89+
processFile(event)
90+
.then(function () {
91+
outputTextArea.remove()
4792
t.equal(outputTextArea.textContent, expectedOutput, 'Text area matches expected output')
4893
t.end()
4994
})

0 commit comments

Comments
 (0)