annotate Framework/Radiography/RadiographySceneWriter.cpp @ 1236:358461330978 broker

global function GetWebGLViewportsRegistry()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 09 Dec 2019 20:45:47 +0100
parents 9ee6b28f53e8
children 1c7ae79c426d
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();
1220
9ee6b28f53e8 RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents: 1197
diff changeset
65 output["font"] = layer.GetFont();
9ee6b28f53e8 RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents: 1197
diff changeset
66 output["fontSize"] = layer.GetFontSize();
9ee6b28f53e8 RadiographyTextLayer: support multiple fonts
Alain Mazy <alain@mazy.be>
parents: 1197
diff changeset
67 output["foreground"] = layer.GetForegroundGreyLevel();
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
68 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
69
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
70 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
71 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
72 output["type"] = "mask";
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
73 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
74 output["foreground"] = layer.GetForeground();
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
75 output["corners"] = Json::arrayValue;
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
76 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
77 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
78 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
79 Json::Value corner;
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
80 corner["x"] = corners[i].GetX();
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
81 corner["y"] = corners[i].GetY();
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
82 output["corners"].append(corner);
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 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
85
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
86 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
87 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
88 output["type"] = "alpha";
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
89
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
90 //output["bitmap"] =
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
91 const Orthanc::ImageAccessor& alpha = layer.GetAlpha();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
92
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
93 Orthanc::PngWriter pngWriter;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
94 std::string pngContent;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
95 std::string pngContentBase64;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
96 pngWriter.WriteToMemory(pngContent, alpha);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
97
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
98 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
99 output["content"] = pngContentBase64;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
100 output["foreground"] = layer.GetForegroundValue();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
101 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
102
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
103 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
104 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
105 const RadiographyLayer::Geometry& geometry = layer.GetGeometry();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
106
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
107 {// crop
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
108 Json::Value crop;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
109 if (geometry.HasCrop())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
110 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
111 unsigned int x, y, width, height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
112 geometry.GetCrop(x, y, width, height);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
113 crop["hasCrop"] = true;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
114 crop["x"] = x;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
115 crop["y"] = y;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
116 crop["width"] = width;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
117 crop["height"] = height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
118 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
119 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
120 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
121 crop["hasCrop"] = false;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
122 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
123
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
124 output["crop"] = crop;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
125 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
126
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
127 output["angle"] = geometry.GetAngle();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
128 output["isResizable"] = geometry.IsResizeable();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
129
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
130 {// pan
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
131 Json::Value pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
132 pan["x"] = geometry.GetPanX();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
133 pan["y"] = geometry.GetPanY();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
134 output["pan"] = pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
135 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
136
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
137 {// pixelSpacing
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
138 Json::Value pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
139 pan["x"] = geometry.GetPixelSpacingX();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
140 pan["y"] = geometry.GetPixelSpacingY();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
141 output["pixelSpacing"] = pan;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
142 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
143
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
144 output["flipVertical"] = geometry.GetFlipVertical();
630
Alain Mazy <alain@mazy.be>
parents: 629
diff changeset
145 output["flipHorizontal"] = geometry.GetFlipHorizontal();
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
146
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
147 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
148 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
149 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
150 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
151 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
152 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
153 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
154 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
155 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
156 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
157 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
158 }
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
159 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
160 {
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 430
diff changeset
161 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
162 }
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
163 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
164 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
166 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
167 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
168 }