ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkOutputPointSet.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 itkOutputPointSet_h
19#define itkOutputPointSet_h
20
21#include "itkPipeline.h"
23
24#ifndef ITK_WASM_NO_MEMORY_IO
25# include "itkWasmExports.h"
26# include "itkWasmPointSet.h"
28#endif
29#ifndef ITK_WASM_NO_FILESYSTEM_IO
30# include "itkMesh.h"
31# include "itkMeshFileWriter.h"
32#endif
33
34namespace itk
35{
36namespace wasm
37{
48template <typename TPointSet>
49class ITK_TEMPLATE_EXPORT OutputPointSet
50{
51public:
52 using PointSetType = TPointSet;
53
54 void
55 Set(const PointSetType * pointSet)
56 {
57 this->m_PointSet = pointSet;
58 }
59
60 const PointSetType *
61 Get() const
62 {
63 return this->m_PointSet.GetPointer();
64 }
65
67 void
68 SetIdentifier(const std::string & identifier)
69 {
70 this->m_Identifier = identifier;
71 }
72 const std::string &
74 {
75 return this->m_Identifier;
76 }
77
78 OutputPointSet() = default;
80 {
82 {
83#ifndef ITK_WASM_NO_MEMORY_IO
84 if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty())
85 {
86 using PointSetToWasmPointSetFilterType = PointSetToWasmPointSetFilter<PointSetType>;
87 auto pointSetToWasmPointSetFilter = PointSetToWasmPointSetFilterType::New();
88 pointSetToWasmPointSetFilter->SetInput(this->m_PointSet);
89 pointSetToWasmPointSetFilter->Update();
90 auto wasmPointSet = pointSetToWasmPointSetFilter->GetOutput();
91 const auto index = std::stoi(this->m_Identifier);
92 setMemoryStoreOutputDataObject(0, index, wasmPointSet);
93
94 if (this->m_PointSet->GetNumberOfPoints() > 0)
95 {
96 const auto pointsAddress = reinterpret_cast<size_t>(&(wasmPointSet->GetPointSet()->GetPoints()->at(0)));
97 const auto pointsSize = wasmPointSet->GetPointSet()->GetPoints()->Size() *
98 sizeof(typename PointSetType::CoordinateType) * PointSetType::PointDimension;
99 setMemoryStoreOutputArray(0, index, 0, pointsAddress, pointsSize);
100 }
101
102 if (this->m_PointSet->GetPointData() != nullptr && this->m_PointSet->GetPointData()->Size() > 0)
103 {
104 using PointPixelType = typename PointSetType::PixelType;
105 using ConvertPointPixelTraits = MeshConvertPixelTraits<PointPixelType>;
106 const auto pointDataAddress = reinterpret_cast<size_t>(&(wasmPointSet->GetPointSet()->GetPointData()->at(0)));
107 const auto pointDataSize = wasmPointSet->GetPointSet()->GetPointData()->Size() *
108 sizeof(typename ConvertPointPixelTraits::ComponentType) *
109 ConvertPointPixelTraits::GetNumberOfComponents();
110 setMemoryStoreOutputArray(0, index, 1, pointDataAddress, pointDataSize);
111 }
112 }
113#else
114 std::cerr << "Memory IO not supported" << std::endl;
115 abort();
116#endif
117 }
118 else
119 {
120#ifndef ITK_WASM_NO_FILESYSTEM_IO
121 if (!this->m_PointSet.IsNull() && !this->m_Identifier.empty())
122 {
124 using PointSetWriterType = itk::MeshFileWriter<MeshType>;
125 auto pointSetWriter = PointSetWriterType::New();
126 pointSetWriter->SetFileName(this->m_Identifier);
127 typename MeshType::Pointer mesh = MeshType::New();
128 mesh->SetPoints(const_cast<typename MeshType::PointsContainer *>(this->m_PointSet->GetPoints()));
129 mesh->SetPointData(const_cast<typename MeshType::PointDataContainer *>(this->m_PointSet->GetPointData()));
130 pointSetWriter->SetInput(mesh);
131 pointSetWriter->Update();
132 }
133#else
134 std::cerr << "Filesystem IO not supported" << std::endl;
135 abort();
136#endif
137 }
138 }
139
140protected:
141 typename TPointSet::ConstPointer m_PointSet;
142
143 std::string m_Identifier;
144};
145
146template <typename TPointSet>
147bool
148lexical_cast(const std::string & input, OutputPointSet<TPointSet> & outputPointSet)
149{
150 outputPointSet.SetIdentifier(input);
151 return true;
152}
153
154} // namespace wasm
155} // namespace itk
156
157#endif
Traits class used to by ConvertPixels to convert blocks of pixels.
Writes mesh data to a single file.
Implements the N-dimensional mesh structure.
Definition itkMesh.h:127
Convert an PointSet to an WasmPointSet object.
Output point set for an itk::wasm::Pipeline.
const PointSetType * Get() const
const std::string & GetIdentifier() const
void Set(const PointSetType *pointSet)
void SetIdentifier(const std::string &identifier)
TPointSet::ConstPointer m_PointSet
static auto get_use_memory_io()
WebAssemblyInterface_EXPORT void setMemoryStoreOutputDataObject(uint32_t memoryIndex, uint32_t index, const WasmDataObject *dataObject)
WebAssemblyInterface_EXPORT void setMemoryStoreOutputArray(uint32_t memoryIndex, uint32_t index, uint32_t subIndex, vcl_size_t address, vcl_size_t size)
bool lexical_cast(const std::string &input, InputImage< TImage > &inputImage)
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....