ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSupportInputTransformTypes.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 itkSupportInputTransformTypes_h
19#define itkSupportInputTransformTypes_h
20#include "itkPipeline.h"
24
25#include "itkTransform.h"
26#include "itkTransformIOBase.h"
28#include "WebAssemblyInterfaceExport.h"
29
30#include "itkTransformJSON.h"
31
32namespace itk
33{
34
35WebAssemblyInterface_EXPORT bool
36lexical_cast(const std::string & input, TransformTypeJSON & transformType);
37
38namespace wasm
39{
40
83template <template <typename TTransform> class TPipelineFunctor, typename... TParameterValuesSupported>
85{
86public:
87 template <unsigned int... VDimensions>
88 static int
89 Dimensions(const std::string & inputTransformOptionName, Pipeline & pipeline)
90 {
91 TransformTypeJSON transformType;
92
93 const auto iwpArgc = pipeline.get_argc();
94 const auto iwpArgv = pipeline.get_argv();
95 bool passThrough = false;
96 for (int ii = 0; ii < iwpArgc; ++ii)
97 {
98 const std::string arg(iwpArgv[ii]);
99 if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
100 {
101 passThrough = true;
102 }
103 }
104 if (passThrough)
105 {
106 return IterateDimensions<VDimensions...>(pipeline, transformType, passThrough);
107 }
108
109 auto tempOption = pipeline.add_option(inputTransformOptionName, transformType, "Read Transform type.");
110
111 ITK_WASM_PRE_PARSE(pipeline);
112
113 pipeline.remove_option(tempOption);
114
115 return IterateDimensions<VDimensions...>(pipeline, transformType);
116 }
117
118private:
119 template <unsigned int VDimension, typename TParameterValues, typename... TParameterValuesRest>
120 static int
121 IterateParameterValueTypes(Pipeline & pipeline, const TransformTypeJSON & transformType, bool passThrough = false)
122 {
123 using ParameterValueType = TParameterValues;
124
126 {
128
129 using PipelineType = TPipelineFunctor<TransformType>;
130 return PipelineType()(pipeline);
131 }
132
133 if constexpr (sizeof...(TParameterValuesRest) > 0)
134 {
135 return IterateParameterValueTypes<VDimension, TParameterValuesRest...>(pipeline, transformType);
136 }
137
138 std::ostringstream ostrm;
139 std::string transformTypeString = glz::write_json(transformType).value_or("error");
140 ostrm << "Unsupported transform type: " << transformTypeString << std::endl;
141 CLI::Error err("Runtime error", ostrm.str(), 1);
142 return pipeline.exit(err);
143 }
144
145 template <unsigned int VDimension, unsigned int... VDimensions>
146 static int
147 IterateDimensions(Pipeline & pipeline, const TransformTypeJSON & transformType, bool passThrough = false)
148 {
149 if (passThrough || VDimension == transformType.inputDimension)
150 {
151 return IterateParameterValueTypes<VDimension, TParameterValuesSupported...>(pipeline, transformType);
152 }
153
154 if constexpr (sizeof...(VDimensions) > 0)
155 {
156 return IterateDimensions<VDimensions...>(pipeline, transformType);
157 }
158
159 std::ostringstream ostrm;
160 ostrm << "Unsupported transform dimension: " << transformType.inputDimension;
161 CLI::Error err("Runtime error", ostrm.str(), 1);
162 return pipeline.exit(err);
163 }
164};
165
166} // end namespace wasm
167} // end namespace itk
168
169#endif
Transform points and vectors from an input space to an output space.
int get_argc() const
char ** get_argv() const
auto exit(const CLI::Error &e) -> int
Instantiatiate a Pipeline functor over multiple transform parameter types and dimensions and match to...
static int IterateParameterValueTypes(Pipeline &pipeline, const TransformTypeJSON &transformType, bool passThrough=false)
static int IterateDimensions(Pipeline &pipeline, const TransformTypeJSON &transformType, bool passThrough=false)
static int Dimensions(const std::string &inputTransformOptionName, Pipeline &pipeline)
#define ITK_WASM_PRE_PARSE(pipeline)
Definition itkPipeline.h:72
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
WebAssemblyInterface_EXPORT bool lexical_cast(const std::string &input, ImageTypeJSON &imageType)
Transform type JSON representation data structure.
JSONFloatTypesEnum parametersValueType
static constexpr JSONFloatTypesEnum JSONFloatTypeEnum