annotate Framework/Radiography/RadiographySceneWriter.cpp @ 1213:86a8266b8888 broker

moving the scene from IViewport to ViewportController
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 04 Dec 2019 17:54:10 +0100
parents a34ba19d2060
children 9ee6b28f53e8
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;
772
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
33 float windowCenter, windowWidth;
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
34 bool hasWindowing = scene.GetWindowing(windowCenter, windowWidth);
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
35 output["hasWindowing"] = hasWindowing;
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
36 if (hasWindowing)
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
37 {
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
38 output["windowCenter"] = windowCenter;
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
39 output["windowWidth"] = windowWidth;
cfb4d39065a4 fix windowing + save windowing
Alain Mazy <alain@mazy.be>
parents: 630
diff changeset
40 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
41 output["layers"] = Json::arrayValue;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
42
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
43 std::vector<size_t> layersIndexes;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
44 scene.GetLayersIndexes(layersIndexes);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
45
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
46 for (std::vector<size_t>::iterator itLayerIndex = layersIndexes.begin(); itLayerIndex < layersIndexes.end(); itLayerIndex++)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
47 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
48 Json::Value layer;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
49 WriteLayer(layer, scene.GetLayer(*itLayerIndex));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
50 output["layers"].append(layer);
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
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
54 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyDicomLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
55 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
56 output["type"] = "dicom";
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
57 output["instanceId"] = layer.GetInstanceId();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
58 output["frame"] = layer.GetFrame();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
59 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
60
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
61 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyTextLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
62 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
63 output["type"] = "text";
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
64 output["text"] = layer.GetText();
1192
91d86144fb79 fix build
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1190
diff changeset
65 output["fontSize"] = static_cast<unsigned int>(layer.GetFontSize());
1190
f417a0ae282b wip: TextLayer with new fonts
Alain Mazy <alain@mazy.be>
parents: 772
diff changeset
66 output["foreground"] = layer.GetForeground();
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
67 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
68
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
69 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyMaskLayer& layer)
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
70 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
71 output["type"] = "mask";
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
72 output["instanceId"] = layer.GetInstanceId(); // the dicom layer it's being linked to
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
73 output["foreground"] = layer.GetForeground();
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
74 output["corners"] = Json::arrayValue;
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
75 const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners = layer.GetCorners();
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
76 for (size_t i = 0; i < corners.size(); i++)
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
77 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
78 Json::Value corner;
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
79 corner["x"] = corners[i].GetX();
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
80 corner["y"] = corners[i].GetY();
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
81 output["corners"].append(corner);
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
82 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
83 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
84
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
85 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
86 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
87 output["type"] = "alpha";
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
88
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
89 //output["bitmap"] =
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
90 const Orthanc::ImageAccessor& alpha = layer.GetAlpha();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
91
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
92 Orthanc::PngWriter pngWriter;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
93 std::string pngContent;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
94 std::string pngContentBase64;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
95 pngWriter.WriteToMemory(pngContent, alpha);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
96
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
97 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
98 output["content"] = pngContentBase64;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
99 output["foreground"] = layer.GetForegroundValue();
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 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
103 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
104 const RadiographyLayer::Geometry& geometry = layer.GetGeometry();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
105
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
106 {// crop
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
107 Json::Value crop;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
108 if (geometry.HasCrop())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
109 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
110 unsigned int x, y, width, height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
111 geometry.GetCrop(x, y, width, height);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
112 crop["hasCrop"] = true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
113 crop["x"] = x;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
114 crop["y"] = y;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
115 crop["width"] = width;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
116 crop["height"] = height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
117 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
118 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
119 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
120 crop["hasCrop"] = false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
121 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
122
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
123 output["crop"] = crop;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
124 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
125
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
126 output["angle"] = geometry.GetAngle();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
127 output["isResizable"] = geometry.IsResizeable();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
128
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
129 {// pan
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
130 Json::Value pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
131 pan["x"] = geometry.GetPanX();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
132 pan["y"] = geometry.GetPanY();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
133 output["pan"] = pan;
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 {// pixelSpacing
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
137 Json::Value pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
138 pan["x"] = geometry.GetPixelSpacingX();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
139 pan["y"] = geometry.GetPixelSpacingY();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
140 output["pixelSpacing"] = pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
141 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
142
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
143 output["flipVertical"] = geometry.GetFlipVertical();
630
Alain Mazy <alain@mazy.be>
parents: 629
diff changeset
144 output["flipHorizontal"] = geometry.GetFlipHorizontal();
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
145
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
146 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
147 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
148 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
149 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
150 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
151 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
152 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
153 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
154 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
155 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
156 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
157 }
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
158 else if (dynamic_cast<const RadiographyMaskLayer*>(&layer) != NULL)
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
159 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
160 WriteLayer(output, dynamic_cast<const RadiographyMaskLayer&>(layer));
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
161 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
162 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
163 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
165 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
166 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
167 }