Mercurial > hg > orthanc
annotate Core/DicomParsing/ParsedDicomDir.cpp @ 3831:83ea6939293d
starting DicomStoreUserConnection::Store()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 10 Apr 2020 17:56:12 +0200 |
parents | 2a170a8f1faf |
children |
rev | line source |
---|---|
3554
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Orthanc - A Lightweight, RESTful DICOM Store |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
3640
94f4a18a79cc
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3555
diff
changeset
|
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium |
3554
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU General Public License as |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * published by the Free Software Foundation, either version 3 of the |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * License, or (at your option) any later version. |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * In addition, as a special exception, the copyright holders of this |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * program give permission to link the code of its release with the |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * that use the same license as the "OpenSSL" library), and distribute |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * the linked executables. You must obey the GNU General Public License |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * in all respects for all of the code used other than "OpenSSL". If you |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * modify file(s) with this exception, you may extend this exception to |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * your version of the file(s), but you are not obligated to do so. If |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * you do not wish to do so, delete this exception statement from your |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * version. If you delete this exception statement from all source files |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 * in the program, then also delete it here. |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 * |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 * This program is distributed in the hope that it will be useful, but |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 * WITHOUT ANY WARRANTY; without even the implied warranty of |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 * General Public License for more details. |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 * |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 * You should have received a copy of the GNU General Public License |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 **/ |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include "../PrecompiledHeaders.h" |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 #include "ParsedDicomDir.h" |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
37 #include "../Compatibility.h" |
3554
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 #include "../OrthancException.h" |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 #include "ParsedDicomFile.h" |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 #include "FromDcmtkBridge.h" |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 #include <dcmtk/dcmdata/dcdeftag.h> |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 namespace Orthanc |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 void ParsedDicomDir::Clear() |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 for (size_t i = 0; i < content_.size(); i++) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 assert(content_[i] != NULL); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 delete content_[i]; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 bool ParsedDicomDir::LookupIndexOfOffset(size_t& target, |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 unsigned int offset) const |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 if (offset == 0) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 return false; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 OffsetToIndex::const_iterator found = offsetToIndex_.find(offset); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 if (found == offsetToIndex_.end()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 // Error in the algorithm that computes the offsets |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 throw OrthancException(ErrorCode_InternalError); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 else |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 target = found->second; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 return true; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 ParsedDicomDir::ParsedDicomDir(const std::string content) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 ParsedDicomFile dicom(content); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 DcmSequenceOfItems* sequence = NULL; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 if (dicom.GetDcmtkObject().getDataset() == NULL || |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 !dicom.GetDcmtkObject().getDataset()->findAndGetSequence(DCM_DirectoryRecordSequence, sequence).good() || |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 sequence == NULL) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 throw OrthancException(ErrorCode_BadFileFormat, "Not a DICOMDIR"); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 content_.resize(sequence->card()); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 nextOffsets_.resize(content_.size()); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 lowerOffsets_.resize(content_.size()); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 // Manually reconstruct the list of all the available offsets of |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 // "DcmItem", as "fStartPosition" is a protected member in DCMTK |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 // API |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 std::set<uint32_t> availableOffsets; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 availableOffsets.insert(0); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 for (unsigned long i = 0; i < sequence->card(); i++) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 DcmItem* item = sequence->getItem(i); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 if (item == NULL) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 Clear(); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 throw OrthancException(ErrorCode_InternalError); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 |
3555 | 111 Uint32 next, lower; |
3554
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 if (!item->findAndGetUint32(DCM_OffsetOfTheNextDirectoryRecord, next).good() || |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 !item->findAndGetUint32(DCM_OffsetOfReferencedLowerLevelDirectoryEntity, lower).good()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 item->writeXML(std::cout); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 throw OrthancException(ErrorCode_BadFileFormat, |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 "Missing offsets in DICOMDIR"); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 nextOffsets_[i] = next; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 lowerOffsets_[i] = lower; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 |
3712
2a170a8f1faf
replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
3640
diff
changeset
|
123 std::unique_ptr<DicomMap> entry(new DicomMap); |
3554
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 FromDcmtkBridge::ExtractDicomSummary(*entry, *item); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 if (next != 0) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 availableOffsets.insert(next); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 if (lower != 0) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 availableOffsets.insert(lower); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 content_[i] = entry.release(); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 if (content_.size() != availableOffsets.size()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 throw OrthancException(ErrorCode_BadFileFormat, |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 "Inconsistent offsets in DICOMDIR"); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 unsigned int index = 0; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 for (std::set<uint32_t>::const_iterator it = availableOffsets.begin(); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 it != availableOffsets.end(); ++it) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 offsetToIndex_[*it] = index; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 index ++; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 const DicomMap& ParsedDicomDir::GetItem(size_t i) const |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 if (i >= content_.size()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 else |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 assert(content_[i] != NULL); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 return *content_[i]; |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 bool ParsedDicomDir::LookupNext(size_t& target, |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 size_t index) const |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 if (index >= nextOffsets_.size()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 else |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 return LookupIndexOfOffset(target, nextOffsets_[index]); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 bool ParsedDicomDir::LookupLower(size_t& target, |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 size_t index) const |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 if (index >= lowerOffsets_.size()) |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 throw OrthancException(ErrorCode_ParameterOutOfRange); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 else |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 { |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 return LookupIndexOfOffset(target, lowerOffsets_[index]); |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
194 } |
8fe89c2ea593
new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
195 } |