-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdtwplot.cpp
More file actions
117 lines (96 loc) · 3.36 KB
/
dtwplot.cpp
File metadata and controls
117 lines (96 loc) · 3.36 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
// Copyright 2014 Gwennael Gate.
//
// Author: Gwennael Gate (gwennaelgate@gmail.com)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// -----------------------------------------------------------------------
#include "dtwplot.h"
DtwPlot::DtwPlot(ublas::matrix<float> * mat,
std::vector< ublas::matrix<unsigned int> > * path) : QWidget(),
fDtw(mat),
fPath(path)
{
}
void DtwPlot::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QRect rect;
int width = 4;
for (int i = 0 ; i < fDtw->size1() ; i++)
for (int j = 0 ; j < fDtw->size2() ; j++)
{
rect.setCoords(j*width,i*width,(j+1)*width,(i+1)*width);
painter.fillRect(rect, QColor(10,10,10, abs(((*fDtw)(i,j)/1000000)*255)));
}
QPen myPen(Qt::red, 2, Qt::SolidLine);
painter.setPen(myPen);
for (int i = 0 ; i < fPath->size() ; ++i)
{
painter.drawEllipse(fPath->at(i)(0,1)*width,
fPath->at(i)(0,0)*width,
width,
width);
}
myPen.setColor(Qt::green);
myPen.setWidth(2);
painter.setPen(myPen);
plotValley(&myPen, &painter, fDtw, fPath);
}
float DtwPlot::plotValley(QPen *pen,
QPainter * painter,
ublas::matrix<float> * dtw,
std::vector< ublas::matrix<unsigned int> > * path)
{
int width = 4;
int radius = 20;
QPoint tangent;
QPoint upper;
QPoint lower;
for (int i = 0 ; i < path->size()-1 ; ++i)
{
int i1 = path->at(i)(0,0);
int j1 = path->at(i)(0,1);
int i2 = path->at(i+1)(0,0);
int j2 = path->at(i+1)(0,1);
tangent.setX(i2-i1);
tangent.setY(j2-j1);
upper.setX(i1 - radius*tangent.y());
upper.setY(j1 + radius*tangent.x());
lower.setX(i1 + radius*tangent.y());
lower.setY(j1 - radius*tangent.x());
if(upper.x() < 5)
upper.setX(5);
if(upper.x() >= dtw->size1()-1)
upper.setX(dtw->size1()-1);
if(upper.y() < 5)
upper.setY(5);
if(upper.y() >= dtw->size2()-1)
upper.setY(dtw->size2()-1);
if(lower.x() < 5)
lower.setX(5);
if(lower.x() >= dtw->size1())
lower.setX(dtw->size1()-1);
if(lower.y() < 5)
lower.setY(5);
if(lower.y() >= dtw->size2())
lower.setY(dtw->size2()-1);
painter->drawEllipse(upper.y()*width,
upper.x()*width,
width,
width);
painter->drawEllipse(lower.y()*width,
lower.x()*width,
width,
width);
}
}