Mercurial > hg > orthanc-stone
annotate Framework/Volumes/StructureSetLoader.cpp @ 343:712acc87fa2e am-2
text layer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 22 Oct 2018 14:20:39 +0200 |
parents | b4abaeb783b1 |
children | 8eb4fe74000f |
rev | line source |
---|---|
130 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
135
e2fe9352f240
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
130
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
130 | 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 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/OrthancException.h> |
130 | 27 |
28 namespace OrthancStone | |
29 { | |
30 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
31 StructureSetLoader::StructureSetLoader(MessageBroker& broker, OrthancApiClient& orthanc) : |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
32 OrthancStone::IObserver(broker), |
130 | 33 orthanc_(orthanc) |
34 { | |
35 } | |
36 | |
37 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
38 void StructureSetLoader::OnReferencedSliceLoaded(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
39 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
40 OrthancPlugins::FullOrthancDataset dataset(message.Response); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
41 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
42 Orthanc::DicomMap slice; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
43 MessagingToolbox::ConvertDataset(slice, dataset); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
44 structureSet_->AddReferencedSlice(slice); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
45 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
46 VolumeLoaderBase::NotifyContentChange(); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
47 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
48 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
49 void StructureSetLoader::OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
50 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
51 OrthancPlugins::FullOrthancDataset dataset(message.Response); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
52 structureSet_.reset(new DicomStructureSet(dataset)); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
53 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
54 std::set<std::string> instances; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
55 structureSet_->GetReferencedInstances(instances); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
56 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
57 for (std::set<std::string>::const_iterator it = instances.begin(); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
58 it != instances.end(); ++it) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
59 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
60 orthanc_.PostBinaryAsyncExpectJson("/tools/lookup", *it, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
61 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnLookupCompleted)); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
62 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
63 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
64 VolumeLoaderBase::NotifyGeometryReady(); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
65 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
66 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
67 void StructureSetLoader::OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
68 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
69 Json::Value lookup = message.Response; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
70 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
71 if (lookup.type() != Json::arrayValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
72 lookup.size() != 1 || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
73 !lookup[0].isMember("Type") || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
74 !lookup[0].isMember("Path") || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
75 lookup[0]["Type"].type() != Json::stringValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
76 lookup[0]["ID"].type() != Json::stringValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
77 lookup[0]["Type"].asString() != "Instance") |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
78 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
80 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
81 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
82 const std::string& instance = lookup[0]["ID"].asString(); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
83 orthanc_.GetJsonAsync("/instances/" + instance + "/tags", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
84 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnReferencedSliceLoaded)); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
85 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
86 |
130 | 87 void StructureSetLoader::ScheduleLoadInstance(const std::string& instance) |
88 { | |
89 if (structureSet_.get() != NULL) | |
90 { | |
91 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
92 } | |
93 else | |
94 { | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
95 orthanc_.GetJsonAsync("/instances/" + instance + "/tags?ignore-length=3006-0050", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
96 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnStructureSetLoaded)); |
130 | 97 } |
98 } | |
99 | |
100 | |
101 DicomStructureSet& StructureSetLoader::GetStructureSet() | |
102 { | |
103 if (structureSet_.get() == NULL) | |
104 { | |
105 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
106 } | |
107 else | |
108 { | |
109 return *structureSet_; | |
110 } | |
111 } | |
112 } |