-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathControllerAreaDescriptor.cpp
More file actions
361 lines (314 loc) · 12.7 KB
/
Copy pathControllerAreaDescriptor.cpp
File metadata and controls
361 lines (314 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#include "ControllerAreaDescriptor.h"
#include "Model/AreaDescriptor/AreaInfo.h"
#include "View/AreaDesciptor/AreaDescriptor.h"
#include "View/AreaDesciptor/RectDescriptor.h"
#include "View/AreaDesciptor/EllipseDescriptor.h"
#include "util/types.h"
#include "ControllerGraphicScene.h"
#include "View/GraphicsView.h"
#include "Model/AreaDescriptor/Rectification.h"
#include "Controller/ControllerPlayer.h"
#include "Controller/ControllerCoreParameter.h"
#include <iostream>
#include "Model/AreaDescriptor/AreaMemory.h"
using namespace AreaMemory;
ControllerAreaDescriptor::ControllerAreaDescriptor(QObject* parent,
IBioTrackerContext* context,
ENUMS::CONTROLLERTYPE ctr)
: IControllerCfg(parent, context, ctr)
{
_watchingVertice = -1;
_watchingVerticeType = BiotrackerTypes::AreaType::NONE;
m_ViewApperture = nullptr;
}
void ControllerAreaDescriptor::triggerUpdateAreaDescriptor()
{
IModelAreaDescriptor* area = dynamic_cast<IModelAreaDescriptor*>(
getModel());
Q_EMIT updateAreaDescriptor(area);
}
void ControllerAreaDescriptor::createView()
{
assert(m_Model);
AreaInfo* mInf = dynamic_cast<AreaInfo*>(getModel());
RectDescriptor* view = new RectDescriptor(this, mInf->_rect.get());
m_View = view;
QObject::connect(this,
&ControllerAreaDescriptor::currentVectorDrag,
view,
&RectDescriptor::receiveDragUpdate);
IController* ctr = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::GRAPHICSVIEW);
auto viewController = qobject_cast<ControllerGraphicScene*>(ctr);
auto gview = dynamic_cast<GraphicsView*>(viewController->getView());
gview->addGraphicsItem(view);
AreaInfo* area = dynamic_cast<AreaInfo*>(getModel());
int v = _cfg->AppertureType;
trackingAreaType(v);
}
void ControllerAreaDescriptor::connectModelToController()
{
}
void ControllerAreaDescriptor::trackingAreaType(int v)
{
IController* ctr1 = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::GRAPHICSVIEW);
auto viewController = qobject_cast<ControllerGraphicScene*>(ctr1);
auto gview = dynamic_cast<GraphicsView*>(viewController->getView());
IController* ctr = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::COMPONENT);
RectDescriptor* view = dynamic_cast<RectDescriptor*>(m_View);
AreaInfo* area = dynamic_cast<AreaInfo*>(getModel());
if (m_ViewApperture) {
gview->removeGraphicsItem(
static_cast<AreaDescriptor*>(m_ViewApperture));
delete m_ViewApperture;
}
if (v == 0) {
m_ViewApperture = new RectDescriptor(this, area->_apperture.get());
area->_apperture->setType(0);
static_cast<RectDescriptor*>(m_ViewApperture)
->setBrush(QBrush(Qt::red));
QObject::connect(this,
&ControllerAreaDescriptor::currentVectorDrag,
static_cast<RectDescriptor*>(m_ViewApperture),
&RectDescriptor::receiveDragUpdate);
_cfg->AppertureType = 0;
} else if (v > 0) {
m_ViewApperture = new EllipseDescriptor(this, area->_apperture.get());
area->_apperture->setType(1);
static_cast<EllipseDescriptor*>(m_ViewApperture)
->setBrush(QBrush(Qt::red));
static_cast<EllipseDescriptor*>(m_ViewApperture)
->setDimensions(_w, _h);
QObject::connect(this,
&ControllerAreaDescriptor::currentVectorDrag,
static_cast<EllipseDescriptor*>(m_ViewApperture),
&EllipseDescriptor::receiveDragUpdate);
_cfg->AppertureType = 1;
}
if (!_visibleApperture)
static_cast<AreaDescriptor*>(m_ViewApperture)->hide();
if (!_visibleRectification)
static_cast<AreaDescriptor*>(m_View)->hide();
gview->addGraphicsItem(static_cast<AreaDescriptor*>(m_ViewApperture));
}
void ControllerAreaDescriptor::rcvPlayerParameters(
std::shared_ptr<const playerParameters> parameters)
{
// Best effort to save performance...
// File has changed
if (_currentFilename != parameters->m_CurrentFilename) {
_currentFilename = parameters->m_CurrentFilename;
// Set area descriptor dimensions
auto ad = static_cast<AreaDescriptor*>(m_ViewApperture);
auto m = parameters->m_CurrentFrame;
if (ad && m) {
_w = m->size().width;
_h = m->size().height;
ad->setDimensions(_w, _h);
}
QVector<QString> v = getVertices(_currentFilename,
_cfg->AreaDefinitions);
if (!v.empty()) {
changeAreaDescriptorType(v[2]);
}
}
}
void ControllerAreaDescriptor::connectControllerToController()
{
{
IController* ctr = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::GRAPHICSVIEW);
auto viewController = qobject_cast<ControllerGraphicScene*>(ctr);
auto view = dynamic_cast<GraphicsView*>(viewController->getView());
QObject::connect(view,
&GraphicsView::onMousePressEvent,
this,
&ControllerAreaDescriptor::mousePressEvent,
Qt::DirectConnection);
QObject::connect(view,
&GraphicsView::onMouseReleaseEvent,
this,
&ControllerAreaDescriptor::mouseReleaseEvent,
Qt::DirectConnection);
QObject::connect(view,
&GraphicsView::onMouseMoveEvent,
this,
&ControllerAreaDescriptor::mouseMoveEvent,
Qt::DirectConnection);
QObject::connect(view,
&GraphicsView::onKeyReleaseEvent,
this,
&ControllerAreaDescriptor::keyReleaseEvent,
Qt::DirectConnection);
// Area info model needs to know video dimensions
auto model = static_cast<AreaInfo*>(getModel());
IController* ctrPl = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::PLAYER);
auto mediaPlayerController = static_cast<ControllerPlayer*>(ctrPl);
MediaPlayer* player = static_cast<MediaPlayer*>(
mediaPlayerController->getModel());
QObject::connect(player,
&MediaPlayer::fwdPlayerParameters,
model,
&AreaInfo::rcvPlayerParameters,
Qt::DirectConnection);
QObject::connect(player,
&MediaPlayer::fwdPlayerParameters,
this,
&ControllerAreaDescriptor::rcvPlayerParameters,
Qt::DirectConnection);
IController* ctrParms = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::COREPARAMETER);
auto parmsController = qobject_cast<ControllerCoreParameter*>(
ctrParms);
QObject::connect(this,
&ControllerAreaDescriptor::changeAreaDescriptorType,
parmsController,
&ControllerCoreParameter::changeAreaDescriptorType,
Qt::DirectConnection);
AreaInfo* area = dynamic_cast<AreaInfo*>(getModel());
QObject::connect(area->_rect.get(),
SIGNAL(updatedVertices()),
this,
SLOT(updateView()));
QObject::connect(area->_apperture.get(),
SIGNAL(updatedVertices()),
this,
SLOT(updateView()));
}
{
// View stuff from the parameter view
IController* ctr = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::GRAPHICSVIEW);
auto viewController = qobject_cast<ControllerGraphicScene*>(ctr);
}
{
IController* ctr = m_BioTrackerContext->requestController(
ENUMS::CONTROLLERTYPE::COREPARAMETER);
ControllerCoreParameter* cctr = static_cast<ControllerCoreParameter*>(
ctr);
cctr->triggerUpdate();
}
}
void ControllerAreaDescriptor::createModel()
{
m_Model = new AreaInfo(this);
}
void ControllerAreaDescriptor::updateView()
{
AreaInfo* area = static_cast<AreaInfo*>(getModel());
RectDescriptor* rd = static_cast<RectDescriptor*>(getView());
rd->updateRect();
AreaDescriptor* ad = static_cast<AreaDescriptor*>(m_ViewApperture);
ad->updateRect();
area->updateRectification();
area->updateApperture();
}
void ControllerAreaDescriptor::keyReleaseEvent(QKeyEvent* event)
{
}
void ControllerAreaDescriptor::mousePressEvent(QMouseEvent* event,
const QPoint& pos)
{
auto model = static_cast<AreaInfo*>(getModel());
// check if rectification vertice is grabbed and visible
RectDescriptor* rd = static_cast<RectDescriptor*>(getView());
int verticeRect = -1;
if (rd->isVisible()) {
verticeRect = model->_rect->getVerticeAtLocation(pos);
if (verticeRect >= 0) {
_watchingVertice = verticeRect;
_watchingVerticeType = BiotrackerTypes::AreaType::RECT;
event->accept();
}
}
// check if apperture vertice is grabbed and visible
AreaDescriptor* ad = static_cast<AreaDescriptor*>(m_ViewApperture);
int verticeApp = -1;
if (ad->isVisible()) {
verticeApp = model->_apperture->getVerticeAtLocation(pos);
if (verticeApp >= 0) {
_watchingVertice = verticeApp;
_watchingVerticeType = BiotrackerTypes::AreaType::APPERTURE;
event->accept();
}
}
// else none is grabbed
if (verticeRect < 0 && verticeApp < 0) {
_watchingVertice = -1;
_watchingVerticeType = BiotrackerTypes::AreaType::NONE;
}
// disable use entire screen when one vertice is grabbed
if (verticeRect > 0 || verticeApp > 0) {
AreaInfo* area = static_cast<AreaInfo*>(getModel());
area->setUseEntireScreen(false);
}
Q_EMIT currentVectorDrag(_watchingVerticeType,
_watchingVertice,
pos.x(),
pos.y());
}
void ControllerAreaDescriptor::mouseReleaseEvent(QMouseEvent* event,
const QPoint& pos)
{
auto model = static_cast<AreaInfo*>(getModel());
if (_watchingVertice >= 0 &&
_watchingVerticeType == BiotrackerTypes::AreaType::RECT) {
model->_rect->setVerticeAtLocation(pos, _watchingVertice);
event->accept();
triggerUpdateAreaDescriptor();
}
if (_watchingVertice >= 0 &&
_watchingVerticeType == BiotrackerTypes::AreaType::APPERTURE) {
model->_apperture->setVerticeAtLocation(pos, _watchingVertice);
event->accept();
triggerUpdateAreaDescriptor();
}
_watchingVerticeType = BiotrackerTypes::AreaType::NONE;
_watchingVertice = -1;
Q_EMIT currentVectorDrag(_watchingVerticeType,
_watchingVertice,
pos.x(),
pos.y());
}
void ControllerAreaDescriptor::mouseMoveEvent(QMouseEvent* event,
const QPoint& pos)
{
Q_EMIT currentVectorDrag(_watchingVerticeType,
_watchingVertice,
pos.x(),
pos.y());
}
void ControllerAreaDescriptor::setRectificationDimensions(double w, double h)
{
_cfg->RectificationHeight = h;
_cfg->RectificationWidth = w;
AreaInfo* area = static_cast<AreaInfo*>(getModel());
area->setRectificationDimensions(w, h);
triggerUpdateAreaDescriptor();
RectDescriptor* rd = static_cast<RectDescriptor*>(getView());
rd->updateRect();
}
void ControllerAreaDescriptor::setDisplayRectificationDefinition(bool b)
{
_visibleRectification = b;
RectDescriptor* rd = static_cast<RectDescriptor*>(getView());
rd->setVisible(b);
}
void ControllerAreaDescriptor::setDisplayTrackingAreaDefinition(bool b)
{
_visibleApperture = b;
AreaDescriptor* ad = static_cast<AreaDescriptor*>(m_ViewApperture);
ad->setVisible(b);
}
void ControllerAreaDescriptor::setTrackingAreaAsEllipse(bool b)
{
// Not passing b as a parameter for clarification reasons
if (b) {
trackingAreaType(1);
} else {
trackingAreaType(0);
}
}