annotate OrthancStone/Sources/Loaders/SeriesFramesLoader.cpp @ 1652:fa9e6bf84958

integrating pdf.js into Stone Web viewer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 16 Nov 2020 20:47:53 +0100
parents 8563ea5d8ae4
children 51bab5188a13
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1271
0ca50d275b9a upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1228
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
8 * modify it under the terms of the GNU Lesser General Public License
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * the License, or (at your option) any later version.
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
16 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * <http://www.gnu.org/licenses/>.
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 **/
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23 #include "SeriesFramesLoader.h"
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "../Oracle/ParseDicomFromFileCommand.h"
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "../Oracle/ParseDicomFromWadoCommand.h"
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #if ORTHANC_ENABLE_DCMTK == 1
1564
e731e62692a9 upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
29 # include <DicomParsing/ParsedDicomFile.h>
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #endif
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1311
diff changeset
32 #include <DicomFormat/DicomInstanceHasher.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1311
diff changeset
33 #include <Images/Image.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1311
diff changeset
34 #include <Images/ImageProcessing.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1311
diff changeset
35 #include <Images/JpegReader.h>
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #include <boost/algorithm/string/predicate.hpp>
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 namespace OrthancStone
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 class SeriesFramesLoader::Payload : public Orthanc::IDynamicObject
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43 private:
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 DicomSource source_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 size_t seriesIndex_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 std::string sopInstanceUid_; // Only used for debug purpose
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 unsigned int quality_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 bool hasWindowing_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 float windowingCenter_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 float windowingWidth_;
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
51 std::unique_ptr<Orthanc::IDynamicObject> userPayload_;
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 public:
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 Payload(const DicomSource& source,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 size_t seriesIndex,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 const std::string& sopInstanceUid,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 unsigned int quality,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 Orthanc::IDynamicObject* userPayload) :
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 source_(source),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 seriesIndex_(seriesIndex),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 sopInstanceUid_(sopInstanceUid),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 quality_(quality),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 hasWindowing_(false),
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
64 windowingCenter_(0),
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
65 windowingWidth_(0),
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 userPayload_(userPayload)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 size_t GetSeriesIndex() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 return seriesIndex_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 const std::string& GetSopInstanceUid() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 return sopInstanceUid_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 unsigned int GetQuality() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 return quality_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 void SetWindowing(float center,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 float width)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 hasWindowing_ = true;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 windowingCenter_ = center;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 windowingWidth_ = width;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 bool HasWindowing() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 return hasWindowing_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 float GetWindowingCenter() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 if (hasWindowing_)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 return windowingCenter_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 float GetWindowingWidth() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 if (hasWindowing_)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 return windowingWidth_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 const DicomSource& GetSource() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 return source_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 Orthanc::IDynamicObject* GetUserPayload() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 return userPayload_.get();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 };
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 SeriesFramesLoader::SeriesFramesLoader(ILoadersContext& context,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 LoadedDicomResources& instances,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 const std::string& dicomDirPath,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 boost::shared_ptr<LoadedDicomResources> dicomDir) :
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 context_(context),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 frames_(instances),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 dicomDirPath_(dicomDirPath),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 dicomDir_(dicomDir)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 void SeriesFramesLoader::EmitMessage(const Payload& payload,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 const Orthanc::ImageAccessor& image)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(payload.GetSeriesIndex());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 const Orthanc::DicomMap& instance = frames_.GetInstance(payload.GetSeriesIndex());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 size_t frameIndex = frames_.GetFrameIndex(payload.GetSeriesIndex());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 if (frameIndex >= parameters.GetImageInformation().GetNumberOfFrames() ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 payload.GetSopInstanceUid() != parameters.GetSopInstanceUid())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 LOG(TRACE) << "Decoded instance " << payload.GetSopInstanceUid() << ", frame "
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 << frameIndex << ": " << image.GetWidth() << "x"
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 << image.GetHeight() << ", " << Orthanc::EnumerationToString(image.GetFormat())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 << ", quality " << payload.GetQuality();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 FrameLoadedMessage message(*this, frameIndex, payload.GetQuality(), image, instance, parameters, payload.GetUserPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 BroadcastMessage(message);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 #if ORTHANC_ENABLE_DCMTK == 1
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 void SeriesFramesLoader::HandleDicom(const Payload& payload,
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1564
diff changeset
171 const Orthanc::ParsedDicomFile& dicom)
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 size_t frameIndex = frames_.GetFrameIndex(payload.GetSeriesIndex());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
175 std::unique_ptr<Orthanc::ImageAccessor> decoded;
1564
e731e62692a9 upgrading Orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
176 decoded.reset(dicom.DecodeFrame(static_cast<unsigned int>(frameIndex)));
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 if (decoded.get() == NULL)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183 EmitMessage(payload, *decoded);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 #endif
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 void SeriesFramesLoader::HandleDicomWebRendered(const Payload& payload,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 const std::string& body,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 const std::map<std::string, std::string>& headers)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 assert(payload.GetSource().IsDicomWeb() &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 payload.HasWindowing());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 bool ok = false;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 for (std::map<std::string, std::string>::const_iterator it = headers.begin();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 it != headers.end(); ++it)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 if (boost::iequals("content-type", it->first) &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 boost::iequals(Orthanc::MIME_JPEG, it->second))
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202 ok = true;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 break;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 if (!ok)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 "The WADO-RS server has not generated a JPEG image on /rendered");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 Orthanc::JpegReader reader;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 reader.ReadFromMemory(body);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 switch (reader.GetFormat())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 case Orthanc::PixelFormat_RGB24:
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 EmitMessage(payload, reader);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 break;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 case Orthanc::PixelFormat_Grayscale8:
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(payload.GetSeriesIndex());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 Orthanc::Image scaled(parameters.GetExpectedPixelFormat(), reader.GetWidth(), reader.GetHeight(), false);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 Orthanc::ImageProcessing::Convert(scaled, reader);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229 float w = payload.GetWindowingWidth();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (w <= 0.01f)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 {
1309
1f877e0846fe Fixed some warnings + fixed build for C++03
Benjamin Golinvaux <bgo@osimis.io>
parents: 1299
diff changeset
232 w = 0.01f; // Prevent division by zero
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 const float c = payload.GetWindowingCenter();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 const float scaling = w / 255.0f;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 const float offset = (c - w / 2.0f) / scaling;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239 Orthanc::ImageProcessing::ShiftScale(scaled, offset, scaling, false /* truncation to speed up */);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 EmitMessage(payload, scaled);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 break;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 default:
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 #if ORTHANC_ENABLE_DCMTK == 1
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 void SeriesFramesLoader::Handle(const ParseDicomSuccessMessage& message)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 assert(message.GetOrigin().HasPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 const Payload& payload = dynamic_cast<const Payload&>(message.GetOrigin().GetPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 if ((payload.GetSource().IsDicomDir() ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257 payload.GetSource().IsDicomWeb()) &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 message.HasPixelData())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 HandleDicom(dynamic_cast<const Payload&>(message.GetOrigin().GetPayload()), message.GetDicom());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267 #endif
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 void SeriesFramesLoader::Handle(const GetOrthancImageCommand::SuccessMessage& message)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 assert(message.GetOrigin().HasPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 const Payload& payload = dynamic_cast<const Payload&>(message.GetOrigin().GetPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275 assert(payload.GetSource().IsOrthanc());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277 EmitMessage(payload, message.GetImage());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 void SeriesFramesLoader::Handle(const GetOrthancWebViewerJpegCommand::SuccessMessage& message)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 assert(message.GetOrigin().HasPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 const Payload& payload = dynamic_cast<const Payload&>(message.GetOrigin().GetPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 assert(payload.GetSource().IsOrthanc());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 EmitMessage(payload, message.GetImage());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 void SeriesFramesLoader::Handle(const OrthancRestApiCommand::SuccessMessage& message)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 // This is to handle "/rendered" in DICOMweb
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 assert(message.GetOrigin().HasPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 HandleDicomWebRendered(dynamic_cast<const Payload&>(message.GetOrigin().GetPayload()),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 message.GetAnswer(), message.GetAnswerHeaders());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 void SeriesFramesLoader::Handle(const HttpCommand::SuccessMessage& message)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303 // This is to handle "/rendered" in DICOMweb
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 assert(message.GetOrigin().HasPayload());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 HandleDicomWebRendered(dynamic_cast<const Payload&>(message.GetOrigin().GetPayload()),
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 message.GetAnswer(), message.GetAnswerHeaders());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 void SeriesFramesLoader::GetPreviewWindowing(float& center,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 float& width,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 size_t index) const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 const Orthanc::DicomMap& instance = frames_.GetInstance(index);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(index);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 if (parameters.HasDefaultWindowing())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319 // TODO - Handle multiple presets (take the largest width)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 center = parameters.GetDefaultWindowingCenter();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 width = parameters.GetDefaultWindowingWidth();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 float a, b;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 if (instance.ParseFloat(a, Orthanc::DICOM_TAG_SMALLEST_IMAGE_PIXEL_VALUE) &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 instance.ParseFloat(b, Orthanc::DICOM_TAG_LARGEST_IMAGE_PIXEL_VALUE) &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 a < b)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330 center = (a + b) / 2.0f;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331 width = (b - a);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 // Cannot infer a suitable windowing from the available tags
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 center = 128.0f;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 width = 256.0f;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343 Orthanc::IDynamicObject& SeriesFramesLoader::FrameLoadedMessage::GetUserPayload() const
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 if (userPayload_)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 return *userPayload_;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 void SeriesFramesLoader::Factory::SetDicomDir(const std::string& dicomDirPath,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 boost::shared_ptr<LoadedDicomResources> dicomDir)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 dicomDirPath_ = dicomDirPath;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 dicomDir_ = dicomDir;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 boost::shared_ptr<IObserver> SeriesFramesLoader::Factory::Create(ILoadersContext::ILock& stone)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366 boost::shared_ptr<SeriesFramesLoader> loader(
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367 new SeriesFramesLoader(stone.GetContext(), instances_, dicomDirPath_, dicomDir_));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 loader->Register<GetOrthancImageCommand::SuccessMessage>(stone.GetOracleObservable(), &SeriesFramesLoader::Handle);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 loader->Register<GetOrthancWebViewerJpegCommand::SuccessMessage>(stone.GetOracleObservable(), &SeriesFramesLoader::Handle);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 loader->Register<HttpCommand::SuccessMessage>(stone.GetOracleObservable(), &SeriesFramesLoader::Handle);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 loader->Register<OrthancRestApiCommand::SuccessMessage>(stone.GetOracleObservable(), &SeriesFramesLoader::Handle);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 #if ORTHANC_ENABLE_DCMTK == 1
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 loader->Register<ParseDicomSuccessMessage>(stone.GetOracleObservable(), &SeriesFramesLoader::Handle);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 #endif
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 return loader;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 void SeriesFramesLoader::ScheduleLoadFrame(int priority,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 const DicomSource& source,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 size_t index,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 unsigned int quality,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 Orthanc::IDynamicObject* userPayload)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
387 std::unique_ptr<Orthanc::IDynamicObject> protection(userPayload);
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 if (index >= frames_.GetFramesCount() ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 quality >= source.GetQualityCount())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 const Orthanc::DicomMap& instance = frames_.GetInstance(index);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 std::string sopInstanceUid;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 if (!instance.LookupStringValue(sopInstanceUid, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false))
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 "Missing SOPInstanceUID in a DICOM instance");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 if (source.IsDicomDir())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 if (dicomDir_.get() == NULL)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 // Should have been set in the factory
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 throw Orthanc::OrthancException(
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 Orthanc::ErrorCode_BadSequenceOfCalls,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 "SeriesFramesLoader::Factory::SetDicomDir() should have been called");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 assert(quality == 0);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 std::string file;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 if (dicomDir_->LookupStringValue(file, sopInstanceUid, Orthanc::DICOM_TAG_REFERENCED_FILE_ID))
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 {
1484
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
419 std::unique_ptr<ParseDicomFromFileCommand> command(new ParseDicomFromFileCommand(source, dicomDirPath_, file));
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 command->SetPixelDataIncluded(true);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 command->AcquirePayload(new Payload(source, index, sopInstanceUid, quality, protection.release()));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
424 std::unique_ptr<ILoadersContext::ILock> lock(context_.Lock());
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 lock->Schedule(GetSharedObserver(), priority, command.release());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 LOG(WARNING) << "Missing tag ReferencedFileID in a DICOMDIR entry";
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 else if (source.IsDicomWeb())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 std::string studyInstanceUid, seriesInstanceUid;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 if (!instance.LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 !instance.LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false))
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 "Missing StudyInstanceUID or SeriesInstanceUID in a DICOM instance");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 const std::string uri = ("/studies/" + studyInstanceUid +
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 "/series/" + seriesInstanceUid +
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 "/instances/" + sopInstanceUid);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 if (source.HasDicomWebRendered() &&
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 quality == 0)
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450 float c, w;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 GetPreviewWindowing(c, w, index);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 std::map<std::string, std::string> arguments, headers;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454 arguments["window"] = (boost::lexical_cast<std::string>(c) + "," +
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 boost::lexical_cast<std::string>(w) + ",linear");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 headers["Accept"] = "image/jpeg";
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
458 std::unique_ptr<Payload> payload(new Payload(source, index, sopInstanceUid, quality, protection.release()));
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 payload->SetWindowing(c, w);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
462 std::unique_ptr<ILoadersContext::ILock> lock(context_.Lock());
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 lock->Schedule(GetSharedObserver(), priority,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 source.CreateDicomWebCommand(uri + "/rendered", arguments, headers, payload.release()));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 assert((source.HasDicomWebRendered() && quality == 1) ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 (!source.HasDicomWebRendered() && quality == 0));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 #if ORTHANC_ENABLE_DCMTK == 1
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
473 std::unique_ptr<Payload> payload(new Payload(source, index, sopInstanceUid, quality, protection.release()));
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 const std::map<std::string, std::string> empty;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
477 std::unique_ptr<ParseDicomFromWadoCommand> command(
1484
121d01aa328e SeriesThumbnailsLoader working on raw dicom files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
478 new ParseDicomFromWadoCommand(source, sopInstanceUid, source.CreateDicomWebCommand(uri, empty, empty, NULL)));
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479 command->AcquirePayload(payload.release());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
482 std::unique_ptr<ILoadersContext::ILock> lock(context_.Lock());
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 lock->Schedule(GetSharedObserver(), priority, command.release());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 #else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487 "DCMTK is not enabled, cannot parse a DICOM instance");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 #endif
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 else if (source.IsOrthanc())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 std::string orthancId;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 std::string patientId, studyInstanceUid, seriesInstanceUid;
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 if (!instance.LookupStringValue(patientId, Orthanc::DICOM_TAG_PATIENT_ID, false) ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 !instance.LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 !instance.LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false))
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 "Missing StudyInstanceUID or SeriesInstanceUID in a DICOM instance");
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 Orthanc::DicomInstanceHasher hasher(patientId, studyInstanceUid, seriesInstanceUid, sopInstanceUid);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 orthancId = hasher.HashInstance();
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 const DicomInstanceParameters& parameters = frames_.GetInstanceParameters(index);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 if (quality == 0 && source.HasOrthancWebViewer1())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
513 std::unique_ptr<GetOrthancWebViewerJpegCommand> command(new GetOrthancWebViewerJpegCommand);
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 command->SetInstance(orthancId);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 command->SetExpectedPixelFormat(parameters.GetExpectedPixelFormat());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 command->AcquirePayload(new Payload(source, index, sopInstanceUid, quality, protection.release()));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
519 std::unique_ptr<ILoadersContext::ILock> lock(context_.Lock());
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520 lock->Schedule(GetSharedObserver(), priority, command.release());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 else if (quality == 0 && source.HasOrthancAdvancedPreview())
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 assert(quality <= 1);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 assert(quality == 0 ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 source.HasOrthancWebViewer1() ||
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 source.HasOrthancAdvancedPreview());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
534 std::unique_ptr<GetOrthancImageCommand> command(new GetOrthancImageCommand);
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 command->SetFrameUri(orthancId, frames_.GetFrameIndex(index), parameters.GetExpectedPixelFormat());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 command->SetExpectedPixelFormat(parameters.GetExpectedPixelFormat());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 command->SetHttpHeader("Accept", Orthanc::MIME_PAM);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 command->AcquirePayload(new Payload(source, index, sopInstanceUid, quality, protection.release()));
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 {
1299
c38c89684d83 replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1271
diff changeset
541 std::unique_ptr<ILoadersContext::ILock> lock(context_.Lock());
1228
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 lock->Schedule(GetSharedObserver(), priority, command.release());
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 else
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 }
c471a0aa137b adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 }