Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/OsiriX/CollectionOfAnnotations.cpp @ 1775:fca942f4b4a7
fix conversion from voxel centers to texture borders
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 12 May 2021 19:57:50 +0200 |
parents | 9ac2a65d4172 |
children | 3889ae96d2e9 |
rev | line source |
---|---|
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
bd180f97c734
parsing osirix annotations
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 |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 * |
bd180f97c734
parsing osirix annotations
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 |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
bd180f97c734
parsing osirix annotations
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:
1593
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/>. |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 #include "CollectionOfAnnotations.h" |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "ArrayValue.h" |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 #include "IntegerValue.h" |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <OrthancException.h> |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <cassert> |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 namespace OrthancStone |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 namespace OsiriX |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 static void GetAttributes(std::map<std::string, std::string>& target, |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 const pugi::xml_node& node) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 for (pugi::xml_attribute attr = node.first_attribute(); attr; attr = attr.next_attribute()) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 target[attr.name()] = attr.value(); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
46 void CollectionOfAnnotations::Clear() |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 for (size_t i = 0; i < annotations_.size(); i++) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 assert(annotations_[i] != NULL); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 delete annotations_[i]; |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 } |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
53 |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
54 annotations_.clear(); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
55 index_.clear(); |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 const Annotation& CollectionOfAnnotations::GetAnnotation(size_t i) const |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 if (i >= annotations_.size()) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 else |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 assert(annotations_[i] != NULL); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 return *annotations_[i]; |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 void CollectionOfAnnotations::AddAnnotation(Annotation* annotation) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 if (annotation == NULL) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 else |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 { |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
81 size_t pos = annotations_.size(); |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 annotations_.push_back(annotation); |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
83 |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
84 SopInstanceUidIndex::iterator found = index_.find(annotation->GetSopInstanceUid()); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
85 if (found == index_.end()) |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
86 { |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
87 std::set<size_t> s; |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
88 s.insert(pos); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
89 index_[annotation->GetSopInstanceUid()] = s; |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
90 } |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
91 else |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
92 { |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
93 found->second.insert(pos); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
94 } |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
98 |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
99 void CollectionOfAnnotations::LookupSopInstanceUid(std::set<size_t>& target, |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
100 const std::string& sopInstanceUid) const |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
101 { |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
102 SopInstanceUidIndex::const_iterator found = index_.find(sopInstanceUid); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
103 if (found == index_.end()) |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
104 { |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
105 target.clear(); |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
106 } |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
107 else |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
108 { |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
109 target = found->second; |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
110 } |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
111 } |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
112 |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
113 |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
114 void CollectionOfAnnotations::LoadXml(const char* xml, |
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
115 size_t size) |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 pugi::xml_document doc; |
1593
b782f78aed42
rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1584
diff
changeset
|
118 pugi::xml_parse_result result = doc.load_buffer(xml, size); |
1584
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 if (!result) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 const pugi::xml_node& root = doc.document_element(); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 if (std::string(root.name()) != "plist" || |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 !root.first_child() || |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 root.first_child() != root.last_child()) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 std::map<std::string, std::string> attributes; |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 GetAttributes(attributes, root); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 std::map<std::string, std::string>::const_iterator version = attributes.find("version"); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 if (version == attributes.end() || |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 version->second != "1.0") |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 std::unique_ptr<IValue> value(IValue::Parse(root.first_child())); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 const DictionaryValue& dict = dynamic_cast<const DictionaryValue&>(*value); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 std::set<std::string> annotations; |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 dict.GetMembers(annotations); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 for (std::set<std::string>::const_iterator |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 it = annotations.begin(); it != annotations.end(); ++it) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 const ArrayValue& images = dynamic_cast<const ArrayValue&>(dict.GetValue(*it)); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 for (size_t i = 0; i < images.GetSize(); i++) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 const DictionaryValue& image = dynamic_cast<const DictionaryValue&>(images.GetValue(i)); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 const IntegerValue& number = dynamic_cast<const IntegerValue&>(image.GetValue("NumberOfROIs")); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 const ArrayValue& rois = dynamic_cast<const ArrayValue&>(image.GetValue("ROIs")); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 if (static_cast<int64_t>(rois.GetSize()) != number.GetValue()) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 for (size_t j = 0; j < rois.GetSize(); j++) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 const DictionaryValue& roi = dynamic_cast<const DictionaryValue&>(rois.GetValue(i)); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 std::unique_ptr<Annotation> annotation(Annotation::Create(roi)); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 if (annotation.get() != NULL) |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 { |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 AddAnnotation(annotation.release()); |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 } |
bd180f97c734
parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 } |