Skip to content

Commit

Permalink
WIP: feat: itk::WasmTransformIO initial addition
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jun 24, 2024
1 parent 2a025c4 commit 1661de4
Show file tree
Hide file tree
Showing 24 changed files with 2,075 additions and 597 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,5 @@ cypress/screenshots/
cypress/videos/

packages/core/typescript/itk-wasm/dist

CMakePresets.json
42 changes: 42 additions & 0 deletions include/itkFloatTypesJSON.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkFloatTypesJSON_h
#define itkFloatTypesJSON_h

#include <vector>

#include "glaze/glaze.hpp"

namespace itk
{
enum class JSONFloatTypesEnum
{
float32,
float64,
};
} // end namespace itk

template <>
struct glz::meta<itk::JSONFloatTypesEnum> {
using enum itk::JSONFloatTypesEnum;
static constexpr auto value = glz::enumerate(float32,
float64
);
};

#endif // itkFloatTypesJSON_h
9 changes: 5 additions & 4 deletions include/itkInputMeshIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "itkPipeline.h"
#include "itkWasmMeshIOBase.h"
#include "itkWasmMeshIO.h"
#include "itkWasmIOCommon.h"

#ifndef ITK_WASM_NO_MEMORY_IO
#include "itkWasmExports.h"
Expand Down Expand Up @@ -87,15 +88,15 @@ bool lexical_cast(const std::string &input, InputMeshIO &inputMeshIO)
const std::string pointsString( pointsJson.GetString() );
const char * pointsPtr = reinterpret_cast< char * >( std::strtoull(pointsString.substr(35).c_str(), nullptr, 10) );
WasmMeshIOBase::DataContainerType * pointsContainer = wasmMeshIOBase->GetPointsContainer();
SizeValueType numberOfBytes = wasmMeshIO->GetNumberOfPoints() * wasmMeshIO->GetPointDimension() * WasmMeshIO::ITKComponentSize( wasmMeshIO->GetPointComponentType() );
SizeValueType numberOfBytes = wasmMeshIO->GetNumberOfPoints() * wasmMeshIO->GetPointDimension() * ITKComponentSize( wasmMeshIO->GetPointComponentType() );
pointsContainer->resize(numberOfBytes);
pointsContainer->assign(pointsPtr, pointsPtr + numberOfBytes);

const rapidjson::Value & cellsJson = document["cells"];
const std::string cellsString( cellsJson.GetString() );
const char * cellsPtr = reinterpret_cast< char * >( std::strtoull(cellsString.substr(35).c_str(), nullptr, 10) );
WasmMeshIOBase::DataContainerType * cellsContainer = wasmMeshIOBase->GetCellsContainer();
numberOfBytes = static_cast< SizeValueType >( wasmMeshIO->GetCellBufferSize() * WasmMeshIO::ITKComponentSize( wasmMeshIO->GetCellComponentType() ));
numberOfBytes = static_cast< SizeValueType >( wasmMeshIO->GetCellBufferSize() * ITKComponentSize( wasmMeshIO->GetCellComponentType() ));
cellsContainer->resize(numberOfBytes);
cellsContainer->assign(cellsPtr, cellsPtr + numberOfBytes);

Expand All @@ -105,7 +106,7 @@ bool lexical_cast(const std::string &input, InputMeshIO &inputMeshIO)
WasmMeshIOBase::DataContainerType * pointDataContainer = wasmMeshIOBase->GetPointDataContainer();
numberOfBytes =
static_cast< SizeValueType >(
wasmMeshIO->GetNumberOfPointPixels() * wasmMeshIO->GetNumberOfPointPixelComponents() * WasmMeshIO::ITKComponentSize( wasmMeshIO->GetPointPixelComponentType() )
wasmMeshIO->GetNumberOfPointPixels() * wasmMeshIO->GetNumberOfPointPixelComponents() * ITKComponentSize( wasmMeshIO->GetPointPixelComponentType() )
);
pointDataContainer->resize(numberOfBytes);
pointDataContainer->assign(pointDataPtr, pointDataPtr + numberOfBytes);
Expand All @@ -116,7 +117,7 @@ bool lexical_cast(const std::string &input, InputMeshIO &inputMeshIO)
WasmMeshIOBase::DataContainerType * cellDataContainer = wasmMeshIOBase->GetCellDataContainer();
numberOfBytes =
static_cast< SizeValueType >(
wasmMeshIO->GetNumberOfPointPixels() * wasmMeshIO->GetNumberOfPointPixelComponents() * WasmMeshIO::ITKComponentSize( wasmMeshIO->GetPointPixelComponentType() )
wasmMeshIO->GetNumberOfPointPixels() * wasmMeshIO->GetNumberOfPointPixelComponents() * ITKComponentSize( wasmMeshIO->GetPointPixelComponentType() )
);
cellDataContainer->resize(numberOfBytes);
cellDataContainer->assign(cellDataPtr, cellDataPtr + numberOfBytes);
Expand Down
Loading

0 comments on commit 1661de4

Please sign in to comment.