annotate OrthancFramework/Sources/DicomParsing/ParsedDicomDir.cpp @ 5311:79fa77e9fa0d am-experimental

merge default -> am-experimental
author Alain Mazy <am@osimis.io>
date Fri, 16 Jun 2023 09:26:33 +0200
parents 0ea402b4d901
children 48b8dae6dc77
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5185
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium
0ea402b4d901 upgrade to year 2023
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4870
diff changeset
6 * Copyright (C) 2021-2023 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
11 * the License, or (at your option) any later version.
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
16 * Lesser General Public License for more details.
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 *
4119
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
19 * License along with this program. If not, see
bf7b9edf6b81 re-licensing the OrthancFramework to LGPL, in order to license Stone of Orthanc under LGPL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4044
diff changeset
20 * <http://www.gnu.org/licenses/>.
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 **/
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22
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 #include "../PrecompiledHeaders.h"
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include "ParsedDicomDir.h"
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
27 #include "../Compatibility.h"
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include "../OrthancException.h"
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "ParsedDicomFile.h"
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "FromDcmtkBridge.h"
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 #include <dcmtk/dcmdata/dcdeftag.h>
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
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace Orthanc
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 void ParsedDicomDir::Clear()
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 for (size_t i = 0; i < content_.size(); i++)
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 assert(content_[i] != NULL);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 delete content_[i];
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
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 bool ParsedDicomDir::LookupIndexOfOffset(size_t& target,
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 unsigned int offset) const
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 if (offset == 0)
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 return false;
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 OffsetToIndex::const_iterator found = offsetToIndex_.find(offset);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 if (found == offsetToIndex_.end())
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 // Error in the algorithm that computes the offsets
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 throw OrthancException(ErrorCode_InternalError);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 else
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 target = found->second;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 return true;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 }
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
4200
7112a8af0b63 cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4137
diff changeset
69 ParsedDicomDir::ParsedDicomDir(const std::string& content)
3554
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 ParsedDicomFile dicom(content);
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 DcmSequenceOfItems* sequence = NULL;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 if (dicom.GetDcmtkObject().getDataset() == NULL ||
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 !dicom.GetDcmtkObject().getDataset()->findAndGetSequence(DCM_DirectoryRecordSequence, sequence).good() ||
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 sequence == NULL)
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 throw OrthancException(ErrorCode_BadFileFormat, "Not a DICOMDIR");
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
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 content_.resize(sequence->card());
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 nextOffsets_.resize(content_.size());
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 lowerOffsets_.resize(content_.size());
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 // Manually reconstruct the list of all the available offsets of
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 // "DcmItem", as "fStartPosition" is a protected member in DCMTK
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 // API
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 std::set<uint32_t> availableOffsets;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 availableOffsets.insert(0);
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
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 for (unsigned long i = 0; i < sequence->card(); i++)
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 DcmItem* item = sequence->getItem(i);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 if (item == NULL)
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 Clear();
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 throw OrthancException(ErrorCode_InternalError);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
3555
99cd59fe8c5c fix for msvc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3554
diff changeset
101 Uint32 next, lower;
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102 if (!item->findAndGetUint32(DCM_OffsetOfTheNextDirectoryRecord, next).good() ||
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 !item->findAndGetUint32(DCM_OffsetOfReferencedLowerLevelDirectoryEntity, lower).good())
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 item->writeXML(std::cout);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 throw OrthancException(ErrorCode_BadFileFormat,
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 "Missing offsets in DICOMDIR");
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 }
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 nextOffsets_[i] = next;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 lowerOffsets_[i] = lower;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112
3712
2a170a8f1faf replacing std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
113 std::unique_ptr<DicomMap> entry(new DicomMap);
4137
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
114
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
115 std::set<DicomTag> ignoreTagLength;
6774605d4341 keep only one signature for FromDcmtkBridge::ExtractDicomSummary()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4136
diff changeset
116 FromDcmtkBridge::ExtractDicomSummary(*entry, *item, 0 /* don't truncate tags */, ignoreTagLength);
3554
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 if (next != 0)
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 availableOffsets.insert(next);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 if (lower != 0)
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 availableOffsets.insert(lower);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 }
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 content_[i] = entry.release();
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 (content_.size() != availableOffsets.size())
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 throw OrthancException(ErrorCode_BadFileFormat,
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 "Inconsistent offsets in DICOMDIR");
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
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 unsigned int index = 0;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 for (std::set<uint32_t>::const_iterator it = availableOffsets.begin();
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 it != availableOffsets.end(); ++it)
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 offsetToIndex_[*it] = index;
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 index ++;
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
4297
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
146 ParsedDicomDir::~ParsedDicomDir()
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
147 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
148 Clear();
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
149 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
150
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
151 size_t ParsedDicomDir::GetSize() const
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
152 {
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
153 return content_.size();
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
154 }
785a2713323e abi continued
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 4200
diff changeset
155
3554
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 const DicomMap& ParsedDicomDir::GetItem(size_t i) const
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 if (i >= content_.size())
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 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 else
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 {
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 assert(content_[i] != NULL);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 return *content_[i];
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
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 bool ParsedDicomDir::LookupNext(size_t& target,
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 size_t index) const
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 if (index >= nextOffsets_.size())
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 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 else
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 return LookupIndexOfOffset(target, nextOffsets_[index]);
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
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 bool ParsedDicomDir::LookupLower(size_t& target,
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 size_t index) const
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 if (index >= lowerOffsets_.size())
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 throw OrthancException(ErrorCode_ParameterOutOfRange);
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 else
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 return LookupIndexOfOffset(target, lowerOffsets_[index]);
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 }
8fe89c2ea593 new class: ParsedDicomDir
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 }