comparison Resources/Graveyard/Deprecated/Samples/Sdl/FusionMprSdl.h @ 1503:553084468225

moving /Deprecated/ to /Resources/Graveyard/Deprecated/
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 11:38:13 +0200
parents Deprecated/Samples/Sdl/FusionMprSdl.h@828a9b4ee1b7
children
comparison
equal deleted inserted replaced
1502:e5729dab3f67 1503:553084468225
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
22 #pragma once
23
24 #include "../../Framework/Viewport/SdlViewport.h"
25
26 #include "../../Framework/Messages/IObserver.h"
27 #include "../../Framework/Messages/IMessageEmitter.h"
28 #include "../../Framework/Oracle/OracleCommandExceptionMessage.h"
29 #include "../../Framework/Scene2DViewport/ViewportController.h"
30 #include "../../Framework/Volumes/DicomVolumeImage.h"
31 #include "../../Framework/Oracle/ThreadedOracle.h"
32
33 #include <boost/enable_shared_from_this.hpp>
34 #include <boost/thread.hpp>
35 #include <boost/noncopyable.hpp>
36
37 #include <SDL.h>
38
39 namespace OrthancStone
40 {
41 class OpenGLCompositor;
42 class IVolumeSlicer;
43 class ILayerStyleConfigurator;
44 class DicomStructureSetLoader;
45 class IOracle;
46 class ThreadedOracle;
47 class VolumeSceneLayerSource;
48 class NativeFusionMprApplicationContext;
49 class SdlOpenGLViewport;
50
51 enum FusionMprGuiTool
52 {
53 FusionMprGuiTool_Rotate = 0,
54 FusionMprGuiTool_Pan,
55 FusionMprGuiTool_Zoom,
56 FusionMprGuiTool_LineMeasure,
57 FusionMprGuiTool_CircleMeasure,
58 FusionMprGuiTool_AngleMeasure,
59 FusionMprGuiTool_EllipseMeasure,
60 FusionMprGuiTool_LAST
61 };
62
63 const char* MeasureToolToString(size_t i);
64
65 static const unsigned int FONT_SIZE_0 = 32;
66 static const unsigned int FONT_SIZE_1 = 24;
67
68 class Scene2D;
69 class UndoStack;
70
71 /**
72 This application subclasses IMessageEmitter to use a mutex before forwarding Oracle messages (that
73 can be sent from multiple threads)
74 */
75 class FusionMprSdlApp : public IObserver
76 , public boost::enable_shared_from_this<FusionMprSdlApp>
77 , public IMessageEmitter
78 {
79 public:
80 // 12 because.
81 FusionMprSdlApp(MessageBroker& broker);
82
83 void PrepareScene();
84 void Run();
85 void SetInfoDisplayMessage(std::string key, std::string value);
86 void DisableTracker();
87
88 Scene2D& GetScene();
89 const Scene2D& GetScene() const;
90
91 void HandleApplicationEvent(const SDL_Event& event);
92
93 /**
94 This method is called when the scene transform changes. It allows to
95 recompute the visual elements whose content depend upon the scene transform
96 */
97 void OnSceneTransformChanged(
98 const ViewportController::SceneTransformChanged& message);
99
100
101 virtual void EmitMessage(const IObserver& observer,
102 const IMessage& message) ORTHANC_OVERRIDE
103 {
104 try
105 {
106 boost::unique_lock<boost::shared_mutex> lock(mutex_);
107 oracleObservable_.EmitMessage(observer, message);
108 }
109 catch (Orthanc::OrthancException& e)
110 {
111 LOG(ERROR) << "Exception while emitting a message: " << e.What();
112 throw;
113 }
114 }
115
116 private:
117 #if 1
118 // if threaded (not wasm)
119 MessageBroker& broker_;
120 IObservable oracleObservable_;
121 ThreadedOracle oracle_;
122 boost::shared_mutex mutex_; // to serialize messages from the ThreadedOracle
123 #endif
124
125 void SelectNextTool();
126
127 /**
128 This returns a random point in the canvas part of the scene, but in
129 scene coordinates
130 */
131 ScenePoint2D GetRandomPointInScene() const;
132
133 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e);
134
135 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker(
136 const SDL_Event& event,
137 const PointerEvent& e);
138
139 void TakeScreenshot(
140 const std::string& target,
141 unsigned int canvasWidth,
142 unsigned int canvasHeight);
143
144 /**
145 This adds the command at the top of the undo stack
146 */
147 void Commit(boost::shared_ptr<TrackerCommand> cmd);
148 void Undo();
149 void Redo();
150
151
152 // TODO private
153 void Handle(const DicomVolumeImage::GeometryReadyMessage& message);
154 void Handle(const OracleCommandExceptionMessage& message);
155
156 void SetVolume1(
157 int depth,
158 const boost::shared_ptr<IVolumeSlicer>& volume,
159 ILayerStyleConfigurator* style);
160
161 void SetVolume2(
162 int depth,
163 const boost::shared_ptr<IVolumeSlicer>& volume,
164 ILayerStyleConfigurator* style);
165
166 void SetStructureSet(
167 int depth,
168 const boost::shared_ptr<DicomStructureSetLoader>& volume);
169
170
171
172 private:
173 void DisplayFloatingCtrlInfoText(const PointerEvent& e);
174 void DisplayInfoText();
175 void HideInfoText();
176
177 private:
178 CoordinateSystem3D plane_;
179
180 boost::shared_ptr<VolumeSceneLayerSource> source1_, source2_, source3_;
181
182 /**
183 WARNING: the measuring tools do store a reference to the scene, and it
184 paramount that the scene gets destroyed AFTER the measurement tools.
185 */
186 boost::shared_ptr<ViewportController> controller_;
187
188 std::map<std::string, std::string> infoTextMap_;
189 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_;
190
191 //static const int LAYER_POSITION = 150;
192
193 int TEXTURE_2x2_1_ZINDEX;
194 int TEXTURE_1x1_ZINDEX;
195 int TEXTURE_2x2_2_ZINDEX;
196 int LINESET_1_ZINDEX;
197 int LINESET_2_ZINDEX;
198 int FLOATING_INFOTEXT_LAYER_ZINDEX;
199 int FIXED_INFOTEXT_LAYER_ZINDEX;
200
201 FusionMprGuiTool currentTool_;
202 boost::shared_ptr<UndoStack> undoStack_;
203 SdlOpenGLViewport viewport_;
204 };
205
206 }
207
208
209