annotate Samples/Sdl/TrackerSampleApp.h @ 844:84cd55245e2d

Merge
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 14 Jun 2019 12:16:38 +0200
parents e42b491f1fb2
children e3c56d4f863f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20
698
8b6adfb62a2f Code is broken -- stashing ongoing work in a branch
Benjamin Golinvaux <bgo@osimis.io>
parents: 660
diff changeset
21
737
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
22 #include "../../Framework/Messages/IObserver.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
23 #include "../../Framework/Scene2D/OpenGLCompositor.h"
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
24 #include "../../Framework/Scene2DViewport/IFlexiblePointerTracker.h"
774
66ac7a2d1e3a A few renames and cleanups + moved GUI constants to controller + start work on
Benjamin Golinvaux <bgo@osimis.io>
parents: 761
diff changeset
25 #include "../../Framework/Scene2DViewport/MeasureTool.h"
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
26 #include "../../Framework/Scene2DViewport/PredeclaredTypes.h"
737
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 722
diff changeset
27 #include "../../Framework/Scene2DViewport/ViewportController.h"
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29 #include <SDL.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 #include <boost/make_shared.hpp>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 #include <boost/shared_ptr.hpp>
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
33 #include <boost/enable_shared_from_this.hpp>
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 namespace OrthancStone
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 enum GuiTool
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 GuiTool_Rotate = 0,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 GuiTool_Pan,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 GuiTool_Zoom,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 GuiTool_LineMeasure,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 GuiTool_CircleMeasure,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 GuiTool_AngleMeasure,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45 GuiTool_EllipseMeasure,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 GuiTool_LAST
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 };
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 const char* MeasureToolToString(size_t i);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
51 static const unsigned int FONT_SIZE_0 = 32;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
52 static const unsigned int FONT_SIZE_1 = 24;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 class Scene2D;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55
654
462a5074f914 Turned the scene into an observable to be able to dynamically react to
Benjamin Golinvaux <bgo@osimis.io>
parents: 644
diff changeset
56 class TrackerSampleApp : public IObserver
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
57 , public boost::enable_shared_from_this<TrackerSampleApp>
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 public:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 // 12 because.
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
61 TrackerSampleApp(MessageBroker& broker);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 void PrepareScene();
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
63 void Run();
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
64 void SetInfoDisplayMessage(std::string key, std::string value);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 void DisableTracker();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
67 boost::shared_ptr<Scene2D> GetScene();
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
68 boost::shared_ptr<const Scene2D> GetScene() const;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
70 void HandleApplicationEvent(const SDL_Event& event);
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
71
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
72 /**
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
73 This method is called when the scene transform changes. It allows to
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
74 recompute the visual elements whose content depend upon the scene transform
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
75 */
700
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 698
diff changeset
76 void OnSceneTransformChanged(
059e1fd05fd6 Introduced the ViewportController that sits between the application and the
Benjamin Golinvaux <bgo@osimis.io>
parents: 698
diff changeset
77 const ViewportController::SceneTransformChanged& message);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 private:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 void SelectNextTool();
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
81 void CreateRandomMeasureTool();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82
761
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
83 /**
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
84 This returns a random point in the canvas part of the scene, but in
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
85 scene coordinates
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
86 */
07adcffba38c truncation warning fixes + CRLF -> LF + random measuring tool creation (keyb
Benjamin Golinvaux <bgo@osimis.io>
parents: 737
diff changeset
87 ScenePoint2D GetRandomPointInScene() const;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
89 boost::shared_ptr<IFlexiblePointerTracker> TrackerHitTest(const PointerEvent& e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
91 boost::shared_ptr<IFlexiblePointerTracker> CreateSuitableTracker(
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 const SDL_Event& event,
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
93 const PointerEvent& e);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 void TakeScreenshot(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 const std::string& target,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 unsigned int canvasWidth,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 unsigned int canvasHeight);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 This adds the command at the top of the undo stack
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 */
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
103 void Commit(boost::shared_ptr<TrackerCommand> cmd);
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 void Undo();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 void Redo();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 private:
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
108 void DisplayFloatingCtrlInfoText(const PointerEvent& e);
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
109 void DisplayInfoText();
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 void HideInfoText();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 private:
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
113 std::auto_ptr<OpenGLCompositor> compositor_;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 WARNING: the measuring tools do store a reference to the scene, and it
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 paramount that the scene gets destroyed AFTER the measurement tools.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 */
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
118 boost::shared_ptr<ViewportController> controller_;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119
660
cb3b76d16234 Added info display map to the app + global logging function + fixed bisecting
Benjamin Golinvaux <bgo@osimis.io>
parents: 656
diff changeset
120 std::map<std::string, std::string> infoTextMap_;
818
e42b491f1fb2 Removed typedefs to shared_ptr by making them explicit. Removed using namespace
Benjamin Golinvaux <bgo@osimis.io>
parents: 774
diff changeset
121 boost::shared_ptr<IFlexiblePointerTracker> activeTracker_;
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 //static const int LAYER_POSITION = 150;
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
124
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 int TEXTURE_2x2_1_ZINDEX;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 int TEXTURE_1x1_ZINDEX;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 int TEXTURE_2x2_2_ZINDEX;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 int LINESET_1_ZINDEX;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 int LINESET_2_ZINDEX;
656
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
130 int FLOATING_INFOTEXT_LAYER_ZINDEX;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
131 int FIXED_INFOTEXT_LAYER_ZINDEX;
002d9562c8f5 Added support to DISABLE legacy scaling in SDL Windows (only in WIN32... this
Benjamin Golinvaux <bgo@osimis.io>
parents: 654
diff changeset
132
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 GuiTool currentTool_;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 };
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 }