comparison Samples/Sdl/FusionMprSdl.h @ 827:2fd96a637a59

Added FusioMpr sample + small dumb changes
author Benjamin Golinvaux <bgo@osimis.io>
date Wed, 29 May 2019 13:44:55 +0200
parents
children 28f99af358fa
comparison
equal deleted inserted replaced
818:e42b491f1fb2 827:2fd96a637a59
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-2019 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/Messages/IObserver.h"
22 #include "../../Framework/Scene2DViewport/ViewportController.h"
23
24 #include <boost/enable_shared_from_this.hpp>
25 #include <SDL.h>
26 #include "../../Framework/Volumes/DicomVolumeImage.h"
27 #include "../../Framework/Oracle/OracleCommandExceptionMessage.h"
28
29 namespace OrthancStone
30 {
31 class OpenGLCompositor;
32 class IVolumeSlicer;
33 class ILayerStyleConfigurator;
34 class DicomStructureSetLoader;
35 class IOracle;
36 class VolumeSceneLayerSource;
37
38 enum FusionMprGuiTool
39 {
40 FusionMprGuiTool_Rotate = 0,
41 FusionMprGuiTool_Pan,
42 FusionMprGuiTool_Zoom,
43 FusionMprGuiTool_LineMeasure,
44 FusionMprGuiTool_CircleMeasure,
45 FusionMprGuiTool_AngleMeasure,
46 FusionMprGuiTool_EllipseMeasure,
47 FusionMprGuiTool_LAST
48 };
49
50 const char* MeasureToolToString(size_t i);
51
52 static const unsigned int FONT_SIZE_0 = 32;
53 static const unsigned int FONT_SIZE_1 = 24;
54
55 class Scene2D;
56
57 class FusionMprSdlApp : public IObserver
58 , public boost::enable_shared_from_this<FusionMprSdlApp>
59 {
60 public:
61 // 12 because.
62 FusionMprSdlApp(MessageBroker& broker);
63 void PrepareScene();
64 void Run();
65 void SetInfoDisplayMessage(std::string key, std::string value);
66 void DisableTracker();
67
68 boost::shared_ptr<Scene2D> GetScene();
69 boost::shared_ptr<const Scene2D> GetScene() const;
70
71 void HandleApplicationEvent(const SDL_Event& event);
72
73 /**
74 This method is called when the scene transform changes. It allows to
75 recompute the visual elements whose content depend upon the scene transform
76 */
77 void OnSceneTransformChanged(
78 const ViewportController::SceneTransformChanged& message);
79
80 private:
81 void SelectNextTool();
82
83 /**
84 This returns a random point in the canvas part of the scene, but in
85 scene coordinates
86 */
87 ScenePoint2D GetRandomPointInScene() const;
88
89 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e);
90
91 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker(
92 const SDL_Event& event,
93 const PointerEvent& e);
94
95 void TakeScreenshot(
96 const std::string& target,
97 unsigned int canvasWidth,
98 unsigned int canvasHeight);
99
100 /**
101 This adds the command at the top of the undo stack
102 */
103 void Commit(boost::shared_ptr<TrackerCommand> cmd);
104 void Undo();
105 void Redo();
106
107
108 // TODO private
109 void Handle(const DicomVolumeImage::GeometryReadyMessage& message);
110 void Handle(const OracleCommandExceptionMessage& message);
111
112 void SetVolume1(
113 int depth,
114 const boost::shared_ptr<IVolumeSlicer>& volume,
115 ILayerStyleConfigurator* style);
116
117 void SetVolume2(
118 int depth,
119 const boost::shared_ptr<IVolumeSlicer>& volume,
120 ILayerStyleConfigurator* style);
121
122 void SetStructureSet(
123 int depth,
124 const boost::shared_ptr<DicomStructureSetLoader>& volume);
125
126
127
128 private:
129 void DisplayFloatingCtrlInfoText(const PointerEvent& e);
130 void DisplayInfoText();
131 void HideInfoText();
132
133 private:
134 CoordinateSystem3D plane_;
135 IOracle* oracle_ = nullptr;
136 boost::shared_ptr<VolumeSceneLayerSource> source1_, source2_, source3_;
137
138 std::auto_ptr<OpenGLCompositor> compositor_;
139 /**
140 WARNING: the measuring tools do store a reference to the scene, and it
141 paramount that the scene gets destroyed AFTER the measurement tools.
142 */
143 boost::shared_ptr<ViewportController> controller_;
144
145 std::map<std::string, std::string> infoTextMap_;
146 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_;
147
148 //static const int LAYER_POSITION = 150;
149
150 int TEXTURE_2x2_1_ZINDEX;
151 int TEXTURE_1x1_ZINDEX;
152 int TEXTURE_2x2_2_ZINDEX;
153 int LINESET_1_ZINDEX;
154 int LINESET_2_ZINDEX;
155 int FLOATING_INFOTEXT_LAYER_ZINDEX;
156 int FIXED_INFOTEXT_LAYER_ZINDEX;
157
158 FusionMprGuiTool currentTool_;
159 };
160
161 }
162
163
164