Mercurial > hg > orthanc-stone
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 |
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(); | |
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 | 68 } |
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 | 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 | 80 corner["x"] = corners[i].GetX(); |
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 | 86 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer) |
87 { | |
88 output["type"] = "alpha"; | |
89 | |
90 //output["bitmap"] = | |
91 const Orthanc::ImageAccessor& alpha = layer.GetAlpha(); | |
92 | |
93 Orthanc::PngWriter pngWriter; | |
94 std::string pngContent; | |
95 std::string pngContentBase64; | |
96 pngWriter.WriteToMemory(pngContent, alpha); | |
97 | |
98 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent); | |
99 output["content"] = pngContentBase64; | |
100 output["foreground"] = layer.GetForegroundValue(); | |
101 } | |
102 | |
103 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer) | |
104 { | |
105 const RadiographyLayer::Geometry& geometry = layer.GetGeometry(); | |
106 | |
107 {// crop | |
108 Json::Value crop; | |
109 if (geometry.HasCrop()) | |
110 { | |
111 unsigned int x, y, width, height; | |
112 geometry.GetCrop(x, y, width, height); | |
113 crop["hasCrop"] = true; | |
114 crop["x"] = x; | |
115 crop["y"] = y; | |
116 crop["width"] = width; | |
117 crop["height"] = height; | |
118 } | |
119 else | |
120 { | |
121 crop["hasCrop"] = false; | |
122 } | |
123 | |
124 output["crop"] = crop; | |
125 } | |
126 | |
127 output["angle"] = geometry.GetAngle(); | |
128 output["isResizable"] = geometry.IsResizeable(); | |
129 | |
130 {// pan | |
131 Json::Value pan; | |
132 pan["x"] = geometry.GetPanX(); | |
133 pan["y"] = geometry.GetPanY(); | |
134 output["pan"] = pan; | |
135 } | |
136 | |
137 {// pixelSpacing | |
138 Json::Value pan; | |
139 pan["x"] = geometry.GetPixelSpacingX(); | |
140 pan["y"] = geometry.GetPixelSpacingY(); | |
141 output["pixelSpacing"] = pan; | |
142 } | |
143 | |
629 | 144 output["flipVertical"] = geometry.GetFlipVertical(); |
630 | 145 output["flipHorizontal"] = geometry.GetFlipHorizontal(); |
620 | 146 |
430 | 147 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL) |
148 { | |
149 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer)); | |
150 } | |
151 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL) | |
152 { | |
153 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer)); | |
154 } | |
155 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL) | |
156 { | |
157 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer)); | |
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 | 163 else |
164 { | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
166 } | |
167 } | |
168 } |