Skip to content

Commit 80d13dd

Browse files
committed
test(mesh-filters): add node tests
1 parent a1c7e49 commit 80d13dd

File tree

6 files changed

+112
-34
lines changed

6 files changed

+112
-34
lines changed

packages/mesh-filters/smooth-remesh.cxx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ int repairMesh(itk::wasm::Pipeline &pipeline, const TMesh *inputMesh)
9797

9898
uint64_t numberPoints = static_cast<uint64_t>(std::ceil(numberPointsPercent * 0.01 * geoMesh.vertices.nb()));
9999

100-
std::cout << "Remeshing with " << numberPoints << " points" << std::endl;
101-
102100
if(triangleShapeAdaptation != 0.0)
103101
{
104102
triangleShapeAdaptation *= 0.02;
@@ -169,11 +167,11 @@ int main(int argc, char *argv[])
169167

170168
return itk::wasm::SupportInputMeshTypes<PipelineFunctor,
171169
uint8_t,
172-
// int8_t,
170+
int8_t,
173171
uint16_t,
174-
// int16_t,
175-
// uint32_t,
176-
// int32_t,
172+
int16_t,
173+
uint32_t,
174+
int32_t,
177175
float,
178176
double>::Dimensions<
179177
3U>("input-mesh", pipeline);

packages/mesh-filters/typescript/package.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
},
1616
"scripts": {
1717
"start": "pnpm copyDemoAppAssets && vite",
18-
"test": "echo \"Error: no test specified\" && exit 1",
18+
"test": "pnpm test:node",
19+
"test:node": "ava",
1920
"build": "pnpm build:tsc && pnpm build:browser:workerEmbedded && pnpm build:browser:workerEmbeddedMin && pnpm build:demo",
2021
"build:browser:workerEmbedded": "esbuild --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.js ./src/index-worker-embedded.ts",
2122
"build:browser:workerEmbeddedMin": "esbuild --minify --loader:.worker.js=dataurl --bundle --format=esm --outfile=./dist/bundle/index-worker-embedded.min.js ./src/index-worker-embedded.min.ts",
@@ -36,11 +37,12 @@
3637
"itk-wasm": "1.0.0-b.183"
3738
},
3839
"devDependencies": {
39-
"@itk-wasm/demo-app": "^0.2.0",
40+
"@itk-wasm/compare-meshes": "workspace:*",
41+
"@itk-wasm/demo-app": "workspace:*",
4042
"@itk-wasm/image-io": "^1.3.1",
41-
"@itk-wasm/mesh-io": "^1.4.2",
42-
"@itk-wasm/transform-io": "^0.1.1",
43+
"@itk-wasm/mesh-io": "workspace:*",
4344
"@types/node": "^20.2.5",
45+
"ava": "^6.1.3",
4446
"esbuild": "^0.19.8",
4547
"shx": "^0.3.4",
4648
"typescript": "^5.3.2",
@@ -50,5 +52,11 @@
5052
"repository": {
5153
"type": "git",
5254
"url": "https://github.com/InsightSoftwareConsortium/ITK-Wasm"
55+
},
56+
"ava": {
57+
"files": [
58+
"test/node/**/*.js",
59+
"!test/node/common.js"
60+
]
5361
}
5462
}
Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,23 @@
11
import test from "ava";
22

3-
import {
4-
keepLargestComponentNode,
5-
} from "../../dist/index-node.js";
3+
import { keepLargestComponentNode } from "../../dist/index-node.js";
64

7-
import { readMeshNode } from "@itk-wasm/mesh-io"
8-
import { compareMeshesNode } from "@itk-wasm/compare-meshes"
5+
import { readMeshNode } from "@itk-wasm/mesh-io";
6+
import { compareMeshesNode } from "@itk-wasm/compare-meshes";
97

10-
import { testInputPath, testBaselinePath, testOutputPath } from "./common.js";
8+
import { testInputPath, testBaselinePath } from "./common.js";
119

