annotate Framework/Radiography/RadiographySceneReader.cpp @ 869:60a403f01c31 toa2019062503

Fixed WARN --> WARNING (unsure how this builds fine under Windows...)
author Benjamin Golinvaux <bgo@osimis.io>
date Tue, 25 Jun 2019 18:04:54 +0200
parents be9c1530d40a
children 238693c3bc51
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
1 /**
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
2 * Stone of Orthanc
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
6 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
10 * the License, or (at your option) any later version.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
11 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
15 * Affero General Public License for more details.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
16 *
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
19 **/
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
20
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
21
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
22 #include "RadiographySceneReader.h"
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
23
732
c35e98d22764 move Deprecated classes to a separate folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 714
diff changeset
24 #include "../Deprecated/Toolbox/DicomFrameConverter.h"
650
200f7e1d57d1 Moved RadiographyDicomLayer::SetDicomFrameConverter to cpp file to prevent
Benjamin Golinvaux <bgo@osimis.io>
parents: 553
diff changeset
25
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
26 #include <Core/Images/FontRegistry.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
27 #include <Core/Images/PngReader.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
28 #include <Core/OrthancException.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
29 #include <Core/Toolbox.h>
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
30
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
31 namespace OrthancStone
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
32 {
553
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
33
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
34 void RadiographySceneBuilder::Read(const Json::Value& input, Orthanc::ImageAccessor* dicomImage /* takes ownership */,
714
d2c0e347ddc2 deprecating DicomFrameConverter
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 658
diff changeset
35 Deprecated::DicomFrameConverter* dicomFrameConverter /* takes ownership */,
739
be9c1530d40a deprecating enum SliceImageQuality
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 732
diff changeset
36 RadiographyPhotometricDisplayMode preferredPhotometricDisplayMode
553
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
37 )
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
38 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
39 dicomImage_.reset(dicomImage);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
40 dicomFrameConverter_.reset(dicomFrameConverter);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
41 preferredPhotometricDisplayMode_ = preferredPhotometricDisplayMode;
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
42 Read(input);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
43 }
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 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
46 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
47 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
48 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
49
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 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
52 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
53 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
54 }
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 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
57 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
58 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
59
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
60 if (version != 1)
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
61 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
62
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
63 RadiographyDicomLayer* dicomLayer = NULL;
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
64 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
65 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
66 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
67 RadiographyLayer::Geometry geometry;
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 if (jsonLayer["type"].asString() == "dicom")
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
70 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
71 ReadLayerGeometry(geometry, jsonLayer);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
72 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
73 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
74 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
75 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
76 if (dicomLayer == NULL)
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 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
79 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
80 ReadLayerGeometry(geometry, jsonLayer);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
81
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
82 float foreground = jsonLayer["foreground"].asFloat();
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
83 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
84 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
85 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
86 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
87 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
88 corners.push_back(corner);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
89 }
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 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
92 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
93 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
94 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
95 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
96 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
97 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
98 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
99
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
100 ReadLayerGeometry(geometry, jsonLayer);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
101 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
102 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
103 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
104 font = &(fontRegistry_->GetFont(0));
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 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
107 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
108 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
109 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
110 ReadLayerGeometry(geometry, jsonLayer);
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
111
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
112 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
113 std::string pngContent;
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
114 std::string mimeType;
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
115 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
116
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
117 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
118 if (mimeType == "image/png")
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
119 {
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
120 image.reset(new Orthanc::PngReader());
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
121 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
122 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
123 else
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
124 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
125
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
126 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
127
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
128 if (!jsonLayer["isUsingWindowing"].asBool())
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 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
131 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
132 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
133 else
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
134 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
135 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
136 }
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
137
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
138
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
139 void RadiographySceneReader::Read(const Json::Value& input)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
140 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
141 unsigned int version = input["version"].asUInt();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
142
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
143 if (version != 1)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
144 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
145
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
146 RadiographyDicomLayer* dicomLayer = NULL;
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
147 for(size_t layerIndex = 0; layerIndex < input["layers"].size(); layerIndex++)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
148 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
149 const Json::Value& jsonLayer = input["layers"][(int)layerIndex];
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
150 RadiographyLayer::Geometry geometry;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
151
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
152 if (jsonLayer["type"].asString() == "dicom")
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
153 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
154 ReadLayerGeometry(geometry, jsonLayer);
481
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
155 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
156 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
157 else if (jsonLayer["type"].asString() == "mask")
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 if (dicomLayer == NULL)
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 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
162 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
163 ReadLayerGeometry(geometry, jsonLayer);
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
164
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
165 float foreground = jsonLayer["foreground"].asFloat();
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
166 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
167 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
168 {
488
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
169 Orthanc::ImageProcessing::ImagePoint corner(jsonLayer["corners"][(int)i]["x"].asInt(),
aede9b042cb7 now using ImageProcessing::FillPolygon
am@osimis.io
parents: 481
diff changeset
170 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
171 corners.push_back(corner);
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
172 }
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
173
159a465e27bd reworked RadiographyScene export to export to an Orthanc::Image too
am@osimis.io
parents: 437
diff changeset
174 scene_.LoadMask(corners, *dicomLayer, foreground, &geometry);
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
175 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
176 else if (jsonLayer["type"].asString() == "text")
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
177 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
178 if (fontRegistry_ == NULL || fontRegistry_->GetSize() == 0)
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
179 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); // you must provide a FontRegistry if you need to re-create text layers.
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
181 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
182
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
183 ReadLayerGeometry(geometry, jsonLayer);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
184 const Orthanc::Font* font = fontRegistry_->FindFont(jsonLayer["fontName"].asString());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
185 if (font == NULL) // if not found, take the first font in the registry
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
186 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
187 font = &(fontRegistry_->GetFont(0));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
188 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
189 scene_.LoadText(*font, jsonLayer["text"].asString(), &geometry);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
190 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
191 else if (jsonLayer["type"].asString() == "alpha")
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
192 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
193 ReadLayerGeometry(geometry, jsonLayer);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
194
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
195 const std::string& pngContentBase64 = jsonLayer["content"].asString();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
196 std::string pngContent;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
197 std::string mimeType;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
198 Orthanc::Toolbox::DecodeDataUriScheme(mimeType, pngContent, pngContentBase64);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
199
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
200 std::auto_ptr<Orthanc::ImageAccessor> image;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
201 if (mimeType == "image/png")
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
202 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
203 image.reset(new Orthanc::PngReader());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
204 dynamic_cast<Orthanc::PngReader*>(image.get())->ReadFromMemory(pngContent);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
205 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
206 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
207 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
208
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
209 RadiographyAlphaLayer& layer = dynamic_cast<RadiographyAlphaLayer&>(scene_.LoadAlphaBitmap(image.release(), &geometry));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
210
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
211 if (!jsonLayer["isUsingWindowing"].asBool())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
212 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
213 layer.SetForegroundValue((float)(jsonLayer["foreground"].asDouble()));
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
214 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
215 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
216 else
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
217 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
218 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
219 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
220
553
92305ee35b1c web-worker consequences: give access to lower level data
Alain Mazy <alain@mazy.be>
parents: 488
diff changeset
221 void RadiographySceneBuilder::ReadLayerGeometry(RadiographyLayer::Geometry& geometry, const Json::Value& jsonLayer)
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
222 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
223 {// crop
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
224 unsigned int x, y, width, height;
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
225 if (jsonLayer["crop"]["hasCrop"].asBool())
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
226 {
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
227 x = jsonLayer["crop"]["x"].asUInt();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
228 y = jsonLayer["crop"]["y"].asUInt();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
229 width = jsonLayer["crop"]["width"].asUInt();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
230 height = jsonLayer["crop"]["height"].asUInt();
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
231 geometry.SetCrop(x, y, width, height);
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
232 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
233 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
234
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
235 geometry.SetAngle(jsonLayer["angle"].asDouble());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
236 geometry.SetResizeable(jsonLayer["isResizable"].asBool());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
237 geometry.SetPan(jsonLayer["pan"]["x"].asDouble(), jsonLayer["pan"]["y"].asDouble());
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
238 geometry.SetPixelSpacing(jsonLayer["pixelSpacing"]["x"].asDouble(), jsonLayer["pixelSpacing"]["y"].asDouble());
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
239
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
240 // these fields were introduced later -> they might not exist
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
241 if (jsonLayer.isMember("flipVertical"))
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
242 {
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
243 geometry.SetFlipVertical(jsonLayer["flipVertical"].asBool());
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
244 }
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
245 if (jsonLayer.isMember("flipHorizontal"))
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
246 {
629
Alain Mazy <alain@mazy.be>
parents: 620
diff changeset
247 geometry.SetFlipHorizontal(jsonLayer["flipHorizontal"].asBool());
620
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
248 }
fd9b9d993fc7 added flip to RadiographyLayer
Alain Mazy <alain@mazy.be>
parents: 553
diff changeset
249
430
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
250 }
b85f635f1eb5 added serialization for RadiographyScene
am@osimis.io
parents:
diff changeset
251 }