comparison Framework/Deprecated/Volumes/StructureSetLoader.cpp @ 732:c35e98d22764

move Deprecated classes to a separate folder
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 21 May 2019 14:27:35 +0200
parents Framework/Volumes/StructureSetLoader.cpp@4f2416d519b4
children 4fe4b221a31f
comparison
equal deleted inserted replaced
729:529189f399ec 732:c35e98d22764
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-2019 Osimis S.A., 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 Deprecated
29 {
30 StructureSetLoader::StructureSetLoader(OrthancStone::MessageBroker& broker,
31 OrthancApiClient& orthanc) :
32 IVolumeLoader(broker),
33 IObserver(broker),
34 orthanc_(orthanc)
35 {
36 }
37
38
39 void StructureSetLoader::OnReferencedSliceLoaded(const OrthancApiClient::JsonResponseReadyMessage& message)
40 {
41 OrthancPlugins::FullOrthancDataset dataset(message.GetJson());
42
43 Orthanc::DicomMap slice;
44 OrthancStone::MessagingToolbox::ConvertDataset(slice, dataset);
45 structureSet_->AddReferencedSlice(slice);
46
47 BroadcastMessage(ContentChangedMessage(*this));
48 }
49
50
51 void StructureSetLoader::OnStructureSetLoaded(const OrthancApiClient::JsonResponseReadyMessage& message)
52 {
53 OrthancPlugins::FullOrthancDataset dataset(message.GetJson());
54 structureSet_.reset(new OrthancStone::DicomStructureSet(dataset));
55
56 std::set<std::string> instances;
57 structureSet_->GetReferencedInstances(instances);
58
59 for (std::set<std::string>::const_iterator it = instances.begin();
60 it != instances.end(); ++it)
61 {
62 orthanc_.PostBinaryAsyncExpectJson("/tools/lookup", *it,
63 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnLookupCompleted));
64 }
65
66 BroadcastMessage(GeometryReadyMessage(*this));
67 }
68
69
70 void StructureSetLoader::OnLookupCompleted(const OrthancApiClient::JsonResponseReadyMessage& message)
71 {
72 const Json::Value& lookup = message.GetJson();
73
74 if (lookup.type() != Json::arrayValue ||
75 lookup.size() != 1 ||
76 !lookup[0].isMember("Type") ||
77 !lookup[0].isMember("Path") ||
78 lookup[0]["Type"].type() != Json::stringValue ||
79 lookup[0]["ID"].type() != Json::stringValue ||
80 lookup[0]["Type"].asString() != "Instance")
81 {
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
83 }
84
85 const std::string& instance = lookup[0]["ID"].asString();
86 orthanc_.GetJsonAsync("/instances/" + instance + "/tags",
87 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnReferencedSliceLoaded));
88 }
89
90
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 {
99 orthanc_.GetJsonAsync("/instances/" + instance + "/tags?ignore-length=3006-0050",
100 new OrthancStone::Callable<StructureSetLoader, OrthancApiClient::JsonResponseReadyMessage>(*this, &StructureSetLoader::OnStructureSetLoaded));
101 }
102 }
103
104
105 OrthancStone::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 }