ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkInputImage.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 itkInputImage_h
19#define itkInputImage_h
20
21#include "itkPipeline.h"
22
23#ifndef ITK_WASM_NO_MEMORY_IO
24# include "itkWasmExports.h"
25# include "itkWasmImage.h"
27#endif
28#ifndef ITK_WASM_NO_FILESYSTEM_IO
29# include "itkImageFileReader.h"
30#endif
31
32namespace itk
33{
34namespace wasm
35{
36
47template <typename TImage>
48class ITK_TEMPLATE_EXPORT InputImage
49{
50public:
51 using ImageType = TImage;
52
53 void
54 Set(const ImageType * image)
55 {
56 this->m_Image = image;
57 }
58
59 const ImageType *
60 Get() const
61 {
62 return this->m_Image.GetPointer();
63 }
64
65 InputImage() = default;
66 ~InputImage() = default;
67
68protected:
69 typename TImage::ConstPointer m_Image;
70};
71
72
73template <typename TImage>
74bool
75lexical_cast(const std::string & input, InputImage<TImage> & inputImage)
76{
77 if (input.empty())
78 {
79 return false;
80 }
81
83 {
84#ifndef ITK_WASM_NO_MEMORY_IO
85 using WasmImageToImageFilterType = WasmImageToImageFilter<TImage>;
86 auto wasmImageToImageFilter = WasmImageToImageFilterType::New();
87 auto wasmImage = WasmImageToImageFilterType::WasmImageType::New();
88 const unsigned int index = std::stoi(input);
89 auto json = getMemoryStoreInputJSON(0, index);
90 wasmImage->SetJSON(json);
91 wasmImageToImageFilter->SetInput(wasmImage);
92 wasmImageToImageFilter->Update();
93 inputImage.Set(wasmImageToImageFilter->GetOutput());
94#else
95 return false;
96#endif
97 }
98 else
99 {
100#ifndef ITK_WASM_NO_FILESYSTEM_IO
101 auto image = itk::ReadImage<TImage>(input);
102 inputImage.Set(image);
103#else
104 return false;
105#endif
106 }
107 return true;
108}
109
110} // end namespace wasm
111} // end namespace itk
112
113#endif
Convert an WasmImage to an Image object.
Input image for an itk::wasm::Pipeline.
TImage::ConstPointer m_Image
void Set(const ImageType *image)
const ImageType * 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....
TOutputImage::Pointer ReadImage(const std::string &filename)