ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkPolyDataJSON.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 itkPolyDataJSON_h
19#define itkPolyDataJSON_h
20
22
24#include "itkWasmMapPixelType.h"
25#include "itkIntTypesJSON.h"
26#include "itkFloatTypesJSON.h"
27#include "itkPixelTypesJSON.h"
28#include "itkWasmPolyData.h"
30
31#include "glaze/glaze.hpp"
32
33namespace itk
34{
50
58{
60
61 std::string name{ "PolyData" };
62
63 size_t numberOfPoints{ 0 };
64 std::string points;
65
66 size_t verticesBufferSize{ 0 };
67 std::string vertices;
68
69 size_t linesBufferSize{ 0 };
70 std::string lines;
71
72 size_t polygonsBufferSize{ 0 };
73 std::string polygons;
74
76 std::string triangleStrips;
77
79 std::string pointData;
80
81 size_t numberOfCellPixels{ 0 };
82 std::string cellData;
83
85};
86
87template <typename TPolyData>
88auto
89polyDataToPolyDataJSON(const TPolyData * polyData, bool inMemory) -> PolyDataJSON
90{
91 using PolyDataType = TPolyData;
92
93 PolyDataJSON polyDataJSON;
94
95 using PointPixelType = typename TPolyData::PixelType;
96 using ConvertPointPixelTraits = MeshConvertPixelTraits<PointPixelType>;
100 polyDataJSON.polyDataType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents();
101
102 using CellPixelType = typename TPolyData::CellPixelType;
103 using ConvertCellPixelTraits = MeshConvertPixelTraits<CellPixelType>;
107 polyDataJSON.polyDataType.cellPixelComponents = ConvertCellPixelTraits::GetNumberOfComponents();
108
109 polyDataJSON.name = polyData->GetObjectName();
110 polyDataJSON.numberOfPoints = polyData->GetNumberOfPoints();
111
112 if (polyData->GetPointData() != nullptr)
113 {
114 polyDataJSON.verticesBufferSize = polyData->GetVertices()->Size();
115 }
116
117 if (polyData->GetPointData() != nullptr)
118 {
119 polyDataJSON.linesBufferSize = polyData->GetLines()->Size();
120 }
121
122 if (polyData->GetPointData() != nullptr)
123 {
124 polyDataJSON.polygonsBufferSize = polyData->GetPolygons()->Size();
125 }
126
127 if (polyData->GetPointData() != nullptr)
128 {
129 polyDataJSON.triangleStripsBufferSize = polyData->GetTriangleStrips()->Size();
130 }
131
132 if (polyData->GetPointData() != nullptr)
133 {
134 polyDataJSON.numberOfPointPixels = polyData->GetPointData()->Size();
135 }
136
137 if (polyData->GetCellData() != nullptr)
138 {
139 polyDataJSON.numberOfCellPixels = polyData->GetCellData()->Size();
140 }
141
142 size_t pointsAddress = 0;
143 if (polyData->GetNumberOfPoints())
144 {
145 pointsAddress = reinterpret_cast<size_t>(&(polyData->GetPoints()->at(0)));
146 }
147 std::ostringstream pointsStream;
148 pointsStream << "data:application/vnd.itk.address,0:";
149 pointsStream << pointsAddress;
150 polyDataJSON.points = pointsStream.str();
151
152 size_t verticesAddress = 0;
153 if (polyData->GetVertices() != nullptr && polyData->GetVertices()->Size() > 0)
154 {
155 verticesAddress = reinterpret_cast<size_t>(&(polyData->GetVertices()->at(0)));
156 }
157 std::ostringstream verticesStream;
158 verticesStream << "data:application/vnd.itk.address,0:";
159 verticesStream << verticesAddress;
160 polyDataJSON.vertices = verticesStream.str();
161
162 size_t linesAddress = 0;
163 if (polyData->GetLines() != nullptr && polyData->GetLines()->Size() > 0)
164 {
165 linesAddress = reinterpret_cast<size_t>(&(polyData->GetLines()->at(0)));
166 }
167 std::ostringstream linesStream;
168 linesStream << "data:application/vnd.itk.address,0:";
169 linesStream << linesAddress;
170 polyDataJSON.lines = linesStream.str();
171
172 size_t polygonsAddress = 0;
173 if (polyData->GetPolygons() != nullptr && polyData->GetPolygons()->Size() > 0)
174 {
175 polygonsAddress = reinterpret_cast<size_t>(&(polyData->GetPolygons()->at(0)));
176 }
177 std::ostringstream polygonsStream;
178 polygonsStream << "data:application/vnd.itk.address,0:";
179 polygonsStream << polygonsAddress;
180 polyDataJSON.polygons = polygonsStream.str();
181
182 size_t triangleStripsAddress = 0;
183 if (polyData->GetTriangleStrips() != nullptr && polyData->GetTriangleStrips()->Size() > 0)
184 {
185 triangleStripsAddress = reinterpret_cast<size_t>(&(polyData->GetTriangleStrips()->at(0)));
186 }
187 std::ostringstream triangleStripsStream;
188 triangleStripsStream << "data:application/vnd.itk.address,0:";
189 triangleStripsStream << triangleStripsAddress;
190 polyDataJSON.triangleStrips = triangleStripsStream.str();
191
192 size_t pointDataAddress = 0;
193 if (polyData->GetPointData() != nullptr && polyData->GetPointData()->Size() > 0)
194 {
195 pointDataAddress = reinterpret_cast<size_t>(&(polyData->GetPointData()->at(0)));
196 }
197 std::ostringstream pointDataStream;
198 pointDataStream << "data:application/vnd.itk.address,0:";
199 pointDataStream << pointDataAddress;
200 polyDataJSON.pointData = pointDataStream.str();
201
202 size_t cellDataAddress = 0;
203 if (polyData->GetCellData() != nullptr && polyData->GetCellData()->Size() > 0)
204 {
205 cellDataAddress = reinterpret_cast<size_t>(&(polyData->GetCellData()->at(0)));
206 }
207 std::ostringstream cellDataStream;
208 cellDataStream << "data:application/vnd.itk.address,0:";
209 cellDataStream << cellDataAddress;
210 polyDataJSON.cellData = cellDataStream.str();
211
212 auto dictionary = polyData->GetMetaDataDictionary();
213 metaDataDictionaryToJSON(dictionary, polyDataJSON.metadata);
214
215 return polyDataJSON;
216}
217} // end namespace itk
218
219#endif // itkPolyDataJSON_h
Traits class used to by ConvertPixels to convert blocks of pixels.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
WebAssemblyInterface_EXPORT void metaDataDictionaryToJSON(const itk::MetaDataDictionary &dictionary, MetadataJSON &metadataJson)
auto polyDataToPolyDataJSON(const TPolyData *polyData, bool inMemory) -> PolyDataJSON
std::vector< MetadataEntryJSON > MetadataJSON
PolyData JSON representation data structure.
std::string triangleStrips
vcl_size_t triangleStripsBufferSize
vcl_size_t polygonsBufferSize
vcl_size_t verticesBufferSize
PolyDataTypeJSON polyDataType
vcl_size_t numberOfPoints
MetadataJSON metadata
vcl_size_t numberOfPointPixels
std::string pointData
vcl_size_t linesBufferSize
vcl_size_t numberOfCellPixels
PolyData type JSON representation data structure.
unsigned int pointPixelComponents
JSONPixelTypesEnum pointPixelType
JSONComponentTypesEnum cellPixelComponentType
JSONComponentTypesEnum pointPixelComponentType
unsigned int cellPixelComponents
JSONPixelTypesEnum cellPixelType
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum