annotate Samples/Sdl/TrackerSampleApp.cpp @ 644:f939f449482c

Ongoing tracker work.
author Benjamin Golinvaux <bgo@osimis.io>
date Fri, 10 May 2019 16:15:55 +0200
parents
children 62f6ff016085
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
644
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
6 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * the License, or (at your option) any later version.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
15 * Affero General Public License for more details.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
16 *
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
19 **/
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
20
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21 #include "TrackerSampleApp.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
23 #include "../Common/CreateLineMeasureTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
24
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25 #include "../../Applications/Sdl/SdlOpenGLWindow.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 #include "../../Framework/Scene2D/PanSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28 #include "../../Framework/Scene2D/RotateSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
29 #include "../../Framework/Scene2D/Scene2D.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
30 #include "../../Framework/Scene2D/ZoomSceneTracker.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 #include "../../Framework/Scene2D/CairoCompositor.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 #include "../../Framework/Scene2D/ColorTextureSceneLayer.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 #include "../../Framework/Scene2D/OpenGLCompositor.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34 #include "../../Framework/StoneInitialization.h"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36 // From Orthanc framework
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 #include <Core/Logging.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 #include <Core/OrthancException.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 #include <Core/Images/Image.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
40 #include <Core/Images/ImageProcessing.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 #include <Core/Images/PngWriter.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 #include <SDL.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 #include <stdio.h>
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 using namespace Orthanc;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 namespace OrthancStone
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50 const char* MeasureToolToString(size_t i)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 static const char* descs[] = {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 "GuiTool_Rotate",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 "GuiTool_Pan",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 "GuiTool_Zoom",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56 "GuiTool_LineMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 "GuiTool_CircleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 "GuiTool_AngleMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 "GuiTool_EllipseMeasure",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 "GuiTool_LAST"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 };
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 if (i >= GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError, "Wrong tool index");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 return descs[i];
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 Scene2D& TrackerSampleApp::GetScene()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 return scene_;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74 void TrackerSampleApp::SelectNextTool()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 currentTool_ = static_cast<GuiTool>(currentTool_ + 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 if (currentTool_ == GuiTool_LAST)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 currentTool_ = static_cast<GuiTool>(0);;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 printf("Current tool is now: %s\n", MeasureToolToString(currentTool_));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 void TrackerSampleApp::DisplayInfoText(const PointerEvent& e)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84 ScenePoint2D p = e.GetMainPosition().Apply(scene_.GetCanvasToSceneTransform());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
86 char buf[64];
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 sprintf(buf, "(%0.02f,%0.02f)", p.GetX(), p.GetY());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 if (scene_.HasLayer(INFOTEXT_LAYER_ZINDEX))
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91 TextSceneLayer& layer =
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 dynamic_cast<TextSceneLayer&>(scene_.GetLayer(INFOTEXT_LAYER_ZINDEX));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 layer.SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94 layer.SetPosition(p.GetX(), p.GetY());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 layer->SetColor(0, 255, 0);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 layer->SetText(buf);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101 layer->SetBorder(20);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 layer->SetAnchor(BitmapAnchor_BottomCenter);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103 layer->SetPosition(p.GetX(), p.GetY());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 scene_.SetLayer(INFOTEXT_LAYER_ZINDEX, layer.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 void TrackerSampleApp::HideInfoText()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110 scene_.DeleteLayer(INFOTEXT_LAYER_ZINDEX);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
113 void TrackerSampleApp::HandleApplicationEvent(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 const OpenGLCompositor & compositor,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 const SDL_Event & event)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 if (event.type == SDL_MOUSEMOTION)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 int scancodeCount = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 const uint8_t* keyboardState = SDL_GetKeyboardState(&scancodeCount);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 if (activeTracker_.get() == NULL &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 SDL_SCANCODE_LCTRL < scancodeCount &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124 keyboardState[SDL_SCANCODE_LCTRL])
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 // The "left-ctrl" key is down, while no tracker is present
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 // Let's display the info text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 PointerEvent e;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 DisplayInfoText(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 HideInfoText();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 //LOG(TRACE) << "(event.type == SDL_MOUSEMOTION)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 if (activeTracker_.get() != NULL)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138 //LOG(TRACE) << "(activeTracker_.get() != NULL)";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 PointerEvent e;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 //LOG(TRACE) << "event.button.x = " << event.button.x << " " <<
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 // "event.button.y = " << event.button.y;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 //LOG(TRACE) << "activeTracker_->PointerMove(e); " <<
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 // e.GetMainPosition().GetX() << " " << e.GetMainPosition().GetY();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 activeTracker_->PointerMove(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151 else if (event.type == SDL_MOUSEBUTTONUP)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 PointerEvent e;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 activeTracker_->PointerUp(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 else if (event.type == SDL_MOUSEBUTTONDOWN)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 PointerEvent e;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 e.AddPosition(compositor.GetPixelCenterCoordinates(event.button.x, event.button.y));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
168 activeTracker_->PointerDown(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
171 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 // we ATTEMPT to create a tracker if need be
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175 activeTracker_ = CreateSuitableTracker(event, e, compositor);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
177 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
178 else if (event.type == SDL_KEYDOWN &&
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 event.key.repeat == 0 /* Ignore key bounce */)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
180 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181 switch (event.key.keysym.sym)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
183 case SDLK_ESCAPE:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 activeTracker_->Cancel();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 if (!activeTracker_->IsActive())
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
192 case SDLK_t:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 if (!activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 SelectNextTool();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
195 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
197 LOG(WARNING) << "You cannot change the active tool when an interaction"
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 " is taking place";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
199 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
200 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 case SDLK_s:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203 scene_.FitContent(compositor.GetCanvasWidth(),
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 compositor.GetCanvasHeight());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 case SDLK_c:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 TakeScreenshot(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 "screenshot.png",
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210 compositor.GetCanvasWidth(),
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 compositor.GetCanvasHeight());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
213
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 break;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 FlexiblePointerTrackerPtr TrackerSampleApp::CreateSuitableTracker(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 const SDL_Event & event,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222 const PointerEvent & e,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 const OpenGLCompositor & compositor)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
225 switch (event.button.button)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
227 case SDL_BUTTON_MIDDLE:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 new PanSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 case SDL_BUTTON_RIGHT:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 new ZoomSceneTracker(scene_, e, compositor.GetCanvasHeight())));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 case SDL_BUTTON_LEFT:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 //LOG(TRACE) << "CreateSuitableTracker: case SDL_BUTTON_LEFT:";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
238 // TODO: we need to iterate on the set of measuring tool and perform
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 // a hit test to check if a tracker needs to be created for edition.
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 // Otherwise, depending upon the active tool, we might want to create
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 // a "measuring tool creation" tracker
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 // TODO: if there are conflicts, we should prefer a tracker that
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 // pertains to the type of measuring tool currently selected (TBD?)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 FlexiblePointerTrackerPtr hitTestTracker = TrackerHitTest(e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
247 if (hitTestTracker != NULL)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
248 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
249 //LOG(TRACE) << "hitTestTracker != NULL";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
250 return hitTestTracker;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
251 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
252 else
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
254 switch (currentTool_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
255 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
256 case GuiTool_Rotate:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
257 //LOG(TRACE) << "Creating RotateSceneTracker";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
258 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
259 new RotateSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
260 case GuiTool_LineMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
261 return FlexiblePointerTrackerPtr(new CreateLineMeasureTracker(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
262 scene_, undoStack_, measureTools_, e));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
263 case GuiTool_Pan:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
264 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
265 new PanSceneTracker(scene_, e)));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
266 case GuiTool_Zoom:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
267 return CreateSimpleTrackerAdapter(PointerTrackerPtr(
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
268 new ZoomSceneTracker(scene_, e, compositor.GetCanvasHeight())));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
269 //case GuiTool_AngleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270 // return new AngleMeasureTracker(scene_, measureTools_, undoStack_, e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
271 //case GuiTool_CircleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
272 // return new CircleMeasureTracker(scene_, measureTools_, undoStack_, e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
273 //case GuiTool_EllipseMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
274 // return new EllipseMeasureTracker(scene_, measureTools_, undoStack_, e);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
275 case GuiTool_AngleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
276 LOG(ERROR) << "Not implemented yet!";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
277 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278 case GuiTool_CircleMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
279 LOG(ERROR) << "Not implemented yet!";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
280 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
281 case GuiTool_EllipseMeasure:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
282 LOG(ERROR) << "Not implemented yet!";
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
283 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
284 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
285 throw OrthancException(ErrorCode_InternalError, "Wrong tool!");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
287 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
288 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
289 default:
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 return NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
291 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
292 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
293
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
295 void TrackerSampleApp::PrepareScene()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
296 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
297 // Texture of 2x2 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
298 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
299 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 2, 2, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
300
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
301 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
302 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
304 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
305
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
306 p[3] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
307 p[4] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
308 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
309
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
310 p = reinterpret_cast<uint8_t*>(i.GetRow(1));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
311 p[0] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
312 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
313 p[2] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
314
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
315 p[3] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
316 p[4] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
317 p[5] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
318
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
319 scene_.SetLayer(TEXTURE_2x2_1_ZINDEX, new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
320
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
321 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
322 l->SetOrigin(-3, 2);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
323 l->SetPixelSpacing(1.5, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
324 l->SetAngle(20.0 / 180.0 * M_PI);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
325 scene_.SetLayer(TEXTURE_2x2_2_ZINDEX, l.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
326 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
327
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
328 // Texture of 1x1 size
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
329 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
330 Orthanc::Image i(Orthanc::PixelFormat_RGB24, 1, 1, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
331
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
332 uint8_t* p = reinterpret_cast<uint8_t*>(i.GetRow(0));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
333 p[0] = 255;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
334 p[1] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
335 p[2] = 0;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
336
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
337 std::auto_ptr<ColorTextureSceneLayer> l(new ColorTextureSceneLayer(i));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
338 l->SetOrigin(-2, 1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
339 l->SetAngle(20.0 / 180.0 * M_PI);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
340 scene_.SetLayer(TEXTURE_1x1_ZINDEX, l.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
341 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
342
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
343 // Some lines
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
344 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
345 std::auto_ptr<PolylineSceneLayer> layer(new PolylineSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
346
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
347 layer->SetThickness(1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
348
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
349 PolylineSceneLayer::Chain chain;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
350 chain.push_back(ScenePoint2D(0 - 0.5, 0 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
351 chain.push_back(ScenePoint2D(0 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
352 chain.push_back(ScenePoint2D(2 - 0.5, 2 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
353 chain.push_back(ScenePoint2D(2 - 0.5, 0 - 0.5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
354 layer->AddChain(chain, true);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
355
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
356 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
357 chain.push_back(ScenePoint2D(-5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
358 chain.push_back(ScenePoint2D(5, -5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
359 chain.push_back(ScenePoint2D(5, 5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
360 chain.push_back(ScenePoint2D(-5, 5));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
361 layer->AddChain(chain, true);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
362
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
363 double dy = 1.01;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
364 chain.clear();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
365 chain.push_back(ScenePoint2D(-4, -4));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
366 chain.push_back(ScenePoint2D(4, -4 + dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
367 chain.push_back(ScenePoint2D(-4, -4 + 2.0 * dy));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
368 chain.push_back(ScenePoint2D(4, 2));
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
369 layer->AddChain(chain, false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
370
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
371 layer->SetColor(0, 255, 255);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
372 scene_.SetLayer(LINESET_1_ZINDEX, layer.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
373 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
374
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
375 // Some text
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
376 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
377 std::auto_ptr<TextSceneLayer> layer(new TextSceneLayer);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
378 layer->SetText("Hello");
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
379 scene_.SetLayer(LINESET_2_ZINDEX, layer.release());
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
380 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
381 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
382
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
383
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
384 void TrackerSampleApp::DisableTracker()
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
385 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
386 if (activeTracker_)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
387 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
388 activeTracker_->Cancel();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
389 activeTracker_ = NULL;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
390 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
391 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
392
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
393 void TrackerSampleApp::TakeScreenshot(const std::string& target,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
394 unsigned int canvasWidth,
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
395 unsigned int canvasHeight)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
396 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
397 // Take a screenshot, then save it as PNG file
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
398 CairoCompositor compositor(scene_, canvasWidth, canvasHeight);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
399 compositor.SetFont(0, Orthanc::EmbeddedResources::UBUNTU_FONT, FONT_SIZE, Orthanc::Encoding_Latin1);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
400 compositor.Refresh();
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
401
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
402 Orthanc::ImageAccessor canvas;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
403 compositor.GetCanvas().GetReadOnlyAccessor(canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
404
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
405 Orthanc::Image png(Orthanc::PixelFormat_RGB24, canvas.GetWidth(), canvas.GetHeight(), false);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
406 Orthanc::ImageProcessing::Convert(png, canvas);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
407
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
408 Orthanc::PngWriter writer;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
409 writer.WriteToFile(target, png);
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
410 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
411
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
412
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
413 FlexiblePointerTrackerPtr TrackerSampleApp::TrackerHitTest(const PointerEvent & e)
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
414 {
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
415 // std::vector<MeasureToolPtr> measureTools_;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
416 return nullptr;
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
417 }
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
418
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
419
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
420
f939f449482c Ongoing tracker work.
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
421 }