Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OrthancDatasets/FullOrthancDataset.cpp @ 2069:5956d7357098 deep-learning
macro ORTHANC_HAS_WASM_SIMD has to be manually defined
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 19 May 2023 17:00:17 +0200 |
parents | 7053b8a0aaec |
children | 07964689cb0b |
rev | line source |
---|---|
1504 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1504 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1504 | 10 * as published by the Free Software Foundation, either version 3 of |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1512
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1504 | 21 **/ |
22 | |
23 | |
24 #include "FullOrthancDataset.h" | |
25 | |
26 #include <OrthancException.h> | |
27 | |
28 #include <stdio.h> | |
29 #include <cassert> | |
30 | |
31 namespace OrthancStone | |
32 { | |
33 static const Json::Value* AccessTag(const Json::Value& dataset, | |
34 const Orthanc::DicomTag& tag) | |
35 { | |
36 if (dataset.type() != Json::objectValue) | |
37 { | |
38 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
39 } | |
40 | |
41 char name[16]; | |
42 sprintf(name, "%04x,%04x", tag.GetGroup(), tag.GetElement()); | |
43 | |
44 if (!dataset.isMember(name)) | |
45 { | |
46 return NULL; | |
47 } | |
48 | |
49 const Json::Value& value = dataset[name]; | |
50 if (value.type() != Json::objectValue || | |
51 !value.isMember("Name") || | |
52 !value.isMember("Type") || | |
53 !value.isMember("Value") || | |
54 value["Name"].type() != Json::stringValue || | |
55 value["Type"].type() != Json::stringValue) | |
56 { | |
57 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
58 } | |
59 | |
60 return &value; | |
61 } | |
62 | |
63 | |
64 static const Json::Value& GetSequenceContent(const Json::Value& sequence) | |
65 { | |
66 assert(sequence.type() == Json::objectValue); | |
67 assert(sequence.isMember("Type")); | |
68 assert(sequence.isMember("Value")); | |
69 | |
70 const Json::Value& value = sequence["Value"]; | |
71 | |
72 if (sequence["Type"].asString() != "Sequence" || | |
73 value.type() != Json::arrayValue) | |
74 { | |
75 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
76 } | |
77 else | |
78 { | |
79 return value; | |
80 } | |
81 } | |
82 | |
83 | |
84 static bool GetStringInternal(std::string& result, | |
85 const Json::Value& tag) | |
86 { | |
87 assert(tag.type() == Json::objectValue); | |
88 assert(tag.isMember("Type")); | |
89 assert(tag.isMember("Value")); | |
90 | |
91 const Json::Value& value = tag["Value"]; | |
92 | |
93 if (tag["Type"].asString() != "String" || | |
94 value.type() != Json::stringValue) | |
95 { | |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
97 } | |
98 else | |
99 { | |
100 result = value.asString(); | |
101 return true; | |
102 } | |
103 } | |
104 | |
105 | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
106 const Json::Value* FullOrthancDataset::LookupPath(const Orthanc::DicomPath& path) const |
1504 | 107 { |
108 const Json::Value* content = &root_; | |
109 | |
110 for (unsigned int depth = 0; depth < path.GetPrefixLength(); depth++) | |
111 { | |
112 const Json::Value* sequence = AccessTag(*content, path.GetPrefixTag(depth)); | |
113 if (sequence == NULL) | |
114 { | |
115 return NULL; | |
116 } | |
117 | |
118 const Json::Value& nextContent = GetSequenceContent(*sequence); | |
119 | |
120 size_t index = path.GetPrefixIndex(depth); | |
121 if (index >= nextContent.size()) | |
122 { | |
123 return NULL; | |
124 } | |
125 else | |
126 { | |
127 content = &nextContent[static_cast<Json::Value::ArrayIndex>(index)]; | |
128 } | |
129 } | |
130 | |
131 return AccessTag(*content, path.GetFinalTag()); | |
132 } | |
133 | |
134 | |
135 void FullOrthancDataset::CheckRoot() const | |
136 { | |
137 if (root_.type() != Json::objectValue) | |
138 { | |
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
140 } | |
141 } | |
142 | |
143 | |
144 FullOrthancDataset::FullOrthancDataset(IOrthancConnection& orthanc, | |
145 const std::string& uri) | |
146 { | |
147 IOrthancConnection::RestApiGet(root_, orthanc, uri); | |
148 CheckRoot(); | |
149 } | |
150 | |
151 | |
152 FullOrthancDataset::FullOrthancDataset(const std::string& content) | |
153 { | |
154 IOrthancConnection::ParseJson(root_, content); | |
155 CheckRoot(); | |
156 } | |
157 | |
158 | |
159 FullOrthancDataset::FullOrthancDataset(const void* content, | |
160 size_t size) | |
161 { | |
162 IOrthancConnection::ParseJson(root_, content, size); | |
163 CheckRoot(); | |
164 } | |
165 | |
166 | |
167 FullOrthancDataset::FullOrthancDataset(const Json::Value& root) : | |
168 root_(root) | |
169 { | |
170 CheckRoot(); | |
171 } | |
172 | |
173 | |
174 bool FullOrthancDataset::GetStringValue(std::string& result, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
175 const Orthanc::DicomPath& path) const |
1504 | 176 { |
177 const Json::Value* value = LookupPath(path); | |
178 | |
179 if (value == NULL) | |
180 { | |
181 return false; | |
182 } | |
183 else | |
184 { | |
185 return GetStringInternal(result, *value); | |
186 } | |
187 } | |
188 | |
189 | |
190 bool FullOrthancDataset::GetSequenceSize(size_t& size, | |
1834
126522623e20
replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
191 const Orthanc::DicomPath& path) const |
1504 | 192 { |
193 const Json::Value* sequence = LookupPath(path); | |
194 | |
195 if (sequence == NULL) | |
196 { | |
197 return false; | |
198 } | |
199 else | |
200 { | |
201 size = GetSequenceContent(*sequence).size(); | |
202 return true; | |
203 } | |
204 } | |
205 } |