1210
test("keepLargestComponentNode keeps the largest component", async (t) => {
1311
const inputMeshPath = `${testInputPath}/suzanne.off`;
1412
const inputMesh = await readMeshNode(inputMeshPath);
1513

1614
const { outputMesh } = await keepLargestComponentNode(inputMesh);
1715

18-
const baselineMeshPath = `${testBaselinePath}/suzanne-keep-largest-component.off`;
16+
const baselineMeshPath = `${testBaselinePath}/suzanne-keep-largest-component.iwm.cbor`;
1917
const baselineMesh = await readMeshNode(baselineMeshPath);
2018

21-
const result = await compareMeshesNode(outputMesh, { baselineMeshes: [baselineMesh,] });
22-
console.log(result)
23-
24-
25-
26-
// const data = new Uint8Array([222, 173, 190, 239]);
27-
// const { output: compressedData } = await compressStringifyNode(data, {
28-
// compressionLevel: 8,
29-
// });
30-
// const { output: decompressedData } =
31-
// await parseStringDecompressNode(compressedData);
32-
33-
// t.is(decompressedData[0], 222);
34-
// t.is(decompressedData[1], 173);
35-
// t.is(decompressedData[2], 190);
36-
// t.is(decompressedData[3], 239);
37-
});
19+
const { metrics } = await compareMeshesNode(outputMesh, {
20+
baselineMeshes: [baselineMesh],
21+
});
22+
t.assert(metrics.almostEqual);
23+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import test from "ava";
2+
3+
import { repairNode } from "../../dist/index-node.js";
4+
5+
import { readMeshNode } from "@itk-wasm/mesh-io";
6+
import { compareMeshesNode } from "@itk-wasm/compare-meshes";
7+
8+
import { testInputPath, testBaselinePath } from "./common.js";
9+
10+
test("repair makes the mesh manifold", async (t) => {
11+
const inputMeshPath = `${testInputPath}/suzanne.off`;
12+
const inputMesh = await readMeshNode(inputMeshPath);
13+
14+
const { outputMesh } = await repairNode(inputMesh);
15+
16+
const baselineMeshPath = `${testBaselinePath}/suzanne-repair.iwm.cbor`;
17+
const baselineMesh = await readMeshNode(baselineMeshPath);
18+
19+
const { metrics } = await compareMeshesNode(outputMesh, {
20+
baselineMeshes: [baselineMesh],
21+
});
22+
t.assert(metrics.almostEqual);
23+
});
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import test from "ava";
2+
3+
import { sliceMeshNode } from "../../dist/index-node.js";
4+
5+
import { readMeshNode } from "@itk-wasm/mesh-io";
6+
import { compareMeshesNode } from "@itk-wasm/compare-meshes";
7+
8+
import { testBaselinePath } from "./common.js";
9+
10+
test("sliceMeshNode extracts polylines at planes", async (t) => {
11+
const inputMeshPath = `${testBaselinePath}/suzanne-repair.off`;
12+
const inputMesh = await readMeshNode(inputMeshPath);
13+
14+
const planes = [
15+
{
16+
origin: [0.0, 0.0, 0.0],
17+
normal: [0.0, 0.0, 1.0],
18+
},
19+
{
20+
origin: [0.0, 0.0, 1.0],
21+
normal: [0.0, 0.0, 1.0],
22+
},
23+
{
24+
origin: [0.0, 0.0, 2.0],
25+
normal: [0.0, 0.0, 1.0],
26+
},
27+
];
28+
29+
const { polylines } = await sliceMeshNode(inputMesh, planes);
30+
31+
const baselineMeshPath = `${testBaselinePath}/suzanne-slice.iwm.cbor`;
32+
const baselineMesh = await readMeshNode(baselineMeshPath);
33+
34+
const { metrics } = await compareMeshesNode(polylines, {
35+
baselineMeshes: [baselineMesh],
36+
});
37+
t.assert(metrics.almostEqual);
38+
});
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import test from "ava";
2+
3+
import { smoothRemeshNode } from "../../dist/index-node.js";
4+
5+
import { readMeshNode, writeMeshNode } from "@itk-wasm/mesh-io";
6+
import { compareMeshesNode } from "@itk-wasm/compare-meshes";
7+
8+
import { testBaselinePath } from "./common.js";
9+
10+
test("repair makes the mesh manifold", async (t) => {
11+
const inputMeshPath = `${testBaselinePath}/suzanne-repair.off`;
12+
const inputMesh = await readMeshNode(inputMeshPath);
13+
14+
const { outputMesh } = await smoothRemeshNode(inputMesh);
15+
writeMeshNode(outputMesh, `/tmp/suzanne-smooth-remesh.off`);
16+
writeMeshNode(outputMesh, `/tmp/suzanne-smooth-remesh.iwm.cbor`);
17+
18+
const baselineMeshPath = `${testBaselinePath}/suzanne-smooth-remesh.iwm.cbor`;
19+
const baselineMesh = await readMeshNode(baselineMeshPath);
20+
21+
const { metrics } = await compareMeshesNode(outputMesh, {
22+
baselineMeshes: [baselineMesh],
23+
});
24+
t.assert(metrics.almostEqual);
25+
});

0 commit comments

Comments
 (0)