Mercurial > hg > orthanc-stone
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 |
rev | line source |
---|---|
430 | 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; | |
772 | 33 float windowCenter, windowWidth; |
34 bool hasWindowing = scene.GetWindowing(windowCenter, windowWidth); | |
35 output["hasWindowing"] = hasWindowing; | |
36 if (hasWindowing) | |
37 { | |
38 output["windowCenter"] = windowCenter; | |
39 output["windowWidth"] = windowWidth; | |
40 } | |
430 | 41 output["layers"] = Json::arrayValue; |
42 | |
43 std::vector<size_t> layersIndexes; | |
44 scene.GetLayersIndexes(layersIndexes); | |
45 | |
46 for (std::vector<size_t>::iterator itLayerIndex = layersIndexes.begin(); itLayerIndex < layersIndexes.end(); itLayerIndex++) | |
47 { | |
48 Json::Value layer; | |
49 WriteLayer(layer, scene.GetLayer(*itLayerIndex)); | |
50 output["layers"].append(layer); | |
51 } | |
52 } | |
53 | |
54 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyDicomLayer& layer) | |
55 { | |
56 output["type"] = "dicom"; | |
57 output["instanceId"] = layer.GetInstanceId(); | |
58 output["frame"] = layer.GetFrame(); | |
59 } | |
60 | |
61 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyTextLayer& layer) | |
62 { | |
63 output["type"] = "text"; | |
64 output["text"] = layer.GetText(); | |
1192 | 65 output["fontSize"] = static_cast<unsigned int>(layer.GetFontSize()); |
1190 | 66 output["foreground"] = layer.GetForeground(); |
430 | 67 } |
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 | 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 | 79 corner["x"] = corners[i].GetX(); |
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 | 85 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer) |
86 { | |
87 output["type"] = "alpha"; | |
88 | |
89 //output["bitmap"] = | |
90 const Orthanc::ImageAccessor& alpha = layer.GetAlpha(); | |
91 | |
92 Orthanc::PngWriter pngWriter; | |
93 std::string pngContent; | |
94 std::string pngContentBase64; | |
95 pngWriter.WriteToMemory(pngContent, alpha); | |
96 | |
97 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent); | |
98 output["content"] = pngContentBase64; | |
99 output["foreground"] = layer.GetForegroundValue(); | |
100 } | |
101 | |
102 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer) | |
103 { | |
104 const RadiographyLayer::Geometry& geometry = layer.GetGeometry(); | |
105 | |
106 {// crop | |
107 Json::Value crop; | |
108 if (geometry.HasCrop()) | |
109 { | |
110 unsigned int x, y, width, height; | |
111 geometry.GetCrop(x, y, width, height); | |
112 crop["hasCrop"] = true; | |
113 crop["x"] = x; | |
114 crop["y"] = y; | |
115 crop["width"] = width; | |
116 crop["height"] = height; | |
117 } | |
118 else | |
119 { | |
120 crop["hasCrop"] = false; | |
121 } | |
122 | |
123 output["crop"] = crop; | |
124 } | |
125 | |
126 output["angle"] = geometry.GetAngle(); | |
127 output["isResizable"] = geometry.IsResizeable(); | |
128 | |
129 {// pan | |
130 Json::Value pan; | |
131 pan["x"] = geometry.GetPanX(); | |
132 pan["y"] = geometry.GetPanY(); | |
133 output["pan"] = pan; | |
134 } | |
135 | |
136 {// pixelSpacing | |
137 Json::Value pan; | |
138 pan["x"] = geometry.GetPixelSpacingX(); | |
139 pan["y"] = geometry.GetPixelSpacingY(); | |
140 output["pixelSpacing"] = pan; | |
141 } | |
142 | |
629 | 143 output["flipVertical"] = geometry.GetFlipVertical(); |
630 | 144 output["flipHorizontal"] = geometry.GetFlipHorizontal(); |
620 | 145 |
430 | 146 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL) |
147 { | |
148 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer)); | |
149 } | |
150 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL) | |
151 { | |
152 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer)); | |
153 } | |
154 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL) | |
155 { | |
156 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer)); | |
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 | 162 else |
163 { | |
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
165 } | |
166 } | |
167 } |