Skip to content

Commit

Permalink
Merge pull request #1183 from thewtex/mesh-metadata
Browse files Browse the repository at this point in the history
feat(Mesh,PolyData): add metadata member in C++
  • Loading branch information
thewtex authored Jul 18, 2024
2 parents c13cf7b + a8fdda0 commit 8924f95
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
3 changes: 2 additions & 1 deletion include/itkImageJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ namespace itk
std::string direction;
std::vector<size_t> size { 0, 0 };

MetadataJSON metadata;
std::string data;

MetadataJSON metadata;
};

template<typename TImage>
Expand Down
6 changes: 6 additions & 0 deletions include/itkMeshJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "itkFloatTypesJSON.h"
#include "itkPixelTypesJSON.h"
#include "itkWasmMesh.h"
#include "itkMetaDataDictionaryJSON.h"

#include "glaze/glaze.hpp"

Expand Down Expand Up @@ -74,6 +75,8 @@ namespace itk

size_t numberOfCellPixels{ 0 };
std::string cellData;

MetadataJSON metadata;
};

template<typename TMesh>
Expand Down Expand Up @@ -164,6 +167,9 @@ auto meshToMeshJSON(const TMesh * mesh, const WasmMesh<TMesh> * wasmMesh, bool i
meshJSON.cellData = "data:application/vnd.itk.path,data/cell-data.raw";
}

auto dictionary = mesh->GetMetaDataDictionary();
metaDataDictionaryToJSON(dictionary, meshJSON.metadata);

return meshJSON;
}
} // end namespace itk
Expand Down
2 changes: 2 additions & 0 deletions include/itkMeshToWasmMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef itkMeshToWasmMeshFilter_hxx
#define itkMeshToWasmMeshFilter_hxx

#include "itkMetaDataDictionaryJSON.h"

#include "glaze/glaze.hpp"

namespace itk
Expand Down
6 changes: 6 additions & 0 deletions include/itkPolyDataJSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "itkFloatTypesJSON.h"
#include "itkPixelTypesJSON.h"
#include "itkWasmPolyData.h"
#include "itkMetaDataDictionaryJSON.h"

#include "glaze/glaze.hpp"

Expand Down Expand Up @@ -79,6 +80,8 @@ namespace itk

size_t numberOfCellPixels { 0 };
std::string cellData;

MetadataJSON metadata;
};

template<typename TPolyData>
Expand Down Expand Up @@ -203,6 +206,9 @@ auto polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDa
cellDataStream << cellDataAddress;
polyDataJSON.cellData = cellDataStream.str();

auto dictionary = polyData->GetMetaDataDictionary();
metaDataDictionaryToJSON(dictionary, polyDataJSON.metadata);

return polyDataJSON;
}
} // end namespace itk
Expand Down
5 changes: 4 additions & 1 deletion include/itkWasmMeshToMeshFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ WasmMeshToMeshFilter<TMesh>
const std::string descriptiveError = glz::format_error(deserializedAttempt, json);
itkExceptionMacro("Failed to deserialize meshJSON: " << descriptiveError);
}
auto meshJSON = deserializedAttempt.value();
const auto meshJSON = deserializedAttempt.value();

const auto dimension = meshJSON.meshType.dimension;
const auto numberOfPointPixels = meshJSON.numberOfPointPixels;
Expand Down Expand Up @@ -482,6 +482,9 @@ WasmMeshToMeshFilter<TMesh>
mesh->GetCellData()->resize(meshJSON.numberOfCellPixels);
mesh->GetCellData()->assign(cellDataPtr, cellDataPtr + meshJSON.numberOfCellPixels);
}

auto dictionary = mesh->GetMetaDataDictionary();
jsonToMetaDataDictionary(meshJSON.metadata, dictionary);
}

template <typename TMesh>
Expand Down
3 changes: 3 additions & 0 deletions include/itkWasmPolyDataToPolyDataFilter.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ WasmPolyDataToPolyDataFilter<TPolyData>
polyData->GetCellData()->resize(numberOfCellPixels * cellPixelComponents);
polyData->GetCellData()->assign(cellDataPtr, cellDataPtr + numberOfCellPixels * cellPixelComponents);
}

auto dictionary = polyData->GetMetaDataDictionary();
jsonToMetaDataDictionary(polyDataJSON.metadata, dictionary);
}

template <typename TPolyData>
Expand Down

0 comments on commit 8924f95

Please sign in to comment.