Mercurial > hg > orthanc-stone
comparison OrthancStone/Sources/Deprecated/Radiography/RadiographySceneWriter.cpp @ 1512:244ad1e4e76a
reorganization of folders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 07 Jul 2020 16:21:02 +0200 |
parents | Framework/Deprecated/Radiography/RadiographySceneWriter.cpp@30deba7bc8e2 |
children |
comparison
equal
deleted
inserted
replaced
1511:9dfeee74c1e6 | 1512:244ad1e4e76a |
---|---|
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-2020 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 <OrthancException.h> | |
25 #include <Images/PngWriter.h> | |
26 #include <Toolbox.h> | |
27 | |
28 namespace OrthancStone | |
29 { | |
30 void RadiographySceneWriter::Write(Json::Value& output, const RadiographyScene& scene) | |
31 { | |
32 output["version"] = 1; | |
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 } | |
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(); | |
65 output["font"] = layer.GetFont(); | |
66 output["fontSize"] = layer.GetFontSize(); | |
67 output["foreground"] = layer.GetForegroundGreyLevel(); | |
68 } | |
69 | |
70 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyMaskLayer& layer) | |
71 { | |
72 output["type"] = "mask"; | |
73 output["instanceId"] = layer.GetInstanceId(); // the dicom layer it's being linked to | |
74 output["foreground"] = layer.GetForeground(); | |
75 output["corners"] = Json::arrayValue; | |
76 const std::vector<Orthanc::ImageProcessing::ImagePoint>& corners = layer.GetCorners(); | |
77 for (size_t i = 0; i < corners.size(); i++) | |
78 { | |
79 Json::Value corner; | |
80 corner["x"] = corners[i].GetX(); | |
81 corner["y"] = corners[i].GetY(); | |
82 output["corners"].append(corner); | |
83 } | |
84 } | |
85 | |
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 | |
144 output["flipVertical"] = geometry.GetFlipVertical(); | |
145 output["flipHorizontal"] = geometry.GetFlipHorizontal(); | |
146 | |
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 } | |
159 else if (dynamic_cast<const RadiographyMaskLayer*>(&layer) != NULL) | |
160 { | |
161 WriteLayer(output, dynamic_cast<const RadiographyMaskLayer&>(layer)); | |
162 } | |
163 else | |
164 { | |
165 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
166 } | |
167 } | |
168 } |