ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSupportInputImageTypes.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 itkSupportInputImageTypes_h
19#define itkSupportInputImageTypes_h
20#include "itkPipeline.h"
25#include "itkWasmMapPixelType.h"
26
27#include "itkImage.h"
28#include "itkVectorImage.h"
29#include "itkImageIOBase.h"
30#include "itkImageIOFactory.h"
32#include "WebAssemblyInterfaceExport.h"
33
34#include "itkImageJSON.h"
35
36namespace itk
37{
38
39WebAssemblyInterface_EXPORT bool
40lexical_cast(const std::string & input, ImageTypeJSON & imageType);
41
42namespace wasm
43{
44
88template <template <typename TImage> class TPipelineFunctor, typename... TPixels>
90{
91public:
92 template <unsigned int... VDimensions>
93 static int
94 Dimensions(const std::string & inputImageOptionName, Pipeline & pipeline)
95 {
96 ImageTypeJSON imageType;
97
98 const auto iwpArgc = pipeline.get_argc();
99 const auto iwpArgv = pipeline.get_argv();
100 for (int ii = 0; ii < iwpArgc; ++ii)
101 {
102 const std::string arg(iwpArgv[ii]);
103 if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
104 {
105 return IterateDimensions<VDimensions...>(pipeline, imageType, true);
106 }
107 }
108
109 auto tempOption = pipeline.add_option(inputImageOptionName, imageType, "Read image type.");
110
111 ITK_WASM_PRE_PARSE(pipeline);
112
113 pipeline.remove_option(tempOption);
114
115 return IterateDimensions<VDimensions...>(pipeline, imageType);
116 }
117
118private:
119 template <unsigned int VDimension, typename TPixel, typename... TPixelsRest>
120 static int
121 IteratePixelTypes(Pipeline & pipeline, const ImageTypeJSON & imageType, bool passThrough = false)
122 {
123 constexpr unsigned int Dimension = VDimension;
124 using PixelType = TPixel;
125 using ConvertPixelTraits = DefaultConvertPixelTraits<PixelType>;
126
127 if (passThrough ||
132 imageType.components == ConvertPixelTraits::GetNumberOfComponents())))
133 {
135 }
136
137 if constexpr (sizeof...(TPixelsRest) > 0)
138 {
139 return IteratePixelTypes<VDimension, TPixelsRest...>(pipeline, imageType);
140 }
141
142 std::ostringstream ostrm;
143 std::string imageTypeString = glz::write_json(imageType).value_or("error");
144 ostrm << "Unsupported image type: " << imageTypeString << std::endl;
145 CLI::Error err("Runtime error", ostrm.str(), 1);
146 return pipeline.exit(err);
147 }
148
149 template <unsigned int VDimension, unsigned int... VDimensions>
150 static int
151 IterateDimensions(Pipeline & pipeline, const ImageTypeJSON & imageType, bool passThrough = false)
152 {
153 if (passThrough || VDimension == imageType.dimension)
154 {
155 return IteratePixelTypes<VDimension, TPixels...>(pipeline, imageType, passThrough);
156 }
157
158 if constexpr (sizeof...(VDimensions) > 0)
159 {
160 return IterateDimensions<VDimensions...>(pipeline, imageType);
161 }
162
163 std::ostringstream ostrm;
164 ostrm << "Unsupported image dimension: " << imageType.dimension;
165 CLI::Error err("Runtime error", ostrm.str(), 1);
166 return pipeline.exit(err);
167 }
168};
169
170} // end namespace wasm
171} // end namespace itk
172
173#endif
Traits class used to by ConvertPixels to convert blocks of pixels.
int get_argc() const
char ** get_argv() const
auto exit(const CLI::Error &e) -> int
Internal class to dispatch for pipeline execution on itk::Image or itk::VectorImage.
Instantiatiate a Pipeline functor over multiple pixel types and dimensions and match to the input ima...
static int IterateDimensions(Pipeline &pipeline, const ImageTypeJSON &imageType, bool passThrough=false)
static int Dimensions(const std::string &inputImageOptionName, Pipeline &pipeline)
static int IteratePixelTypes(Pipeline &pipeline, const ImageTypeJSON &imageType, bool passThrough=false)
#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)
Image type JSON representation data structure.
unsigned int components
unsigned int dimension
JSONPixelTypesEnum pixelType
JSONComponentTypesEnum componentType
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum