comparison Samples/Common/RtViewerApp.h @ 1404:3e644f6fadd4

Three-viewport is now OK in SDL and Wasm
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 29 Apr 2020 22:06:24 +0200
parents Samples/Common/RtViewer.h@27e0a00bd3e8
children 5d7ee14dc1eb
comparison
equal deleted inserted replaced
1395:62dc0d737e7b 1404:3e644f6fadd4
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21 #include <Framework/Viewport/IViewport.h>
22
23 #include <Framework/Loaders/DicomStructureSetLoader.h>
24 #include <Framework/Loaders/OrthancMultiframeVolumeLoader.h>
25 #include <Framework/Loaders/OrthancSeriesVolumeProgressiveLoader.h>
26 #include <Framework/Loaders/ILoadersContext.h>
27 #include <Framework/Messages/IMessageEmitter.h>
28 #include <Framework/Messages/IObserver.h>
29 #include <Framework/Messages/ObserverBase.h>
30 #include <Framework/Oracle/OracleCommandExceptionMessage.h>
31 #include <Framework/Scene2DViewport/ViewportController.h>
32 #include <Framework/Volumes/DicomVolumeImage.h>
33
34 #include <boost/enable_shared_from_this.hpp>
35 #include <boost/thread.hpp>
36 #include <boost/noncopyable.hpp>
37
38 #if ORTHANC_ENABLE_SDL
39 #include <SDL.h>
40 #endif
41
42 namespace OrthancStone
43 {
44 class OpenGLCompositor;
45 class IVolumeSlicer;
46 class ILayerStyleConfigurator;
47 class DicomStructureSetLoader;
48 class IOracle;
49 class ThreadedOracle;
50 class VolumeSceneLayerSource;
51 class SdlOpenGLViewport;
52 class RtViewerView;
53
54 enum RtViewerGuiTool
55 {
56 RtViewerGuiTool_Rotate = 0,
57 RtViewerGuiTool_Pan,
58 RtViewerGuiTool_Zoom,
59 RtViewerGuiTool_LineMeasure,
60 RtViewerGuiTool_CircleMeasure,
61 RtViewerGuiTool_AngleMeasure,
62 RtViewerGuiTool_EllipseMeasure,
63 RtViewerGuiTool_LAST
64 };
65
66 const char* MeasureToolToString(size_t i);
67
68 static const unsigned int FONT_SIZE_0 = 32;
69 static const unsigned int FONT_SIZE_1 = 24;
70
71 class Scene2D;
72 class UndoStack;
73
74 /**
75 This application subclasses IMessageEmitter to use a mutex before forwarding Oracle messages (that
76 can be sent from multiple threads)
77 */
78 class RtViewerApp : public ObserverBase<RtViewerApp>
79 {
80 public:
81
82 void PrepareScene();
83
84 #if ORTHANC_ENABLE_SDL
85 public:
86 void RunSdl(int argc, char* argv[]);
87 private:
88 void ProcessOptions(int argc, char* argv[]);
89 void HandleApplicationEvent(const SDL_Event& event);
90 #elif ORTHANC_ENABLE_WASM
91 public:
92 void RunWasm();
93 #else
94 # error Either ORTHANC_ENABLE_SDL or ORTHANC_ENABLE_WASM must be enabled
95 #endif
96
97 public:
98 void DisableTracker();
99
100 /**
101 Called by command-line option processing or when parsing the URL
102 parameters.
103 */
104 void SetArgument(const std::string& key, const std::string& value);
105
106 const VolumeImageGeometry& GetMainGeometry();
107
108 static boost::shared_ptr<RtViewerApp> Create();
109
110 void CreateView(const std::string& canvasId, VolumeProjection projection);
111
112 protected:
113 RtViewerApp();
114
115 private:
116 void CreateLoaders();
117 void StartLoaders();
118 void SelectNextTool();
119
120 // argument handling
121 // SetArgument is above (public section)
122 std::map<std::string, std::string> arguments_;
123
124 const std::string& GetArgument(const std::string& key) const;
125 bool HasArgument(const std::string& key) const;
126
127 /**
128 This adds the command at the top of the undo stack
129 */
130 //void Commit(boost::shared_ptr<TrackerCommand> cmd);
131 void Undo();
132 void Redo();
133
134 void HandleGeometryReady(const DicomVolumeImage::GeometryReadyMessage& message);
135
136 // TODO: wire this
137 void HandleCTLoaded(const OrthancSeriesVolumeProgressiveLoader::VolumeImageReadyInHighQuality& message);
138 void HandleCTContentUpdated(const OrthancStone::DicomVolumeImage::ContentUpdatedMessage& message);
139 void HandleDoseLoaded(const OrthancStone::DicomVolumeImage::ContentUpdatedMessage& message);
140 void HandleStructuresReady(const OrthancStone::DicomStructureSetLoader::StructuresReady& message);
141 void HandleStructuresUpdated(const OrthancStone::DicomStructureSetLoader::StructuresUpdated& message);
142
143
144 private:
145 void RetrieveGeometry();
146 void FitContent();
147 void InvalidateAllViewports();
148 void UpdateLayersInAllViews();
149
150 private:
151 boost::shared_ptr<DicomVolumeImage> ctVolume_;
152 boost::shared_ptr<DicomVolumeImage> doseVolume_;
153
154 std::vector<boost::shared_ptr<RtViewerView> > views_;
155
156 boost::shared_ptr<OrthancSeriesVolumeProgressiveLoader> ctLoader_;
157 boost::shared_ptr<OrthancMultiframeVolumeLoader> doseLoader_;
158 boost::shared_ptr<DicomStructureSetLoader> rtstructLoader_;
159
160 /** encapsulates resources shared by loaders */
161 boost::shared_ptr<ILoadersContext> loadersContext_;
162
163 /**
164 another interface to the ctLoader object (that also implements the IVolumeSlicer interface), that serves as the
165 reference for the geometry (position and dimensions of the volume + size of each voxel). It could be changed to be
166 the dose instead, but the CT is chosen because it usually has a better spatial resolution.
167 */
168 boost::shared_ptr<OrthancStone::IGeometryProvider> geometryProvider_;
169
170
171 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_;
172
173 RtViewerGuiTool currentTool_;
174 boost::shared_ptr<UndoStack> undoStack_;
175 };
176
177 }
178
179
180