ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkInputPolyData.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 itkInputPolyData_h
19#define itkInputPolyData_h
20
21#include "itkPipeline.h"
22
23#ifndef ITK_WASM_NO_MEMORY_IO
24# include "itkWasmExports.h"
25# include "itkWasmPolyData.h"
27#endif
28#ifndef ITK_WASM_NO_FILESYSTEM_IO
29# include "itkMeshFileReader.h"
32#endif
33
34namespace itk
35{
36namespace wasm
37{
38
49template <typename TPolyData>
50class ITK_TEMPLATE_EXPORT InputPolyData
51{
52public:
53 using PolyDataType = TPolyData;
54
55 void
56 Set(const PolyDataType * polyData)
57 {
58 this->m_PolyData = polyData;
59 }
60
61 const PolyDataType *
62 Get() const
63 {
64 return this->m_PolyData.GetPointer();
65 }
66
67 InputPolyData() = default;
68 ~InputPolyData() = default;
69
70protected:
71 typename TPolyData::ConstPointer m_PolyData;
72};
73
74
75template <typename TPolyData>
76bool
77lexical_cast(const std::string & input, InputPolyData<TPolyData> & inputPolyData)
78{
79 if (input.empty())
80 {
81 return false;
82 }
83
85 {
86#ifndef ITK_WASM_NO_MEMORY_IO
87 using WasmPolyDataToPolyDataFilterType = WasmPolyDataToPolyDataFilter<TPolyData>;
88 auto wasmPolyDataToPolyDataFilter = WasmPolyDataToPolyDataFilterType::New();
89 auto wasmPolyData = WasmPolyDataToPolyDataFilterType::WasmPolyDataType::New();
90 const unsigned int index = std::stoi(input);
91 auto json = getMemoryStoreInputJSON(0, index);
92 wasmPolyData->SetJSON(json);
93 wasmPolyDataToPolyDataFilter->SetInput(wasmPolyData);
94 wasmPolyDataToPolyDataFilter->Update();
95 inputPolyData.Set(wasmPolyDataToPolyDataFilter->GetOutput());
96#else
97 return false;
98#endif
99 }
100 else
101 {
102#ifndef ITK_WASM_NO_FILESYSTEM_IO
103 using PolyDataToMeshFilterType = PolyDataToMeshFilter<TPolyData>;
104 using MeshType = typename PolyDataToMeshFilterType::OutputMeshType;
105 using ReaderType = MeshFileReader<MeshType>;
106 auto reader = ReaderType::New();
107 reader->SetFileName(input);
108 using MeshToPolyDataFilterType = MeshToPolyDataFilter<MeshType>;
109 auto meshToPolyData = MeshToPolyDataFilterType::New();
110 meshToPolyData->SetInput(reader->GetOutput());
111 meshToPolyData->Update();
112 auto polyData = meshToPolyData->GetOutput();
113 inputPolyData.Set(polyData);
114#else
115 return false;
116#endif
117 }
118 return true;
119}
120
121} // end namespace wasm
122} // end namespace itk
123
124#endif
Mesh source that reads mesh data from a single file.
Convert a PointSet or Mesh to PolyData.
Convert PolyData to a Mesh.
Convert an WasmPolyData to an PolyData object.
Input polyData for an itk::wasm::Pipeline.
const PolyDataType * Get() const
TPolyData::ConstPointer m_PolyData
void Set(const PolyDataType *polyData)
static auto get_use_memory_io()
const WebAssemblyInterface_EXPORT std::string & getMemoryStoreInputJSON(uint32_t memoryIndex, uint32_t index)
bool lexical_cast(const std::string &input, InputImage< TImage > &inputImage)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....