annotate OrthancStone/Sources/Toolbox/OrthancDatasets/FullOrthancDataset.cpp @ 1770:073484e33bee

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