annotate Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApplication.h @ 1474:d1dde1f86d4a

fix build of wasm samples
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Jun 2020 18:21:34 +0200
parents 474360793956
children 169adf9090a6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1457
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
1 /**
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
2 * Stone of Orthanc
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
4 * Department, University Hospital of Liege, Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
6 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
7 * This program is free software: you can redistribute it and/or
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
10 * the License, or (at your option) any later version.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
11 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
12 * This program is distributed in the hope that it will be useful, but
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
15 * Affero General Public License for more details.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
16 *
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
19 **/
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
21
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22 #pragma once
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23
1457
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
24 #include "../../../Framework/Loaders/DicomResourcesLoader.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
25 #include "../../../Framework/Loaders/ILoadersContext.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
26 #include "../../../Framework/Loaders/SeriesFramesLoader.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
27 #include "../../../Framework/Loaders/SeriesThumbnailsLoader.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1354
diff changeset
28 #include "../../../Framework/Viewport/IViewport.h"
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 #include <boost/make_shared.hpp>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 namespace OrthancStone
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 class Application : public ObserverBase<Application>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 private:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 ILoadersContext& context_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 boost::shared_ptr<IViewport> viewport_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 boost::shared_ptr<DicomResourcesLoader> dicomLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 boost::shared_ptr<SeriesFramesLoader> framesLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 Application(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 boost::shared_ptr<IViewport> viewport) :
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 context_(context),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 viewport_(viewport)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 void Handle(const SeriesFramesLoader::FrameLoadedMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 LOG(INFO) << "Frame decoded! "
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 << message.GetImage().GetWidth() << "x" << message.GetImage().GetHeight()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 << " " << Orthanc::EnumerationToString(message.GetImage().GetFormat());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 std::auto_ptr<TextureBaseSceneLayer> layer(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 message.GetInstanceParameters().CreateTexture(message.GetImage()));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 layer->SetLinearInterpolation(true);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 std::auto_ptr<IViewport::ILock> lock(viewport_->Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 lock->GetController().GetScene().SetLayer(0, layer.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 lock->GetCompositor().FitContent(lock->GetController().GetScene());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 lock->Invalidate();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 void Handle(const DicomResourcesLoader::SuccessMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 if (message.GetResources()->GetSize() != 1)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 //message.GetResources()->GetResource(0).Print(stdout);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 SeriesFramesLoader::Factory f(*message.GetResources());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 framesLoader_ = boost::dynamic_pointer_cast<SeriesFramesLoader>(f.Create(*lock));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 Register<SeriesFramesLoader::FrameLoadedMessage>(*framesLoader_, &Application::Handle);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 assert(message.HasUserPayload());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 const Orthanc::SingleValueObject<unsigned int>& payload =
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86 dynamic_cast<const Orthanc::SingleValueObject<unsigned int>&>(message.GetUserPayload());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88 LOG(INFO) << "Loading pixel data of frame: " << payload.GetValue();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 framesLoader_->ScheduleLoadFrame(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 0, message.GetDicomSource(), payload.GetValue(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91 message.GetDicomSource().GetQualityCount() - 1 /* download best quality available */,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 NULL);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 static boost::shared_ptr<Application> Create(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 boost::shared_ptr<IViewport> viewport)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 boost::shared_ptr<Application> application(new Application(context, viewport));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 std::auto_ptr<ILoadersContext::ILock> lock(context.Lock());
1472
474360793956 DicomResourcesLoader::Create()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
104 application->dicomLoader_ = DicomResourcesLoader::Create(*lock);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 application->Register<DicomResourcesLoader::SuccessMessage>(*application->dicomLoader_, &Application::Handle);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109 return application;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 void LoadOrthancFrame(const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
113 const std::string& instanceId,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 unsigned int frame)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 dicomLoader_->ScheduleLoadOrthancResource(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_SOP_INSTANCE_UID),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 0, source, Orthanc::ResourceType_Instance, instanceId,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121 new Orthanc::SingleValueObject<unsigned int>(frame));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 void LoadDicomWebFrame(const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 const std::string& seriesInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 const std::string& sopInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 unsigned int frame)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 // We first must load the "/metadata" to know the number of frames
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 dicomLoader_->ScheduleGetDicomWeb(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_SOP_INSTANCE_UID), 0, source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/instances/" + sopInstanceUid + "/metadata",
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 new Orthanc::SingleValueObject<unsigned int>(frame));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 void FitContent()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 std::auto_ptr<IViewport::ILock> lock(viewport_->Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 lock->GetCompositor().FitContent(lock->GetController().GetScene());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 lock->Invalidate();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 class IWebViewerLoadersObserver : public boost::noncopyable
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 virtual ~IWebViewerLoadersObserver()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156 virtual void SignalSeriesUpdated(LoadedDicomResources& series) = 0;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 virtual void SignalThumbnailLoaded(const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 const std::string& seriesInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 SeriesThumbnailType type) = 0;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 class WebViewerLoaders : public ObserverBase<WebViewerLoaders>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 private:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167 static const int PRIORITY_ADD_RESOURCES = 0;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
168 static const int PRIORITY_THUMBNAILS = OracleScheduler::PRIORITY_LOW + 100;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170 enum Type
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
171 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 Type_Orthanc = 1,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 Type_DicomWeb = 2
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 ILoadersContext& context_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
177 std::auto_ptr<IWebViewerLoadersObserver> observer_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
178 bool loadThumbnails_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 DicomSource source_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
180 std::set<std::string> scheduledSeries_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181 std::set<std::string> scheduledThumbnails_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182 std::set<std::string> scheduledStudies_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183 boost::shared_ptr<LoadedDicomResources> loadedSeries_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 boost::shared_ptr<LoadedDicomResources> loadedStudies_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 boost::shared_ptr<DicomResourcesLoader> resourcesLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 boost::shared_ptr<SeriesThumbnailsLoader> thumbnailsLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 WebViewerLoaders(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 IWebViewerLoadersObserver* observer) :
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 context_(context),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191 observer_(observer),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
192 loadThumbnails_(false)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 loadedSeries_ = boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195 loadedStudies_ = boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
197
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 static Orthanc::IDynamicObject* CreatePayload(Type type)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 return new Orthanc::SingleValueObject<Type>(type);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202
1474
d1dde1f86d4a fix build of wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1472
diff changeset
203 void HandleThumbnail(const SeriesThumbnailsLoader::SuccessMessage& message)
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 if (observer_.get() != NULL)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 observer_->SignalThumbnailLoaded(message.GetStudyInstanceUid(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 message.GetSeriesInstanceUid(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 message.GetType());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
213 void HandleLoadedResources(const DicomResourcesLoader::SuccessMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 LoadedDicomResources series(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217 switch (dynamic_cast<const Orthanc::SingleValueObject<Type>&>(message.GetUserPayload()).GetValue())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 case Type_DicomWeb:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 for (size_t i = 0; i < loadedSeries_->GetSize(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 std::string study;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 if (loadedSeries_->GetResource(i).LookupStringValue(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 study, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 loadedStudies_->HasResource(study))
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
227 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 Orthanc::DicomMap m;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 m.Assign(loadedSeries_->GetResource(i));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 loadedStudies_->MergeResource(m, study);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 series.AddResource(m);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 break;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 case Type_Orthanc:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 for (size_t i = 0; i < message.GetResources()->GetSize(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 series.AddResource(message.GetResources()->GetResource(i));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 break;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248 default:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
252 if (loadThumbnails_ &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 (!source_.IsDicomWeb() ||
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 source_.HasDicomWebRendered()))
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 for (size_t i = 0; i < series.GetSize(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 std::string patientId, studyInstanceUid, seriesInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 if (series.GetResource(i).LookupStringValue(patientId, Orthanc::DICOM_TAG_PATIENT_ID, false) &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 series.GetResource(i).LookupStringValue(studyInstanceUid, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 series.GetResource(i).LookupStringValue(seriesInstanceUid, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false) &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 scheduledThumbnails_.find(seriesInstanceUid) == scheduledThumbnails_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
263 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 scheduledThumbnails_.insert(seriesInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
265 thumbnailsLoader_->ScheduleLoadThumbnail(source_, patientId, studyInstanceUid, seriesInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
266 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
267 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
268 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
269
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270 if (observer_.get() != NULL &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 series.GetSize() > 0)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
272 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 observer_->SignalSeriesUpdated(series);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 void HandleOrthancRestApi(const OrthancRestApiCommand::SuccessMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
279 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280 message.ParseJsonBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
281
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
282 if (body.type() != Json::arrayValue)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
283 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
287 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
288 for (Json::Value::ArrayIndex i = 0; i < body.size(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 if (body[i].type() == Json::stringValue)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
292 AddOrthancSeries(body[i].asString());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
295 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
296 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
297 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
298 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
299 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
300 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
301
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
302 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 static boost::shared_ptr<WebViewerLoaders> Create(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
304 const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
305 bool loadThumbnails,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
306 IWebViewerLoadersObserver* observer)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
307 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
308 boost::shared_ptr<WebViewerLoaders> application(new WebViewerLoaders(context, observer));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
309 application->source_ = source;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
310 application->loadThumbnails_ = loadThumbnails;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
311
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
312 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
313 std::auto_ptr<ILoadersContext::ILock> lock(context.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
314
1472
474360793956 DicomResourcesLoader::Create()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
315 application->resourcesLoader_ = DicomResourcesLoader::Create(*lock);
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
316
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
317 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
318 SeriesThumbnailsLoader::Factory f;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
319 f.SetPriority(PRIORITY_THUMBNAILS);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
320 application->thumbnailsLoader_ = boost::dynamic_pointer_cast<SeriesThumbnailsLoader>(f.Create(*lock));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
321 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
322
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
323 application->Register<OrthancRestApiCommand::SuccessMessage>(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324 lock->GetOracleObservable(), &WebViewerLoaders::HandleOrthancRestApi);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
325
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
326 application->Register<DicomResourcesLoader::SuccessMessage>(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
327 *application->resourcesLoader_, &WebViewerLoaders::HandleLoadedResources);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
328
1474
d1dde1f86d4a fix build of wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1472
diff changeset
329 application->Register<SeriesThumbnailsLoader::SuccessMessage>(
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330 *application->thumbnailsLoader_, &WebViewerLoaders::HandleThumbnail);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
331
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
332 lock->AddLoader(application);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
333 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
334
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
335 return application;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
336 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
337
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
338 void AddDicomAllSeries()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
339 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
340 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
341
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
342 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
343 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
344 resourcesLoader_->ScheduleGetDicomWeb(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
345 "/series", CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
346 resourcesLoader_->ScheduleGetDicomWeb(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
347 "/studies", CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
348 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
349 else if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
350 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
351 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
352 command->SetMethod(Orthanc::HttpMethod_Get);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
353 command->SetUri("/series");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
354 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
355 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
356 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
357 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
358 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
359 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
360 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
361
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
362 void AddDicomStudy(const std::string& studyInstanceUid)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
363 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
364 // Avoid adding twice the same study
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
365 if (scheduledStudies_.find(studyInstanceUid) == scheduledStudies_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
366 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
367 scheduledStudies_.insert(studyInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
368
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
369 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
370 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
371 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
372 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
373
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
374 std::set<Orthanc::DicomTag> tags;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
375
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
376 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
379 resourcesLoader_->ScheduleQido(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
380 Orthanc::ResourceType_Study, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
381
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
382 resourcesLoader_->ScheduleQido(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383 Orthanc::ResourceType_Series, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
386 else if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
387 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 command->SetMethod(Orthanc::HttpMethod_Post);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
390 command->SetUri("/tools/find");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
391
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
392 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 body["Level"] = "Series";
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
394 body["Query"] = Json::objectValue;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
395 body["Query"]["StudyInstanceUID"] = studyInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
396 command->SetBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
397
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
399 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
401 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
402 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
406 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
407 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
408 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
409
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
410 void AddDicomSeries(const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
411 const std::string& seriesInstanceUid)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
412 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
413 std::set<Orthanc::DicomTag> tags;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
414
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
415 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
416
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
417 if (scheduledStudies_.find(studyInstanceUid) == scheduledStudies_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
418 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
419 scheduledStudies_.insert(studyInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
420
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
421 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
422 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
423 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
424 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
425
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
426 resourcesLoader_->ScheduleQido(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
427 Orthanc::ResourceType_Study, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
428 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
429 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
430
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
431 if (scheduledSeries_.find(seriesInstanceUid) == scheduledSeries_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
432 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
433 scheduledSeries_.insert(seriesInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
434
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
435 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
436 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
437 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
438 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
439 filter.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, seriesInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
440
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
441 resourcesLoader_->ScheduleQido(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
442 Orthanc::ResourceType_Series, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
443 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
444 else if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
445 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
446 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
447 command->SetMethod(Orthanc::HttpMethod_Post);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
448 command->SetUri("/tools/find");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
449
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
450 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
451 body["Level"] = "Series";
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
452 body["Query"] = Json::objectValue;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
453 body["Query"]["StudyInstanceUID"] = studyInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
454 body["Query"]["SeriesInstanceUID"] = seriesInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
455 command->SetBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
456
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
457 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
458 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
459 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
460 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
461 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
462 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
463 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
464 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
465
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
466 void AddOrthancStudy(const std::string& orthancId)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
467 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
468 if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
469 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
470 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
471 resourcesLoader_->ScheduleLoadOrthancResources(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
472 loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
473 Orthanc::ResourceType_Study, orthancId, Orthanc::ResourceType_Series,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
474 CreatePayload(Type_Orthanc));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
475 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
476 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
477 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
478 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
479 "Only applicable to Orthanc DICOM sources");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
480 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
481 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
482
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
483 void AddOrthancSeries(const std::string& orthancId)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
484 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
485 if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
486 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
487 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
488 resourcesLoader_->ScheduleLoadOrthancResource(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
489 loadedSeries_, PRIORITY_ADD_RESOURCES,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
490 source_, Orthanc::ResourceType_Series, orthancId,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
491 CreatePayload(Type_Orthanc));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
492 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
493 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
494 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
495 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadParameterType,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
496 "Only applicable to Orthanc DICOM sources");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
497 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
498 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
499 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
500 }