ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkSupportInputPointSetTypes.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 itkSupportInputPointSetTypes_h
19#define itkSupportInputPointSetTypes_h
20#include "itkPipeline.h"
25#include "itkWasmMapPixelType.h"
26
27#include "itkPointSet.h"
28#include "itkMeshIOBase.h"
29#include "itkMeshIOFactory.h"
30#include "WebAssemblyInterfaceExport.h"
31
32#include "itkPointSetJSON.h"
33
34namespace itk
35{
36
37WebAssemblyInterface_EXPORT bool
38lexical_cast(const std::string & input, PointSetTypeJSON & pointSetType);
39
40namespace wasm
41{
42
90template <template <typename TPointSet> class TPipelineFunctor, typename... TPixels>
92{
93public:
94 template <unsigned int... VDimensions>
95 static int
96 Dimensions(const std::string & inputPointSetOptionName, Pipeline & pipeline)
97 {
98 PointSetTypeJSON pointSetType;
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, pointSetType, passThrough);
114 }
115
116 auto tempOption = pipeline.add_option(inputPointSetOptionName, pointSetType, "Read pointSet type.");
117
118 ITK_WASM_PRE_PARSE(pipeline);
119
120 pipeline.remove_option(tempOption);
121
122 return IterateDimensions<VDimensions...>(pipeline, pointSetType);
123 }
124
125private:
126 template <unsigned int VDimension, typename TPixel, typename... TPixelsRest>
127 static int
128 IteratePixelTypes(Pipeline & pipeline, const PointSetTypeJSON & pointSetType, bool passThrough = false)
129 {
130 constexpr unsigned int Dimension = VDimension;
131 using PixelType = TPixel;
132 using ConvertPixelTraits = MeshConvertPixelTraits<PixelType>;
133
134 const auto components = pointSetType.pointPixelComponents;
135
136 if (passThrough || components == 0 ||
137 pointSetType.pointPixelComponentType ==
140 {
143 {
144 // todo: VectorPointSet support for ImportPointSetFilter?
145 // using PointSetType = itk::VectorPointSet<typename ConvertPixelTraits::ComponentType, Dimension>;
146
147 // using PipelineType = TPipelineFunctor<PointSetType>;
148 // return PipelineType()(pipeline);
149 }
150 else if (passThrough || components == ConvertPixelTraits::GetNumberOfComponents() || components == 0)
151 {
152 using PointSetType = PointSet<PixelType, Dimension>;
153
154 using PipelineType = TPipelineFunctor<PointSetType>;
155 return PipelineType()(pipeline);
156 }
157 }
158
159 if constexpr (sizeof...(TPixelsRest) > 0)
160 {
161 return IteratePixelTypes<VDimension, TPixelsRest...>(pipeline, pointSetType);
162 }
163
164 std::ostringstream ostrm;
165 std::string pointSetTypeString = glz::write_json(pointSetType).value_or("error");
166 ostrm << "Unsupported pointSet type: " << pointSetTypeString << std::endl;
167 CLI::Error err("Runtime error", ostrm.str(), 1);
168 return pipeline.exit(err);
169 }
170
171 template <unsigned int VDimension, unsigned int... VDimensions>
172 static int
173 IterateDimensions(Pipeline & pipeline, const PointSetTypeJSON & pointSetType, bool passThrough = false)
174 {
175 if (passThrough || VDimension == pointSetType.dimension)
176 {
177 return IteratePixelTypes<VDimension, TPixels...>(pipeline, pointSetType);
178 }
179
180 if constexpr (sizeof...(VDimensions) > 0)
181 {
182 return IterateDimensions<VDimensions...>(pipeline, pointSetType);
183 }
184
185 std::ostringstream ostrm;
186 ostrm << "Unsupported pointSet dimension: " << pointSetType.dimension;
187 CLI::Error err("Runtime error", ostrm.str(), 1);
188 return pipeline.exit(err);
189 }
190};
191
192} // end namespace wasm
193} // end namespace itk
194
195#endif
Traits class used to by ConvertPixels to convert blocks of pixels.
A superclass of the N-dimensional mesh structure; supports point (geometric coordinate and attribute)...
Definition itkPointSet.h:82
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 poi...
static int IterateDimensions(Pipeline &pipeline, const PointSetTypeJSON &pointSetType, bool passThrough=false)
static int Dimensions(const std::string &inputPointSetOptionName, Pipeline &pipeline)
static int IteratePixelTypes(Pipeline &pipeline, const PointSetTypeJSON &pointSetType, 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)
PointSet type JSON representation data structure.
unsigned int pointPixelComponents
JSONPixelTypesEnum pointPixelType
JSONComponentTypesEnum pointPixelComponentType
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum