Mercurial > hg > orthanc-stone
annotate Framework/Radiography/RadiographySceneReader.cpp @ 598:a806abb497b8
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 17:57:57 +0200 |
parents | 92305ee35b1c |
children | fd9b9d993fc7 200f7e1d57d1 |
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 "RadiographySceneReader.h" | |
23 | |
24 #include <Core/Images/FontRegistry.h> | |
25 #include <Core/Images/PngReader.h> | |
26 #include <Core/OrthancException.h> | |
27 #include <Core/Toolbox.h> | |
28 | |
29 namespace OrthancStone | |
30 { | |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
31 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
32 void RadiographySceneBuilder::Read(const Json::Value& input, Orthanc::ImageAccessor* dicomImage /* takes ownership */, |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
33 DicomFrameConverter* dicomFrameConverter /* takes ownership */, |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
34 PhotometricDisplayMode preferredPhotometricDisplayMode |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
35 ) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
36 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
37 dicomImage_.reset(dicomImage); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
38 dicomFrameConverter_.reset(dicomFrameConverter); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
39 preferredPhotometricDisplayMode_ = preferredPhotometricDisplayMode; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
40 Read(input); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
41 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
42 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
43 RadiographyDicomLayer* RadiographySceneBuilder::LoadDicom(const std::string& instanceId, unsigned int frame, RadiographyLayer::Geometry* geometry) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
44 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
45 return dynamic_cast<RadiographyDicomLayer*>(&(scene_.LoadDicomImage(dicomImage_.release(), instanceId, frame, dicomFrameConverter_.release(), preferredPhotometricDisplayMode_, geometry))); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
46 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
47 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
48 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
49 RadiographyDicomLayer* RadiographySceneReader::LoadDicom(const std::string& instanceId, unsigned int frame, RadiographyLayer::Geometry* geometry) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
50 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
51 return dynamic_cast<RadiographyDicomLayer*>(&(scene_.LoadDicomFrame(orthancApiClient_, instanceId, frame, false, geometry))); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
52 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
53 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
54 void RadiographySceneBuilder::Read(const Json::Value& input) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
55 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
56 unsigned int version = input["version"].asUInt(); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
57 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
58 if (version != 1) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
59 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
60 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
61 RadiographyDicomLayer* dicomLayer = NULL; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
62 for(size_t layerIndex = 0; layerIndex < input["layers"].size(); layerIndex++) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
63 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
64 const Json::Value& jsonLayer = input["layers"][(int)layerIndex]; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
65 RadiographyLayer::Geometry geometry; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
66 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
67 if (jsonLayer["type"].asString() == "dicom") |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
68 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
69 ReadLayerGeometry(geometry, jsonLayer); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
70 dicomLayer = LoadDicom(jsonLayer["instanceId"].asString(), jsonLayer["frame"].asUInt(), &geometry); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
71 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
72 else if (jsonLayer["type"].asString() == "mask") |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
73 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
74 if (dicomLayer == NULL) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
75 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
76 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // we always assumed the dicom layer was read before the mask |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
77 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
78 ReadLayerGeometry(geometry, jsonLayer); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
79 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
80 float foreground = jsonLayer["foreground"].asFloat(); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
81 std::vector<Orthanc::ImageProcessing::ImagePoint> corners; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
82 for (size_t i = 0; i < jsonLayer["corners"].size(); i++) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
83 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
84 Orthanc::ImageProcessing::ImagePoint corner(jsonLayer["corners"][(int)i]["x"].asInt(), |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
85 jsonLayer["corners"][(int)i]["y"].asInt()); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
86 corners.push_back(corner); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
87 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
88 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
89 scene_.LoadMask(corners, *dicomLayer, foreground, &geometry); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
90 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
91 else if (jsonLayer["type"].asString() == "text") |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
92 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
93 if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
94 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers. |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
96 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
97 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
98 ReadLayerGeometry(geometry, jsonLayer); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
99 const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString()); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
100 if (font == NULL) // if not found, take the first font in the registry |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
101 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
102 font = &(fontRegistry_->GetFont(0)); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
103 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
104 scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
105 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
106 else if (jsonLayer["type"].asString() == "alpha") |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
107 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
108 ReadLayerGeometry(geometry, jsonLayer); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
109 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
110 const std::string& pngContentBase64 = jsonLayer["content"].asString(); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
111 std::string pngContent; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
112 std::string mimeType; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
113 Orthanc::Toolbox::DecodeDataUriScheme(mimeType, pngContent, pngContentBase64); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
114 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
115 std::auto_ptr<Orthanc::ImageAccessor> image; |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
116 if (mimeType == "image/png") |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
117 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
118 image.reset(new Orthanc::PngReader()); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
119 dynamic_cast<Orthanc::PngReader*>(image.get())->ReadFromMemory(pngContent); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
120 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
121 else |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
123 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
124 RadiographyAlphaLayer& layer = dynamic_cast<RadiographyAlphaLayer&>(scene_.LoadAlphaBitmap(image.release(), &geometry)); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
125 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
126 if (!jsonLayer["isUsingWindowing"].asBool()) |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
127 { |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
128 layer.SetForegroundValue((float)(jsonLayer["foreground"].asDouble())); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
129 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
130 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
131 else |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
132 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
133 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
134 } |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
135 |
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
136 |
430 | 137 void RadiographySceneReader::Read(const Json::Value& input) |
138 { | |
139 unsigned int version = input["version"].asUInt(); | |
140 | |
141 if (version != 1) | |
142 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
143 | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
144 RadiographyDicomLayer* dicomLayer = NULL; |
430 | 145 for(size_t layerIndex = 0; layerIndex < input["layers"].size(); layerIndex++) |
146 { | |
147 const Json::Value& jsonLayer = input["layers"][(int)layerIndex]; | |
148 RadiographyLayer::Geometry geometry; | |
149 | |
150 if (jsonLayer["type"].asString() == "dicom") | |
151 { | |
152 ReadLayerGeometry(geometry, jsonLayer); | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
153 dicomLayer = dynamic_cast<RadiographyDicomLayer*>(&(scene_.LoadDicomFrame(orthancApiClient_, jsonLayer["instanceId"].asString(), jsonLayer["frame"].asUInt(), false, &geometry))); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
154 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
155 else if (jsonLayer["type"].asString() == "mask") |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
156 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
157 if (dicomLayer == NULL) |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
158 { |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // we always assumed the dicom layer was read before the mask |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
160 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
161 ReadLayerGeometry(geometry, jsonLayer); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
162 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
163 float foreground = jsonLayer["foreground"].asFloat(); |
488 | 164 std::vector<Orthanc::ImageProcessing::ImagePoint> corners; |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
165 for (size_t i = 0; i < jsonLayer["corners"].size(); i++) |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
166 { |
488 | 167 Orthanc::ImageProcessing::ImagePoint corner(jsonLayer["corners"][(int)i]["x"].asInt(), |
168 jsonLayer["corners"][(int)i]["y"].asInt()); | |
481
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
169 corners.push_back(corner); |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
170 } |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
171 |
159a465e27bd
reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents:
437
diff
changeset
|
172 scene_.LoadMask(corners, *dicomLayer, foreground, &geometry); |
430 | 173 } |
174 else if (jsonLayer["type"].asString() == "text") | |
175 { | |
176 if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0) | |
177 { | |
178 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers. | |
179 } | |
180 | |
181 ReadLayerGeometry(geometry, jsonLayer); | |
182 const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString()); | |
183 if (font == NULL) // if not found, take the first font in the registry | |
184 { | |
185 font = &(fontRegistry_->GetFont(0)); | |
186 } | |
187 scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry); | |
188 } | |
189 else if (jsonLayer["type"].asString() == "alpha") | |
190 { | |
191 ReadLayerGeometry(geometry, jsonLayer); | |
192 | |
193 const std::string& pngContentBase64 = jsonLayer["content"].asString(); | |
194 std::string pngContent; | |
195 std::string mimeType; | |
196 Orthanc::Toolbox::DecodeDataUriScheme(mimeType, pngContent, pngContentBase64); | |
197 | |
198 std::auto_ptr<Orthanc::ImageAccessor> image; | |
199 if (mimeType == "image/png") | |
200 { | |
201 image.reset(new Orthanc::PngReader()); | |
202 dynamic_cast<Orthanc::PngReader*>(image.get())->ReadFromMemory(pngContent); | |
203 } | |
204 else | |
205 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
206 | |
207 RadiographyAlphaLayer& layer = dynamic_cast<RadiographyAlphaLayer&>(scene_.LoadAlphaBitmap(image.release(), &geometry)); | |
208 | |
209 if (!jsonLayer["isUsingWindowing"].asBool()) | |
210 { | |
211 layer.SetForegroundValue((float)(jsonLayer["foreground"].asDouble())); | |
212 } | |
213 } | |
214 else | |
215 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
216 } | |
217 } | |
218 | |
553
92305ee35b1c
web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents:
488
diff
changeset
|
219 void RadiographySceneBuilder::ReadLayerGeometry(RadiographyLayer::Geometry& geometry, const Json::Value& jsonLayer) |
430 | 220 { |
221 {// crop | |
222 unsigned int x, y, width, height; | |
223 if (jsonLayer["crop"]["hasCrop"].asBool()) | |
224 { | |
225 x = jsonLayer["crop"]["x"].asUInt(); | |
226 y = jsonLayer["crop"]["y"].asUInt(); | |
227 width = jsonLayer["crop"]["width"].asUInt(); | |
228 height = jsonLayer["crop"]["height"].asUInt(); | |
229 geometry.SetCrop(x, y, width, height); | |
230 } | |
231 } | |
232 | |
233 geometry.SetAngle(jsonLayer["angle"].asDouble()); | |
234 geometry.SetResizeable(jsonLayer["isResizable"].asBool()); | |
235 geometry.SetPan(jsonLayer["pan"]["x"].asDouble(), jsonLayer["pan"]["y"].asDouble()); | |
236 geometry.SetPixelSpacing(jsonLayer["pixelSpacing"]["x"].asDouble(), jsonLayer["pixelSpacing"]["y"].asDouble()); | |
237 } | |
238 } |