ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkInputTransform.h
Go to the documentation of this file.
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 * https://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 itkInputTransform_h
19#define itkInputTransform_h
20
21#include "itkPipeline.h"
22
23#ifndef ITK_WASM_NO_MEMORY_IO
24# include "itkWasmExports.h"
25# include "itkWasmTransform.h"
27#endif
28#ifndef ITK_WASM_NO_FILESYSTEM_IO
30#endif
31
32namespace itk
33{
34namespace wasm
35{
36
47template <typename TTransform>
48class ITK_TEMPLATE_EXPORT InputTransform
49{
50public:
51 using TransformType = TTransform;
52
53 void
54 Set(const TransformType * transform)
55 {
56 this->m_Transform = transform;
57 }
58
59 const TransformType *
60 Get() const
61 {
62 return this->m_Transform.GetPointer();
63 }
64
65 InputTransform() = default;
66 ~InputTransform() = default;
67
68protected:
69 typename TTransform::ConstPointer m_Transform;
70};
71
72
73template <typename TTransform>
74bool
75lexical_cast(const std::string & input, InputTransform<TTransform> & inputTransform)
76{
77 if (input.empty())
78 {
79 return false;
80 }
81
83 {
84#ifndef ITK_WASM_NO_MEMORY_IO
85 using WasmTransformToTransformFilterType = WasmTransformToTransformFilter<TTransform>;
86 auto wasmTransformToTransformFilter = WasmTransformToTransformFilterType::New();
87 auto wasmTransform = WasmTransformToTransformFilterType::WasmTransformType::New();
88 const unsigned int index = std::stoi(input);
89 auto json = getMemoryStoreInputJSON(0, index);
90 wasmTransform->SetJSON(json);
91 wasmTransformToTransformFilter->SetInput(wasmTransform);
92 wasmTransformToTransformFilter->Update();
93 inputTransform.Set(wasmTransformToTransformFilter->GetOutput());
94#else
95 return false;
96#endif
97 }
98 else
99 {
100#ifndef ITK_WASM_NO_FILESYSTEM_IO
101 using ParametersValueType = typename TTransform::ParametersValueType;
103 auto reader = ReaderType::New();
104 reader->SetFileName(input);
105 reader->Update();
106 auto transformList = reader->GetTransformList();
107 if (transformList->empty())
108 {
109 return false;
110 }
111 auto transform = dynamic_cast<const TTransform *>(transformList->front().GetPointer());
112 if (!transform)
113 {
114 return false;
115 }
116 inputTransform.Set(transform);
117#else
118 return false;
119#endif
120 }
121 return true;
122}
123
124} // end namespace wasm
125} // end namespace itk
126
127#endif
Convert an WasmTransform to an Transform object.
Input transform for an itk::wasm::Pipeline.
void Set(const TransformType *transform)
TTransform::ConstPointer m_Transform
const TransformType * Get() const
static auto get_use_memory_io()
const WebAssemblyInterface_EXPORT std::string & getMemoryStoreInputJSON(uint32_t memoryIndex, uint32_t index)
bool lexical_cast(const std::string &input, InputImage< TImage > &inputImage)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....