Mercurial > hg > orthanc-stone
comparison Framework/Radiography/RadiographySceneReader.cpp @ 430:b85f635f1eb5 am-vsol-upgrade
added serialization for RadiographyScene
author | am@osimis.io |
---|---|
date | Thu, 29 Nov 2018 15:11:19 +0100 |
parents | |
children | 8f7220433b59 |
comparison
equal
deleted
inserted
replaced
429:c7fb700a7d12 | 430:b85f635f1eb5 |
---|---|
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 { | |
31 void RadiographySceneReader::Read(const Json::Value& input) | |
32 { | |
33 unsigned int version = input["version"].asUInt(); | |
34 | |
35 if (version != 1) | |
36 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
37 | |
38 for(size_t layerIndex = 0; layerIndex < input["layers"].size(); layerIndex++) | |
39 { | |
40 const Json::Value& jsonLayer = input["layers"][(int)layerIndex]; | |
41 RadiographyLayer::Geometry geometry; | |
42 | |
43 if (jsonLayer["type"].asString() == "dicom") | |
44 { | |
45 ReadLayerGeometry(geometry, jsonLayer); | |
46 scene_.LoadDicomFrame(orthancApiClient_, jsonLayer["instanceId"].asString(), jsonLayer["frame"].asUInt(), true, &geometry); | |
47 } | |
48 else if (jsonLayer["type"].asString() == "text") | |
49 { | |
50 if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0) | |
51 { | |
52 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers. | |
53 } | |
54 | |
55 ReadLayerGeometry(geometry, jsonLayer); | |
56 const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString()); | |
57 if (font == NULL) // if not found, take the first font in the registry | |
58 { | |
59 font = &(fontRegistry_->GetFont(0)); | |
60 } | |
61 scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry); | |
62 } | |
63 else if (jsonLayer["type"].asString() == "alpha") | |
64 { | |
65 ReadLayerGeometry(geometry, jsonLayer); | |
66 | |
67 const std::string& pngContentBase64 = jsonLayer["content"].asString(); | |
68 std::string pngContent; | |
69 std::string mimeType; | |
70 Orthanc::Toolbox::DecodeDataUriScheme(mimeType, pngContent, pngContentBase64); | |
71 | |
72 std::auto_ptr<Orthanc::ImageAccessor> image; | |
73 if (mimeType == "image/png") | |
74 { | |
75 image.reset(new Orthanc::PngReader()); | |
76 dynamic_cast<Orthanc::PngReader*>(image.get())->ReadFromMemory(pngContent); | |
77 } | |
78 else | |
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
80 | |
81 RadiographyAlphaLayer& layer = dynamic_cast<RadiographyAlphaLayer&>(scene_.LoadAlphaBitmap(image.release(), &geometry)); | |
82 | |
83 if (!jsonLayer["isUsingWindowing"].asBool()) | |
84 { | |
85 layer.SetForegroundValue((float)(jsonLayer["foreground"].asDouble())); | |
86 } | |
87 } | |
88 else | |
89 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); | |
90 } | |
91 } | |
92 | |
93 void RadiographySceneReader::ReadLayerGeometry(RadiographyLayer::Geometry& geometry, const Json::Value& jsonLayer) | |
94 { | |
95 {// crop | |
96 unsigned int x, y, width, height; | |
97 if (jsonLayer["crop"]["hasCrop"].asBool()) | |
98 { | |
99 x = jsonLayer["crop"]["x"].asUInt(); | |
100 y = jsonLayer["crop"]["y"].asUInt(); | |
101 width = jsonLayer["crop"]["width"].asUInt(); | |
102 height = jsonLayer["crop"]["height"].asUInt(); | |
103 geometry.SetCrop(x, y, width, height); | |
104 } | |
105 } | |
106 | |
107 geometry.SetAngle(jsonLayer["angle"].asDouble()); | |
108 geometry.SetResizeable(jsonLayer["isResizable"].asBool()); | |
109 geometry.SetPan(jsonLayer["pan"]["x"].asDouble(), jsonLayer["pan"]["y"].asDouble()); | |
110 geometry.SetPixelSpacing(jsonLayer["pixelSpacing"]["x"].asDouble(), jsonLayer["pixelSpacing"]["y"].asDouble()); | |
111 } | |
112 } |