Mercurial > hg > orthanc
annotate OrthancServer/DicomProtocol/DicomFindAnswers.cpp @ 1926:2a129de4b5e2
EnumerationToString for PixelFormat
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Mar 2016 09:53:41 +0100 |
parents | b1291df2f780 |
children | f0acfa753973 |
rev | line source |
---|---|
0 | 1 /** |
62 | 2 * Orthanc - A Lightweight, RESTful DICOM Store |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
831
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
0 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
136 | 10 * |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
0 | 22 * |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
831
84513f2ee1f3
pch for unit tests and server
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
824
diff
changeset
|
33 #include "../PrecompiledHeadersServer.h" |
0 | 34 #include "DicomFindAnswers.h" |
35 | |
36 #include "../FromDcmtkBridge.h" | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
37 #include "../ToDcmtkBridge.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
38 #include "../../Core/OrthancException.h" |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
39 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
40 #include <memory> |
1789 | 41 #include <dcmtk/dcmdata/dcfilefo.h> |
1847 | 42 #include <boost/noncopyable.hpp> |
1789 | 43 |
0 | 44 |
62 | 45 namespace Orthanc |
0 | 46 { |
1847 | 47 class DicomFindAnswers::Answer : public boost::noncopyable |
1789 | 48 { |
49 private: | |
50 ParsedDicomFile* dicom_; | |
51 DicomMap* map_; | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
52 |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
53 void CleanupDicom() |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
54 { |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
55 if (dicom_ != NULL) |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
56 { |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
57 dicom_->Remove(DICOM_TAG_MEDIA_STORAGE_SOP_INSTANCE_UID); |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
58 dicom_->Remove(DICOM_TAG_SOP_INSTANCE_UID); |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
59 } |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
60 } |
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
61 |
1789 | 62 public: |
63 Answer(ParsedDicomFile& dicom) : | |
64 dicom_(dicom.Clone()), | |
65 map_(NULL) | |
66 { | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
67 CleanupDicom(); |
1789 | 68 } |
69 | |
70 Answer(const char* dicom, | |
71 size_t size) : | |
72 dicom_(new ParsedDicomFile(dicom, size)), | |
73 map_(NULL) | |
74 { | |
1797
23722a191e4e
worklists are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
75 CleanupDicom(); |
1789 | 76 } |
77 | |
78 Answer(const DicomMap& map) : | |
79 dicom_(NULL), | |
80 map_(map.Clone()) | |
81 { | |
82 } | |
83 | |
84 ~Answer() | |
85 { | |
86 if (dicom_ != NULL) | |
87 { | |
88 delete dicom_; | |
89 } | |
90 | |
91 if (map_ != NULL) | |
92 { | |
93 delete map_; | |
94 } | |
95 } | |
96 | |
97 ParsedDicomFile& GetDicomFile() | |
98 { | |
99 if (dicom_ == NULL) | |
100 { | |
101 assert(map_ != NULL); | |
102 dicom_ = new ParsedDicomFile(*map_); | |
103 } | |
104 | |
105 return *dicom_; | |
106 } | |
107 | |
108 DcmDataset* ExtractDcmDataset() const | |
109 { | |
110 if (dicom_ != NULL) | |
111 { | |
112 return new DcmDataset(*dicom_->GetDcmtkObject().getDataset()); | |
113 } | |
114 else | |
115 { | |
116 assert(map_ != NULL); | |
117 return ToDcmtkBridge::Convert(*map_); | |
118 } | |
119 } | |
120 }; | |
121 | |
122 | |
0 | 123 void DicomFindAnswers::Clear() |
124 { | |
1789 | 125 for (size_t i = 0; i < answers_.size(); i++) |
0 | 126 { |
1789 | 127 assert(answers_[i] != NULL); |
128 delete answers_[i]; | |
0 | 129 } |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
130 |
1789 | 131 answers_.clear(); |
0 | 132 } |
133 | |
1789 | 134 |
0 | 135 void DicomFindAnswers::Reserve(size_t size) |
136 { | |
1789 | 137 if (size > answers_.size()) |
0 | 138 { |
1789 | 139 answers_.reserve(size); |
0 | 140 } |
141 } | |
142 | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
143 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
144 void DicomFindAnswers::Add(const DicomMap& map) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
145 { |
1789 | 146 answers_.push_back(new Answer(map)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
147 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
148 |
1789 | 149 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
150 void DicomFindAnswers::Add(ParsedDicomFile& dicom) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
151 { |
1789 | 152 answers_.push_back(new Answer(dicom)); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
153 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
154 |
1789 | 155 |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
156 void DicomFindAnswers::Add(const char* dicom, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
157 size_t size) |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
158 { |
1789 | 159 answers_.push_back(new Answer(dicom, size)); |
160 } | |
161 | |
162 | |
163 DicomFindAnswers::Answer& DicomFindAnswers::GetAnswerInternal(size_t index) const | |
164 { | |
165 if (index < answers_.size()) | |
166 { | |
167 return *answers_.at(index); | |
168 } | |
169 else | |
170 { | |
171 throw OrthancException(ErrorCode_ParameterOutOfRange); | |
172 } | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
173 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
174 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
175 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
176 ParsedDicomFile& DicomFindAnswers::GetAnswer(size_t index) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
177 { |
1789 | 178 return GetAnswerInternal(index).GetDicomFile(); |
179 } | |
180 | |
181 | |
182 DcmDataset* DicomFindAnswers::ExtractDcmDataset(size_t index) const | |
183 { | |
184 return GetAnswerInternal(index).ExtractDcmDataset(); | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
185 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
186 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
187 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
188 void DicomFindAnswers::ToJson(Json::Value& target, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
189 size_t index, |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
190 bool simplify) const |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
191 { |
1860
c7d70f659190
DicomToJsonFormat_Simple -> DicomToJsonFormat_Human
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1847
diff
changeset
|
192 DicomToJsonFormat format = (simplify ? DicomToJsonFormat_Human : DicomToJsonFormat_Full); |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
193 GetAnswer(index).ToJson(target, format, DicomToJsonFlags_None, 0); |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
194 } |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
195 |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
196 |
1368 | 197 void DicomFindAnswers::ToJson(Json::Value& target, |
198 bool simplify) const | |
0 | 199 { |
200 target = Json::arrayValue; | |
201 | |
202 for (size_t i = 0; i < GetSize(); i++) | |
203 { | |
1787
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
204 Json::Value answer; |
1b1d5470233f
refactoring of DicomFindAnswers
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1368
diff
changeset
|
205 ToJson(answer, i, simplify); |
0 | 206 target.append(answer); |
207 } | |
208 } | |
209 } |