comparison Core/DicomParsing/ParsedDicomFile.cpp @ 2394:75c779ca948c

fix compilation without Web server
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 30 Aug 2017 16:23:10 +0200
parents 7284093111b0
children e4045b3c9772
comparison
equal deleted inserted replaced
2393:807ddffc0eeb 2394:75c779ca948c
144 #if DCMTK_VERSION_NUMBER <= 360 144 #if DCMTK_VERSION_NUMBER <= 360
145 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax 145 # define EXS_JPEGProcess1 EXS_JPEGProcess1TransferSyntax
146 #endif 146 #endif
147 147
148 148
149 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
150
151
152 149
153 namespace Orthanc 150 namespace Orthanc
154 { 151 {
155 struct ParsedDicomFile::PImpl 152 struct ParsedDicomFile::PImpl
156 { 153 {
157 std::auto_ptr<DcmFileFormat> file_; 154 std::auto_ptr<DcmFileFormat> file_;
158 std::auto_ptr<DicomFrameIndex> frameIndex_; 155 std::auto_ptr<DicomFrameIndex> frameIndex_;
159 }; 156 };
160 157
161 158
159 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
160 static const char* CONTENT_TYPE_OCTET_STREAM = "application/octet-stream";
161
162 static void ParseTagAndGroup(DcmTagKey& key,
163 const std::string& tag)
164 {
165 DicomTag t = FromDcmtkBridge::ParseTag(tag);
166 key = DcmTagKey(t.GetGroup(), t.GetElement());
167 }
168
169
170 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData,
171 E_TransferSyntax transferSyntax)
172 {
173 DcmPixelSequence* pixelSequence = NULL;
174 if (pixelData.getEncapsulatedRepresentation
175 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
176 {
177 return pixelSequence->card();
178 }
179 else
180 {
181 return 1;
182 }
183 }
184
185
162 static void SendPathValueForDictionary(RestApiOutput& output, 186 static void SendPathValueForDictionary(RestApiOutput& output,
163 DcmItem& dicom) 187 DcmItem& dicom)
164 { 188 {
165 Json::Value v = Json::arrayValue; 189 Json::Value v = Json::arrayValue;
166 190
176 } 200 }
177 201
178 output.AnswerJson(v); 202 output.AnswerJson(v);
179 } 203 }
180 204
181 static inline uint16_t GetCharValue(char c)
182 {
183 if (c >= '0' && c <= '9')
184 return c - '0';
185 else if (c >= 'a' && c <= 'f')
186 return c - 'a' + 10;
187 else if (c >= 'A' && c <= 'F')
188 return c - 'A' + 10;
189 else
190 return 0;
191 }
192
193 static inline uint16_t GetTagValue(const char* c)
194 {
195 return ((GetCharValue(c[0]) << 12) +
196 (GetCharValue(c[1]) << 8) +
197 (GetCharValue(c[2]) << 4) +
198 GetCharValue(c[3]));
199 }
200
201 static void ParseTagAndGroup(DcmTagKey& key,
202 const std::string& tag)
203 {
204 DicomTag t = FromDcmtkBridge::ParseTag(tag);
205 key = DcmTagKey(t.GetGroup(), t.GetElement());
206 }
207
208 205
209 static void SendSequence(RestApiOutput& output, 206 static void SendSequence(RestApiOutput& output,
210 DcmSequenceOfItems& sequence) 207 DcmSequenceOfItems& sequence)
211 { 208 {
212 // This element is a sequence 209 // This element is a sequence
216 { 213 {
217 v.append(boost::lexical_cast<std::string>(i)); 214 v.append(boost::lexical_cast<std::string>(i));
218 } 215 }
219 216
220 output.AnswerJson(v); 217 output.AnswerJson(v);
221 }
222
223
224 static unsigned int GetPixelDataBlockCount(DcmPixelData& pixelData,
225 E_TransferSyntax transferSyntax)
226 {
227 DcmPixelSequence* pixelSequence = NULL;
228 if (pixelData.getEncapsulatedRepresentation
229 (transferSyntax, NULL, pixelSequence).good() && pixelSequence)
230 {
231 return pixelSequence->card();
232 }
233 else
234 {
235 return 1;
236 }
237 } 218 }
238 219
239 220
240 namespace 221 namespace
241 { 222 {
411 392
412 return false; 393 return false;
413 } 394 }
414 395
415 396
416
417 static void SendPathValueForLeaf(RestApiOutput& output, 397 static void SendPathValueForLeaf(RestApiOutput& output,
418 const std::string& tag, 398 const std::string& tag,
419 DcmItem& dicom, 399 DcmItem& dicom,
420 E_TransferSyntax transferSyntax) 400 E_TransferSyntax transferSyntax)
421 { 401 {
439 { 419 {
440 DicomFieldStream stream(*element, transferSyntax); 420 DicomFieldStream stream(*element, transferSyntax);
441 output.AnswerStream(stream); 421 output.AnswerStream(stream);
442 } 422 }
443 } 423 }
444 424 #endif
425
426
427 static inline uint16_t GetCharValue(char c)
428 {
429 if (c >= '0' && c <= '9')
430 return c - '0';
431 else if (c >= 'a' && c <= 'f')
432 return c - 'a' + 10;
433 else if (c >= 'A' && c <= 'F')
434 return c - 'A' + 10;
435 else
436 return 0;
437 }
438
439
440 static inline uint16_t GetTagValue(const char* c)
441 {
442 return ((GetCharValue(c[0]) << 12) +
443 (GetCharValue(c[1]) << 8) +
444 (GetCharValue(c[2]) << 4) +
445 GetCharValue(c[3]));
446 }
447
448
449 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
445 void ParsedDicomFile::SendPathValue(RestApiOutput& output, 450 void ParsedDicomFile::SendPathValue(RestApiOutput& output,
446 const UriComponents& uri) 451 const UriComponents& uri)
447 { 452 {
448 DcmItem* dicom = pimpl_->file_->getDataset(); 453 DcmItem* dicom = pimpl_->file_->getDataset();
449 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer(); 454 E_TransferSyntax transferSyntax = pimpl_->file_->getDataset()->getOriginalXfer();
496 else 501 else
497 { 502 {
498 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax); 503 SendPathValueForLeaf(output, uri.back(), *dicom, transferSyntax);
499 } 504 }
500 } 505 }
501 506 #endif
507
502 508
503 void ParsedDicomFile::Remove(const DicomTag& tag) 509 void ParsedDicomFile::Remove(const DicomTag& tag)
504 { 510 {
505 InvalidateCache(); 511 InvalidateCache();
506 512
780 } 786 }
781 } 787 }
782 } 788 }
783 789
784 790
791 #if ORTHANC_ENABLE_CIVETWEB == 1 || ORTHANC_ENABLE_MONGOOSE == 1
785 void ParsedDicomFile::Answer(RestApiOutput& output) 792 void ParsedDicomFile::Answer(RestApiOutput& output)
786 { 793 {
787 std::string serialized; 794 std::string serialized;
788 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset())) 795 if (FromDcmtkBridge::SaveToMemoryBuffer(serialized, *pimpl_->file_->getDataset()))
789 { 796 {
790 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM); 797 output.AnswerBuffer(serialized, CONTENT_TYPE_OCTET_STREAM);
791 } 798 }
792 } 799 }
793 800 #endif
794 801
795 802
796 bool ParsedDicomFile::GetTagValue(std::string& value, 803 bool ParsedDicomFile::GetTagValue(std::string& value,
797 const DicomTag& tag) 804 const DicomTag& tag)
798 { 805 {