Skip to content

Commit a3fbbd3

Browse files
committed
feat(IO): Use cbor over zip
1 parent 2254292 commit a3fbbd3

File tree

19 files changed

+1048
-734
lines changed

19 files changed

+1048
-734
lines changed

CMakeLists.txt

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ endif()
2626

2727
include(FetchContent)
2828
set(_itk_build_testing ${BUILD_TESTING})
29+
set(BUILD_TESTING OFF)
2930
set(_itk_build_shared ${BUILD_SHARED_LIBS})
3031

3132
# Uses newer CMake
@@ -42,27 +43,6 @@ FetchContent_Declare(
4243
GIT_TAG ${RapidJSON_GIT_TAG}
4344
)
4445

45-
set(minizip-ng_GIT_REPOSITORY https://github.com/zlib-ng/minizip-ng.git)
46-
# 3.0.3
47-
set(minizip-ng_GIT_TAG 0930f1aebebb3554570a94357464f0a67b387c6d)
48-
option(MZ_COMPAT OFF "Enables compatibility layer")
49-
option(MZ_ZLIB OFF "Enables ZLIB compression")
50-
option(MZ_BZIP2 OFF "Enables BZIP2 compression")
51-
option(MZ_LZMA OFF "Enables LZMA & XZ compression")
52-
option(MZ_ZSTD OFF "Enables ZSTD compression")
53-
option(MZ_PKCRYPT OFF "Enables PKWARE traditional encryption")
54-
option(MZ_WZAES OFF "Enables WinZIP AES encryption")
55-
option(MZ_OPENSSL OFF "Enables OpenSSL encryption")
56-
option(MZ_LIBBSD OFF "Build with libbsd for crypto random")
57-
option(MZ_SIGNING OFF "Enables zip signing support")
58-
option(MZ_ICONV OFF "Enables iconv string encoding conversion library")
59-
set(MZ_PROJECT_SUFFIX "-itk" CACHE STRING "Minizip name suffix")
60-
FetchContent_Declare(
61-
minizip-ng
62-
GIT_REPOSITORY ${minizip-ng_GIT_REPOSITORY}
63-
GIT_TAG ${minizip-ng_GIT_TAG}
64-
)
65-
6646
set(CLI11_GIT_REPOSITORY "https://github.com/CLIUtils/CLI11")
6747
set(CLI11_GIT_REPOSITORY "https://github.com/thewtex/CLI11")
6848
# v2.1.2 + WASI
@@ -83,12 +63,26 @@ FetchContent_Declare(
8363
GIT_TAG ${rang_GIT_TAG}
8464
)
8565

66+
set(libcbor_GIT_REPOSITORY "https://github.com/PJK/libcbor")
67+
set(libcbor_GIT_REPOSITORY "https://github.com/thewtex/libcbor")
68+
set(libcbor_GIT_TAG "de9762657d99ccb4d72c78e49819ea5d2a7a413d")
69+
FetchContent_Declare(
70+
libcbor
71+
GIT_REPOSITORY ${libcbor_GIT_REPOSITORY}
72+
GIT_TAG ${libcbor_GIT_TAG}
73+
)
74+
set(WITH_TESTS OFF CACHE BOOL "Build libcbor tests")
75+
set(WITH_EXAMPLES OFF CACHE BOOL "Build libcbor examples")
76+
8677

87-
FetchContent_MakeAvailable(rapidjson_lib minizip-ng cli11 rang)
78+
list(APPEND CMAKE_MODULE_PATH ${libcbor_SOURCE_DIR}/CMakeModules)
79+
FetchContent_MakeAvailable(rapidjson_lib cli11 rang libcbor)
8880
set(RapidJSON_INCLUDE_DIR "${rapidjson_lib_SOURCE_DIR}/include")
89-
set(minizip-ng_INCLUDE_DIR "${minizip-ng_SOURCE_DIR}")
9081
set(cli11_INCLUDE_DIR "${cli11_SOURCE_DIR}/include")
9182
set(rang_INCLUDE_DIR "${rang_SOURCE_DIR}/include")
83+
set(libcbor_INCLUDE_DIR "${libcbor_SOURCE_DIR}/src")
84+
set(libcbor_EXPORT_DIR "${libcbor_BINARY_DIR}/src")
85+
set(libcbor_CONFIGURATION_DIR "${libcbor_BINARY_DIR}/")
9286

9387
set(BUILD_TESTING ${_itk_build_testing})
9488
set(BUILD_SHARED_LIBS ${_itk_build_shared})
@@ -98,11 +92,13 @@ find_path(RapidJSON_INCLUDE_DIR
9892
)
9993
set(WebAssemblyInterface_INCLUDE_DIRS
10094
${RapidJSON_INCLUDE_DIR}
101-
${minizip-ng_INCLUDE_DIR}
10295
${cli11_INCLUDE_DIR}
10396
${rang_INCLUDE_DIR}
97+
${libcbor_INCLUDE_DIR}
98+
${libcbor_EXPORT_DIR}
99+
${libcbor_CONFIGURATION_DIR}
104100
)
105-
list(APPEND WebAssemblyInterface_LIBRARIES minizip-itk)
101+
list(APPEND WebAssemblyInterface_LIBRARIES cbor)
106102

107103
get_filename_component(_module_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
108104
set(CMAKE_MODULE_PATH "${_module_dir}/CMake/" ${CMAKE_MODULE_PATH})
@@ -115,6 +111,6 @@ if(NOT ITK_SOURCE_DIR)
115111
else()
116112
itk_module_impl()
117113
endif()
118-
itk_module_target_label(minizip-itk)
119-
itk_module_target_export(minizip-itk)
120-
itk_module_target_install(minizip-itk)
114+
itk_module_target_label(cbor)
115+
itk_module_target_export(cbor)
116+
itk_module_target_install(cbor)

doc/content/docs/file_formats.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ title: ITK WASM File Formats
33

44
While IO modules are available to work with a number of [scientific image](./image_formats.html) and [mesh](./mesh_formats.html) file formats, itk-wasm execution pipeline WebAssembly modules only support the ITK WASM File Formats by default. This ensures that size of the WebAssembly pipeline binary is minimal.
55

6-
The itk-wasm file formats provide performant mapping to the [interface types](./interface_types.html) in a simple JSON + binary array buffer format. The formats can be output in a directory or bundled in a single `.zip` file.
6+
The itk-wasm file formats provide performant mapping to the [interface types](./interface_types.html) in a simple JSON + binary array buffer format. The formats can be output in a directory or bundled in a single `.cbor` file.
77

88
<dl>
9-
<dt><b>ITK WASM Image (.iwi,.iwi.zip)</b><dt><dd>Serialization of an [Image](../Image.html).</dd>
10-
<dt><b>ITK WASM Mesh (.iwm,.iwm.zip)</b><dt><dd>Serialization of a [Mesh](../Mesh.html), or [PolyData](../PolyData.html).</dd>
11-
</dl>
9+
<dt><b>ITK WASM Image (.iwi,.iwi.cbor)</b><dt><dd>Serialization of an [Image](../Image.html).</dd>
10+
<dt><b>ITK WASM Mesh (.iwm,.iwm.cbor)</b><dt><dd>Serialization of a [Mesh](../Mesh.html), or [PolyData](../PolyData.html).</dd>
11+
</dl>

doc/content/docs/itk_js_to_itk_wasm_migration_guide.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,12 @@ Addresses an important issue in image orientation support.
121121

122122
## Image file format
123123

124-
The JSON file format is replaced by a WASM file format with a different layout. A directory ending in `.iwi` or a `.iwi.zip` file is supported for images and a directory ending in `.iwm` and `.iwm.zip` is supported for meshes.
124+
The JSON file format is replaced by a WASM file format with a different layout. A directory ending in `.iwi` or a `.iwi.cbor` file is supported for images and a directory ending in `.iwm` and `.iwm.cbor` is supported for meshes.
125125

126126
## Node Sync functions
127127

128128
Node `*Sync` functions have been removed -- use the equivalent async versions instead.
129129

130130
## VTK support
131131

132-
The VTK Docker images, VTK PolyData IO, `readPolyDataFile`, `readPolyDataBlob`, `readPolyDataArrayBuffer`, based on VTK were removed.
132+
The VTK Docker images, VTK PolyData IO, `readPolyDataFile`, `readPolyDataBlob`, `readPolyDataArrayBuffer`, based on VTK were removed.

include/itkWASMImageIO.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ class WebAssemblyInterface_EXPORT WASMImageIO: public StreamingImageIOBase
9494
return 0;
9595
}
9696

97+
void ReadCBOR(void * buffer = nullptr);
98+
void WriteCBOR(const void * buffer = nullptr);
99+
97100
private:
98101
ITK_DISALLOW_COPY_AND_ASSIGN(WASMImageIO);
99102
};

