annotate Samples/WebAssembly/SingleFrameViewer/SingleFrameViewerApplication.h @ 1354:c0e4eb14c912 broker

SingleFrameViewer WASM working OK
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 15 Apr 2020 12:59:15 +0200
parents
children 15173a383a00
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1354
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 #pragma once
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 #include <Framework/Viewport/IViewport.h>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 #include <Framework/Loaders/DicomResourcesLoader.h>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 #include <Framework/Loaders/ILoadersContext.h>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 #include <Framework/Loaders/SeriesFramesLoader.h>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 #include <Framework/Loaders/SeriesThumbnailsLoader.h>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 #include <boost/make_shared.hpp>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 namespace OrthancStone
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 class Application : public ObserverBase<Application>
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 private:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 ILoadersContext& context_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 boost::shared_ptr<IViewport> viewport_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 boost::shared_ptr<DicomResourcesLoader> dicomLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20 boost::shared_ptr<SeriesFramesLoader> framesLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22 Application(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23 boost::shared_ptr<IViewport> viewport) :
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24 context_(context),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25 viewport_(viewport)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29 void Handle(const SeriesFramesLoader::FrameLoadedMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 LOG(INFO) << "Frame decoded! "
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 << message.GetImage().GetWidth() << "x" << message.GetImage().GetHeight()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 << " " << Orthanc::EnumerationToString(message.GetImage().GetFormat());
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 std::auto_ptr<TextureBaseSceneLayer> layer(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 message.GetInstanceParameters().CreateTexture(message.GetImage()));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 layer->SetLinearInterpolation(true);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 std::auto_ptr<IViewport::ILock> lock(viewport_->Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 lock->GetController().GetScene().SetLayer(0, layer.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 lock->GetCompositor().FitContent(lock->GetController().GetScene());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 lock->Invalidate();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 void Handle(const DicomResourcesLoader::SuccessMessage& message)
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 if (message.GetResources()->GetSize() != 1)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 //message.GetResources()->GetResource(0).Print(stdout);
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 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 SeriesFramesLoader::Factory f(*message.GetResources());
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 framesLoader_ = boost::dynamic_pointer_cast<SeriesFramesLoader>(f.Create(*lock));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 Register<SeriesFramesLoader::FrameLoadedMessage>(*framesLoader_, &Application::Handle);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 assert(message.HasUserPayload());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 const Orthanc::SingleValueObject<unsigned int>& payload =
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 dynamic_cast<const Orthanc::SingleValueObject<unsigned int>&>(message.GetUserPayload());
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 LOG(INFO) << "Loading pixel data of frame: " << payload.GetValue();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 framesLoader_->ScheduleLoadFrame(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 0, message.GetDicomSource(), payload.GetValue(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 message.GetDicomSource().GetQualityCount() - 1 /* download best quality available */,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 NULL);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 }
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 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 static boost::shared_ptr<Application> Create(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 boost::shared_ptr<IViewport> viewport)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 boost::shared_ptr<Application> application(new Application(context, viewport));
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 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 std::auto_ptr<ILoadersContext::ILock> lock(context.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83 DicomResourcesLoader::Factory f;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 application->dicomLoader_ = boost::dynamic_pointer_cast<DicomResourcesLoader>(f.Create(*lock));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 application->Register<DicomResourcesLoader::SuccessMessage>(*application->dicomLoader_, &Application::Handle);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 return application;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 void LoadOrthancFrame(const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 const std::string& instanceId,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 unsigned int frame)
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 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 dicomLoader_->ScheduleLoadOrthancResource(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_SOP_INSTANCE_UID),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 0, source, Orthanc::ResourceType_Instance, instanceId,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 new Orthanc::SingleValueObject<unsigned int>(frame));
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 void LoadDicomWebFrame(const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 const std::string& seriesInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 const std::string& sopInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 unsigned int frame)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
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 // 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
113 dicomLoader_->ScheduleGetDicomWeb(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 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
115 "/studies/" + studyInstanceUid + "/series/" + seriesInstanceUid + "/instances/" + sopInstanceUid + "/metadata",
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 new Orthanc::SingleValueObject<unsigned int>(frame));
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 void FitContent()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121 std::auto_ptr<IViewport::ILock> lock(viewport_->Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 lock->GetCompositor().FitContent(lock->GetController().GetScene());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 lock->Invalidate();
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 class IWebViewerLoadersObserver : public boost::noncopyable
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 virtual ~IWebViewerLoadersObserver()
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 virtual void SignalSeriesUpdated(LoadedDicomResources& series) = 0;
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 virtual void SignalThumbnailLoaded(const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 const std::string& seriesInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 SeriesThumbnailType type) = 0;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 };
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 class WebViewerLoaders : public ObserverBase<WebViewerLoaders>
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 private:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147 static const int PRIORITY_ADD_RESOURCES = 0;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 static const int PRIORITY_THUMBNAILS = OracleScheduler::PRIORITY_LOW + 100;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 enum Type
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 Type_Orthanc = 1,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153 Type_DicomWeb = 2
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 ILoadersContext& context_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 std::auto_ptr<IWebViewerLoadersObserver> observer_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 bool loadThumbnails_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 DicomSource source_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 std::set<std::string> scheduledSeries_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 std::set<std::string> scheduledThumbnails_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 std::set<std::string> scheduledStudies_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 boost::shared_ptr<LoadedDicomResources> loadedSeries_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 boost::shared_ptr<LoadedDicomResources> loadedStudies_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 boost::shared_ptr<DicomResourcesLoader> resourcesLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 boost::shared_ptr<SeriesThumbnailsLoader> thumbnailsLoader_;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
168 WebViewerLoaders(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169 IWebViewerLoadersObserver* observer) :
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170 context_(context),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
171 observer_(observer),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 loadThumbnails_(false)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 loadedSeries_ = boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175 loadedStudies_ = boost::make_shared<LoadedDicomResources>(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
177
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
178 static Orthanc::IDynamicObject* CreatePayload(Type type)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
180 return new Orthanc::SingleValueObject<Type>(type);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183 void HandleThumbnail(const SeriesThumbnailsLoader::ThumbnailLoadedMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 if (observer_.get() != NULL)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 observer_->SignalThumbnailLoaded(message.GetStudyInstanceUid(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 message.GetSeriesInstanceUid(),
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 message.GetType());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
192
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 void HandleLoadedResources(const DicomResourcesLoader::SuccessMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195 LoadedDicomResources series(Orthanc::DICOM_TAG_SERIES_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 switch (dynamic_cast<const Orthanc::SingleValueObject<Type>&>(message.GetUserPayload()).GetValue())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199 case Type_DicomWeb:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 for (size_t i = 0; i < loadedSeries_->GetSize(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203 std::string study;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 if (loadedSeries_->GetResource(i).LookupStringValue(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 study, Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, false) &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206 loadedStudies_->HasResource(study))
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 Orthanc::DicomMap m;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 m.Assign(loadedSeries_->GetResource(i));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 loadedStudies_->MergeResource(m, study);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 series.AddResource(m);
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 }
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 break;
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 case Type_Orthanc:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 for (size_t i = 0; i < message.GetResources()->GetSize(); i++)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 series.AddResource(message.GetResources()->GetResource(i));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 break;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 }
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 default:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 if (loadThumbnails_ &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 (!source_.IsDicomWeb() ||
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 source_.HasDicomWebRendered()))
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 for (size_t i = 0; i < series.GetSize(); i++)
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 std::string patientId, studyInstanceUid, seriesInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 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
240 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
241 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
242 scheduledThumbnails_.find(seriesInstanceUid) == scheduledThumbnails_.end())
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 scheduledThumbnails_.insert(seriesInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 thumbnailsLoader_->ScheduleLoadThumbnail(source_, patientId, studyInstanceUid, seriesInstanceUid);
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 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 if (observer_.get() != NULL &&
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 series.GetSize() > 0)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
252 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 observer_->SignalSeriesUpdated(series);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 }
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 void HandleOrthancRestApi(const OrthancRestApiCommand::SuccessMessage& message)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 message.ParseJsonBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 if (body.type() != Json::arrayValue)
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
265 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
266 else
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 for (Json::Value::ArrayIndex i = 0; i < body.size(); i++)
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 (body[i].type() == Json::stringValue)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
272 AddOrthancSeries(body[i].asString());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 else
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 }
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 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280 }
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 public:
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
283 static boost::shared_ptr<WebViewerLoaders> Create(ILoadersContext& context,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 const DicomSource& source,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 bool loadThumbnails,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 IWebViewerLoadersObserver* observer)
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 boost::shared_ptr<WebViewerLoaders> application(new WebViewerLoaders(context, observer));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 application->source_ = source;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 application->loadThumbnails_ = loadThumbnails;
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 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293 std::auto_ptr<ILoadersContext::ILock> lock(context.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294
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 DicomResourcesLoader::Factory f;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
297 application->resourcesLoader_ = boost::dynamic_pointer_cast<DicomResourcesLoader>(f.Create(*lock));
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 SeriesThumbnailsLoader::Factory f;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
302 f.SetPriority(PRIORITY_THUMBNAILS);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 application->thumbnailsLoader_ = boost::dynamic_pointer_cast<SeriesThumbnailsLoader>(f.Create(*lock));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
304 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
305
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
306 application->Register<OrthancRestApiCommand::SuccessMessage>(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
307 lock->GetOracleObservable(), &WebViewerLoaders::HandleOrthancRestApi);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
308
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
309 application->Register<DicomResourcesLoader::SuccessMessage>(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
310 *application->resourcesLoader_, &WebViewerLoaders::HandleLoadedResources);
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 application->Register<SeriesThumbnailsLoader::ThumbnailLoadedMessage>(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
313 *application->thumbnailsLoader_, &WebViewerLoaders::HandleThumbnail);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
314
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
315 lock->AddLoader(application);
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 return application;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
319 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
320
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
321 void AddDicomAllSeries()
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 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
325 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
326 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
327 resourcesLoader_->ScheduleGetDicomWeb(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
328 "/series", CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
329 resourcesLoader_->ScheduleGetDicomWeb(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330 "/studies", CreatePayload(Type_DicomWeb));
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 else if (source_.IsOrthanc())
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 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
335 command->SetMethod(Orthanc::HttpMethod_Get);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
336 command->SetUri("/series");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
337 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
338 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
339 else
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
340 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
341 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
342 }
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
345 void AddDicomStudy(const std::string& studyInstanceUid)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
346 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
347 // Avoid adding twice the same study
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
348 if (scheduledStudies_.find(studyInstanceUid) == scheduledStudies_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
349 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
350 scheduledStudies_.insert(studyInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
351
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
352 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
353 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
354 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
355 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
356
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
357 std::set<Orthanc::DicomTag> tags;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
358
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 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
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 resourcesLoader_->ScheduleQido(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
363 Orthanc::ResourceType_Study, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
364
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
365 resourcesLoader_->ScheduleQido(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
366 Orthanc::ResourceType_Series, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
367 }
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 else if (source_.IsOrthanc())
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 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
372 command->SetMethod(Orthanc::HttpMethod_Post);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
373 command->SetUri("/tools/find");
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
374
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
375 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
376 body["Level"] = "Series";
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377 body["Query"] = Json::objectValue;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378 body["Query"]["StudyInstanceUID"] = studyInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
379 command->SetBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
380
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 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
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
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
390 }
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 void AddDicomSeries(const std::string& studyInstanceUid,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
394 const std::string& seriesInstanceUid)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
395 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
396 std::set<Orthanc::DicomTag> tags;
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 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
399
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 if (scheduledStudies_.find(studyInstanceUid) == scheduledStudies_.end())
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 scheduledStudies_.insert(studyInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
406 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
407 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
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 resourcesLoader_->ScheduleQido(loadedStudies_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
410 Orthanc::ResourceType_Study, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
411 }
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
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
414 if (scheduledSeries_.find(seriesInstanceUid) == scheduledSeries_.end())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
415 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
416 scheduledSeries_.insert(seriesInstanceUid);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
417
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
418 if (source_.IsDicomWeb())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
419 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
420 Orthanc::DicomMap filter;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
421 filter.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, studyInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
422 filter.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, seriesInstanceUid, false);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
423
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
424 resourcesLoader_->ScheduleQido(loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
425 Orthanc::ResourceType_Series, filter, tags, CreatePayload(Type_DicomWeb));
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
426 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
427 else if (source_.IsOrthanc())
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 std::auto_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
430 command->SetMethod(Orthanc::HttpMethod_Post);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
431 command->SetUri("/tools/find");
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 Json::Value body;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
434 body["Level"] = "Series";
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
435 body["Query"] = Json::objectValue;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
436 body["Query"]["StudyInstanceUID"] = studyInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
437 body["Query"]["SeriesInstanceUID"] = seriesInstanceUid;
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
438 command->SetBody(body);
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
439
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
440 lock->Schedule(GetSharedObserver(), PRIORITY_ADD_RESOURCES, command.release());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
441 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
442 else
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
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 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
447 }
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
448
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
449 void AddOrthancStudy(const std::string& orthancId)
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
450 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
451 if (source_.IsOrthanc())
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
452 {
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
453 std::auto_ptr<ILoadersContext::ILock> lock(context_.Lock());
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
454 resourcesLoader_->ScheduleLoadOrthancResources(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
455 loadedSeries_, PRIORITY_ADD_RESOURCES, source_,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
456 Orthanc::ResourceType_Study, orthancId, Orthanc::ResourceType_Series,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
457 CreatePayload(Type_Orthanc));
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_BadParameterType,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
462 "Only applicable to Orthanc DICOM sources");
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 AddOrthancSeries(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_->ScheduleLoadOrthancResource(
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
472 loadedSeries_, PRIORITY_ADD_RESOURCES,
c0e4eb14c912 SingleFrameViewer WASM working OK
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
473 source_, Orthanc::ResourceType_Series, orthancId,
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 }