annotate Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 2129:169e2e586ef7 StoneWebViewer-2.2

closing StoneWebViewer-2.2
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 30 May 2024 17:08:21 +0200
parents 36430d73e36c
children 3889ae96d2e9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
1 /**
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
2 * Stone of Orthanc
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
4 * Department, University Hospital of Liege, Belgium
1739
9ac2a65d4172 upgrade to year 2021
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
5 * Copyright (C) 2017-2021 Osimis S.A., Belgium
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
6 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
7 * This program is free software: you can redistribute it and/or
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
10 * the License, or (at your option) any later version.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
11 *
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
12 * This program is distributed in the hope that it will be useful, but
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
15 * Affero General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1591
diff changeset
16 *
1458
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
19 **/
828a9b4ee1b7 added missing copyright
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1457
diff changeset
20
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
22
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
23 #define SAMPLE_USE_OPENGL 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
24 #define SAMPLE_USE_ANNOTATIONS_LAYER 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
25
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
26
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 #include "SdlSimpleViewerApplication.h"
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
28 #include "../SdlHelpers.h"
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
29 #include "../../Common/SampleHelpers.h"
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30
1542
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
31 #include "../../../../OrthancStone/Sources/Loaders/GenericLoadersContext.h"
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1803
diff changeset
32 #include "../../../../OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.h"
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
33 #include "../../../../OrthancStone/Sources/Scene2DViewport/AngleMeasureTool.h"
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
34 #include "../../../../OrthancStone/Sources/Scene2DViewport/LineMeasureTool.h"
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
35 #include "../../../../OrthancStone/Sources/Scene2DViewport/UndoStack.h"
1542
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
36 #include "../../../../OrthancStone/Sources/StoneException.h"
6e0da8370270 fixing paths
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1538
diff changeset
37 #include "../../../../OrthancStone/Sources/StoneInitialization.h"
1560
b4ccd4963d37 fix sdl and wasm samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1542
diff changeset
38 #include "../../../../OrthancStone/Sources/Viewport/DefaultViewportInteractor.h"
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
39 #include "../../../Platforms/Sdl/SdlViewport.h"
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
41 #include <EmbeddedResources.h>
1507
169adf9090a6 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1458
diff changeset
42 #include <Compatibility.h> // For std::unique_ptr<>
1457
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1426
diff changeset
43 #include <OrthancException.h>
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
44
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
45 #include <boost/program_options.hpp>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
46 #include <SDL.h>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
47
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
48 #include <string>
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
49
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50
1804
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1803
diff changeset
51 static std::string orthancUrl;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1803
diff changeset
52 static std::string instanceId;
5a872e69c74f reorganization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1803
diff changeset
53 static int frameIndex = 0;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
55
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
56 static void ProcessOptions(int argc, char* argv[])
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
57 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
58 namespace po = boost::program_options;
1532
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
59 po::options_description desc("Usage");
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
61 desc.add_options()
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
62 ("loglevel", po::value<std::string>()->default_value("WARNING"),
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
63 "You can choose WARNING, INFO or TRACE for the logging level: Errors and warnings will always be displayed. (default: WARNING)")
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
65 ("orthanc", po::value<std::string>()->default_value("http://localhost:8042"),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
66 "Base URL of the Orthanc instance")
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
68 ("instance", po::value<std::string>()->default_value("285dece8-e1956b38-cdc7d084-6ce3371e-536a9ffc"),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
69 "Orthanc ID of the instance to display")
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
70
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
71 ("frame_index", po::value<int>()->default_value(0),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
72 "The zero-based index of the frame (for multi-frame instances)")
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
73 ;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74
1532
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
75 std::cout << desc << std::endl;
c7a37c3a0b8e print help in sdl samples
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
76
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
77 std::cout << std::endl << "Keyboard shorcuts:" << std::endl
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
78 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
79 << " a\tCreate angle annotations" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
80 << " c\tCreate circle annotations" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
81 << " d\tDelete mode for annotations" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
82 << " e\tEdit mode, don't create annotation (default)" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
83 << " l\tCreate line annotations" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
84 #else
1799
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
85 << " a\tEnable/disable the angle annotation tool" << std::endl
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
86 << " l\tEnable/disable the line annotation tool" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
87 << " r\tRedo the last edit to the annotation tools" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
88 << " u\tUndo the last edit to the annotation tools" << std::endl
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
89 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
90 << " f\tToggle fullscreen display" << std::endl
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
91 << " q\tExit" << std::endl
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
92 << " s\tFit the viewpoint to the image" << std::endl
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
93 << std::endl << "Mouse buttons:" << std::endl
1799
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
94 << " left \tChange windowing, or edit annotation" << std::endl
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
95 << " center\tMove the viewpoint, or edit annotation" << std::endl
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
96 << " right \tZoom, or edit annotation" << std::endl
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
97 << std::endl;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
98
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
99 po::variables_map vm;
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
100 try
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
101 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
102 po::store(po::parse_command_line(argc, argv, desc), vm);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
103 po::notify(vm);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
104 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
105 catch (std::exception& e)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
106 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
107 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
110 if (vm.count("loglevel") > 0)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111 {
1387
4ebf246f3919 Fixed big mistake (factoring the option parsing, which only adds noise to the people reading the code)
Benjamin Golinvaux <bgo@osimis.io>
parents: 1383
diff changeset
112 std::string logLevel = vm["loglevel"].as<std::string>();
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
113 OrthancStoneHelpers::SetLogLevel(logLevel);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
114 }
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
116 if (vm.count("orthanc") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
117 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
118 // maybe check URL validity here
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
119 orthancUrl = vm["orthanc"].as<std::string>();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
122 if (vm.count("instance") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
123 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
124 instanceId = vm["instance"].as<std::string>();
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
125 }
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
126
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
127 if (vm.count("frame_index") > 0)
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
128 {
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
129 frameIndex = vm["frame_index"].as<int>();
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
130 }
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
131 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
132
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
133
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
134 enum ActiveTool
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
135 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
136 ActiveTool_None,
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
137 ActiveTool_Line,
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
138 ActiveTool_Angle
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
139 };
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
140
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
141
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 /**
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 * IMPORTANT: The full arguments to "main()" are needed for SDL on
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 * Windows. Otherwise, one gets the linking error "undefined reference
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146 **/
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147 int main(int argc, char* argv[])
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 try
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 OrthancStone::StoneInitialize();
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
152 OrthancStone::SdlWindow::GlobalInitialize();
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
153
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
154 ProcessOptions(argc, argv);
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
155
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
156 //Orthanc::Logging::EnableInfoLevel(true);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 //Orthanc::Logging::EnableTraceLevel(true);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 {
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
160 #if SAMPLE_USE_OPENGL == 1
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
161 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 #else
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 boost::shared_ptr<OrthancStone::SdlViewport> viewport =
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 #endif
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
168 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
169 boost::shared_ptr<OrthancStone::UndoStack> undoStack(new OrthancStone::UndoStack);
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
170 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
171
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 OrthancStone::GenericLoadersContext context(1, 4, 1);
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
173
1395
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
174 Orthanc::WebServiceParameters orthancWebService;
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
175 orthancWebService.SetUrl(orthancUrl);
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
176 context.SetOrthancParameters(orthancWebService);
62dc0d737e7b build script for wasm sample + updated instructions + fixed Sdl sample for Orthanc listening on other ports that 8042
Alain Mazy <alain@mazy.be>
parents: 1392
diff changeset
177
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
178 context.StartOracle();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
180 {
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
181 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
182 std::string font;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
183 Orthanc::EmbeddedResources::GetFileResource(font, Orthanc::EmbeddedResources::UBUNTU_FONT);
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
184
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
185 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
186 lock->GetCompositor().SetFont(0, font, 16, Orthanc::Encoding_Latin1);
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
187
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
188 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
189 lock->GetController().SetUndoStack(undoStack);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
190 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
191 }
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
192
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
193 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
194 OrthancStone::AnnotationsSceneLayer annotations(10);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
195 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit);
1806
0840a25c6d41 removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1805
diff changeset
196
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
197 #else
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
198 ActiveTool activeTool = ActiveTool_None;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
199
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
200 boost::shared_ptr<OrthancStone::LineMeasureTool> lineMeasureTool(OrthancStone::LineMeasureTool::Create(viewport));
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
201 bool lineMeasureFirst = true;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
202 lineMeasureTool->Disable();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
204 boost::shared_ptr<OrthancStone::AngleMeasureTool> angleMeasureTool(OrthancStone::AngleMeasureTool::Create(viewport));
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
205 bool angleMeasureFirst = true;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
206 angleMeasureTool->Disable();
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
207 #endif
1799
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
208
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 boost::shared_ptr<SdlSimpleViewerApplication> application(
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 SdlSimpleViewerApplication::Create(context, viewport));
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212 OrthancStone::DicomSource source;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
213
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 application->LoadOrthancFrame(source, instanceId, frameIndex);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 OrthancStone::DefaultViewportInteractor interactor;
1535
301571299212 DefaultViewportInteractor::SetWindowingLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1532
diff changeset
217 interactor.SetWindowingLayer(0);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 int scancodeCount = 0;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 bool stop = false;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 while (!stop)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 {
1821
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1809
diff changeset
226 annotations.SetUnits(application->GetUnits());
36430d73e36c introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1809
diff changeset
227
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 bool paint = false;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 SDL_Event event;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230 while (SDL_PollEvent(&event))
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 if (event.type == SDL_QUIT)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 stop = true;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 break;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 else if (viewport->IsRefreshEvent(event))
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 paint = true;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 else if (event.type == SDL_WINDOWEVENT &&
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
242 (event.window.event == SDL_WINDOWEVENT_RESIZED ||
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
243 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED))
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 viewport->UpdateSize(event.window.data1, event.window.data2);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247 else if (event.type == SDL_WINDOWEVENT &&
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
248 (event.window.event == SDL_WINDOWEVENT_SHOWN ||
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
249 event.window.event == SDL_WINDOWEVENT_EXPOSED))
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 {
1576
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1560
diff changeset
251 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
92fca2b3ba3d sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1560
diff changeset
252 lock->RefreshCanvasSize();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 else if (event.type == SDL_KEYDOWN &&
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255 event.key.repeat == 0 /* Ignore key bounce */)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 switch (event.key.keysym.sym)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 {
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
259 case SDLK_f:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
260 viewport->ToggleMaximize();
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
261 break;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
262
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
263 case SDLK_s:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
264 application->FitContent();
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
265 break;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
266
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
267 case SDLK_q:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
268 stop = true;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
269 break;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
271 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
272 case SDLK_u:
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
273 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
274 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
275 if (lock->GetController().CanUndo())
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
276 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
277 lock->GetController().Undo();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
278 }
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
279 break;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
280 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
281 #endif
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
282
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
283 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
284 case SDLK_r:
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
285 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
286 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
287 if (lock->GetController().CanRedo())
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
288 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
289 lock->GetController().Redo();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
290 }
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
291 break;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
292 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
293 #endif
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
294
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
295 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
296 case SDLK_c:
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
297 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Circle);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
298 break;
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
299 #endif
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
300
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
301 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
302 case SDLK_e:
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
303 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
304 break;
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
305 #endif
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
306
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
307 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
308 case SDLK_d:
1809
79a5838739a6 starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1806
diff changeset
309 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Remove);
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
310 break;
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
311 #endif
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
312
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
313 case SDLK_l:
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
314 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
315 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Segment);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
316 #else
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
317 if (activeTool == ActiveTool_Line)
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
318 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
319 lineMeasureTool->Disable();
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
320 activeTool = ActiveTool_None;
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
321 }
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
322 else
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
323 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
324 if (lineMeasureFirst)
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
325 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
326 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
327 OrthancStone::Extent2D extent;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
328 lock->GetController().GetScene().GetBoundingBox(extent);
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
329 if (!extent.IsEmpty())
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
330 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
331 OrthancStone::ScenePoint2D p(extent.GetCenterX(), extent.GetCenterY());
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
332 lineMeasureTool->Set(p, p);
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
333 }
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
334 lineMeasureFirst = false;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
335 }
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
336
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
337 lineMeasureTool->Enable();
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
338 angleMeasureTool->Disable();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
339 activeTool = ActiveTool_Line;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
340 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
341 #endif
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
342 break;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
343
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
344 case SDLK_a:
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
345 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
346 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Angle);
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
347 #else
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
348 if (activeTool == ActiveTool_Angle)
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
349 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
350 angleMeasureTool->Disable();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
351 activeTool = ActiveTool_None;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
352 }
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
353 else
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
354 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
355 if (angleMeasureFirst)
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
356 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
357 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
358 OrthancStone::Extent2D extent;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
359 lock->GetController().GetScene().GetBoundingBox(extent);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
360 if (!extent.IsEmpty())
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
361 {
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
362 OrthancStone::ScenePoint2D p1(1.0 * extent.GetX1() / 3.0 + 2.0 * extent.GetX2() / 3.0,
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
363 2.0 * extent.GetY1() / 3.0 + 2.0 * extent.GetY2() / 3.0);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
364 OrthancStone::ScenePoint2D p2(1.0 * extent.GetX1() / 2.0 + 1.0 * extent.GetX2() / 2.0,
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
365 1.0 * extent.GetY1() / 3.0 + 1.0 * extent.GetY2() / 3.0);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
366 OrthancStone::ScenePoint2D p3(2.0 * extent.GetX1() / 3.0 + 1.0 * extent.GetX2() / 3.0,
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
367 2.0 * extent.GetY1() / 3.0 + 2.0 * extent.GetY2() / 3.0);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
368 angleMeasureTool->SetSide1End(p1);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
369 angleMeasureTool->SetCenter(p2);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
370 angleMeasureTool->SetSide2End(p3);
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
371 }
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
372 angleMeasureFirst = false;
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
373 }
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
374
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
375 lineMeasureTool->Disable();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
376 angleMeasureTool->Enable();
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
377 activeTool = ActiveTool_Angle;
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
378 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
379 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
380 break;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
381
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
382 default:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
383 break;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
386 else if (event.type == SDL_MOUSEBUTTONDOWN ||
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
387 event.type == SDL_MOUSEMOTION ||
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388 event.type == SDL_MOUSEBUTTONUP)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 {
1507
169adf9090a6 replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1458
diff changeset
390 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
391 if (lock->HasCompositor())
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
392 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 OrthancStone::PointerEvent p;
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
394 OrthancStoneHelpers::GetPointerEvent(p, lock->GetCompositor(),
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
395 event, keyboardState, scancodeCount);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
396
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
397 switch (event.type)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398 {
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
399 case SDL_MOUSEBUTTONDOWN:
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 {
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
401 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t;
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
402
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
403 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
1799
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
404 if (p.GetMouseButton() == OrthancStone::MouseButton_Left)
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
405 {
1803
d1849468729b added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1801
diff changeset
406 t.reset(annotations.CreateTracker(p.GetMainPosition(), lock->GetController().GetScene()));
1799
1125793d82d3 serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1798
diff changeset
407 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
408 #else
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
409 if (t.get() == NULL)
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
410 {
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
411 switch (activeTool)
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
412 {
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
413 case ActiveTool_Angle:
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
414 t = angleMeasureTool->CreateEditionTracker(p);
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
415 break;
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
416
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
417 case ActiveTool_Line:
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
418 t = lineMeasureTool->CreateEditionTracker(p);
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
419 break;
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
420
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
421 case ActiveTool_None:
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
422 break;
1790
b325761e0bd3 angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1789
diff changeset
423
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
424 default:
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
425 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
426 }
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
427 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
428 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
429
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
430 if (t.get() != NULL)
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
431 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
432 lock->GetController().AcquireActiveTracker(t);
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
433 }
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
434 else
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
435 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
436 lock->GetController().HandleMousePress(interactor, p,
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
437 lock->GetCompositor().GetCanvasWidth(),
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
438 lock->GetCompositor().GetCanvasHeight());
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
439 }
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
440 lock->Invalidate();
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
441 break;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
442 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
443
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
444 case SDL_MOUSEMOTION:
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
445 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
446 if (lock->GetController().HandleMouseMove(p))
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
447 {
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
448 lock->Invalidate();
1803
d1849468729b added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1801
diff changeset
449 if (annotations.ClearHover())
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
450 {
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
451 paint = true;
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
452 }
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
453 }
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
454 else
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
455 {
1803
d1849468729b added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1801
diff changeset
456 if (annotations.SetMouseHover(p.GetMainPosition(), lock->GetController().GetScene()))
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
457 {
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
458 paint = true;
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
459 }
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
460 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
461 #else
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
462 if (lock->GetController().HandleMouseMove(p))
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
463 {
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
464 lock->Invalidate();
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
465 paint = true;
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
466 }
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
467 #endif
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
468 break;
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
469
1789
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
470 case SDL_MOUSEBUTTONUP:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
471 lock->GetController().HandleMouseRelease(p);
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
472 lock->Invalidate();
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
473 break;
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
474
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
475 default:
462d7a0e064e added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
476 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
477 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
478 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
479 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
480 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
481
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
482 if (paint)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
483 {
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
484 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
485 {
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
486 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock());
1803
d1849468729b added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1801
diff changeset
487 annotations.Render(lock->GetController().GetScene());
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
488 }
1805
de7cea710008 recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1804
diff changeset
489 #endif
1796
20a0aba0ede5 creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1790
diff changeset
490
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
491 viewport->Paint();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
492 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
493
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
494 // Small delay to avoid using 100% of CPU
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
495 SDL_Delay(1);
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
496 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
497 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
498 context.StopOracle();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
499 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
500 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
501
1591
5887a4f8594b moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1576
diff changeset
502 OrthancStone::SdlWindow::GlobalFinalize();
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
503 OrthancStone::StoneFinalize();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
504 return 0;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
505 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
506 catch (Orthanc::OrthancException& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
507 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
508 LOG(ERROR) << "OrthancException: " << e.What();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
509 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
510 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
511 catch (OrthancStone::StoneException& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
512 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
513 LOG(ERROR) << "StoneException: " << e.What();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
514 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
515 }
1382
9d138883be66 Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents: 1368
diff changeset
516 catch (std::runtime_error& e)
1368
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
517 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
518 LOG(ERROR) << "Runtime error: " << e.what();
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
519 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
520 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
521 catch (...)
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
522 {
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
523 LOG(ERROR) << "Native exception";
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
524 return -1;
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
525 }
33da5d02885f SdlSimpleViewer rename
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
526 }