comparison Framework/Radiography/RadiographySceneWriter.cpp @ 430:b85f635f1eb5 am-vsol-upgrade

added serialization for RadiographyScene
author am@osimis.io
date Thu, 29 Nov 2018 15:11:19 +0100
parents
children 159a465e27bd
comparison
equal deleted inserted replaced
429:c7fb700a7d12 430:b85f635f1eb5
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "RadiographySceneWriter.h"
23
24 #include <Core/OrthancException.h>
25 #include <Core/Images/PngWriter.h>
26 #include <Core/Toolbox.h>
27
28 namespace OrthancStone
29 {
30 void RadiographySceneWriter::Write(Json::Value& output, const RadiographyScene& scene)
31 {
32 output["version"] = 1;
33 output["layers"] = Json::arrayValue;
34
35 std::vector<size_t> layersIndexes;
36 scene.GetLayersIndexes(layersIndexes);
37
38 for (std::vector<size_t>::iterator itLayerIndex = layersIndexes.begin(); itLayerIndex < layersIndexes.end(); itLayerIndex++)
39 {
40 Json::Value layer;
41 WriteLayer(layer, scene.GetLayer(*itLayerIndex));
42 output["layers"].append(layer);
43 }
44 }
45
46 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyDicomLayer& layer)
47 {
48 output["type"] = "dicom";
49 output["instanceId"] = layer.GetInstanceId();
50 output["frame"] = layer.GetFrame();
51 }
52
53 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyTextLayer& layer)
54 {
55 output["type"] = "text";
56 output["text"] = layer.GetText();
57 output["fontName"] = layer.GetFontName();
58 }
59
60 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer)
61 {
62 output["type"] = "alpha";
63
64 //output["bitmap"] =
65 const Orthanc::ImageAccessor& alpha = layer.GetAlpha();
66
67 Orthanc::PngWriter pngWriter;
68 std::string pngContent;
69 std::string pngContentBase64;
70 pngWriter.WriteToMemory(pngContent, alpha);
71
72 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent);
73 output["content"] = pngContentBase64;
74 output["foreground"] = layer.GetForegroundValue();
75 output["isUsingWindowing"] = layer.IsUsingWindowing();
76 }
77
78 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer)
79 {
80 const RadiographyLayer::Geometry& geometry = layer.GetGeometry();
81
82 {// crop
83 Json::Value crop;
84 if (geometry.HasCrop())
85 {
86 unsigned int x, y, width, height;
87 geometry.GetCrop(x, y, width, height);
88 crop["hasCrop"] = true;
89 crop["x"] = x;
90 crop["y"] = y;
91 crop["width"] = width;
92 crop["height"] = height;
93 }
94 else
95 {
96 crop["hasCrop"] = false;
97 }
98
99 output["crop"] = crop;
100 }
101
102 output["angle"] = geometry.GetAngle();
103 output["isResizable"] = geometry.IsResizeable();
104
105 {// pan
106 Json::Value pan;
107 pan["x"] = geometry.GetPanX();
108 pan["y"] = geometry.GetPanY();
109 output["pan"] = pan;
110 }
111
112 {// pixelSpacing
113 Json::Value pan;
114 pan["x"] = geometry.GetPixelSpacingX();
115 pan["y"] = geometry.GetPixelSpacingY();
116 output["pixelSpacing"] = pan;
117 }
118
119 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL)
120 {
121 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer));
122 }
123 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL)
124 {
125 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer));
126 }
127 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL)
128 {
129 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer));
130 }
131 else
132 {
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
134 }
135 }
136 }