comparison Deprecated/Samples/Sdl/FusionMprSdl.h @ 1402:65e1e4b08302

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