Mercurial > hg > orthanc-stone
annotate Applications/Samples/Sdl/SingleFrameViewer/SdlSimpleViewer.cpp @ 1999:709b90ae0f89
starting text annotations
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 02 Nov 2022 13:44:13 +0100 |
parents | 1fa3f484008e |
children | 07964689cb0b |
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 |
1982
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
83 << " e\tCreate ellipse probe" << std::endl |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
84 << " l\tCreate length annotations" << std::endl |
1982
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
85 << " m\tModification/edit mode, don't create annotation (default)" << std::endl |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
86 << " p\tCreate pixel probe" << std::endl |
1982
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
87 << " r\tCreate rectangle probe" << std::endl |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
88 #else |
1799
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
89 << " 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
|
90 << " 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
|
91 << " 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
|
92 << " 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
|
93 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
94 << " 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
|
95 << " q\tExit" << std::endl |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
96 << " 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
|
97 << std::endl << "Mouse buttons:" << std::endl |
1799
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
98 << " left \tChange windowing, or edit annotation" << std::endl |
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
99 << " center\tMove the viewpoint, or edit annotation" << std::endl |
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
100 << " 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
|
101 << std::endl; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
102 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
103 po::variables_map vm; |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
104 try |
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 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
|
107 po::notify(vm); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
108 } |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
109 catch (std::exception& e) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
110 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
111 std::cerr << "Please check your command line options! (\"" << e.what() << "\")" << std::endl; |
1368 | 112 } |
113 | |
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
|
114 if (vm.count("loglevel") > 0) |
1368 | 115 { |
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
|
116 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
|
117 OrthancStoneHelpers::SetLogLevel(logLevel); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
118 } |
1368 | 119 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
120 if (vm.count("orthanc") > 0) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
121 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
122 // maybe check URL validity here |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
123 orthancUrl = vm["orthanc"].as<std::string>(); |
1368 | 124 } |
125 | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
126 if (vm.count("instance") > 0) |
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 instanceId = vm["instance"].as<std::string>(); |
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 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
131 if (vm.count("frame_index") > 0) |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
132 { |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
133 frameIndex = vm["frame_index"].as<int>(); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
134 } |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
135 } |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
136 |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
137 |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
138 enum ActiveTool |
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 ActiveTool_None, |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
141 ActiveTool_Line, |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
142 ActiveTool_Angle |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
143 }; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
144 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
145 |
1368 | 146 /** |
147 * IMPORTANT: The full arguments to "main()" are needed for SDL on | |
148 * Windows. Otherwise, one gets the linking error "undefined reference | |
149 * to `SDL_main'". https://wiki.libsdl.org/FAQWindows | |
150 **/ | |
151 int main(int argc, char* argv[]) | |
152 { | |
153 try | |
154 { | |
155 OrthancStone::StoneInitialize(); | |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
156 OrthancStone::SdlWindow::GlobalInitialize(); |
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
157 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
158 ProcessOptions(argc, argv); |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
159 |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
160 //Orthanc::Logging::EnableInfoLevel(true); |
1368 | 161 //Orthanc::Logging::EnableTraceLevel(true); |
162 | |
163 { | |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
164 #if SAMPLE_USE_OPENGL == 1 |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
165 boost::shared_ptr<OrthancStone::SdlViewport> viewport = |
1368 | 166 OrthancStone::SdlOpenGLViewport::Create("Stone of Orthanc", 800, 600); |
167 #else | |
168 boost::shared_ptr<OrthancStone::SdlViewport> viewport = | |
169 OrthancStone::SdlCairoViewport::Create("Stone of Orthanc", 800, 600); | |
170 #endif | |
171 | |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
172 #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
|
173 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
|
174 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
175 |
1368 | 176 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
|
177 |
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
|
178 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
|
179 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
|
180 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
|
181 |
1368 | 182 context.StartOracle(); |
183 | |
184 { | |
1789
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::string font; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
187 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
|
188 |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
189 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
|
190 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
|
191 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
192 #if SAMPLE_USE_ANNOTATIONS_LAYER != 1 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
193 lock->GetController().SetUndoStack(undoStack); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
194 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
195 } |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
196 |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
197 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
198 OrthancStone::AnnotationsSceneLayer annotations(10); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
199 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit); |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
200 annotations.SetProbedLayer(0); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1805
diff
changeset
|
201 |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
202 #else |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
203 ActiveTool activeTool = ActiveTool_None; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
204 |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
205 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
|
206 bool lineMeasureFirst = true; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
207 lineMeasureTool->Disable(); |
1368 | 208 |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
209 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
|
210 bool angleMeasureFirst = true; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
211 angleMeasureTool->Disable(); |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
212 #endif |
1799
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
213 |
1368 | 214 boost::shared_ptr<SdlSimpleViewerApplication> application( |
215 SdlSimpleViewerApplication::Create(context, viewport)); | |
216 | |
217 OrthancStone::DicomSource source; | |
218 | |
219 application->LoadOrthancFrame(source, instanceId, frameIndex); | |
220 | |
221 OrthancStone::DefaultViewportInteractor interactor; | |
1535
301571299212
DefaultViewportInteractor::SetWindowingLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1532
diff
changeset
|
222 interactor.SetWindowingLayer(0); |
1368 | 223 |
224 { | |
225 int scancodeCount = 0; | |
226 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount); | |
227 | |
228 bool stop = false; | |
229 while (!stop) | |
230 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
231 annotations.SetUnits(application->GetUnits()); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
232 |
1368 | 233 bool paint = false; |
234 SDL_Event event; | |
235 while (SDL_PollEvent(&event)) | |
236 { | |
237 if (event.type == SDL_QUIT) | |
238 { | |
239 stop = true; | |
240 break; | |
241 } | |
242 else if (viewport->IsRefreshEvent(event)) | |
243 { | |
244 paint = true; | |
245 } | |
246 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
|
247 (event.window.event == SDL_WINDOWEVENT_RESIZED || |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
248 event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED)) |
1368 | 249 { |
250 viewport->UpdateSize(event.window.data1, event.window.data2); | |
251 } | |
252 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
|
253 (event.window.event == SDL_WINDOWEVENT_SHOWN || |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
254 event.window.event == SDL_WINDOWEVENT_EXPOSED)) |
1368 | 255 { |
1576
92fca2b3ba3d
sanitizing the handling of canvas size
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1560
diff
changeset
|
256 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
|
257 lock->RefreshCanvasSize(); |
1368 | 258 } |
259 else if (event.type == SDL_KEYDOWN && | |
260 event.key.repeat == 0 /* Ignore key bounce */) | |
261 { | |
262 switch (event.key.keysym.sym) | |
263 { | |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
264 case SDLK_f: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
265 viewport->ToggleMaximize(); |
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_s: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
269 application->FitContent(); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
270 break; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
271 |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
272 case SDLK_q: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
273 stop = true; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
274 break; |
1368 | 275 |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
276 #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
|
277 case SDLK_u: |
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 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
|
280 if (lock->GetController().CanUndo()) |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
281 { |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
282 lock->GetController().Undo(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
283 } |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
284 break; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
285 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
286 #endif |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
287 |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
288 #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
|
289 case SDLK_r: |
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 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
|
292 if (lock->GetController().CanRedo()) |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
293 { |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
294 lock->GetController().Redo(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
295 } |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
296 break; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
297 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
298 #endif |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
299 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
300 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
301 case SDLK_c: |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
302 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Circle); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
303 break; |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
304 #endif |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
305 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
306 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
1982
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
307 case SDLK_m: |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
308 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Edit); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
309 break; |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
310 #endif |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
311 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
312 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
313 case SDLK_d: |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
314 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Remove); |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
315 break; |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
316 #endif |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
317 |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
318 case SDLK_l: |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
319 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
1998
1fa3f484008e
added arrows to AnnotationsSceneLayer::Segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1982
diff
changeset
|
320 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Length); |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
321 #else |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
322 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
|
323 { |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
324 lineMeasureTool->Disable(); |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
325 activeTool = ActiveTool_None; |
1789
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 else |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
328 { |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
329 if (lineMeasureFirst) |
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 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
|
332 OrthancStone::Extent2D extent; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
333 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
|
334 if (!extent.IsEmpty()) |
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 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
|
337 lineMeasureTool->Set(p, p); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
338 } |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
339 lineMeasureFirst = false; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
340 } |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
341 |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
342 lineMeasureTool->Enable(); |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
343 angleMeasureTool->Disable(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
344 activeTool = ActiveTool_Line; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
345 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
346 #endif |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
347 break; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
348 |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
349 case SDLK_a: |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
350 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
351 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_Angle); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
352 #else |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
353 if (activeTool == ActiveTool_Angle) |
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 angleMeasureTool->Disable(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
356 activeTool = ActiveTool_None; |
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 else |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
359 { |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
360 if (angleMeasureFirst) |
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 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
|
363 OrthancStone::Extent2D extent; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
364 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
|
365 if (!extent.IsEmpty()) |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
366 { |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
367 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
|
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 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
|
370 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
|
371 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
|
372 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
|
373 angleMeasureTool->SetSide1End(p1); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
374 angleMeasureTool->SetCenter(p2); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
375 angleMeasureTool->SetSide2End(p3); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
376 } |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
377 angleMeasureFirst = false; |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
378 } |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
379 |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
380 lineMeasureTool->Disable(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
381 angleMeasureTool->Enable(); |
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
382 activeTool = ActiveTool_Angle; |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
383 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
384 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
385 break; |
1368 | 386 |
1975
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
387 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
388 case SDLK_p: |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
389 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_PixelProbe); |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
390 break; |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
391 #endif |
5a434f5889f8
starting pixel probe
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1901
diff
changeset
|
392 |
1982
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
393 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
394 case SDLK_e: |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
395 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_EllipseProbe); |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
396 break; |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
397 #endif |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
398 |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
399 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
400 case SDLK_r: |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
401 annotations.SetActiveTool(OrthancStone::AnnotationsSceneLayer::Tool_RectangleProbe); |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
402 break; |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
403 #endif |
ba45e1b0812a
preparing interfaces for rectangle probe, ellipse probe and text annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1975
diff
changeset
|
404 |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
405 default: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
406 break; |
1368 | 407 } |
408 } | |
409 else if (event.type == SDL_MOUSEBUTTONDOWN || | |
410 event.type == SDL_MOUSEMOTION || | |
411 event.type == SDL_MOUSEBUTTONUP) | |
412 { | |
1507
169adf9090a6
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1458
diff
changeset
|
413 std::unique_ptr<OrthancStone::IViewport::ILock> lock(viewport->Lock()); |
1368 | 414 if (lock->HasCompositor()) |
415 { | |
416 OrthancStone::PointerEvent p; | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
417 OrthancStoneHelpers::GetPointerEvent(p, lock->GetCompositor(), |
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
418 event, keyboardState, scancodeCount); |
1368 | 419 |
420 switch (event.type) | |
421 { | |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
422 case SDL_MOUSEBUTTONDOWN: |
1368 | 423 { |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
424 boost::shared_ptr<OrthancStone::IFlexiblePointerTracker> t; |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
425 |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
426 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
1799
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
427 if (p.GetMouseButton() == OrthancStone::MouseButton_Left) |
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
428 { |
1803
d1849468729b
added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1801
diff
changeset
|
429 t.reset(annotations.CreateTracker(p.GetMainPosition(), lock->GetController().GetScene())); |
1799
1125793d82d3
serialization of annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1798
diff
changeset
|
430 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
431 #else |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
432 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
|
433 { |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
434 switch (activeTool) |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
435 { |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
436 case ActiveTool_Angle: |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
437 t = angleMeasureTool->CreateEditionTracker(p); |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
438 break; |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
439 |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
440 case ActiveTool_Line: |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
441 t = lineMeasureTool->CreateEditionTracker(p); |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
442 break; |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
443 |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
444 case ActiveTool_None: |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
445 break; |
1790
b325761e0bd3
angle measure and undo/redo in sdl simple viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1789
diff
changeset
|
446 |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
447 default: |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
448 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
449 } |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
450 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
451 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
452 |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
453 if (t.get() != NULL) |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
454 { |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
455 lock->GetController().AcquireActiveTracker(t); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
456 } |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
457 else |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
458 { |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
459 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
|
460 lock->GetCompositor().GetCanvasWidth(), |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
461 lock->GetCompositor().GetCanvasHeight()); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
462 } |
1368 | 463 lock->Invalidate(); |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
464 break; |
1368 | 465 } |
466 | |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
467 case SDL_MOUSEMOTION: |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
468 #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
|
469 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
|
470 { |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
471 lock->Invalidate(); |
1803
d1849468729b
added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1801
diff
changeset
|
472 if (annotations.ClearHover()) |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
473 { |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
474 paint = true; |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
475 } |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
476 } |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
477 else |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
478 { |
1803
d1849468729b
added messages to AnnotationsLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1801
diff
changeset
|
479 if (annotations.SetMouseHover(p.GetMainPosition(), lock->GetController().GetScene())) |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
480 { |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
481 paint = true; |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
482 } |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
483 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
484 #else |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
485 if (lock->GetController().HandleMouseMove(p)) |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
486 { |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
487 lock->Invalidate(); |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
488 paint = true; |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
489 } |
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
490 #endif |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
491 break; |
1368 | 492 |
1789
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
493 case SDL_MOUSEBUTTONUP: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
494 lock->GetController().HandleMouseRelease(p); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
495 lock->Invalidate(); |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
496 break; |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
497 |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
498 default: |
462d7a0e064e
added line measures to sdl single frame viewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1739
diff
changeset
|
499 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
1368 | 500 } |
501 } | |
502 } | |
503 } | |
504 | |
505 if (paint) | |
506 { | |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
507 #if SAMPLE_USE_ANNOTATIONS_LAYER == 1 |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
508 { |
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
509 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
|
510 annotations.Render(lock->GetController().GetScene()); |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
511 } |
1805
de7cea710008
recovery of old SdlSimpleViewer sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
512 #endif |
1796
20a0aba0ede5
creation of AnnotationsOverlay
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1790
diff
changeset
|
513 |
1368 | 514 viewport->Paint(); |
515 } | |
516 | |
517 // Small delay to avoid using 100% of CPU | |
518 SDL_Delay(1); | |
519 } | |
520 } | |
521 context.StopOracle(); | |
522 } | |
523 } | |
524 | |
1591
5887a4f8594b
moving platform-specific files out of the "OrthancStone" folder
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1576
diff
changeset
|
525 OrthancStone::SdlWindow::GlobalFinalize(); |
1368 | 526 OrthancStone::StoneFinalize(); |
527 return 0; | |
528 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
529 catch (Orthanc::OrthancException& e) |
1368 | 530 { |
531 LOG(ERROR) << "OrthancException: " << e.What(); | |
532 return -1; | |
533 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
534 catch (OrthancStone::StoneException& e) |
1368 | 535 { |
536 LOG(ERROR) << "StoneException: " << e.What(); | |
537 return -1; | |
538 } | |
1382
9d138883be66
Proper command-line parameter management for SDL sample
Benjamin Golinvaux <bgo@osimis.io>
parents:
1368
diff
changeset
|
539 catch (std::runtime_error& e) |
1368 | 540 { |
541 LOG(ERROR) << "Runtime error: " << e.what(); | |
542 return -1; | |
543 } | |
544 catch (...) | |
545 { | |
546 LOG(ERROR) << "Native exception"; | |
547 return -1; | |
548 } | |
549 } |