Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Volumes/StructureSetLoader.cpp @ 959:13e078adfb94 toa2019082301
Better error log in fetch failure callback +
timeout 600sec in OrthancRestApiCommand +
guard against dead controller access in PanSceneTracker +
relaxed DicomStructureSet AddReferenceSlice method to accept extraneous adds
of the same slice (while trying to understand how it happens in the first place)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 23 Aug 2019 14:16:45 +0200 |
parents | 4fe4b221a31f |
children | b537002f83a9 2d8ab34c8c91 |
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 | |
439 | 5 * Copyright (C) 2017-2019 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 | |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
24 #include "../Toolbox/MessagingToolbox.h" |
130 | 25 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/OrthancException.h> |
130 | 27 |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
28 namespace Deprecated |
130 | 29 { |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
30 StructureSetLoader::StructureSetLoader(OrthancStone::MessageBroker& broker, |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
31 OrthancApiClient& orthanc) : |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
32 IVolumeLoader(broker), |
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
33 IObserver(broker), |
130 | 34 orthanc_(orthanc) |
35 { | |
36 } | |
37 | |
38 | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
39 void StructureSetLoader::OnReferencedSliceLoaded(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
40 { |
377 | 41 OrthancPlugins::FullOrthancDataset dataset(message.GetJson()); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
42 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
43 Orthanc::DicomMap slice; |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
44 MessagingToolbox::ConvertDataset(slice, dataset); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
45 structureSet_->AddReferencedSlice(slice); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
46 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
47 BroadcastMessage(ContentChangedMessage(*this)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
48 } |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
49 |
300
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 void StructureSetLoader::OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
52 { |
377 | 53 OrthancPlugins::FullOrthancDataset dataset(message.GetJson()); |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
54 structureSet_.reset(new OrthancStone::DicomStructureSet(dataset)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
55 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
56 std::set<std::string> instances; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
57 structureSet_->GetReferencedInstances(instances); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
58 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
59 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
|
60 it != instances.end(); ++it) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
61 { |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
62 orthanc_.PostBinaryAsyncExpectJson("/tools/lookup", *it, |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
63 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnLookupCompleted)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
64 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
65 |
623
42dadae61fa9
renamed IObservable::EmitMessage() as BroadcastMessage()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
439
diff
changeset
|
66 BroadcastMessage(GeometryReadyMessage(*this)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
67 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
68 |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
69 |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
70 void StructureSetLoader::OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message) |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
71 { |
377 | 72 const Json::Value& lookup = message.GetJson(); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
73 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
74 if (lookup.type() != Json::arrayValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
75 lookup.size() != 1 || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
76 !lookup[0].isMember("Type") || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
77 !lookup[0].isMember("Path") || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
78 lookup[0]["Type"].type() != Json::stringValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
79 lookup[0]["ID"].type() != Json::stringValue || |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
80 lookup[0]["Type"].asString() != "Instance") |
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
83 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
84 |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
85 const std::string& instance = lookup[0]["ID"].asString(); |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
86 orthanc_.GetJsonAsync("/instances/" + instance + "/tags", |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
87 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnReferencedSliceLoaded)); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
88 } |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
89 |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
90 |
130 | 91 void StructureSetLoader::ScheduleLoadInstance(const std::string& instance) |
92 { | |
93 if (structureSet_.get() != NULL) | |
94 { | |
95 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
96 } | |
97 else | |
98 { | |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
99 orthanc_.GetJsonAsync("/instances/" + instance + "/tags?ignore-length=3006-0050", |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
100 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnStructureSetLoaded)); |
130 | 101 } |
102 } | |
103 | |
104 | |
726
4f2416d519b4
moving layers, widgets and loaders to Deprecated namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
623
diff
changeset
|
105 OrthancStone::DicomStructureSet& StructureSetLoader::GetStructureSet() |
130 | 106 { |
107 if (structureSet_.get() == NULL) | |
108 { | |
109 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
110 } | |
111 else | |
112 { | |
113 return *structureSet_; | |
114 } | |
115 } | |
792
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
116 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
117 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
118 OrthancStone::DicomStructureSet* StructureSetLoader::SynchronousLoad( |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
119 OrthancPlugins::IOrthancConnection& orthanc, |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
120 const std::string& instanceId) |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
121 { |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
122 const std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3006-0050"; |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
123 OrthancPlugins::FullOrthancDataset dataset(orthanc, uri); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
124 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
125 std::auto_ptr<OrthancStone::DicomStructureSet> result |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
126 (new OrthancStone::DicomStructureSet(dataset)); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
127 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
128 std::set<std::string> instances; |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
129 result->GetReferencedInstances(instances); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
130 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
131 for (std::set<std::string>::const_iterator it = instances.begin(); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
132 it != instances.end(); ++it) |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
133 { |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
134 Json::Value lookup; |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
135 MessagingToolbox::RestApiPost(lookup, orthanc, "/tools/lookup", *it); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
136 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
137 if (lookup.type() != Json::arrayValue || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
138 lookup.size() != 1 || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
139 !lookup[0].isMember("Type") || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
140 !lookup[0].isMember("Path") || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
141 lookup[0]["Type"].type() != Json::stringValue || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
142 lookup[0]["ID"].type() != Json::stringValue || |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
143 lookup[0]["Type"].asString() != "Instance") |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
144 { |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
145 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
146 } |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
147 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
148 OrthancPlugins::FullOrthancDataset slice |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
149 (orthanc, "/instances/" + lookup[0]["ID"].asString() + "/tags"); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
150 Orthanc::DicomMap m; |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
151 MessagingToolbox::ConvertDataset(m, slice); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
152 result->AddReferencedSlice(m); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
153 } |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
154 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
155 result->CheckReferencedSlices(); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
156 |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
157 return result.release(); |
4fe4b221a31f
deprecating MessagingToolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
732
diff
changeset
|
158 } |
130 | 159 } |