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