Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Loaders/LoadedDicomResources.cpp @ 1543:4cfdaf4ef3fe
fixing paths
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Aug 2020 14:08:51 +0200 |
parents | 244ad1e4e76a |
children | 4fb8fdf03314 |
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:
1250
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 **/ |
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 #include "LoadedDicomResources.h" |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1271
diff
changeset
|
24 #include <OrthancException.h> |
1228
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include <cassert> |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 namespace OrthancStone |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 void LoadedDicomResources::Flatten() |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 // Lazy generation of a "std::vector" from the "std::map" |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 if (flattened_.empty()) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 flattened_.resize(resources_.size()); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 size_t pos = 0; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 for (Resources::const_iterator it = resources_.begin(); it != resources_.end(); ++it) |
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 assert(it->second != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 flattened_[pos++] = it->second; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 else |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 // No need to flatten |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 assert(flattened_.size() == resources_.size()); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
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 void LoadedDicomResources::AddFromDicomWebInternal(const Json::Value& dicomweb) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 assert(dicomweb.type() == Json::objectValue); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 Orthanc::DicomMap dicom; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 dicom.FromDicomWeb(dicomweb); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 AddResource(dicom); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 LoadedDicomResources::LoadedDicomResources(const LoadedDicomResources& other, |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 const Orthanc::DicomTag& indexedTag) : |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 indexedTag_(indexedTag) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 for (Resources::const_iterator it = other.resources_.begin(); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 it != other.resources_.end(); ++it) |
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 assert(it->second != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 AddResource(*it->second); |
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 } |
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 void LoadedDicomResources::Clear() |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 for (Resources::iterator it = resources_.begin(); it != resources_.end(); ++it) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 assert(it->second != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 delete it->second; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 } |
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 resources_.clear(); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 flattened_.clear(); |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 Orthanc::DicomMap& LoadedDicomResources::GetResource(size_t index) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 Flatten(); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 if (index >= flattened_.size()) |
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
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 else |
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 assert(flattened_[index] != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 return *flattened_[index]; |
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 } |
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 |
1250
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
103 void LoadedDicomResources::MergeResource(Orthanc::DicomMap& target, |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
104 const std::string& id) const |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
105 { |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
106 Resources::const_iterator it = resources_.find(id); |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
107 |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
108 if (it == resources_.end()) |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
109 { |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
110 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
111 } |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
112 else |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
113 { |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
114 assert(it->second != NULL); |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
115 target.Merge(*it->second); |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
116 } |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
117 } |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
118 |
a8248b08115c
LoadedDicomResources::MergeResource()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1228
diff
changeset
|
119 |
1228
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 bool LoadedDicomResources::LookupStringValue(std::string& target, |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 const std::string& id, |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 const Orthanc::DicomTag& tag) 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 Resources::const_iterator found = resources_.find(id); |
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 if (found == resources_.end()) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 return false; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 else |
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 assert(found->second != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 return found->second->LookupStringValue(target, tag, false); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 void LoadedDicomResources::AddResource(const Orthanc::DicomMap& dicom) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 std::string id; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 if (dicom.LookupStringValue(id, indexedTag_, false /* no binary value */) && |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 resources_.find(id) == resources_.end() /* Don't index twice the same resource */) |
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 resources_[id] = dicom.Clone(); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 flattened_.clear(); // Invalidate the flattened version |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 } |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 void LoadedDicomResources::AddFromOrthanc(const Json::Value& tags) |
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 Orthanc::DicomMap dicom; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 dicom.FromDicomAsJson(tags); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 AddResource(dicom); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 } |
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 void LoadedDicomResources::AddFromDicomWeb(const Json::Value& dicomweb) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 if (dicomweb.type() == Json::objectValue) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 AddFromDicomWebInternal(dicomweb); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 else if (dicomweb.type() == Json::arrayValue) |
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 for (Json::Value::ArrayIndex i = 0; i < dicomweb.size(); i++) |
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 (dicomweb[i].type() == Json::objectValue) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 AddFromDicomWebInternal(dicomweb[i]); |
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 else |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 } |
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 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 else |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
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 } |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 bool LoadedDicomResources::LookupTagValueConsensus(std::string& target, |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 const Orthanc::DicomTag& tag) const |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 typedef std::map<std::string, unsigned int> Counter; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
190 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
191 Counter counter; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
192 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
193 for (Resources::const_iterator it = resources_.begin(); it != resources_.end(); ++it) |
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 assert(it->second != NULL); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
196 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
197 std::string value; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
198 if (it->second->LookupStringValue(value, tag, false)) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
199 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
200 Counter::iterator found = counter.find(value); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
201 if (found == counter.end()) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
202 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
203 counter[value] = 1; |
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 else |
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 found->second ++; |
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 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
210 } |
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 Counter::const_iterator best = counter.end(); |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
213 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
214 for (Counter::const_iterator it = counter.begin(); it != counter.end(); ++it) |
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 if (best == counter.end() || |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
217 best->second < it->second) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
218 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
219 best = it; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
220 } |
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 |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
223 if (best == counter.end()) |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
224 { |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
225 return false; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
226 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
227 else |
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 target = best->first; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
230 return true; |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
231 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
232 } |
c471a0aa137b
adding the next generation of loaders
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
233 } |