-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmfccplot.cpp
More file actions
145 lines (125 loc) · 4.41 KB
/
mfccplot.cpp
File metadata and controls
145 lines (125 loc) · 4.41 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
// 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 "mfccplot.h"
MfccPlot::MfccPlot(ublas::matrix<float> *utt1,
ublas::matrix<float> *utt2,
std::vector< ublas::matrix<unsigned int> > *path,
ublas::matrix<float> *dtw) : QWidget(),
fUtt1(utt1),
fUtt2(utt2),
fPath(path),
fDtw(dtw),
fIndex(0)
{
}
void MfccPlot::setIndex(int k)
{
fIndex = k;
update();
}
void MfccPlot::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QPen myPen(Qt::blue, 2, Qt::SolidLine);
painter.setPen(myPen);
unsigned int zeroAxis1 = 200;
unsigned int zeroAxis2 = 500;
unsigned int step = 7;
unsigned int zoom = 5;
myPen.setColor(Qt::black);
painter.setPen(myPen);
painter.drawLine(0, zeroAxis1, 1500, zeroAxis1);
myPen.setColor(Qt::red);
painter.setPen(myPen);
for(unsigned int i = 0 ; i < fUtt1->size1()-1 ; i++)
{
painter.drawLine(i*step,
zeroAxis1 - zoom*(*fUtt1)(i,fIndex),
(i+1)*step,
zeroAxis1 - zoom*(*fUtt1)(i+1,fIndex));
}
myPen.setColor(Qt::black);
painter.setPen(myPen);
painter.drawLine(0, zeroAxis2, 1500, zeroAxis2);
myPen.setColor(Qt::blue);
painter.setPen(myPen);
for(unsigned int i = 0 ; i < fUtt2->size1()-1 ; i++)
{
painter.drawLine(i*step,
zeroAxis2 - zoom*(*fUtt2)(i,fIndex),
(i+1)*step,
zeroAxis2 - zoom*(*fUtt2)(i+1,fIndex));
}
myPen.setColor(Qt::gray);
myPen.setWidth(1);
painter.setPen(myPen);
for (unsigned int i = 0 ; i < fPath->size() ; i++)
{
if(fPath->at(i)(0,0) < fUtt1->size1()
&& fPath->at(i)(0,1) < fUtt2->size1())
{
painter.drawLine(fPath->at(i)(0,0)*step,
zeroAxis1 - zoom*(*fUtt1)(fPath->at(i)(0,0),fIndex),
fPath->at(i)(0,1)*step,
zeroAxis2 - zoom*(*fUtt2)(fPath->at(i)(0,1),fIndex));
}
}
float zoom2 = 0.001;
myPen.setColor(Qt::green);
myPen.setWidth(2);
painter.setPen(myPen);
for (unsigned int i = 0 ; i < fPath->size()-3 ; i++)
{
painter.drawLine(fPath->at(i)(0,0)*step,
zeroAxis1 - zoom2*valleyDeepness(fDtw, fPath->at(i)(0,0), fPath->at(i)(0,1), fPath->at(i+1)(0,0), fPath->at(i+1)(0,1)),
fPath->at(i+1)(0,0)*step,
zeroAxis1 - zoom2*valleyDeepness(fDtw, fPath->at(i+1)(0,0), fPath->at(i+1)(0,1), fPath->at(i+2)(0,0), fPath->at(i+2)(0,1)));
}
}
float MfccPlot::valleyDeepness(ublas::matrix<float> * dtw,
int i1, int j1,
int i2, int j2)
{
int radius = 20;
QPoint tangent;
tangent.setX(i2-i1);
tangent.setY(j2-j1);
QPoint upper;
QPoint lower;
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);
return (*dtw)(upper.x(), upper.y()) - (*dtw)(i1, j1) +
(*dtw)(lower.x(), lower.y()) - (*dtw)(i1, j1);
}