130
|
1 /**
|
|
2 * Stone of Orthanc
|
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
|
|
4 * Department, University Hospital of Liege, Belgium
|
|
5 * Copyright (C) 2017 Osimis, Belgium
|
|
6 *
|
|
7 * This program is free software: you can redistribute it and/or
|
|
8 * modify it under the terms of the GNU Affero General Public License
|
|
9 * as published by the Free Software Foundation, either version 3 of
|
|
10 * the License, or (at your option) any later version.
|
|
11 *
|
|
12 * This program is distributed in the hope that it will be useful, but
|
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
15 * Affero General Public License for more details.
|
|
16 *
|
|
17 * You should have received a copy of the GNU Affero General Public License
|
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19 **/
|
|
20
|
|
21
|
|
22 #include "StructureSetLoader.h"
|
|
23
|
|
24 #include "../Toolbox/MessagingToolbox.h"
|
|
25
|
|
26 #include <Core/OrthancException.h>
|
|
27
|
|
28 namespace OrthancStone
|
|
29 {
|
|
30 class StructureSetLoader::Operation : public Orthanc::IDynamicObject
|
|
31 {
|
|
32 public:
|
|
33 enum Type
|
|
34 {
|
|
35 Type_LoadStructureSet,
|
|
36 Type_LookupSopInstanceUid,
|
|
37 Type_LoadReferencedSlice
|
|
38 };
|
|
39
|
|
40 private:
|
|
41 Type type_;
|
|
42 std::string value_;
|
|
43
|
|
44 public:
|
|
45 Operation(Type type,
|
|
46 const std::string& value) :
|
|
47 type_(type),
|
|
48 value_(value)
|
|
49 {
|
|
50 }
|
|
51
|
|
52 Type GetType() const
|
|
53 {
|
|
54 return type_;
|
|
55 }
|
|
56
|
|
57 const std::string& GetIdentifier() const
|
|
58 {
|
|
59 return value_;
|
|
60 }
|
|
61 };
|
|
62
|
|
63
|
|
64 void StructureSetLoader::NotifyError(const std::string& uri,
|
|
65 Orthanc::IDynamicObject* payload)
|
|
66 {
|
|
67 // TODO
|
|
68 }
|
|
69
|
|
70
|
|
71 void StructureSetLoader::NotifySuccess(const std::string& uri,
|
|
72 const void* answer,
|
|
73 size_t answerSize,
|
|
74 Orthanc::IDynamicObject* payload)
|
|
75 {
|
|
76 std::auto_ptr<Operation> op(dynamic_cast<Operation*>(payload));
|
|
77
|
|
78 switch (op->GetType())
|
|
79 {
|
|
80 case Operation::Type_LoadStructureSet:
|
|
81 {
|
|
82 OrthancPlugins::FullOrthancDataset dataset(answer, answerSize);
|
|
83 structureSet_.reset(new DicomStructureSet(dataset));
|
|
84
|
|
85 std::set<std::string> instances;
|
|
86 structureSet_->GetReferencedInstances(instances);
|
|
87
|
|
88 for (std::set<std::string>::const_iterator it = instances.begin();
|
|
89 it != instances.end(); ++it)
|
|
90 {
|
|
91 orthanc_.SchedulePostRequest(*this, "/tools/lookup", *it,
|
|
92 new Operation(Operation::Type_LookupSopInstanceUid, *it));
|
|
93 }
|
|
94
|
|
95 VolumeLoaderBase::NotifyGeometryReady();
|
|
96
|
|
97 break;
|
|
98 }
|
|
99
|
|
100 case Operation::Type_LookupSopInstanceUid:
|
|
101 {
|
|
102 Json::Value lookup;
|
|
103
|
|
104 if (MessagingToolbox::ParseJson(lookup, answer, answerSize))
|
|
105 {
|
|
106 if (lookup.type() != Json::arrayValue ||
|
|
107 lookup.size() != 1 ||
|
|
108 !lookup[0].isMember("Type") ||
|
|
109 !lookup[0].isMember("Path") ||
|
|
110 lookup[0]["Type"].type() != Json::stringValue ||
|
|
111 lookup[0]["ID"].type() != Json::stringValue ||
|
|
112 lookup[0]["Type"].asString() != "Instance")
|
|
113 {
|
|
114 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
|
|
115 }
|
|
116
|
|
117 const std::string& instance = lookup[0]["ID"].asString();
|
|
118 orthanc_.ScheduleGetRequest(*this, "/instances/" + instance + "/tags",
|
|
119 new Operation(Operation::Type_LoadReferencedSlice, instance));
|
|
120 }
|
|
121 else
|
|
122 {
|
|
123 // TODO
|
|
124 }
|
|
125
|
|
126 break;
|
|
127 }
|
|
128
|
|
129 case Operation::Type_LoadReferencedSlice:
|
|
130 {
|
|
131 OrthancPlugins::FullOrthancDataset dataset(answer, answerSize);
|
|
132
|
|
133 Orthanc::DicomMap slice;
|
|
134 MessagingToolbox::ConvertDataset(slice, dataset);
|
|
135 structureSet_->AddReferencedSlice(slice);
|
|
136
|
|
137 VolumeLoaderBase::NotifyContentChange();
|
|
138
|
|
139 break;
|
|
140 }
|
|
141
|
|
142 default:
|
|
143 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
|
|
144 }
|
|
145 }
|
|
146
|
|
147
|
|
148 StructureSetLoader::StructureSetLoader(IWebService& orthanc) :
|
|
149 orthanc_(orthanc)
|
|
150 {
|
|
151 }
|
|
152
|
|
153
|
|
154 void StructureSetLoader::ScheduleLoadInstance(const std::string& instance)
|
|
155 {
|
|
156 if (structureSet_.get() != NULL)
|
|
157 {
|
|
158 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
|
|
159 }
|
|
160 else
|
|
161 {
|
|
162 const std::string uri = "/instances/" + instance + "/tags?ignore-length=3006-0050";
|
|
163 orthanc_.ScheduleGetRequest(*this, uri, new Operation(Operation::Type_LoadStructureSet, instance));
|
|
164 }
|
|
165 }
|
|
166
|
|
167
|
|
168 DicomStructureSet& StructureSetLoader::GetStructureSet()
|
|
169 {
|
|
170 if (structureSet_.get() == NULL)
|
|
171 {
|
|
172 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
|
|
173 }
|
|
174 else
|
|
175 {
|
|
176 return *structureSet_;
|
|
177 }
|
|
178 }
|
|
179 }
|