Mercurial > hg > orthanc-stone
comparison Framework/Layers/DicomStructureSetRendererFactory.cpp @ 130:1982d6c1d2ff wasm
IVolumeLoader
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 16 Nov 2017 13:46:03 +0100 |
parents | a823122db53d |
children | 35c2b85836ce |
comparison
equal
deleted
inserted
replaced
129:a823122db53d | 130:1982d6c1d2ff |
---|---|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #include "DicomStructureSetRendererFactory.h" | 22 #include "DicomStructureSetRendererFactory.h" |
23 | |
24 #include "../Toolbox/MessagingToolbox.h" | |
25 | |
26 #include <Core/OrthancException.h> | |
27 | 23 |
28 namespace OrthancStone | 24 namespace OrthancStone |
29 { | 25 { |
30 class DicomStructureSetRendererFactory::Renderer : public ILayerRenderer | 26 class DicomStructureSetRendererFactory::Renderer : public ILayerRenderer |
31 { | 27 { |
101 return true; | 97 return true; |
102 } | 98 } |
103 }; | 99 }; |
104 | 100 |
105 | 101 |
106 class DicomStructureSetRendererFactory::Operation : public Orthanc::IDynamicObject | |
107 { | |
108 public: | |
109 enum Type | |
110 { | |
111 Type_LoadStructureSet, | |
112 Type_LookupSopInstanceUid, | |
113 Type_LoadReferencedSlice | |
114 }; | |
115 | |
116 private: | |
117 Type type_; | |
118 std::string value_; | |
119 | |
120 public: | |
121 Operation(Type type, | |
122 const std::string& value) : | |
123 type_(type), | |
124 value_(value) | |
125 { | |
126 } | |
127 | |
128 Type GetType() const | |
129 { | |
130 return type_; | |
131 } | |
132 | |
133 const std::string& GetIdentifier() const | |
134 { | |
135 return value_; | |
136 } | |
137 }; | |
138 | |
139 | |
140 void DicomStructureSetRendererFactory::NotifyError(const std::string& uri, | |
141 Orthanc::IDynamicObject* payload) | |
142 { | |
143 // TODO | |
144 } | |
145 | |
146 | |
147 void DicomStructureSetRendererFactory::NotifySuccess(const std::string& uri, | |
148 const void* answer, | |
149 size_t answerSize, | |
150 Orthanc::IDynamicObject* payload) | |
151 { | |
152 std::auto_ptr<Operation> op(dynamic_cast<Operation*>(payload)); | |
153 | |
154 switch (op->GetType()) | |
155 { | |
156 case Operation::Type_LoadStructureSet: | |
157 { | |
158 OrthancPlugins::FullOrthancDataset dataset(answer, answerSize); | |
159 structureSet_.reset(new DicomStructureSet(dataset)); | |
160 | |
161 std::set<std::string> instances; | |
162 structureSet_->GetReferencedInstances(instances); | |
163 | |
164 for (std::set<std::string>::const_iterator it = instances.begin(); | |
165 it != instances.end(); ++it) | |
166 { | |
167 orthanc_.SchedulePostRequest(*this, "/tools/lookup", *it, | |
168 new Operation(Operation::Type_LookupSopInstanceUid, *it)); | |
169 } | |
170 | |
171 break; | |
172 } | |
173 | |
174 case Operation::Type_LookupSopInstanceUid: | |
175 { | |
176 Json::Value lookup; | |
177 | |
178 if (MessagingToolbox::ParseJson(lookup, answer, answerSize)) | |
179 { | |
180 if (lookup.type() != Json::arrayValue || | |
181 lookup.size() != 1 || | |
182 !lookup[0].isMember("Type") || | |
183 !lookup[0].isMember("Path") || | |
184 lookup[0]["Type"].type() != Json::stringValue || | |
185 lookup[0]["ID"].type() != Json::stringValue || | |
186 lookup[0]["Type"].asString() != "Instance") | |
187 { | |
188 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); | |
189 } | |
190 | |
191 const std::string& instance = lookup[0]["ID"].asString(); | |
192 orthanc_.ScheduleGetRequest(*this, "/instances/" + instance + "/tags", | |
193 new Operation(Operation::Type_LoadReferencedSlice, instance)); | |
194 } | |
195 else | |
196 { | |
197 // TODO | |
198 } | |
199 | |
200 break; | |
201 } | |
202 | |
203 case Operation::Type_LoadReferencedSlice: | |
204 { | |
205 OrthancPlugins::FullOrthancDataset dataset(answer, answerSize); | |
206 | |
207 Orthanc::DicomMap slice; | |
208 MessagingToolbox::ConvertDataset(slice, dataset); | |
209 structureSet_->AddReferencedSlice(slice); | |
210 | |
211 LayerSourceBase::NotifyContentChange(); | |
212 | |
213 break; | |
214 } | |
215 | |
216 default: | |
217 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | |
218 } | |
219 } | |
220 | |
221 | |
222 DicomStructureSetRendererFactory::DicomStructureSetRendererFactory(IWebService& orthanc) : | |
223 orthanc_(orthanc) | |
224 { | |
225 } | |
226 | |
227 | |
228 void DicomStructureSetRendererFactory::ScheduleLoadInstance(const std::string& instance) | |
229 { | |
230 if (structureSet_.get() != NULL) | |
231 { | |
232 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
233 } | |
234 else | |
235 { | |
236 const std::string uri = "/instances/" + instance + "/tags?ignore-length=3006-0050"; | |
237 orthanc_.ScheduleGetRequest(*this, uri, new Operation(Operation::Type_LoadStructureSet, instance)); | |
238 } | |
239 } | |
240 | |
241 | |
242 void DicomStructureSetRendererFactory::ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) | 102 void DicomStructureSetRendererFactory::ScheduleLayerCreation(const CoordinateSystem3D& viewportSlice) |
243 { | 103 { |
244 if (structureSet_.get() != NULL) | 104 if (loader_.HasStructureSet()) |
245 { | 105 { |
246 NotifyLayerReady(new Renderer(*structureSet_, viewportSlice), viewportSlice, false); | 106 NotifyLayerReady(new Renderer(loader_.GetStructureSet(), viewportSlice), viewportSlice, false); |
247 } | 107 } |
248 } | 108 } |
249 } | 109 } |