include/itkWASMMeshIO.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@
1919
#define itkWASMMeshIO_h
2020
#include "WebAssemblyInterfaceExport.h"
2121

22-
2322
#include "itkMeshIOBase.h"
2423
#include <fstream>
2524

25+
#include "cbor.h"
26+
2627
namespace itk
2728
{
2829
/** \class WASMMeshIO
@@ -127,8 +128,19 @@ class WebAssemblyInterface_EXPORT WASMMeshIO: public MeshIOBase
127128
/** Convenient method to read a buffer as binary. Return true on success. */
128129
bool ReadBufferAsBinary(std::istream & os, void *buffer, SizeValueType numberOfBytesToBeRead);
129130

131+
bool FileNameIsCBOR();
132+
void ReadCBORBuffer(const char * dataName, void * buffer, SizeValueType numberOfBytesToBeRead);
133+
void WriteCBORBuffer(const char * dataName, void * buffer, SizeValueType numberOfBytesToWrite, IOComponentEnum ioComponent);
134+
135+
/** Reads in the mesh information and populates the related buffers. */
136+
void ReadCBOR();
137+
/** Writes the buffers into the CBOR item and the buffer out to disk. */
138+
void WriteCBOR();
139+
130140
private:
131141
ITK_DISALLOW_COPY_AND_ASSIGN(WASMMeshIO);
142+
143+
cbor_item_t * m_CBORRoot{ nullptr };
132144
};
133145
} // end namespace itk
134146

