Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographySceneWriter.cpp @ 739:be9c1530d40a
deprecating enum SliceImageQuality
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 22 May 2019 09:13:04 +0200 |
parents | 0c5398c3b994 |
children | cfb4d39065a4 |
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; | |
33 output["layers"] = Json::arrayValue; | |
34 | |
35 std::vector<size_t> layersIndexes; | |
36 scene.GetLayersIndexes(layersIndexes); | |
37 | |
38 for (std::vector<size_t>::iterator itLayerIndex = layersIndexes.begin(); itLayerIndex < layersIndexes.end(); itLayerIndex++) | |
39 { | |
40 Json::Value layer; | |
41 WriteLayer(layer, scene.GetLayer(*itLayerIndex)); | |
42 output["layers"].append(layer); | |
43 } | |
44 } | |
45 | |
46 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyDicomLayer& layer) | |
47 { | |
48 output["type"] = "dicom"; | |
49 output["instanceId"] = layer.GetInstanceId(); | |
50 output["frame"] = layer.GetFrame(); | |
51 } | |
52 | |
53 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyTextLayer& layer) | |
54 { | |
55 output["type"] = "text"; | |
56 output["text"] = layer.GetText(); | |
57 output["fontName"] = layer.GetFontName(); | |
58 } | |
59 | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
60 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
|
61 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
62 output["type"] = "mask"; |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
63 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
|
64 output["foreground"] = layer.GetForeground(); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
65 output["corners"] = Json::arrayValue; |
488 | 66 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
|
67 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
|
68 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
69 Json::Value corner; |
488 | 70 corner["x"] = corners[i].GetX(); |
71 corner["y"] = corners[i].GetY(); | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
72 output["corners"].append(corner); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
73 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
74 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
75 |
430 | 76 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyAlphaLayer& layer) |
77 { | |
78 output["type"] = "alpha"; | |
79 | |
80 //output["bitmap"] = | |
81 const Orthanc::ImageAccessor& alpha = layer.GetAlpha(); | |
82 | |
83 Orthanc::PngWriter pngWriter; | |
84 std::string pngContent; | |
85 std::string pngContentBase64; | |
86 pngWriter.WriteToMemory(pngContent, alpha); | |
87 | |
88 Orthanc::Toolbox::EncodeDataUriScheme(pngContentBase64, "image/png", pngContent); | |
89 output["content"] = pngContentBase64; | |
90 output["foreground"] = layer.GetForegroundValue(); | |
91 output["isUsingWindowing"] = layer.IsUsingWindowing(); | |
92 } | |
93 | |
94 void RadiographySceneWriter::WriteLayer(Json::Value& output, const RadiographyLayer& layer) | |
95 { | |
96 const RadiographyLayer::Geometry& geometry = layer.GetGeometry(); | |
97 | |
98 {// crop | |
99 Json::Value crop; | |
100 if (geometry.HasCrop()) | |
101 { | |
102 unsigned int x, y, width, height; | |
103 geometry.GetCrop(x, y, width, height); | |
104 crop["hasCrop"] = true; | |
105 crop["x"] = x; | |
106 crop["y"] = y; | |
107 crop["width"] = width; | |
108 crop["height"] = height; | |
109 } | |
110 else | |
111 { | |
112 crop["hasCrop"] = false; | |
113 } | |
114 | |
115 output["crop"] = crop; | |
116 } | |
117 | |
118 output["angle"] = geometry.GetAngle(); | |
119 output["isResizable"] = geometry.IsResizeable(); | |
120 | |
121 {// pan | |
122 Json::Value pan; | |
123 pan["x"] = geometry.GetPanX(); | |
124 pan["y"] = geometry.GetPanY(); | |
125 output["pan"] = pan; | |
126 } | |
127 | |
128 {// pixelSpacing | |
129 Json::Value pan; | |
130 pan["x"] = geometry.GetPixelSpacingX(); | |
131 pan["y"] = geometry.GetPixelSpacingY(); | |
132 output["pixelSpacing"] = pan; | |
133 } | |
134 | |
629 | 135 output["flipVertical"] = geometry.GetFlipVertical(); |
630 | 136 output["flipHorizontal"] = geometry.GetFlipHorizontal(); |
620 | 137 |
430 | 138 if (dynamic_cast<const RadiographyTextLayer*>(&layer) != NULL) |
139 { | |
140 WriteLayer(output, dynamic_cast<const RadiographyTextLayer&>(layer)); | |
141 } | |
142 else if (dynamic_cast<const RadiographyDicomLayer*>(&layer) != NULL) | |
143 { | |
144 WriteLayer(output, dynamic_cast<const RadiographyDicomLayer&>(layer)); | |
145 } | |
146 else if (dynamic_cast<const RadiographyAlphaLayer*>(&layer) != NULL) | |
147 { | |
148 WriteLayer(output, dynamic_cast<const RadiographyAlphaLayer&>(layer)); | |
149 } | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
150 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
|
151 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
430
diff
changeset
|
152 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
|
153 } |
430 | 154 else |
155 { | |
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
157 } | |
158 } | |
159 } |