Skip to content

Commit 574604a

Browse files
authored
Merge pull request #231 from thewtex/example-mesh
Example mesh
2 parents 07f69e2 + 1fea666 commit 574604a

File tree

14 files changed

+159
-20
lines changed

14 files changed

+159
-20
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
})

examples/UnpkgIO/dist/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
5+
<link rel="stylesheet" href="styles.css">
56
</head>
67
<body>
78
<div>

examples/UnpkgIO/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"dependencies": {
2727
"curry": "^1.2.0",
2828
"expose-loader": "^0.7.5",
29-
"itk": "^9.2.0"
29+
"itk": "^9.5.0"
3030
},
3131
"devDependencies": {
3232
"@babel/core": "^7.2.0",

examples/UnpkgIO/src/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import readImageFile from 'itk/readImageFile'
1+
import readFile from 'itk/readFile'
22
import curry from 'curry'
33

44
const outputFileInformation = curry(function outputFileInformation (outputTextArea, event) {
55
const dataTransfer = event.dataTransfer
66
const files = event.target.files || dataTransfer.files
7-
return readImageFile(null, files[0])
8-
.then(function ({ image, webWorker }) {
7+
return readFile(null, files[0])
8+
.then(function ({ image, mesh, webWorker }) {
99
webWorker.terminate()
10+
const imageOrMesh = image || mesh
11+
1012
function replacer (key, value) {
1113
if (!!value && value.byteLength !== undefined) {
1214
return String(value.slice(0, 6)) + '...'
1315
}
1416
return value
1517
}
16-
outputTextArea.textContent = JSON.stringify(image, replacer, 4)
18+
outputTextArea.textContent = JSON.stringify(imageOrMesh, replacer, 4)
1719
})
1820
})
1921

examples/UnpkgIO/test/index.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import config from './itkConfig'
66
import { outputFileInformation } from '../src/index'
77
console.log(config)
88

9-
test('Loading an image file and displaying its contents', (t) => {
9+
test('Load an image file and display its contents', (t) => {
1010
const expectedOutput = `{
1111
"imageType": {
1212
"dimension": 2,
@@ -49,8 +49,52 @@ test('Loading an image file and displaying its contents', (t) => {
4949
document.body.appendChild(outputTextArea)
5050
outputFileInformation(outputTextArea, event)
5151
.then(function () {
52+
outputTextArea.remove()
5253
t.equal(outputTextArea.textContent, expectedOutput)
5354
t.end()
5455
})
5556
})
5657
})
58+
59+
test('Load a mesh file and display its contents', (t) => {
60+
const expectedOutput = `{
61+
"meshType": {
62+
"dimension": 3,
63+
"pointComponentType": "float",
64+
"pointPixelComponentType": null,
65+
"pointPixelType": 1,
66+
"pointPixelComponents": 0,
67+
"cellComponentType": "uint32_t",
68+
"cellPixelComponentType": null,
69+
"cellPixelType": 1,
70+
"cellPixelComponents": 0
71+
},
72+
"name": "Mesh",
73+
"numberOfPoints": 2903,
74+
"points": "3.716360092163086,2.3433899879455566,0,4.126560211181641,0.6420270204544067,0...",
75+
"numberOfPointPixels": 0,
76+
"pointData": null,
77+
"numberOfCells": 3263,
78+
"cells": "4,4,250,251,210,252...",
79+
"numberOfCellPixels": 0,
80+
"cellData": null,
81+
"cellBufferSize": 18856,
82+
"numberofPointPixels": 0,
83+
"numberofCellPixels": 0
84+
}`
85+
const meshURL = 'https://data.kitware.com/api/v1/file/5c72abb18d777f072b610e69/download'
86+
return axios.get(meshURL, { responseType: 'blob' })
87+
.then((response) => {
88+
const testFile = new window.File([response.data], 'cow.vtk')
89+
// mock the event
90+
const event = { target: { files: [testFile] } }
91+
const outputTextArea = document.createElement('textarea')
92+
document.body.appendChild(outputTextArea)
93+
outputFileInformation(outputTextArea, event)
94+
.then(function () {
95+
outputTextArea.remove()
96+
t.equal(outputTextArea.textContent, expectedOutput, 'Text area matches expected output')
97+
t.end()
98+
})
99+
})
100+
})

0 commit comments

Comments
 (0)