src/docker/itk-wasm-base/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
ARG BASE_IMAGE=dockcross/web-wasm
2-
FROM $BASE_IMAGE:20220127-ce9c068
2+
FROM $BASE_IMAGE:20220222-c383c8e
33
ARG BASE_IMAGE
44

55
LABEL maintainer="Matt McCormick <[email protected]>"

src/docker/itk-wasm/Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ RUN cd / && \
2424
cmake \
2525
-G Ninja \
2626
-DITK_DIR=/ITK-build \
27-
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} \
27+
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE_DOCKCROSS} \
28+
-DBUILD_TESTING:BOOL=OFF \
29+
-DSANITIZE:BOOL=OFF \
2830
-DITK_WASM_NO_INTERFACE_LINK:BOOL=1 \
2931
-DCMAKE_BUILD_TYPE:STRING=$CMAKE_BUILD_TYPE \
3032
../ITKWebAssemblyInterface && \

src/io/getFileExtension.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ function getFileExtension (filePath: string): string {
33
if (extension.toLowerCase() === 'gz') {
44
const index = filePath.slice(0, -3).lastIndexOf('.')
55
extension = filePath.slice((index - 1 >>> 0) + 2)
6+
} else if (extension.toLowerCase() === 'cbor') {
7+
const index = filePath.slice(0, -5).lastIndexOf('.')
8+
extension = filePath.slice((index - 1 >>> 0) + 2)
69
} else if (extension.toLowerCase() === 'zip') {
710
const index = filePath.slice(0, -4).lastIndexOf('.')
811
extension = filePath.slice((index - 1 >>> 0) + 2)

src/io/internal/extensionToImageIO.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const extensionToIO = new Map([
1616
['JPEG', 'itkJPEGImageIO'],
1717

1818
['iwi', 'itkWASMImageIO'],
19-
['iwi.zip', 'itkWASMImageIO'],
19+
['iwi.cbor', 'itkWASMImageIO'],
2020

2121
['lsm', 'itkLSMImageIO'],
2222

0 commit comments

Comments
 (0)