Mercurial > hg > orthanc-stone
annotate Framework/Volumes/StructureSetLoader.cpp @ 411:3aa058dcd5fb
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 12 Nov 2018 16:07:42 +0100 |
parents | ba4ace20454e |
children | b70e9be013e4 |
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 { | |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
30 StructureSetLoader::StructureSetLoader(MessageBroker& broker, |
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; |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
44 MessagingToolbox::ConvertDataset(slice, dataset); |
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 |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
47 EmitMessage(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()); |
300
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
54 structureSet_.reset(new DicomStructureSet(dataset)); |
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, |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
63 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnLookupCompleted)); |
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 |
404
ba4ace20454e
use of MessageBroker in DicomStructureSetSlicer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
377
diff
changeset
|
66 EmitMessage(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", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
87 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnReferencedSliceLoaded)); |
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", |
b4abaeb783b1
messaging refactoring almost complete: works fine in native
am@osimis.io
parents:
257
diff
changeset
|
100 new Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnStructureSetLoaded)); |
130 | 101 } |
102 } | |
103 | |
104 | |
105 DicomStructureSet& StructureSetLoader::GetStructureSet() | |
106 { | |
107 if (structureSet_.get() == NULL) | |
108 { | |
109 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
110 } | |
111 else | |
112 { | |
113 return *structureSet_; | |
114 } | |
115 } | |
116 } |