annotate Framework/Toolbox/OrthancSlicesLoader.cpp @ 418:c23df8b3433b

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 15 Nov 2018 18:32:48 +0100
parents aee3d7941c9b
children f87f28624b96 b70e9be013e4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
135
e2fe9352f240 upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 128
diff changeset
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * Affero General Public License for more details.
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
16 *
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "OrthancSlicesLoader.h"
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "MessagingToolbox.h"
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
26 #include <Core/Compression/GzipCompressor.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
27 #include <Core/Endianness.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
28 #include <Core/Images/Image.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
29 #include <Core/Images/ImageProcessing.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
30 #include <Core/Images/JpegReader.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
31 #include <Core/Images/PngReader.h>
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
32 #include <Core/Images/PamReader.h>
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
33 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
34 #include <Core/OrthancException.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
35 #include <Core/Toolbox.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 203
diff changeset
36 #include <Plugins/Samples/Common/FullOrthancDataset.h>
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 #include <boost/lexical_cast.hpp>
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
40
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
41
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
42 /**
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
43 * TODO This is a SLOW implementation of base64 decoding, because
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
44 * "Orthanc::Toolbox::DecodeBase64()" does not work properly with
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
45 * WASM. UNDERSTAND WHY.
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
46 * https://stackoverflow.com/a/34571089/881731
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
47 **/
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
48 static std::string base64_decode(const std::string &in)
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
49 {
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
50 std::string out;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
51
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
52 std::vector<int> T(256,-1);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
53 for (int i=0; i<64; i++) T["ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"[i]] = i;
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
54
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
55 int val=0, valb=-8;
128
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 127
diff changeset
56 for (size_t i = 0; i < in.size(); i++) {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 127
diff changeset
57 unsigned char c = in[i];
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
58 if (T[c] == -1) break;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
59 val = (val<<6) + T[c];
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
60 valb += 6;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
61 if (valb>=0) {
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
62 out.push_back(char((val>>valb)&0xFF));
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
63 valb-=8;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
64 }
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
65 }
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
66 return out;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
67 }
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
68
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
69
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
70
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 namespace OrthancStone
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 class OrthancSlicesLoader::Operation : public Orthanc::IDynamicObject
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 private:
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
76 Mode mode_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
77 unsigned int frame_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
78 unsigned int sliceIndex_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
79 const Slice* slice_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
80 std::string instanceId_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
81 SliceImageQuality quality_;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 Operation(Mode mode) :
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 mode_(mode)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 public:
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 Mode GetMode() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 return mode_;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
94 SliceImageQuality GetQuality() const
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
95 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
96 assert(mode_ == Mode_LoadImage ||
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
97 mode_ == Mode_LoadRawImage);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
98 return quality_;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
99 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
100
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 unsigned int GetSliceIndex() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 {
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
103 assert(mode_ == Mode_LoadImage ||
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
104 mode_ == Mode_LoadRawImage);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 return sliceIndex_;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 const Slice& GetSlice() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 {
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
110 assert(mode_ == Mode_LoadImage ||
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
111 mode_ == Mode_LoadRawImage);
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
112 assert(slice_ != NULL);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return *slice_;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 unsigned int GetFrame() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
118 assert(mode_ == Mode_FrameGeometry);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 return frame_;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
121
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const std::string& GetInstanceId() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
124 assert(mode_ == Mode_FrameGeometry ||
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
125 mode_ == Mode_InstanceGeometry);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 return instanceId_;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
129 static Operation* DownloadInstanceGeometry(const std::string& instanceId)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 std::auto_ptr<Operation> operation(new Operation(Mode_InstanceGeometry));
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 operation->instanceId_ = instanceId;
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
133 return operation.release();
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
134 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
135
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
136 static Operation* DownloadFrameGeometry(const std::string& instanceId,
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
137 unsigned int frame)
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
138 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
139 std::auto_ptr<Operation> operation(new Operation(Mode_FrameGeometry));
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
140 operation->instanceId_ = instanceId;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 operation->frame_ = frame;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 return operation.release();
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 static Operation* DownloadSliceImage(unsigned int sliceIndex,
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
146 const Slice& slice,
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
147 SliceImageQuality quality)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadImage));
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 tmp->sliceIndex_ = sliceIndex;
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 tmp->slice_ = &slice;
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
152 tmp->quality_ = quality;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 return tmp.release();
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 }
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
155
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
156 static Operation* DownloadSliceRawImage(unsigned int sliceIndex,
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
157 const Slice& slice)
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
158 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
159 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadRawImage));
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
160 tmp->sliceIndex_ = sliceIndex;
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
161 tmp->slice_ = &slice;
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
162 tmp->quality_ = SliceImageQuality_InternalRaw;
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
163 return tmp.release();
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
164 }
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
166 static Operation* DownloadDicomFile(const Slice& slice)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
168 std::auto_ptr<Operation> tmp(new Operation(Mode_LoadDicomFile));
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
169 tmp->slice_ = &slice;
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
170 return tmp.release();
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 };
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
175 void OrthancSlicesLoader::NotifySliceImageSuccess(const Operation& operation,
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
176 const Orthanc::ImageAccessor& image)
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
177 {
406
5d359b115b29 use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
178 OrthancSlicesLoader::SliceImageReadyMessage msg
5d359b115b29 use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
179 (*this, operation.GetSliceIndex(), operation.GetSlice(), image, operation.GetQuality());
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
180 EmitMessage(msg);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
181 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
182
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
183
268
5bd4161bf11b removed constness of the observable when emitting a message
am@osimis.io
parents: 267
diff changeset
184 void OrthancSlicesLoader::NotifySliceImageError(const Operation& operation)
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
185 {
406
5d359b115b29 use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
186 OrthancSlicesLoader::SliceImageErrorMessage msg
5d359b115b29 use of callables in OrthancVolumeImage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 382
diff changeset
187 (*this, operation.GetSliceIndex(), operation.GetSlice(), operation.GetQuality());
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 257
diff changeset
188 EmitMessage(msg);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
189 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
190
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
191
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
192 void OrthancSlicesLoader::SortAndFinalizeSlices()
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
193 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
194 bool ok = false;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
195
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
196 if (slices_.GetSliceCount() > 0)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
197 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
198 Vector normal;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
199 if (slices_.SelectNormal(normal))
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
200 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
201 slices_.FilterNormal(normal);
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
202 slices_.SetNormal(normal);
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
203 slices_.Sort();
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
204 ok = true;
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
205 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
206 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
207
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
208 state_ = State_GeometryReady;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
209
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
210 if (ok)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
211 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
212 LOG(INFO) << "Loaded a series with " << slices_.GetSliceCount() << " slice(s)";
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 268
diff changeset
213 EmitMessage(SliceGeometryReadyMessage(*this));
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
214 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
215 else
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
216 {
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
217 LOG(ERROR) << "This series is empty";
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 268
diff changeset
218 EmitMessage(SliceGeometryErrorMessage(*this));
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
219 }
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
220 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
221
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
222 void OrthancSlicesLoader::OnGeometryError(const IWebService::HttpRequestErrorMessage& message)
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
223 {
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
224 EmitMessage(SliceGeometryErrorMessage(*this));
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
225 state_ = State_Error;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
226 }
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
227
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
228 void OrthancSlicesLoader::OnSliceImageError(const IWebService::HttpRequestErrorMessage& message)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
230 NotifySliceImageError(dynamic_cast<const Operation&>(message.GetPayload()));
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
231 state_ = State_Error;
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
232 }
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
234 void OrthancSlicesLoader::ParseSeriesGeometry(const OrthancApiClient::JsonResponseReadyMessage& message)
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
235 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
236 const Json::Value& series = message.GetJson();
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 Json::Value::Members instances = series.getMemberNames();
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
238
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 slices_.Reserve(instances.size());
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
240
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 for (size_t i = 0; i < instances.size(); i++)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 OrthancPlugins::FullOrthancDataset dataset(series[instances[i]]);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
244
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
245 Orthanc::DicomMap dicom;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
246 MessagingToolbox::ConvertDataset(dicom, dataset);
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
247
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
248 unsigned int frames;
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
249 if (!dicom.ParseUnsignedInteger32(frames, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES))
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
250 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
251 frames = 1;
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
252 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
253
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
254 for (unsigned int frame = 0; frame < frames; frame++)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
256 std::auto_ptr<Slice> slice(new Slice);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
257 if (slice->ParseOrthancFrame(dicom, instances[i], frame))
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
258 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
259 slices_.AddSlice(slice.release());
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
260 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
261 else
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
262 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
263 LOG(WARNING) << "Skipping invalid frame " << frame << " within instance " << instances[i];
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
264 }
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
267
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
268 SortAndFinalizeSlices();
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
270
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
271 void OrthancSlicesLoader::ParseInstanceGeometry(const OrthancApiClient::JsonResponseReadyMessage& message)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
273 const Json::Value& tags = message.GetJson();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
274 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId();
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276 OrthancPlugins::FullOrthancDataset dataset(tags);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
277
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
278 Orthanc::DicomMap dicom;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
279 MessagingToolbox::ConvertDataset(dicom, dataset);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
280
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
281 unsigned int frames;
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
282 if (!dicom.ParseUnsignedInteger32(frames, Orthanc::DICOM_TAG_NUMBER_OF_FRAMES))
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
283 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
284 frames = 1;
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
285 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
286
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
287 LOG(INFO) << "Instance " << instanceId << " contains " << frames << " frame(s)";
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
288
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
289 for (unsigned int frame = 0; frame < frames; frame++)
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
290 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
291 std::auto_ptr<Slice> slice(new Slice);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
292 if (slice->ParseOrthancFrame(dicom, instanceId, frame))
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
293 {
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
294 slices_.AddSlice(slice.release());
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
295 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
296 else
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
297 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
298 LOG(WARNING) << "Skipping invalid multi-frame instance " << instanceId;
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 268
diff changeset
299 EmitMessage(SliceGeometryErrorMessage(*this));
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
300 return;
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
301 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
302 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
303
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
304 SortAndFinalizeSlices();
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
305 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
306
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
307
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
308 void OrthancSlicesLoader::ParseFrameGeometry(const OrthancApiClient::JsonResponseReadyMessage& message)
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
309 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
310 const Json::Value& tags = message.GetJson();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
311 const std::string& instanceId = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetInstanceId();
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
312 unsigned int frame = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload()).GetFrame();
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
313
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
314 OrthancPlugins::FullOrthancDataset dataset(tags);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
315
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 state_ = State_GeometryReady;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
317
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
318 Orthanc::DicomMap dicom;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 117
diff changeset
319 MessagingToolbox::ConvertDataset(dicom, dataset);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
320
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
321 std::auto_ptr<Slice> slice(new Slice);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
322 if (slice->ParseOrthancFrame(dicom, instanceId, frame))
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 257
diff changeset
324 LOG(INFO) << "Loaded instance geometry " << instanceId;
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
325 slices_.AddSlice(slice.release());
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
326 EmitMessage(SliceGeometryReadyMessage(*this));
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 LOG(WARNING) << "Skipping invalid instance " << instanceId;
299
3897f9f28cfa backup work in progress: updated messaging framework with ICallable
am@osimis.io
parents: 268
diff changeset
331 EmitMessage(SliceGeometryErrorMessage(*this));
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
334
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
335
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
336 void OrthancSlicesLoader::ParseSliceImagePng(const OrthancApiClient::BinaryResponseReadyMessage& message)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
338 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload());
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
339 std::auto_ptr<Orthanc::ImageAccessor> image;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
340
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
341 try
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
342 {
99
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 97
diff changeset
343 image.reset(new Orthanc::PngReader);
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
344 dynamic_cast<Orthanc::PngReader&>(*image).ReadFromMemory(message.GetAnswer(), message.GetAnswerSize());
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
345 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
346 catch (Orthanc::OrthancException&)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
347 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
348 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
349 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
350 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
351
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
352 if (image->GetWidth() != operation.GetSlice().GetWidth() ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
353 image->GetHeight() != operation.GetSlice().GetHeight())
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
354 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
355 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
356 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
357 }
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
359 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() ==
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 Orthanc::PixelFormat_SignedGrayscale16)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 {
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
368 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
369 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
370 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
371 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
372
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
373 NotifySliceImageSuccess(operation, *image);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
374 }
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
375
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
376 void OrthancSlicesLoader::ParseSliceImagePam(const OrthancApiClient::BinaryResponseReadyMessage& message)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
378 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload());
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
379 std::auto_ptr<Orthanc::ImageAccessor> image;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
381 try
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
382 {
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
383 image.reset(new Orthanc::PamReader);
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
384 dynamic_cast<Orthanc::PamReader&>(*image).ReadFromMemory(message.GetAnswer(), message.GetAnswerSize());
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
385 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
386 catch (Orthanc::OrthancException&)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
387 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
388 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
389 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
390 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
391
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
392 if (image->GetWidth() != operation.GetSlice().GetWidth() ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
393 image->GetHeight() != operation.GetSlice().GetHeight())
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
394 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
395 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
396 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
397 }
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
398
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
399 if (operation.GetSlice().GetConverter().GetExpectedPixelFormat() ==
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 Orthanc::PixelFormat_SignedGrayscale16)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 if (image->GetFormat() == Orthanc::PixelFormat_Grayscale16)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 image->SetFormat(Orthanc::PixelFormat_SignedGrayscale16);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
408 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
409 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
410 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
411 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
412
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
413 NotifySliceImageSuccess(operation, *image);
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
414 }
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
415
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
416
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
417 void OrthancSlicesLoader::ParseSliceImageJpeg(const OrthancApiClient::JsonResponseReadyMessage& message)
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
418 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
419 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload());
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
420
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
421 const Json::Value& encoded = message.GetJson();
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
422 if (encoded.type() != Json::objectValue ||
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
423 !encoded.isMember("Orthanc") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
424 encoded["Orthanc"].type() != Json::objectValue)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
425 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
426 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
427 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
428 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
429
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
430 const Json::Value& info = encoded["Orthanc"];
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
431 if (!info.isMember("PixelData") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
432 !info.isMember("Stretched") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
433 !info.isMember("Compression") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
434 info["Compression"].type() != Json::stringValue ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
435 info["PixelData"].type() != Json::stringValue ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
436 info["Stretched"].type() != Json::booleanValue ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
437 info["Compression"].asString() != "Jpeg")
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
438 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
439 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
440 return;
94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
441 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
442
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
443 bool isSigned = false;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
444 bool isStretched = info["Stretched"].asBool();
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
445
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
446 if (info.isMember("IsSigned"))
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
447 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
448 if (info["IsSigned"].type() != Json::booleanValue)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
449 {
94
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
450 NotifySliceImageError(operation);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 93
diff changeset
451 return;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
452 }
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
453 else
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
454 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
455 isSigned = info["IsSigned"].asBool();
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
458
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
459 std::auto_ptr<Orthanc::ImageAccessor> reader;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
460
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
461 {
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
462 std::string jpeg;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
463 //Orthanc::Toolbox::DecodeBase64(jpeg, info["PixelData"].asString());
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
464 jpeg = base64_decode(info["PixelData"].asString());
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
465
100
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
466 try
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
467 {
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
468 reader.reset(new Orthanc::JpegReader);
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
469 dynamic_cast<Orthanc::JpegReader&>(*reader).ReadFromMemory(jpeg);
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
470 }
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
471 catch (Orthanc::OrthancException&)
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
472 {
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
473 NotifySliceImageError(operation);
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
474 return;
166a555becbf fix jpeg decoding in wasm
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 99
diff changeset
475 }
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
476 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
477
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
478 Orthanc::PixelFormat expectedFormat =
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
479 operation.GetSlice().GetConverter().GetExpectedPixelFormat();
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
480
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
481 if (reader->GetFormat() == Orthanc::PixelFormat_RGB24) // This is a color image
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
483 if (expectedFormat != Orthanc::PixelFormat_RGB24)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
484 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
485 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
486 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
487 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
488
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
489 if (isSigned || isStretched)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
490 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
491 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
492 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
493 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
494 else
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
495 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
496 NotifySliceImageSuccess(operation, *reader);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
497 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
498 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
499 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
500
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
501 if (reader->GetFormat() != Orthanc::PixelFormat_Grayscale8)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
502 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
503 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
504 return;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
506
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
507 if (!isStretched)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
508 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
509 if (expectedFormat != reader->GetFormat())
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
510 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
511 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
512 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
513 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
514 else
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
515 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
516 NotifySliceImageSuccess(operation, *reader);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
517 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
518 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
519 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
520
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
521 int32_t stretchLow = 0;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
522 int32_t stretchHigh = 0;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
523
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
524 if (!info.isMember("StretchLow") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
525 !info.isMember("StretchHigh") ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
526 info["StretchLow"].type() != Json::intValue ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
527 info["StretchHigh"].type() != Json::intValue)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 {
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
529 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
530 return;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
532
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
533 stretchLow = info["StretchLow"].asInt();
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
534 stretchHigh = info["StretchHigh"].asInt();
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
535
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
536 if (stretchLow < -32768 ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
537 stretchHigh > 65535 ||
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
538 (stretchLow < 0 && stretchHigh > 32767))
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
539 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
540 // This range cannot be represented with a uint16_t or an int16_t
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
541 NotifySliceImageError(operation);
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
542 return;
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
543 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
544
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
545 // Decode a grayscale JPEG 8bpp image coming from the Web viewer
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
546 std::auto_ptr<Orthanc::ImageAccessor> image
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
547 (new Orthanc::Image(expectedFormat, reader->GetWidth(), reader->GetHeight(), false));
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
548
203
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
549 Orthanc::ImageProcessing::Convert(*image, *reader);
334
c34784e5f299 compatibility fixes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 318
diff changeset
550 reader.reset();
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
551
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
552 float scaling = static_cast<float>(stretchHigh - stretchLow) / 255.0f;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
553
203
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
554 if (!LinearAlgebra::IsCloseToZero(scaling))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
555 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
556 float offset = static_cast<float>(stretchLow) / scaling;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
557 Orthanc::ImageProcessing::ShiftScale(*image, offset, scaling, true);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
558 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
559
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
560 NotifySliceImageSuccess(operation, *image);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
562
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
563
316
ce48c3b3b0e9 fix for new ImageAccessor API
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
564 class StringImage : public Orthanc::ImageAccessor
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
565 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
566 private:
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
567 std::string buffer_;
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
569 public:
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
570 StringImage(Orthanc::PixelFormat format,
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
571 unsigned int width,
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
572 unsigned int height,
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
573 std::string& buffer)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
574 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
575 if (buffer.size() != Orthanc::GetBytesPerPixel(format) * width * height)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
576 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
577 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
578 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
579
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
580 buffer_.swap(buffer); // The source buffer is now empty
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
581
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
582 void* data = (buffer_.empty() ? NULL : &buffer_[0]);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
583
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
584 AssignWritable(format, width, height,
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
585 Orthanc::GetBytesPerPixel(format) * width, data);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
586 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
587 };
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
588
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
589 void OrthancSlicesLoader::ParseSliceRawImage(const OrthancApiClient::BinaryResponseReadyMessage& message)
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
590 {
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
591 const Operation& operation = dynamic_cast<const OrthancSlicesLoader::Operation&>(message.GetPayload());
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
592 Orthanc::GzipCompressor compressor;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
593
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
594 std::string raw;
377
8eb4fe74000f refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 369
diff changeset
595 compressor.Uncompress(raw, message.GetAnswer(), message.GetAnswerSize());
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
596
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
597 const Orthanc::DicomImageInformation& info = operation.GetSlice().GetImageInformation();
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
598
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
599 if (info.GetBitsAllocated() == 32 &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
600 info.GetBitsStored() == 32 &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
601 info.GetHighBit() == 31 &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
602 info.GetChannelCount() == 1 &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
603 !info.IsSigned() &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
604 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 &&
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
605 raw.size() == info.GetWidth() * info.GetHeight() * 4)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
606 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
607 // This is the case of RT-DOSE (uint32_t values)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
608
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
609 std::auto_ptr<Orthanc::ImageAccessor> image
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
610 (new StringImage(Orthanc::PixelFormat_Grayscale32, info.GetWidth(),
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
611 info.GetHeight(), raw));
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
612
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
613 // TODO - Only for big endian
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
614 for (unsigned int y = 0; y < image->GetHeight(); y++)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
615 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
616 uint32_t *p = reinterpret_cast<uint32_t*>(image->GetRow(y));
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
617 for (unsigned int x = 0; x < image->GetWidth(); x++, p++)
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
618 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
619 *p = le32toh(*p);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
620 }
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
621 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
622
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
623 NotifySliceImageSuccess(operation, *image);
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
624 }
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
625 else if (info.GetBitsAllocated() == 16 &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
626 info.GetBitsStored() == 16 &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
627 info.GetHighBit() == 15 &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
628 info.GetChannelCount() == 1 &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
629 !info.IsSigned() &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
630 info.GetPhotometricInterpretation() == Orthanc::PhotometricInterpretation_Monochrome2 &&
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
631 raw.size() == info.GetWidth() * info.GetHeight() * 2)
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
632 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
633 std::auto_ptr<Orthanc::ImageAccessor> image
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
634 (new StringImage(Orthanc::PixelFormat_Grayscale16, info.GetWidth(),
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
635 info.GetHeight(), raw));
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
636
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
637 // TODO - Big endian ?
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
638
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
639 NotifySliceImageSuccess(operation, *image);
120
063f7f3d9f14 fix 3d locations of the doses
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 119
diff changeset
640 }
119
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
641 else
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
642 {
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
643 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
ba83e38cf3ff rendering of rt-dose
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
644 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
645
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
646 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
647
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
648
251
192e6e349e69 first usage of new message system (in SDL only)
am@osimis.io
parents: 212
diff changeset
649 OrthancSlicesLoader::OrthancSlicesLoader(MessageBroker& broker,
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
650 OrthancApiClient& orthanc) :
266
c9cf95b49a86 removed OrthancSlicesLoader::ISliceLoaderObserver; now using standard messages instead
am@osimis.io
parents: 257
diff changeset
651 IObservable(broker),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
652 IObserver(broker),
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 orthanc_(orthanc),
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 state_(State_Initialization)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
657
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 void OrthancSlicesLoader::ScheduleLoadSeries(const std::string& seriesId)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 if (state_ != State_Initialization)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 state_ = State_LoadingGeometry;
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
668 orthanc_.GetJsonAsync("/series/" + seriesId + "/instances-tags",
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
669 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSeriesGeometry),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
670 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
671 NULL);
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
674
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
675 void OrthancSlicesLoader::ScheduleLoadInstance(const std::string& instanceId)
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
676 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
677 if (state_ != State_Initialization)
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
678 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
679 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
680 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
681 else
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
682 {
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
683 state_ = State_LoadingGeometry;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
684
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
685 // Tag "3004-000c" is "Grid Frame Offset Vector", which is
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
686 // mandatory to read RT DOSE, but is too long to be returned by default
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
687 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags?ignore-length=3004-000c",
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
688 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseInstanceGeometry),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
689 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
690 Operation::DownloadInstanceGeometry(instanceId));
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
691 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
692 }
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
693
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
694
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
695 void OrthancSlicesLoader::ScheduleLoadFrame(const std::string& instanceId,
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
696 unsigned int frame)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 if (state_ != State_Initialization)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 state_ = State_LoadingGeometry;
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
705
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
706 orthanc_.GetJsonAsync("/instances/" + instanceId + "/tags",
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
707 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseFrameGeometry),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
708 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnGeometryError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
709 Operation::DownloadFrameGeometry(instanceId, frame));
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
713
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
714 bool OrthancSlicesLoader::IsGeometryReady() const
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
715 {
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
716 return state_ == State_GeometryReady;
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
717 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
718
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
719
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720 size_t OrthancSlicesLoader::GetSliceCount() const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 if (state_ != State_GeometryReady)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
726
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 return slices_.GetSliceCount();
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
729
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 const Slice& OrthancSlicesLoader::GetSlice(size_t index) const
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 if (state_ != State_GeometryReady)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
737
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 return slices_.GetSlice(index);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
741
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
742 bool OrthancSlicesLoader::LookupSlice(size_t& index,
110
53025eecbc95 renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 100
diff changeset
743 const CoordinateSystem3D& plane) const
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
744 {
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
745 if (state_ != State_GeometryReady)
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
746 {
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
747 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
748 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
749
77
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
750 return slices_.LookupSlice(index, plane);
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
751 }
f5f54ed8d307 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 73
diff changeset
752
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
753
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
754 void OrthancSlicesLoader::ScheduleSliceImagePng(const Slice& slice,
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
755 size_t index)
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
756 {
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
757 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
758 boost::lexical_cast<std::string>(slice.GetFrame()));
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
759
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
760 switch (slice.GetConverter().GetExpectedPixelFormat())
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
761 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
762 case Orthanc::PixelFormat_RGB24:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
763 uri += "/preview";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
764 break;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
765
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
766 case Orthanc::PixelFormat_Grayscale16:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
767 uri += "/image-uint16";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
768 break;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
769
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
770 case Orthanc::PixelFormat_SignedGrayscale16:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
771 uri += "/image-int16";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
772 break;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
773
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
774 default:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
775 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
776 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
777
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
778 orthanc_.GetBinaryAsync(uri, "image/png",
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
779 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePng),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
780 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
781 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPng));
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
782 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
783
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
784 void OrthancSlicesLoader::ScheduleSliceImagePam(const Slice& slice,
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
785 size_t index)
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
786 {
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
787 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
788 boost::lexical_cast<std::string>(slice.GetFrame()));
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
789
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
790 switch (slice.GetConverter().GetExpectedPixelFormat())
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
791 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
792 case Orthanc::PixelFormat_RGB24:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
793 uri += "/preview";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
794 break;
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
795
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
796 case Orthanc::PixelFormat_Grayscale16:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
797 uri += "/image-uint16";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
798 break;
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
799
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
800 case Orthanc::PixelFormat_SignedGrayscale16:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
801 uri += "/image-int16";
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
802 break;
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
803
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
804 default:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
805 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
806 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
807
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
808 orthanc_.GetBinaryAsync(uri, "image/x-portable-arbitrarymap",
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
809 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImagePam),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
810 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
811 Operation::DownloadSliceImage(index, slice, SliceImageQuality_FullPam));
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
812 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
813
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
814
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
815
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
816 void OrthancSlicesLoader::ScheduleSliceImageJpeg(const Slice& slice,
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
817 size_t index,
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
818 SliceImageQuality quality)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
819 {
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
820 unsigned int value;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
821
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
822 switch (quality)
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
823 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
824 case SliceImageQuality_Jpeg50:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
825 value = 50;
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
826 break;
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
827
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
828 case SliceImageQuality_Jpeg90:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
829 value = 90;
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
830 break;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
831
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
832 case SliceImageQuality_Jpeg95:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
833 value = 95;
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
834 break;
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
835
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
836 default:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
837 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
838 }
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
839
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
840 // This requires the official Web viewer plugin to be installed!
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
841 std::string uri = ("/web-viewer/instances/jpeg" +
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
842 boost::lexical_cast<std::string>(value) +
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
843 "-" + slice.GetOrthancInstanceId() + "_" +
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
844 boost::lexical_cast<std::string>(slice.GetFrame()));
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
845
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
846 orthanc_.GetJsonAsync(uri,
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
847 new Callable<OrthancSlicesLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceImageJpeg),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
848 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
849 Operation::DownloadSliceImage(index, slice, quality));
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
850 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
851
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
852
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
853
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
854 void OrthancSlicesLoader::ScheduleLoadSliceImage(size_t index,
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
855 SliceImageQuality quality)
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 if (state_ != State_GeometryReady)
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 {
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 }
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
861
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
862 const Slice& slice = GetSlice(index);
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
863
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
864 if (slice.HasOrthancDecoding())
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
865 {
257
9afafb192180 using PAM
am@osimis.io
parents: 252
diff changeset
866 switch (quality)
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
867 {
378
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
868 case SliceImageQuality_FullPng:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
869 ScheduleSliceImagePng(slice, index);
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
870 break;
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
871 case SliceImageQuality_FullPam:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
872 ScheduleSliceImagePam(slice, index);
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
873 break;
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
874 default:
814fa32e2fcc refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 377
diff changeset
875 ScheduleSliceImageJpeg(slice, index, quality);
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
876 }
93
5945e81734a3 decoding of JPEG images
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 77
diff changeset
877 }
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 else
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 {
252
40b21c1f8b8d more usage of IObservable/IObserver
am@osimis.io
parents: 251
diff changeset
880 std::string uri = ("/instances/" + slice.GetOrthancInstanceId() + "/frames/" +
117
42c05a3baee3 loading multi-frame instances as 3D volumes
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
881 boost::lexical_cast<std::string>(slice.GetFrame()) + "/raw.gz");
417
aee3d7941c9b preparing to load images using DICOMweb
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 406
diff changeset
882 orthanc_.GetBinaryAsync(uri, IWebService::HttpHeaders(),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
883 new Callable<OrthancSlicesLoader, OrthancApiClient::BinaryResponseReadyMessage>(*this, &OrthancSlicesLoader::ParseSliceRawImage),
382
dd4c7e82b4be removed class OrthancApiClient::HttpErrorMessage, redundant with IWebService::HttpRequestErrorMessage
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 378
diff changeset
884 new Callable<OrthancSlicesLoader, IWebService::HttpRequestErrorMessage>(*this, &OrthancSlicesLoader::OnSliceImageError),
300
b4abaeb783b1 messaging refactoring almost complete: works fine in native
am@osimis.io
parents: 299
diff changeset
885 Operation::DownloadSliceRawImage(index, slice));
73
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 }
ffa6dded91bd reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 }