ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkPointSetJSON.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 itkPointSetJSON_h
19#define itkPointSetJSON_h
20
22
24#include "itkWasmMapPixelType.h"
25#include "itkIntTypesJSON.h"
26#include "itkFloatTypesJSON.h"
27#include "itkPixelTypesJSON.h"
28#include "itkWasmPointSet.h"
30
31#include "glaze/glaze.hpp"
32
33namespace itk
34{
49
57{
59
60 std::string name{ "PointSet" };
61
62 size_t numberOfPoints{ 0 };
63 std::string points;
64
66 std::string pointData;
67
69};
70
71template <typename TPointSet>
72auto
73pointSetToPointSetJSON(const TPointSet * pointSet, const WasmPointSet<TPointSet> * wasmPointSet, bool inMemory)
75{
76 using PointSetType = TPointSet;
77
78 PointSetJSON pointSetJSON;
79
80 pointSetJSON.pointSetType.dimension = PointSetType::PointDimension;
81
82 pointSetJSON.pointSetType.pointComponentType =
84 using PointPixelType = typename TPointSet::PixelType;
85 using ConvertPointPixelTraits = MeshConvertPixelTraits<PointPixelType>;
89 pointSetJSON.pointSetType.pointPixelComponents = ConvertPointPixelTraits::GetNumberOfComponents();
90
91 pointSetJSON.name = pointSet->GetObjectName();
92 pointSetJSON.numberOfPoints = pointSet->GetNumberOfPoints();
93 if (pointSet->GetPointData() == nullptr)
94 {
95 pointSetJSON.numberOfPointPixels = 0;
96 }
97 else
98 {
99 pointSetJSON.numberOfPointPixels = pointSet->GetPointData()->Size();
100 }
101 if (inMemory)
102 {
103 const auto pointsAddress = reinterpret_cast<size_t>(&(pointSet->GetPoints()->at(0)));
104 std::ostringstream pointsStream;
105 pointsStream << "data:application/vnd.itk.address,0:";
106 pointsStream << pointsAddress;
107 pointSetJSON.points = pointsStream.str();
108
109 size_t pointDataAddress = 0;
110 if (pointSet->GetPointData() != nullptr && pointSet->GetPointData()->Size() > 0)
111 {
112 pointDataAddress = reinterpret_cast<size_t>(&(pointSet->GetPointData()->at(0)));
113 }
114 std::ostringstream pointDataStream;
115 pointDataStream << "data:application/vnd.itk.address,0:";
116 pointDataStream << pointDataAddress;
117 pointSetJSON.pointData = pointDataStream.str();
118 }
119 else
120 {
121 pointSetJSON.points = "data:application/vnd.itk.path,data/points.raw";
122 pointSetJSON.pointData = "data:application/vnd.itk.path,data/point-data.raw";
123 }
124
125 auto dictionary = pointSet->GetMetaDataDictionary();
126 metaDataDictionaryToJSON(dictionary, pointSetJSON.metadata);
127
128 return pointSetJSON;
129}
130} // end namespace itk
131
132#endif // itkPointSetJSON_h
Traits class used to by ConvertPixels to convert blocks of pixels.
JSON representation for an itk::PointSet.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
WebAssemblyInterface_EXPORT void metaDataDictionaryToJSON(const itk::MetaDataDictionary &dictionary, MetadataJSON &metadataJson)
auto pointSetToPointSetJSON(const TPointSet *pointSet, const WasmPointSet< TPointSet > *wasmPointSet, bool inMemory) -> PointSetJSON
std::vector< MetadataEntryJSON > MetadataJSON
PointSet JSON representation data structure.
vcl_size_t numberOfPointPixels
PointSetTypeJSON pointSetType
MetadataJSON metadata
std::string pointData
vcl_size_t numberOfPoints
PointSet type JSON representation data structure.
unsigned int pointPixelComponents
JSONFloatTypesEnum pointComponentType
JSONPixelTypesEnum pointPixelType
JSONComponentTypesEnum pointPixelComponentType
static constexpr JSONComponentTypesEnum JSONComponentEnum
static constexpr JSONFloatTypesEnum JSONFloatTypeEnum
static constexpr JSONPixelTypesEnum JSONPixelEnum