Skip to content

Commit 462f263

Browse files
committed
test(mesh-io): add obj-point-set-test
And support infrastructure.
1 parent 5fdb454 commit 462f263

File tree

11 files changed

+411
-69
lines changed

11 files changed

+411
-69
lines changed

include/itkWasmMeshIO.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <fstream>
2424

2525
#include "itkMeshJSON.h"
26+
#include "itkPointSetJSON.h"
2627
#include "cbor.h"
2728

2829
namespace itk
@@ -72,6 +73,9 @@ class WebAssemblyInterface_EXPORT WasmMeshIO: public MeshIOBase
7273
/** Set the JSON representation of the image information. */
7374
void SetJSON(const MeshJSON & json);
7475

76+
/** Set the JSON representation of the image information. */
77+
void SetJSON(const PointSetJSON & json);
78+
7579
/*-------- This part of the interfaces deals with writing data ----- */
7680

7781
/** Writes the data to disk from the memory buffer provided. Make sure
@@ -93,6 +97,9 @@ class WebAssemblyInterface_EXPORT WasmMeshIO: public MeshIOBase
9397
#if !defined(ITK_WRAPPING_PARSER)
9498
/** Get the JSON representation of the mesh information. */
9599
auto GetJSON() -> MeshJSON;
100+
101+
/** Get the JSON representation of the point set information. */
102+
auto GetPointSetJSON() -> PointSetJSON;
96103
#endif
97104

98105
protected:
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
const defaultImageTag = '20240825-1a89d0e6'
1+
const defaultImageTag = '20240918-572a017e'
22
export default defaultImageTag

packages/core/typescript/itk-wasm/src/pipeline/internal/run-pipeline-emscripten.ts

Lines changed: 73 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import TextFile from '../../interface-types/text-file.js'
77
import BinaryFile from '../../interface-types/binary-file.js'
88
import Image from '../../interface-types/image.js'
99
import Mesh from '../../interface-types/mesh.js'
10+
import PointSet from '../../interface-types/point-set.js'
1011
import PolyData from '../../interface-types/poly-data.js'
12+
// import Transform from '../../interface-types/transform.js'
1113
import FloatTypes from '../../interface-types/float-types.js'
1214
import IntTypes from '../../interface-types/int-types.js'
1315

@@ -20,7 +22,7 @@ const haveSharedArrayBuffer = typeof globalThis.SharedArrayBuffer === 'function'
2022
const encoder = new TextEncoder()
2123
const decoder = new TextDecoder('utf-8')
2224

23-
function readFileSharedArray (
25+
function readFileSharedArray(
2426
emscriptenModule: PipelineEmscriptenModule,
2527
path: string
2628
): Uint8Array {
@@ -40,7 +42,7 @@ function readFileSharedArray (
4042
return array
4143
}
4244

43-
function memoryUint8SharedArray (
45+
function memoryUint8SharedArray(
4446
emscriptenModule: PipelineEmscriptenModule,
4547
byteOffset: number,
4648
length: number
@@ -61,7 +63,7 @@ function memoryUint8SharedArray (
6163
return array
6264
}
6365

64-
function setPipelineModuleInputArray (
66+
function setPipelineModuleInputArray(
6567
emscriptenModule: PipelineEmscriptenModule,
6668
dataArray: TypedArray | null,
6769
inputIndex: number,
@@ -80,7 +82,7 @@ function setPipelineModuleInputArray (
8082
return dataPtr
8183
}
8284

83-
function setPipelineModuleInputJSON (
85+
function setPipelineModuleInputJSON(
8486
emscriptenModule: PipelineEmscriptenModule,
8587
dataObject: object,
8688
inputIndex: number
@@ -96,13 +98,13 @@ function setPipelineModuleInputJSON (
9698
emscriptenModule.stringToUTF8(dataJSON, jsonPtr, length)
9799
}
98100

99-
function getPipelineModuleOutputArray (
101+
function getPipelineModuleOutputArray(
100102
emscriptenModule: PipelineEmscriptenModule,
101103
outputIndex: number,
102104
subIndex: number,
103105
componentType:
104-
| (typeof IntTypes)[keyof typeof IntTypes]
105-
| (typeof FloatTypes)[keyof typeof FloatTypes]
106+
| (typeof IntTypes)[keyof typeof IntTypes]
107+
| (typeof FloatTypes)[keyof typeof FloatTypes]
106108
): TypedArray | Float32Array | Uint32Array | null {
107109
const dataPtr = emscriptenModule.ccall(
108110
'itk_wasm_output_array_address',
@@ -121,7 +123,7 @@ function getPipelineModuleOutputArray (
121123
return data
122124
}
123125

124-
function getPipelineModuleOutputJSON (
126+
function getPipelineModuleOutputJSON(
125127
emscriptenModule: PipelineEmscriptenModule,
126128
outputIndex: number
127129
): object {
@@ -136,7 +138,7 @@ function getPipelineModuleOutputJSON (
136138
return dataObject
137139
}
138140

139-
function runPipelineEmscripten (
141+
function runPipelineEmscripten(
140142
pipelineModule: PipelineEmscriptenModule,
141143
args: string[],
142144
outputs: PipelineOutput[] | null,
@@ -281,6 +283,33 @@ function runPipelineEmscripten (
281283
setPipelineModuleInputJSON(pipelineModule, meshJSON, index)
282284
break
283285
}
286+
case InterfaceTypes.PointSet: {
287+
const pointSet = input.data as PointSet
288+
const pointsPtr = setPipelineModuleInputArray(
289+
pipelineModule,
290+
pointSet.points,
291+
index,
292+
0
293+
)
294+
const pointDataPtr = setPipelineModuleInputArray(
295+
pipelineModule,
296+
pointSet.pointData,
297+
index,
298+
1
299+
)
300+
const pointSetJSON = {
301+
pointSetType: pointSet.pointSetType,
302+
name: pointSet.name,
303+
304+
numberOfPoints: pointSet.numberOfPoints,
305+
points: `data:application/vnd.itk.address,0:${pointsPtr}`,
306+
307+
numberOfPointPixels: pointSet.numberOfPointPixels,
308+
pointData: `data:application/vnd.itk.address,0:${pointDataPtr}`
309+
}
310+
setPipelineModuleInputJSON(pipelineModule, pointSetJSON, index)
311+
break
312+
}
284313
case InterfaceTypes.PolyData: {
285314
const polyData = input.data as PolyData
286315
const pointsPtr = setPipelineModuleInputArray(
@@ -555,6 +584,41 @@ function runPipelineEmscripten (
555584
outputData = mesh
556585
break
557586
}
587+
case InterfaceTypes.PointSet: {
588+
const pointSet = getPipelineModuleOutputJSON(
589+
pipelineModule,
590+
index
591+
) as PointSet
592+
console.log(pointSet)
593+
if (pointSet.numberOfPoints > 0) {
594+
pointSet.points = getPipelineModuleOutputArray(
595+
pipelineModule,
596+
index,
597+
0,
598+
pointSet.pointSetType.pointComponentType
599+
)
600+
} else {
601+
pointSet.points = bufferToTypedArray(
602+
pointSet.pointSetType.pointComponentType,
603+
new ArrayBuffer(0)
604+
)
605+
}
606+
if (pointSet.numberOfPointPixels > 0) {
607+
pointSet.pointData = getPipelineModuleOutputArray(
608+
pipelineModule,
609+
index,
610+
1,
611+
pointSet.pointSetType.pointPixelComponentType
612+
)
613+
} else {
614+
pointSet.pointData = bufferToTypedArray(
615+
pointSet.pointSetType.pointPixelComponentType,
616+
new ArrayBuffer(0)
617+
)
618+
}
619+
outputData = pointSet
620+
break
621+
}
558622
case InterfaceTypes.PolyData: {
559623
const polyData = getPipelineModuleOutputJSON(
560624
pipelineModule,

packages/mesh-io/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ foreach(io_module ${WebAssemblyInterface_MeshIOModules} WebAssemblyInterface)
9595
list(APPEND extra_srcs itkWasmZstdMeshIO.cxx)
9696
endif()
9797

98-
add_executable(${read_binary} read-mesh.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
98+
add_executable(${read_binary} read-mesh.cxx itkWasmPointSetIOBase.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
9999
target_link_libraries(${read_binary} PUBLIC ${ITK_LIBRARIES})
100100
target_compile_definitions(${read_binary} PUBLIC -DMESH_IO_CLASS=${meshio_id_${meshio}} -DMESH_IO_KEBAB_NAME=${ioname})
101-
add_executable(${write_binary} write-mesh.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
101+
add_executable(${write_binary} write-mesh.cxx itkWasmPointSetIOBase.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
102102
target_link_libraries(${write_binary} PUBLIC ${ITK_LIBRARIES})
103103
target_compile_definitions(${write_binary} PUBLIC -DMESH_IO_CLASS=${meshio_id_${meshio}} -DMESH_IO_KEBAB_NAME=${ioname})
104104
if (EMSCRIPTEN)
@@ -197,10 +197,10 @@ foreach(io_module ${WebAssemblyInterface_PointSetIOModules} WebAssemblyInterface
197197
list(APPEND extra_srcs itkWasmZstdMeshIO.cxx)
198198
endif()
199199

200-
add_executable(${read_binary} read-point-set.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
200+
add_executable(${read_binary} read-point-set.cxx itkWasmPointSetIOBase.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
201201
target_link_libraries(${read_binary} PUBLIC ${ITK_LIBRARIES})
202202
target_compile_definitions(${read_binary} PUBLIC -DMESH_IO_CLASS=${pointsetio_id_${pointsetio}} -DPOINT_SET_IO_KEBAB_NAME=${ioname})
203-
add_executable(${write_binary} write-point-set.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
203+
add_executable(${write_binary} write-point-set.cxx itkWasmPointSetIOBase.cxx itkWasmMeshIOBase.cxx ${extra_srcs})
204204
target_link_libraries(${write_binary} PUBLIC ${ITK_LIBRARIES})
205205
target_compile_definitions(${write_binary} PUBLIC -DMESH_IO_CLASS=${pointsetio_id_${pointsetio}} -DPOINT_SET_IO_KEBAB_NAME=${ioname})
206206
if (EMSCRIPTEN)

packages/mesh-io/itkWasmMeshIOBase.cxx

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,6 @@ WasmMeshIOBase::PrintSelf(std::ostream & os, Indent indent) const
138138
{
139139
Superclass::PrintSelf(os, indent);
140140

141-
os << indent << "PointsContainer";
142-
if (this->m_PointsContainer->size())
143-
{
144-
this->m_PointsContainer->Print(os, indent);
145-
}
146-
else
147-
{
148-
os << ": (empty)" << std::endl;
149-
}
150141
os << indent << "CellsContainer";
151142
if (this->m_CellsContainer->size())
152143
{
@@ -157,15 +148,6 @@ WasmMeshIOBase::PrintSelf(std::ostream & os, Indent indent) const
157148
os << ": (empty)" << std::endl;
158149
}
159150
os << indent << "CellDataContainer";
160-
if (this->m_PointDataContainer->size())
161-
{
162-
this->m_PointDataContainer->Print(os, indent);
163-
}
164-
else
165-
{
166-
os << ": (empty)" << std::endl;
167-
}
168-
os << indent << "PointDataContainer";
169151
if (this->m_CellDataContainer->size())
170152
{
171153
this->m_CellDataContainer->Print(os, indent);

packages/mesh-io/itkWasmMeshIOBase.h

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define itkWasmMeshIOBase_h
2020
#include "WebAssemblyInterfaceExport.h"
2121

22-
#include "itkWasmDataObject.h"
22+
#include "itkWasmPointSetIOBase.h"
2323
#include "itkMeshIOBase.h"
2424
#include "itkVectorContainer.h"
2525

@@ -30,48 +30,36 @@ namespace itk
3030
* \brief JSON representation for an itk::MeshIOBase
3131
*
3232
* JSON representation for an itk::MeshIOBase for interfacing across programming languages and runtimes.
33-
*
33+
*
3434
* Points, Cells, PointData, CellData binary array buffer's are stored as strings with memory addresses or paths on disks or a virtual filesystem.
35-
*
35+
*
3636
* Arrays:
37-
*
37+
*
3838
* - 0: Points
3939
* - 1: Cells
4040
* - 2: PointData
4141
* - 3: CellData
42-
*
42+
*
4343
* \ingroup WebAssemblyInterface
4444
*/
45-
class WebAssemblyInterface_EXPORT WasmMeshIOBase : public WasmDataObject
45+
class WebAssemblyInterface_EXPORT WasmMeshIOBase : public WasmPointSetIOBase
4646
{
4747
public:
4848
ITK_DISALLOW_COPY_AND_MOVE(WasmMeshIOBase);
4949

5050
/** Standard class type aliases. */
5151
using Self = WasmMeshIOBase;
52-
using Superclass = WasmDataObject;
52+
using Superclass = WasmPointSetIOBase;
5353
using Pointer = SmartPointer<Self>;
5454
using ConstPointer = SmartPointer<const Self>;
5555

5656
itkNewMacro(Self);
5757
/** Run-time type information (and related methods). */
58-
itkTypeMacro(WasmMeshIOBase, WasmDataObject);
58+
itkTypeMacro(WasmMeshIOBase, WasmPointSetIOBase);
5959

60-
using DataContainerType = VectorContainer<SizeValueType, char>;
60+
using DataContainerType = Superclass::DataContainerType;
6161

6262
void SetMeshIO(MeshIOBase * imageIO, bool readMesh = true);
63-
const MeshIOBase * GetMeshIO() const {
64-
return m_MeshIOBase.GetPointer();
65-
}
66-
67-
const DataContainerType * GetPointsContainer() const
68-
{
69-
return this->m_PointsContainer.GetPointer();
70-
}
71-
DataContainerType * GetPointsContainer()
72-
{
73-
return this->m_PointsContainer.GetPointer();
74-
}
7563

7664
const DataContainerType * GetCellsContainer() const
7765
{
@@ -82,15 +70,6 @@ class WebAssemblyInterface_EXPORT WasmMeshIOBase : public WasmDataObject
8270
return this->m_CellsContainer.GetPointer();
8371
}
8472

85-
const DataContainerType * GetPointDataContainer() const
86-
{
87-
return this->m_PointDataContainer.GetPointer();
88-
}
89-
DataContainerType * GetPointDataContainer()
90-
{
91-
return this->m_PointDataContainer.GetPointer();
92-
}
93-
9473
const DataContainerType * GetCellDataContainer() const
9574
{
9675
return this->m_CellDataContainer.GetPointer();
@@ -107,12 +86,8 @@ class WebAssemblyInterface_EXPORT WasmMeshIOBase : public WasmDataObject
10786
void
10887
PrintSelf(std::ostream & os, Indent indent) const override;
10988

110-
DataContainerType::Pointer m_PointsContainer;
11189
DataContainerType::Pointer m_CellsContainer;
112-
DataContainerType::Pointer m_PointDataContainer;
11390
DataContainerType::Pointer m_CellDataContainer;
114-
115-
MeshIOBase::ConstPointer m_MeshIOBase;
11691
};
11792

11893
} // namespace itk

0 commit comments

Comments
 (0)