annotate OrthancStone/Sources/Toolbox/OsiriX/CollectionOfAnnotations.cpp @ 1961:cbf54cd28d59

added CoordinateSystem3D::GetOrientationMarkers()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 27 Oct 2022 18:43:20 +0200
parents 7053b8a0aaec
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
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
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * the License, or (at your option) any later version.
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
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: 1593
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/>.
1584
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "CollectionOfAnnotations.h"
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "ArrayValue.h"
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include "IntegerValue.h"
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include <OrthancException.h>
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 #include <cassert>
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 namespace OrthancStone
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 namespace OsiriX
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 static void GetAttributes(std::map<std::string, std::string>& target,
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 const pugi::xml_node& node)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 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
41 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 target[attr.name()] = attr.value();
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
47 void CollectionOfAnnotations::Clear()
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 for (size_t i = 0; i < annotations_.size(); i++)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 assert(annotations_[i] != NULL);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 delete annotations_[i];
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 }
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
54
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
55 annotations_.clear();
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
56 index_.clear();
1584
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 const Annotation& CollectionOfAnnotations::GetAnnotation(size_t i) const
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 if (i >= annotations_.size())
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 }
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 else
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 assert(annotations_[i] != NULL);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 return *annotations_[i];
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 void CollectionOfAnnotations::AddAnnotation(Annotation* annotation)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 if (annotation == NULL)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 }
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 else
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 {
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
82 size_t pos = annotations_.size();
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 annotations_.push_back(annotation);
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
84
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
85 SopInstanceUidIndex::iterator found = index_.find(annotation->GetSopInstanceUid());
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
86 if (found == index_.end())
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
87 {
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
88 std::set<size_t> s;
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
89 s.insert(pos);
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
90 index_[annotation->GetSopInstanceUid()] = s;
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
91 }
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
92 else
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
93 {
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
94 found->second.insert(pos);
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
95 }
1584
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 }
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
99
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
100 void CollectionOfAnnotations::LookupSopInstanceUid(std::set<size_t>& target,
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
101 const std::string& sopInstanceUid) const
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
102 {
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
103 SopInstanceUidIndex::const_iterator found = index_.find(sopInstanceUid);
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
104 if (found == index_.end())
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
105 {
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
106 target.clear();
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
107 }
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
108 else
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
109 {
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
110 target = found->second;
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
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
115 void CollectionOfAnnotations::LoadXml(const char* xml,
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
116 size_t size)
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 pugi::xml_document doc;
1593
b782f78aed42 rendering osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1584
diff changeset
119 pugi::xml_parse_result result = doc.load_buffer(xml, size);
1584
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 if (!result)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 const pugi::xml_node& root = doc.document_element();
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 if (std::string(root.name()) != "plist" ||
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 !root.first_child() ||
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128 root.first_child() != root.last_child())
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 std::map<std::string, std::string> attributes;
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 GetAttributes(attributes, root);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136 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
137 if (version == attributes.end() ||
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 version->second != "1.0")
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 std::unique_ptr<IValue> value(IValue::Parse(root.first_child()));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 const DictionaryValue& dict = dynamic_cast<const DictionaryValue&>(*value);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147 std::set<std::string> annotations;
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 dict.GetMembers(annotations);
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 for (std::set<std::string>::const_iterator
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 it = annotations.begin(); it != annotations.end(); ++it)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 const ArrayValue& images = dynamic_cast<const ArrayValue&>(dict.GetValue(*it));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 for (size_t i = 0; i < images.GetSize(); i++)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 const DictionaryValue& image = dynamic_cast<const DictionaryValue&>(images.GetValue(i));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 const IntegerValue& number = dynamic_cast<const IntegerValue&>(image.GetValue("NumberOfROIs"));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 const ArrayValue& rois = dynamic_cast<const ArrayValue&>(image.GetValue("ROIs"));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (static_cast<int64_t>(rois.GetSize()) != number.GetValue())
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 for (size_t j = 0; j < rois.GetSize(); j++)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 const DictionaryValue& roi = dynamic_cast<const DictionaryValue&>(rois.GetValue(i));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 std::unique_ptr<Annotation> annotation(Annotation::Create(roi));
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 if (annotation.get() != NULL)
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 {
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 AddAnnotation(annotation.release());
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 }
bd180f97c734 parsing osirix annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180 }