ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSupportInputPolyDataTypes.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 itkSupportInputPolyDataTypes_h
19#define itkSupportInputPolyDataTypes_h
20#include "itkPipeline.h"
25#include "itkWasmMapPixelType.h"
26
27#include "itkPolyData.h"
28#include "itkMeshIOBase.h"
29#include "itkMeshIOFactory.h"
30#include "WebAssemblyInterfaceExport.h"
31
32#include "itkPolyDataJSON.h"
33
34namespace itk
35{
36
37WebAssemblyInterface_EXPORT bool
38lexical_cast(const std::string & input, PolyDataTypeJSON & polyDataType);
39
40namespace wasm
41{
42
86template <template <typename TPolyData> class TPipelineFunctor>
88{
89public:
90 template <typename... TPixels>
91 static int
92 PixelTypes(const std::string & inputPolyDataOptionName, Pipeline & pipeline)
93 {
94 PolyDataTypeJSON polyDataType;
95
96 const auto iwpArgc = pipeline.get_argc();
97 const auto iwpArgv = pipeline.get_argv();
98 bool passThrough = false;
99 for (int ii = 0; ii < iwpArgc; ++ii)
100 {
101 const std::string arg(iwpArgv[ii]);
102 if (arg == "-h" || arg == "--help" || arg == "--interface-json" || arg == "--version")
103 {
104 passThrough = true;
105 }
106 }
107 if (passThrough)
108 {
109 return IteratePixelTypes<TPixels...>(pipeline, polyDataType, passThrough);
110 }
111
112 auto tempOption = pipeline.add_option(inputPolyDataOptionName, polyDataType, "Read PolyData type.");
113
114 ITK_WASM_PRE_PARSE(pipeline);
115
116 pipeline.remove_option(tempOption);
117
118 return IteratePixelTypes<TPixels...>(pipeline, polyDataType);
119 }
120
121private:
122 template <typename TPixel, typename... TPixelsRest>
123 static int
124 IteratePixelTypes(Pipeline & pipeline, const PolyDataTypeJSON & polyDataType, bool passThrough = false)
125 {
126 using PixelType = TPixel;
127 using ConvertPixelTraits = MeshConvertPixelTraits<PixelType>;
128
129 const auto components =
130 polyDataType.pointPixelComponents ? polyDataType.pointPixelComponents : polyDataType.cellPixelComponents;
131
132 if (passThrough || components == 0 ||
133 polyDataType.pointPixelComponentType ==
136 {
139 {
140 // todo: VectorMesh support for ImportMeshFilter?
141 // using MeshType = itk::VectorMesh<typename ConvertPixelTraits::ComponentType, Dimension>;
142
143 // using PipelineType = TPipelineFunctor<MeshType>;
144 // return PipelineType()(pipeline);
145 }
146 else if (passThrough || components == ConvertPixelTraits::GetNumberOfComponents() || components == 0)
147 {
148 using PolyDataType = PolyData<PixelType>;
149
150 using PipelineType = TPipelineFunctor<PolyDataType>;
151 return PipelineType()(pipeline);
152 }
153 }
154
155 if constexpr (sizeof...(TPixelsRest) > 0)
156 {
157 return IteratePixelTypes<TPixelsRest...>(pipeline, polyDataType);
158 }
159
160 std::ostringstream ostrm;
161 std::string polyDataTypeString = glz::write_json(polyDataType).value_or("error");
162 ostrm << "Unsupported polyData type: " << polyDataTypeString << std::endl;
163 CLI::Error err("Runtime error", ostrm.str(), 1);
164 return pipeline.exit(err);
165 }
166};
167
168} // end namespace wasm
169} // end namespace itk
170
171#endif
Traits class used to by ConvertPixels to convert blocks of pixels.
Geometry class compatible with vtk.js PolyData.
Definition itkPolyData.h:36
int get_argc() const
char ** get_argv() const
auto exit(const CLI::Error &e) -> int
Instantiatiate a Pipeline functor over multiple pixel types and match to the input polydata type.
static int IteratePixelTypes(Pipeline &pipeline, const PolyDataTypeJSON &polyDataType, bool passThrough=false)
static int PixelTypes(const std::string &inputPolyDataOptionName, 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)
PolyData type JSON representation data structure.
unsigned int pointPixelComponents
JSONPixelTypesEnum pointPixelType
JSONComponentTypesEnum pointPixelComponentType
unsigned int cellPixelComponents
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum