ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkInputMesh.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 itkInputMesh_h
19#define itkInputMesh_h
20
21#include "itkPipeline.h"
22
23#ifndef ITK_WASM_NO_MEMORY_IO
24# include "itkWasmExports.h"
25# include "itkWasmMesh.h"
27#endif
28#ifndef ITK_WASM_NO_FILESYSTEM_IO
29# include "itkMeshFileReader.h"
30#endif
31
32namespace itk
33{
34namespace wasm
35{
36
47template <typename TMesh>
48class ITK_TEMPLATE_EXPORT InputMesh
49{
50public:
51 using MeshType = TMesh;
52
53 void
54 Set(const MeshType * mesh)
55 {
56 this->m_Mesh = mesh;
57 }
58
59 const MeshType *
60 Get() const
61 {
62 return this->m_Mesh.GetPointer();
63 }
64
65 InputMesh() = default;
66 ~InputMesh() = default;
67
68protected:
69 typename TMesh::ConstPointer m_Mesh;
70};
71
72
73template <typename TMesh>
74bool
75lexical_cast(const std::string & input, InputMesh<TMesh> & inputMesh)
76{
77 if (input.empty())
78 {
79 return false;
80 }
81
83 {
84#ifndef ITK_WASM_NO_MEMORY_IO
85 using WasmMeshToMeshFilterType = WasmMeshToMeshFilter<TMesh>;
86 auto wasmMeshToMeshFilter = WasmMeshToMeshFilterType::New();
87 auto wasmMesh = WasmMeshToMeshFilterType::WasmMeshType::New();
88 const unsigned int index = std::stoi(input);
89 auto json = getMemoryStoreInputJSON(0, index);
90 wasmMesh->SetJSON(json);
91 wasmMeshToMeshFilter->SetInput(wasmMesh);
92 wasmMeshToMeshFilter->Update();
93 inputMesh.Set(wasmMeshToMeshFilter->GetOutput());
94#else
95 return false;
96#endif
97 }
98 else
99 {
100#ifndef ITK_WASM_NO_FILESYSTEM_IO
101 using ReaderType = MeshFileReader<TMesh>;
102 auto reader = ReaderType::New();
103 reader->SetFileName(input);
104 reader->Update();
105 auto mesh = reader->GetOutput();
106 inputMesh.Set(mesh);
107#else
108 return false;
109#endif
110 }
111 return true;
112}
113
114} // end namespace wasm
115} // end namespace itk
116
117#endif
Mesh source that reads mesh data from a single file.
Convert an WasmMesh to a Mesh or QuadEdgeMesh object.
Input mesh for an itk::wasm::Pipeline.
TMesh::ConstPointer m_Mesh
void Set(const MeshType *mesh)
const MeshType * Get() const
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....