annotate Framework/Radiography/RadiographyScene.cpp @ 412:71c16998fcc8

fix msvc
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 12 Nov 2018 16:29:36 +0100
parents 6decc0ba9da5
children aee3d7941c9b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "RadiographyScene.h"
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "../Toolbox/DicomFrameConverter.h"
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <Core/Images/Image.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <Core/Images/ImageProcessing.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <Core/Images/PamReader.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <Core/Images/PamWriter.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include <Core/Images/PngWriter.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <Core/OrthancException.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #include <Core/Toolbox.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <Plugins/Samples/Common/DicomDatasetReader.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <Plugins/Samples/Common/FullOrthancDataset.h>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35
412
71c16998fcc8 fix msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 410
diff changeset
36 #include <boost/math/special_functions/round.hpp>
71c16998fcc8 fix msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 410
diff changeset
37
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancStone
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 RadiographyScene::LayerAccessor::LayerAccessor(RadiographyScene& scene,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 size_t index) :
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 scene_(scene),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 index_(index)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 Layers::iterator layer = scene.layers_.find(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 if (layer == scene.layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 layer_ = NULL;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 assert(layer->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 layer_ = layer->second;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 RadiographyScene::LayerAccessor::LayerAccessor(RadiographyScene& scene,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 double x,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 double y) :
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 scene_(scene),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 index_(0) // Dummy initialization
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 if (scene.LookupLayer(index_, x, y))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 Layers::iterator layer = scene.layers_.find(index_);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 if (layer == scene.layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 assert(layer->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 layer_ = layer->second;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 layer_ = NULL;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 RadiographyScene& RadiographyScene::LayerAccessor::GetScene() const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 if (IsValid())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 return scene_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 size_t RadiographyScene::LayerAccessor::GetIndex() const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 if (IsValid())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 return index_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
112 RadiographyLayer& RadiographyScene::LayerAccessor::GetLayer() const
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 if (IsValid())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 return *layer_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
126 class RadiographyScene::AlphaLayer : public RadiographyLayer
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 private:
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 const RadiographyScene& scene_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 std::auto_ptr<Orthanc::ImageAccessor> alpha_; // Grayscale8
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 bool useWindowing_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 float foreground_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 public:
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 AlphaLayer(const RadiographyScene& scene) :
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 scene_(scene),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 useWindowing_(true),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 foreground_(0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 void SetForegroundValue(float foreground)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 useWindowing_ = false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 foreground_ = foreground;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 void SetAlpha(Orthanc::ImageAccessor* image)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 if (image == NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 if (image->GetFormat() != Orthanc::PixelFormat_Grayscale8)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 SetSize(image->GetWidth(), image->GetHeight());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 alpha_ = raii;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 void LoadText(const Orthanc::Font& font,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 const std::string& utf8)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 SetAlpha(font.RenderAlpha(utf8));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176 virtual bool GetDefaultWindowing(float& center,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 float& width) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 virtual void Render(Orthanc::ImageAccessor& buffer,
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
184 const AffineTransform2D& viewTransform,
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 ImageInterpolation interpolation) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 if (alpha_.get() == NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 return;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 if (buffer.GetFormat() != Orthanc::PixelFormat_Float32)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 unsigned int cropX, cropY, cropWidth, cropHeight;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 GetCrop(cropX, cropY, cropWidth, cropHeight);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
200 const AffineTransform2D t = AffineTransform2D::Combine(
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
201 viewTransform, GetTransform(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
202 AffineTransform2D::CreateOffset(cropX, cropY));
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 Orthanc::ImageAccessor cropped;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 alpha_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 Orthanc::Image tmp(Orthanc::PixelFormat_Grayscale8, buffer.GetWidth(), buffer.GetHeight(), false);
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
208
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
209 t.Apply(tmp, cropped, interpolation, true /* clear */);
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 // Blit
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212 const unsigned int width = buffer.GetWidth();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 const unsigned int height = buffer.GetHeight();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 float value = foreground_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 if (useWindowing_)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 float center, width;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 if (scene_.GetWindowing(center, width))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 value = center + width / 2.0f;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 for (unsigned int y = 0; y < height; y++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 float *q = reinterpret_cast<float*>(buffer.GetRow(y));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 const uint8_t *p = reinterpret_cast<uint8_t*>(tmp.GetRow(y));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 for (unsigned int x = 0; x < width; x++, p++, q++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 float a = static_cast<float>(*p) / 255.0f;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 *q = (a * value + (1.0f - a) * (*q));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 virtual bool GetRange(float& minValue,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 float& maxValue) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 if (useWindowing_)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 minValue = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 maxValue = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 if (foreground_ < 0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 minValue = foreground_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (foreground_ > 0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 maxValue = foreground_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 return true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 };
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
270 class RadiographyScene::DicomLayer : public RadiographyLayer
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 private:
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 std::auto_ptr<Orthanc::ImageAccessor> source_; // Content of PixelData
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 std::auto_ptr<DicomFrameConverter> converter_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 std::auto_ptr<Orthanc::ImageAccessor> converted_; // Float32
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 static OrthancPlugins::DicomTag ConvertTag(const Orthanc::DicomTag& tag)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279 return OrthancPlugins::DicomTag(tag.GetGroup(), tag.GetElement());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 void ApplyConverter()
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 if (source_.get() != NULL &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 converter_.get() != NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 converted_.reset(converter_->ConvertFrame(*source_));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 public:
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 void SetDicomTags(const OrthancPlugins::FullOrthancDataset& dataset)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 converter_.reset(new DicomFrameConverter);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 converter_->ReadParameters(dataset);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 ApplyConverter();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 std::string tmp;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 Vector pixelSpacing;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 if (dataset.GetStringValue(tmp, ConvertTag(Orthanc::DICOM_TAG_PIXEL_SPACING)) &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 LinearAlgebra::ParseVector(pixelSpacing, tmp) &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 pixelSpacing.size() == 2)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 SetPixelSpacing(pixelSpacing[0], pixelSpacing[1]);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309 //SetPan(-0.5 * GetPixelSpacingX(), -0.5 * GetPixelSpacingY());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 OrthancPlugins::DicomDatasetReader reader(dataset);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 unsigned int width, height;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 if (!reader.GetUnsignedIntegerValue(width, ConvertTag(Orthanc::DICOM_TAG_COLUMNS)) ||
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 !reader.GetUnsignedIntegerValue(height, ConvertTag(Orthanc::DICOM_TAG_ROWS)))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 SetSize(width, height);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 void SetSourceImage(Orthanc::ImageAccessor* image) // Takes ownership
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 std::auto_ptr<Orthanc::ImageAccessor> raii(image);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 if (image == NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 SetSize(image->GetWidth(), image->GetHeight());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 source_ = raii;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 ApplyConverter();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 virtual void Render(Orthanc::ImageAccessor& buffer,
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
343 const AffineTransform2D& viewTransform,
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 ImageInterpolation interpolation) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 if (converted_.get() != NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 unsigned int cropX, cropY, cropWidth, cropHeight;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 GetCrop(cropX, cropY, cropWidth, cropHeight);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
356 AffineTransform2D t = AffineTransform2D::Combine(
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
357 viewTransform, GetTransform(),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
358 AffineTransform2D::CreateOffset(cropX, cropY));
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 Orthanc::ImageAccessor cropped;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 converted_->GetRegion(cropped, cropX, cropY, cropWidth, cropHeight);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
363 t.Apply(buffer, cropped, interpolation, false);
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 virtual bool GetDefaultWindowing(float& center,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 float& width) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 if (converter_.get() != NULL &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372 converter_->HasDefaultWindow())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 center = static_cast<float>(converter_->GetDefaultWindowCenter());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 width = static_cast<float>(converter_->GetDefaultWindowWidth());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 return true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 virtual bool GetRange(float& minValue,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 float& maxValue) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 if (converted_.get() != NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 if (converted_->GetFormat() != Orthanc::PixelFormat_Float32)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 Orthanc::ImageProcessing::GetMinMaxFloatValue(minValue, maxValue, *converted_);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 return true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 };
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
406 RadiographyLayer& RadiographyScene::RegisterLayer(RadiographyLayer* layer)
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 if (layer == NULL)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
413 std::auto_ptr<RadiographyLayer> raii(layer);
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415 size_t index = countLayers_++;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 raii->SetIndex(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 layers_[index] = raii.release();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 EmitMessage(GeometryChangedMessage(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 EmitMessage(ContentChangedMessage(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422 return *layer;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 RadiographyScene::RadiographyScene(MessageBroker& broker,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 OrthancApiClient& orthanc) :
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 IObserver(broker),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 IObservable(broker),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 orthanc_(orthanc),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 countLayers_(0),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 hasWindowing_(false),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 windowingCenter_(0), // Dummy initialization
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 windowingWidth_(0) // Dummy initialization
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 RadiographyScene::~RadiographyScene()
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 for (Layers::iterator it = layers_.begin(); it != layers_.end(); it++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 assert(it->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 delete it->second;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 bool RadiographyScene::GetWindowing(float& center,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 float& width) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 if (hasWindowing_)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 center = windowingCenter_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 width = windowingWidth_;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 return true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 void RadiographyScene::GetWindowingWithDefault(float& center,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 float& width) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 if (!GetWindowing(center, width))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 center = 128;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 width = 256;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 void RadiographyScene::SetWindowing(float center,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 float width)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 hasWindowing_ = true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 windowingCenter_ = center;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 windowingWidth_ = width;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
485 RadiographyLayer& RadiographyScene::LoadText(const Orthanc::Font& font,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
486 const std::string& utf8)
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 std::auto_ptr<AlphaLayer> alpha(new AlphaLayer(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 alpha->LoadText(font, utf8);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 return RegisterLayer(alpha.release());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
495 RadiographyLayer& RadiographyScene::LoadTestBlock(unsigned int width,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
496 unsigned int height)
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 std::auto_ptr<Orthanc::Image> block(new Orthanc::Image(Orthanc::PixelFormat_Grayscale8, width, height, false));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 for (unsigned int padding = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 (width > 2 * padding) && (height > 2 * padding);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 padding++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 uint8_t color;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 if (255 > 10 * padding)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 color = 255 - 10 * padding;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 color = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 Orthanc::ImageAccessor region;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 block->GetRegion(region, padding, padding, width - 2 * padding, height - 2 * padding);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 Orthanc::ImageProcessing::Set(region, color);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 std::auto_ptr<AlphaLayer> alpha(new AlphaLayer(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 alpha->SetAlpha(block.release());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 return RegisterLayer(alpha.release());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
526 RadiographyLayer& RadiographyScene::LoadDicomFrame(const std::string& instance,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
527 unsigned int frame,
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
528 bool httpCompression)
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 {
410
6decc0ba9da5 rename RadiographyScene::Layer as RadiographyLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 409
diff changeset
530 RadiographyLayer& layer = RegisterLayer(new DicomLayer);
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 IWebService::Headers headers;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 std::string uri = "/instances/" + instance + "/tags";
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 orthanc_.GetBinaryAsync(
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 uri, headers,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 new Callable<RadiographyScene, OrthancApiClient::BinaryResponseReadyMessage>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 (*this, &RadiographyScene::OnTagsReceived), NULL,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 new Orthanc::SingleValueObject<size_t>(layer.GetIndex()));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 IWebService::Headers headers;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 headers["Accept"] = "image/x-portable-arbitrarymap";
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 if (httpCompression)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 headers["Accept-Encoding"] = "gzip";
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 std::string uri = ("/instances/" + instance + "/frames/" +
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 boost::lexical_cast<std::string>(frame) + "/image-uint16");
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 orthanc_.GetBinaryAsync(
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556 uri, headers,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 new Callable<RadiographyScene, OrthancApiClient::BinaryResponseReadyMessage>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 (*this, &RadiographyScene::OnFrameReceived), NULL,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559 new Orthanc::SingleValueObject<size_t>(layer.GetIndex()));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 return layer;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 void RadiographyScene::OnTagsReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 (message.GetPayload()).GetValue();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 LOG(INFO) << "JSON received: " << message.GetUri().c_str()
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 Layers::iterator layer = layers_.find(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575 if (layer != layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 assert(layer->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 OrthancPlugins::FullOrthancDataset dicom(message.GetAnswer(), message.GetAnswerSize());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580 dynamic_cast<DicomLayer*>(layer->second)->SetDicomTags(dicom);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 float c, w;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583 if (!hasWindowing_ &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 layer->second->GetDefaultWindowing(c, w))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 hasWindowing_ = true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 windowingCenter_ = c;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 windowingWidth_ = w;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 EmitMessage(GeometryChangedMessage(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 void RadiographyScene::OnFrameReceived(const OrthancApiClient::BinaryResponseReadyMessage& message)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 size_t index = dynamic_cast<const Orthanc::SingleValueObject<size_t>&>(message.GetPayload()).GetValue();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 LOG(INFO) << "DICOM frame received: " << message.GetUri().c_str()
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601 << " (" << message.GetAnswerSize() << " bytes) for layer " << index;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 Layers::iterator layer = layers_.find(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 if (layer != layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 assert(layer->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 std::string content;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609 if (message.GetAnswerSize() > 0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 content.assign(reinterpret_cast<const char*>(message.GetAnswer()), message.GetAnswerSize());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 std::auto_ptr<Orthanc::PamReader> reader(new Orthanc::PamReader);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615 reader->ReadFromMemory(content);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 dynamic_cast<DicomLayer*>(layer->second)->SetSourceImage(reader.release());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 EmitMessage(ContentChangedMessage(*this));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 Extent2D RadiographyScene::GetSceneExtent() const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625 Extent2D extent;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 for (Layers::const_iterator it = layers_.begin();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 it != layers_.end(); ++it)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 assert(it->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 extent.Union(it->second->GetExtent());
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 return extent;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 void RadiographyScene::Render(Orthanc::ImageAccessor& buffer,
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
639 const AffineTransform2D& viewTransform,
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 ImageInterpolation interpolation) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 Orthanc::ImageProcessing::Set(buffer, 0);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644 // Render layers in the background-to-foreground order
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 for (size_t index = 0; index < countLayers_; index++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 Layers::const_iterator it = layers_.find(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 if (it != layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 assert(it->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 it->second->Render(buffer, viewTransform, interpolation);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 bool RadiographyScene::LookupLayer(size_t& index /* out */,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 double x,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 double y) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 // Render layers in the foreground-to-background order
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 for (size_t i = countLayers_; i > 0; i--)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 index = i - 1;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 Layers::const_iterator it = layers_.find(index);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 if (it != layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 assert(it->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 if (it->second->Contains(x, y))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 return true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 return false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 void RadiographyScene::DrawBorder(CairoContext& context,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 unsigned int layer,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 double zoom)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 Layers::const_iterator found = layers_.find(layer);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 if (found != layers_.end())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 context.SetSourceColor(255, 0, 0);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689 found->second->DrawBorders(context, zoom);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 void RadiographyScene::GetRange(float& minValue,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 float& maxValue) const
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 bool first = true;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 for (Layers::const_iterator it = layers_.begin();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 it != layers_.end(); it++)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 assert(it->second != NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 float a, b;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 if (it->second->GetRange(a, b))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 if (first)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709 minValue = a;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 maxValue = b;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 first = false;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 minValue = std::min(a, minValue);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 maxValue = std::max(b, maxValue);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 if (first)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 minValue = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 maxValue = 0;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729 // Export using PAM is faster than using PNG, but requires Orthanc
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 // core >= 1.4.3
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 void RadiographyScene::ExportDicom(const Orthanc::DicomMap& dicom,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 double pixelSpacingX,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 double pixelSpacingY,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 bool invert,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 ImageInterpolation interpolation,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 bool usePam)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 if (pixelSpacingX <= 0 ||
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 pixelSpacingY <= 0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 LOG(INFO) << "Exporting DICOM";
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 Extent2D extent = GetSceneExtent();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 int w = std::ceil(extent.GetWidth() / pixelSpacingX);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 int h = std::ceil(extent.GetHeight() / pixelSpacingY);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751 if (w < 0 || h < 0)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 Orthanc::Image layers(Orthanc::PixelFormat_Float32,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 static_cast<unsigned int>(w),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758 static_cast<unsigned int>(h), false);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759
409
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
760 AffineTransform2D view = AffineTransform2D::Combine(
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
761 AffineTransform2D::CreateScaling(1.0 / pixelSpacingX, 1.0 / pixelSpacingY),
99c9b3238008 AffineTransform2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 408
diff changeset
762 AffineTransform2D::CreateOffset(-extent.GetX1(), -extent.GetY1()));
408
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 Render(layers, view, interpolation);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 Orthanc::Image rendered(Orthanc::PixelFormat_Grayscale16,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 layers.GetWidth(), layers.GetHeight(), false);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768 Orthanc::ImageProcessing::Convert(rendered, layers);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 std::string base64;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 std::string content;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775 if (usePam)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 Orthanc::PamWriter writer;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 writer.WriteToMemory(content, rendered);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 else
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782 Orthanc::PngWriter writer;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783 writer.WriteToMemory(content, rendered);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 Orthanc::Toolbox::EncodeBase64(base64, content);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 std::set<Orthanc::DicomTag> tags;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 dicom.GetTags(tags);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792 Json::Value json = Json::objectValue;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 json["Tags"] = Json::objectValue;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 for (std::set<Orthanc::DicomTag>::const_iterator
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 tag = tags.begin(); tag != tags.end(); ++tag)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798 const Orthanc::DicomValue& value = dicom.GetValue(*tag);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 if (!value.IsNull() &&
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 !value.IsBinary())
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 json["Tags"][tag->Format()] = value.GetContent();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 json["Tags"][Orthanc::DICOM_TAG_PHOTOMETRIC_INTERPRETATION.Format()] =
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 (invert ? "MONOCHROME1" : "MONOCHROME2");
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 // WARNING: The order of PixelSpacing is Y/X. We use "%0.8f" to
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 // avoid floating-point numbers to grow over 16 characters,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811 // which would be invalid according to DICOM standard
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 // ("dciodvfy" would complain).
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 char buf[32];
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 sprintf(buf, "%0.8f\\%0.8f", pixelSpacingY, pixelSpacingX);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 json["Tags"][Orthanc::DICOM_TAG_PIXEL_SPACING.Format()] = buf;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818 float center, width;
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 if (GetWindowing(center, width))
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 json["Tags"][Orthanc::DICOM_TAG_WINDOW_CENTER.Format()] =
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 boost::lexical_cast<std::string>(boost::math::iround(center));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824 json["Tags"][Orthanc::DICOM_TAG_WINDOW_WIDTH.Format()] =
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 boost::lexical_cast<std::string>(boost::math::iround(width));
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 // This is Data URI scheme: https://en.wikipedia.org/wiki/Data_URI_scheme
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 json["Content"] = ("data:" +
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830 std::string(usePam ? Orthanc::MIME_PAM : Orthanc::MIME_PNG) +
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 ";base64," + base64);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 orthanc_.PostJsonAsyncExpectJson(
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 "/tools/create-dicom", json,
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 new Callable<RadiographyScene, OrthancApiClient::JsonResponseReadyMessage>
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 (*this, &RadiographyScene::OnDicomExported),
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837 NULL, NULL);
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 void RadiographyScene::OnDicomExported(const OrthancApiClient::JsonResponseReadyMessage& message)
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 {
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843 LOG(INFO) << "DICOM export was successful:"
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844 << message.GetJson().toStyledString();
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 }
6834c236b36d reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846 }