annotate Deprecated/Samples/MultiPlatform/BasicScene/BasicScene.cpp @ 1499:8e5f69c94fea

sync
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jun 2020 07:58:56 +0200
parents 182bf3106ee2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1463
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
1 /**
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
2 * Stone of Orthanc
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
4 * Department, University Hospital of Liege, Belgium
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
6 *
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
7 * This program is free software: you can redistribute it and/or
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
10 * the License, or (at your option) any later version.
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
11 *
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
12 * This program is distributed in the hope that it will be useful, but
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
15 * Affero General Public License for more details.
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
16 *
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
19 **/
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
20
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
21 #include "BasicScene.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
22
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
23 // From Stone
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
24 #include "Framework/Scene2D/Scene2D.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
25 #include "Framework/Scene2D/ColorTextureSceneLayer.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
26 #include "Framework/Scene2D/PolylineSceneLayer.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
27 #include "Framework/Scene2D/TextSceneLayer.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
28
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
29 #include "Framework/Scene2D/PanSceneTracker.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
30 #include "Framework/Scene2D/ZoomSceneTracker.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
31 #include "Framework/Scene2D/RotateSceneTracker.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
32
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
33 #include "Framework/Scene2D/CairoCompositor.h"
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
34
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
35 // From Orthanc framework
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
36 #include <Core/Images/Image.h>
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
37 #include <Core/Images/ImageProcessing.h>
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
38 #include <Core/Images/PngWriter.h>
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
39
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
40 using namespace OrthancStone;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
41
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
42 const unsigned int BASIC_SCENE_FONT_SIZE = 32;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
43 const int BASIC_SCENE_LAYER_POSITION = 150;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
44
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
45 void PrepareScene(Scene2D& scene)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
46 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
47 //Scene2D& scene(*controller->GetScene());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
48 // Texture of 2x2 size
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
49 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
50 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
51
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
52 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
53 p[0] = 255;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
54 p[1] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
55 p[2] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
56
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
57 p[3] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
58 p[4] = 255;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
59 p[5] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
60
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
61 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
62 p[0] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
63 p[1] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
64 p[2] = 255;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
65
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
66 p[3] = 255;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
67 p[4] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
68 p[5] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
69
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
70 scene.SetLayer(12, new ColorTextureSceneLayer(i));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
71
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
72 std::unique_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
73 l->SetOrigin(-3, 2);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
74 l->SetPixelSpacing(1.5, 1);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
75 l->SetAngle(20.0 / 180.0 * 3.14);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
76 scene.SetLayer(14, l.release());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
77 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
78
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
79 // Texture of 1x1 size
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
80 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
81 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
82
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
83 uint8_t *p = reinterpret_cast<uint8_t*>(i.GetRow(0));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
84 p[0] = 255;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
85 p[1] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
86 p[2] = 0;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
87
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
88 std::unique_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
89 l->SetOrigin(-2, 1);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
90 l->SetAngle(20.0 / 180.0 * 3.14);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
91 scene.SetLayer(13, l.release());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
92 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
93
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
94 // Some lines
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
95 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
96 std::unique_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
97
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
98 layer->SetThickness(1);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
99
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
100 PolylineSceneLayer::Chain chain;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
101 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
102 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
103 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
104 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
105 layer->AddChain(chain, true, 255, 0, 0);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
106
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
107 chain.clear();
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
108 chain.push_back(ScenePoint2D(-5, -5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
109 chain.push_back(ScenePoint2D(5, -5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
110 chain.push_back(ScenePoint2D(5, 5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
111 chain.push_back(ScenePoint2D(-5, 5));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
112 layer->AddChain(chain, true, 0, 255, 0);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
113
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
114 double dy = 1.01;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
115 chain.clear();
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
116 chain.push_back(ScenePoint2D(-4, -4));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
117 chain.push_back(ScenePoint2D(4, -4 + dy));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
118 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
119 chain.push_back(ScenePoint2D(4, 2));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
120 layer->AddChain(chain, false, 0, 0, 255);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
121
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
122 // layer->SetColor(0,255, 255);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
123 scene.SetLayer(50, layer.release());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
124 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
125
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
126 // Some text
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
127 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
128 std::unique_ptr<TextSceneLayer> layer(new TextSceneLayer);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
129 layer->SetText("Hello");
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
130 scene.SetLayer(100, layer.release());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
131 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
132 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
133
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
134 #if ORTHANC_SANDBOXED == 0
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
135 void TakeScreenshot(const std::string& target,
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
136 const OrthancStone::Scene2D& scene,
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
137 unsigned int canvasWidth,
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
138 unsigned int canvasHeight)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
139 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
140 using namespace OrthancStone;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
141 // Take a screenshot, then save it as PNG file
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
142 CairoCompositor compositor(scene, canvasWidth, canvasHeight);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
143 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, BASIC_SCENE_FONT_SIZE, Orthanc::Encoding_Latin1);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
144 compositor.Refresh();
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
145
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
146 Orthanc::ImageAccessor canvas;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
147 compositor.GetCanvas().GetReadOnlyAccessor(canvas);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
148
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
149 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
150 Orthanc::ImageProcessing::Convert(png, canvas);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
151
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
152 Orthanc::PngWriter writer;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
153 writer.WriteToFile(target, png);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
154 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
155 #endif
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
156
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
157 void ShowCursorInfo(Scene2D& scene, const PointerEvent& pointerEvent)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
158 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
159 ScenePoint2D p = pointerEvent.GetMainPosition().Apply(scene.GetCanvasToSceneTransform());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
160
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
161 char buf[64];
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
162 sprintf(buf, "(%0.02f,%0.02f)", p.GetX(), p.GetY());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
163
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
164 if (scene.HasLayer(BASIC_SCENE_LAYER_POSITION))
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
165 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
166 TextSceneLayer& layer =
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
167 dynamic_cast<TextSceneLayer&>(scene.GetLayer(BASIC_SCENE_LAYER_POSITION));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
168 layer.SetText(buf);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
169 layer.SetPosition(p.GetX(), p.GetY());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
170 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
171 else
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
172 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
173 std::unique_ptr<TextSceneLayer>
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
174 layer(new TextSceneLayer);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
175 layer->SetColor(0, 255, 0);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
176 layer->SetText(buf);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
177 layer->SetBorder(20);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
178 layer->SetAnchor(BitmapAnchor_BottomCenter);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
179 layer->SetPosition(p.GetX(), p.GetY());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
180 scene.SetLayer(BASIC_SCENE_LAYER_POSITION, layer.release());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
181 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
182 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
183
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
184
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
185
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
186 bool BasicScene2DInteractor::OnMouseEvent(const GuiAdapterMouseEvent& event, const PointerEvent& pointerEvent)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
187 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
188 if (currentTracker_.get() != NULL)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
189 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
190 switch (event.type)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
191 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
192 case GUIADAPTER_EVENT_MOUSEUP:
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
193 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
194 currentTracker_->PointerUp(pointerEvent);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
195 if (!currentTracker_->IsAlive())
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
196 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
197 currentTracker_.reset();
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
198 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
199 };break;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
200 case GUIADAPTER_EVENT_MOUSEMOVE:
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
201 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
202 currentTracker_->PointerMove(pointerEvent);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
203 };break;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
204 default:
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
205 return false;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
206 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
207 return true;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
208 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
209 else if (event.type == GUIADAPTER_EVENT_MOUSEDOWN)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
210 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
211 if (event.button == GUIADAPTER_MOUSEBUTTON_LEFT)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
212 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
213 currentTracker_.reset(new RotateSceneTracker(viewportController_, pointerEvent));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
214 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
215 else if (event.button == GUIADAPTER_MOUSEBUTTON_MIDDLE)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
216 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
217 currentTracker_.reset(new PanSceneTracker(viewportController_, pointerEvent));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
218 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
219 else if (event.button == GUIADAPTER_MOUSEBUTTON_RIGHT)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
220 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
221 currentTracker_.reset(new ZoomSceneTracker(viewportController_, pointerEvent, viewportController_->GetViewport().GetCanvasHeight()));
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
222 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
223 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
224 else if (event.type == GUIADAPTER_EVENT_MOUSEMOVE)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
225 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
226 if (showCursorInfo_)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
227 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
228 Scene2D& scene(viewportController_->GetScene());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
229 ShowCursorInfo(scene, pointerEvent);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
230 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
231 return true;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
232 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
233 return false;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
234 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
235
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
236 bool BasicScene2DInteractor::OnKeyboardEvent(const GuiAdapterKeyboardEvent& guiEvent)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
237 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
238 if (guiEvent.type == GUIADAPTER_EVENT_KEYDOWN)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
239 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
240 switch (guiEvent.sym[0])
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
241 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
242 case 's':
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
243 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
244 //viewportController_->FitContent(viewportController_->GetViewport().GetCanvasWidth(), viewportController_->GetViewport().GetCanvasHeight());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
245 viewportController_->FitContent();
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
246 return true;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
247 };
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
248 #if ORTHANC_SANDBOXED == 0
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
249 case 'c':
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
250 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
251 Scene2D& scene(viewportController_->GetScene());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
252 TakeScreenshot("screenshot.png", scene, viewportController_->GetViewport().GetCanvasWidth(), viewportController_->GetViewport().GetCanvasHeight());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
253 return true;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
254 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
255 #endif
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
256 case 'd':
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
257 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
258 showCursorInfo_ = !showCursorInfo_;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
259 if (!showCursorInfo_)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
260 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
261 Scene2D& scene(viewportController_->GetScene());
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
262 scene.DeleteLayer(BASIC_SCENE_LAYER_POSITION);
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
263 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
264
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
265 return true;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
266 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
267 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
268 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
269 return false;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
270 }
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
271
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
272 bool BasicScene2DInteractor::OnWheelEvent(const GuiAdapterWheelEvent& guiEvent)
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
273 {
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
274 return false;
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1402
diff changeset
275 }