ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSupportInputMeshTypes.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 itkSupportInputMeshTypes_h
19#define itkSupportInputMeshTypes_h
20#include "itkPipeline.h"
25#include "itkWasmMapPixelType.h"
26
27#include "itkMesh.h"
28#include "itkMeshIOBase.h"
29#include "itkMeshIOFactory.h"
30#include "WebAssemblyInterfaceExport.h"
31
32#include "itkMeshJSON.h"
33
34namespace itk
35{
36
37WebAssemblyInterface_EXPORT bool
38lexical_cast(const std::string & input, MeshTypeJSON & meshType);
39
40namespace wasm
41{
42
90template <template <typename TMesh> class TPipelineFunctor, typename... TPixels>
92{
93public:
94 template <unsigned int... VDimensions>
95 static int
96 Dimensions(const std::string & inputMeshOptionName, Pipeline & pipeline)
97 {
98 MeshTypeJSON meshType;
99
100 const auto iwpArgc = pipeline.get_argc();
101 const auto iwpArgv = pipeline.get_argv();
102 bool passThrough = false;
103 for (int ii = 0; ii < iwpArgc; ++ii)
104 {
105 const std::string arg(iwpArgv[ii]);
106 if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
107 {
108 passThrough = true;
109 }
110 }
111 if (passThrough)
112 {
113 return IterateDimensions<VDimensions...>(pipeline, meshType, passThrough);
114 }
115
116 auto tempOption = pipeline.add_option(inputMeshOptionName, meshType, "Read mesh type.");
117
118 ITK_WASM_PRE_PARSE(pipeline);
119
120 pipeline.remove_option(tempOption);
121
122 return IterateDimensions<VDimensions...>(pipeline, meshType);
123 }
124
125private:
126 template <unsigned int VDimension, typename TPixel, typename... TPixelsRest>
127 static int
128 IteratePixelTypes(Pipeline & pipeline, const MeshTypeJSON & meshType, bool passThrough = false)
129 {
130 constexpr unsigned int Dimension = VDimension;
131 using PixelType = TPixel;
132 using ConvertPixelTraits = MeshConvertPixelTraits<PixelType>;
133
134 const auto components =
136
137 if (passThrough || components == 0 ||
138 meshType.pointPixelComponentType ==
141 {
144 {
145 // todo: VectorMesh support for ImportMeshFilter?
146 // using MeshType = itk::VectorMesh<typename ConvertPixelTraits::ComponentType, Dimension>;
147
148 // using PipelineType = TPipelineFunctor<MeshType>;
149 // return PipelineType()(pipeline);
150 }
151 else if (passThrough || components == ConvertPixelTraits::GetNumberOfComponents() || components == 0)
152 {
153 using MeshType = Mesh<PixelType, Dimension>;
154
155 using PipelineType = TPipelineFunctor<MeshType>;
156 return PipelineType()(pipeline);
157 }
158 }
159
160 if constexpr (sizeof...(TPixelsRest) > 0)
161 {
162 return IteratePixelTypes<VDimension, TPixelsRest...>(pipeline, meshType);
163 }
164
165 std::ostringstream ostrm;
166 std::string meshTypeString = glz::write_json(meshType).value_or("error");
167 ostrm << "Unsupported mesh type: " << meshTypeString << std::endl;
168 CLI::Error err("Runtime error", ostrm.str(), 1);
169 return pipeline.exit(err);
170 }
171
172 template <unsigned int VDimension, unsigned int... VDimensions>
173 static int
174 IterateDimensions(Pipeline & pipeline, const MeshTypeJSON & meshType, bool passThrough = false)
175 {
176 if (passThrough || VDimension == meshType.dimension)
177 {
178 return IteratePixelTypes<VDimension, TPixels...>(pipeline, meshType);
179 }
180
181 if constexpr (sizeof...(VDimensions) > 0)
182 {
183 return IterateDimensions<VDimensions...>(pipeline, meshType);
184 }
185
186 std::ostringstream ostrm;
187 ostrm << "Unsupported mesh dimension: " << meshType.dimension;
188 CLI::Error err("Runtime error", ostrm.str(), 1);
189 return pipeline.exit(err);
190 }
191};
192
193} // end namespace wasm
194} // end namespace itk
195
196#endif
Traits class used to by ConvertPixels to convert blocks of pixels.
Implements the N-dimensional mesh structure.
Definition itkMesh.h:127
int get_argc() const
char ** get_argv() const
auto exit(const CLI::Error &e) -> int
Instantiatiate a Pipeline functor over multiple pixel types and dimensions and match to the input mes...
static int IterateDimensions(Pipeline &pipeline, const MeshTypeJSON &meshType, bool passThrough=false)
static int IteratePixelTypes(Pipeline &pipeline, const MeshTypeJSON &meshType, bool passThrough=false)
static int Dimensions(const std::string &inputMeshOptionName, 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)
Mesh type JSON representation data structure.
Definition itkMeshJSON.h:43
unsigned int dimension
Definition itkMeshJSON.h:44
JSONPixelTypesEnum pointPixelType
Definition itkMeshJSON.h:47
JSONComponentTypesEnum pointPixelComponentType
Definition itkMeshJSON.h:46
unsigned int cellPixelComponents
Definition itkMeshJSON.h:52
unsigned int pointPixelComponents
Definition itkMeshJSON.h:48
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum