annotate Framework/Radiography/RadiographySceneWriter.cpp @ 504:7cdb4634846c

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