Skip to content

Commit

Permalink
feat(itkWasmExports): provide getMemoryInputArrayStore
Browse files Browse the repository at this point in the history
Enable advanced usage of the input arrays in C++.
  • Loading branch information
thewtex committed Oct 27, 2023
1 parent 57a831b commit 19713e3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions include/itkWasmExports.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,17 @@ namespace itk
namespace wasm
{

// dataset index, array index
using InputArrayStoreKeyType = std::pair<uint32_t, uint32_t>;
using InputArrayStoreValueType = std::vector<uint8_t>;
using InputArrayStoreType = std::map<InputArrayStoreKeyType, InputArrayStoreValueType>;

// Function for the Pipeline Input's and Output's to set / get from the memory store

WebAssemblyInterface_EXPORT const std::string & getMemoryStoreInputJSON(uint32_t memoryIndex, uint32_t index);

WebAssemblyInterface_EXPORT const InputArrayStoreType & getMemoryInputArrayStore();

WebAssemblyInterface_EXPORT void setMemoryStoreOutputDataObject(uint32_t memoryIndex, uint32_t index, const WasmDataObject * dataObject);

WebAssemblyInterface_EXPORT void setMemoryStoreOutputArray(uint32_t memoryIndex, uint32_t index, uint32_t subIndex, size_t address, size_t size);
Expand Down
10 changes: 6 additions & 4 deletions src/itkWasmExports.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ namespace itk
namespace wasm
{

// dataset index, array index
using InputArrayStoreKeyType = std::pair<uint32_t, uint32_t>;
using InputArrayStoreType = std::map<InputArrayStoreKeyType, std::vector<char>>;
static InputArrayStoreType inputArrayStore;

// index
Expand All @@ -43,6 +40,11 @@ const std::string & getMemoryStoreInputJSON(uint32_t memoryIndex, uint32_t index
return inputJSONStore[index];
}

const InputArrayStoreType & getMemoryInputArrayStore()
{
return inputArrayStore;
}

using OutputWasmDataObjectStoreType = std::map<uint32_t, WasmDataObject::ConstPointer>;
static OutputWasmDataObjectStoreType outputWasmDataObjectStore;

Expand Down Expand Up @@ -75,7 +77,7 @@ size_t itk_wasm_input_array_alloc(uint32_t memoryIndex, uint32_t index, uint32_t
const auto key = std::make_pair(index, subIndex);
if (inputArrayStore.count(key))
{
inputArrayStore[key] = std::vector<char>(size);
inputArrayStore[key] = InputArrayStoreValueType(size);
}
else
{
Expand Down

0 comments on commit 19713e3

Please sign in to comment.