Skip to content

Commit a679a18

Browse files
committed
Merge branch 'wasm-mesh-io'
2 parents 3d61d18 + f293f90 commit a679a18

11 files changed

+605
-185
lines changed

include/itkImageToJSONFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ ImageToJSONFilter<TImage>
180180

181181
const auto direction = reinterpret_cast< size_t >( image->GetDirection().GetVnlMatrix().begin() );
182182
std::ostringstream directionStream;
183-
directionStream << "address:";
183+
directionStream << "data:application/vnd.itk.address,";
184184
directionStream << direction;
185185
rapidjson::Value directionString;
186186
directionString.SetString( directionStream.str().c_str(), allocator );
@@ -197,7 +197,7 @@ ImageToJSONFilter<TImage>
197197

198198
const auto data = reinterpret_cast< size_t >( image->GetBufferPointer() );
199199
std::ostringstream dataStream;
200-
dataStream << "address:";
200+
dataStream << "data:application/vnd.itk.address,";
201201
dataStream << data;
202202
rapidjson::Value dataString;
203203
dataString.SetString( dataStream.str().c_str(), allocator );

include/itkJSONFromMesh.h

Lines changed: 0 additions & 153 deletions
This file was deleted.

include/itkJSONToImageFilter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ namespace itk
2727
*\class JSONToImageFilter
2828
* \brief Convert an ImageJSON to an Image object.
2929
*
30+
* TImage must match the type stored in the JSON representation or an exception will be shown.
31+
*
3032
* \ingroup WebAssemblyInterface
3133
*/
3234
template <typename TImage>

include/itkJSONToImageFilter.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ JSONToImageFilter<TImage>
195195
using DirectionType = typename ImageType::DirectionType;
196196
const rapidjson::Value & directionJson = document["direction"];
197197
const std::string directionString( directionJson.GetString() );
198-
const double * directionPtr = reinterpret_cast< double * >( std::atol(directionString.substr(8).c_str()) );
198+
const double * directionPtr = reinterpret_cast< double * >( std::atol(directionString.substr(33).c_str()) );
199199
using VnlMatrixType = typename DirectionType::InternalMatrixType;
200200
const VnlMatrixType vnlMatrix(directionPtr);
201201
const DirectionType direction(vnlMatrix);
@@ -219,7 +219,7 @@ JSONToImageFilter<TImage>
219219

220220
const rapidjson::Value & dataJson = document["data"];
221221
const std::string dataString( dataJson.GetString() );
222-
PixelType * dataPtr = reinterpret_cast< PixelType * >( std::atol(dataString.substr(8).c_str()) );
222+
PixelType * dataPtr = reinterpret_cast< PixelType * >( std::atol(dataString.substr(33).c_str()) );
223223
const bool letImageContainerManageMemory = false;
224224
filter->SetImportPointer( dataPtr, totalSize, letImageContainerManageMemory );
225225

include/itkJSONToMeshFilter.h

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*=========================================================================
2+
*
3+
* Copyright NumFOCUS
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0.txt
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*=========================================================================*/
18+
#ifndef itkJSONToMeshFilter_h
19+
#define itkJSONToMeshFilter_h
20+
21+
#include "itkProcessObject.h"
22+
#include "itkMeshJSON.h"
23+
24+
namespace itk
25+
{
26+
/**
27+
*\class JSONToMeshFilter
28+
* \brief Convert an MeshJSON to an Mesh object.
29+
*
30+
* TMesh must match the type stored in the JSON representation or an exception will be shown.
31+
*
32+
* \ingroup WebAssemblyInterface
33+
*/
34+
template <typename TMesh>
35+
class ITK_TEMPLATE_EXPORT JSONToMeshFilter : public ProcessObject
36+
{
37+
public:
38+
ITK_DISALLOW_COPY_AND_MOVE(JSONToMeshFilter);
39+
40+
/** Standard class type aliases. */
41+
using Self = JSONToMeshFilter;
42+
using Superclass = ProcessObject;
43+
using Pointer = SmartPointer<Self>;
44+
using ConstPointer = SmartPointer<const Self>;
45+
46+
/** Method for creation through the object factory. */
47+
itkNewMacro(Self);
48+
49+
/** Run-time type information (and related methods). */
50+
itkTypeMacro(JSONToMeshFilter, ProcessObject);
51+
52+
using DataObjectIdentifierType = Superclass::DataObjectIdentifierType;
53+
using DataObjectPointerArraySizeType = Superclass::DataObjectPointerArraySizeType;
54+
55+
using MeshType = TMesh;
56+
using MeshJSONType = MeshJSON<MeshType>;
57+
58+
/** Set/Get the path input of this process object. */
59+
using Superclass::SetInput;
60+
virtual void
61+
SetInput(const MeshJSONType * mesh);
62+
63+
virtual void
64+
SetInput(unsigned int, const MeshJSONType * mesh);
65+
66+
const MeshJSONType *
67+
GetInput();
68+
69+
const MeshJSONType *
70+
GetInput(unsigned int idx);
71+
72+
MeshType *
73+
GetOutput();
74+
const MeshType *
75+
GetOutput() const;
76+
77+
MeshType *
78+
GetOutput(unsigned int idx);
79+
80+
protected:
81+
JSONToMeshFilter();
82+
~JSONToMeshFilter() override = default;
83+
84+
ProcessObject::DataObjectPointer
85+
MakeOutput(ProcessObject::DataObjectPointerArraySizeType idx) override;
86+
ProcessObject::DataObjectPointer
87+
MakeOutput(const ProcessObject::DataObjectIdentifierType &) override;
88+
89+
void
90+
GenerateOutputInformation() override
91+
{} // do nothing
92+
void
93+
GenerateData() override;
94+
95+
void
96+
PrintSelf(std::ostream & os, Indent indent) const override;
97+
};
98+
} // end namespace itk
99+
100+
#ifndef ITK_MANUAL_INSTANTIATION
101+
# include "itkJSONToMeshFilter.hxx"
102+
#endif
103+
104+
#endif

0 commit comments

Comments
 (0)