-
Notifications
You must be signed in to change notification settings - Fork 17
/
Signal.cpp
181 lines (124 loc) · 3.94 KB
/
Signal.cpp
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
/////////////////////////////////////////////////////////////////////////////////////////
//
// gro is protected by the UW OPEN SOURCE LICENSE, which is summarized here.
// Please see the file LICENSE.txt for the complete license.
//
// THE SOFTWARE (AS DEFINED BELOW) AND HARDWARE DESIGNS (AS DEFINED BELOW) IS PROVIDED
// UNDER THE TERMS OF THIS OPEN SOURCE LICENSE (“LICENSE”). THE SOFTWARE IS PROTECTED
// BY COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THIS SOFTWARE OTHER THAN AS
// AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
//
// BY EXERCISING ANY RIGHTS TO THE SOFTWARE AND/OR HARDWARE PROVIDED HERE, YOU ACCEPT AND
// AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY BE
// CONSIDERED A CONTRACT, THE UNIVERSITY OF WASHINGTON (“UW”) GRANTS YOU THE RIGHTS
// CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
//
// TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
//
//
#include "Micro.h"
Signal::Signal ( cpVect p, cpVect q, int nx, int ny, float kdi, float kde )
: minp ( p ), maxp ( q ), numx ( nx ), numy ( ny ), kdiff ( kdi ), kdeg ( kde ) {
int i, j;
sig.resize ( nx );
dsig.resize ( nx );
for ( i=0; i<nx; i++ ) {
sig[i].resize(ny);
dsig[i].resize(ny);
}
for ( i=0; i<nx; i++ )
for ( j=0; j<ny; j++ ) {
sig[i][j] = 0.0;
dsig[i][j] = 0.0;
}
w = q.x - p.x;
h = q.y - p.y;
dw = w/nx;
dh = h/ny;
}
Signal::~Signal ( void ) {
}
//void Signal::render ( GroPainter * painter, int index ) {
// int i, j;
// QColor col;
// for ( i=0; i<numx; i++ ) {
// for ( j=0; j<numy; j++ ) {
// double a = sig[i][j];
// double b = sig[i][j];
// col.setRgbF( qMin(1.0,a), 0.0, qMin(1.0,b), 0.5 );
// painter->fillRect((int)minp.x+dw*i,(int)minp.y+dh*j,(int)dw,(int)dh,col);
// }
// }
//}
void Signal::integrate ( float dt ) {
int i, j, k, l;
for ( i=1; i<numx-1; i++ ) {
for ( j=1; j<numy-1; j++ ) {
dsig[i][j] = - 6*kdiff*sig[i][j] - kdeg*sig[i][j];
dsig[i][j] += kdiff * (
0.5*sig[i+1][j-1] + sig[i+1][j] + 0.5*sig[i+1][j+1]
+ sig[i][j-1] + sig[i][j+1]
+ 0.5*sig[i-1][j-1] + sig[i-1][j] + 0.5*sig[i-1][j+1] );
}
}
for ( i=0; i<numx; i++ ) {
for ( j=0; j<numy; j++ ) {
sig[i][j] += dt * dsig[i][j];
if ( sig[i][j] < 0.0 )
sig[i][j] = 0.0; // just in case
}
}
}
void Signal::zero ( void ) {
int i, j;
for ( i=0; i<numx; i++ )
for ( j=0; j<numy; j++ )
sig[i][j] = 0.0;
}
void Signal::set ( int i, int j, float c ) {
if ( i >=0 && i<numx && j >=0 && j < numy )
sig[i][j] = c;
}
void Signal::set ( float x, float y, float c ) {
int i = row(x), j = col(y);
if ( i >=0 && i<numx && j >=0 && j < numy )
sig[i][j] = c;
}
void Signal::inc ( int i, int j, float c ) {
if ( i > 1 && i<numx-1 && j > 1 && j < numy-1 )
sig[i][j] += c;
}
void Signal::inc ( float x, float y, float c ) {
int i = row(x), j = col(y);
if ( i > 1 && i<numx-1 && j > 1 && j < numy-1 )
sig[i][j] += c;
}
void Signal::dec ( int i, int j, float c ) {
if ( i >=0 && i<numx && j >=0 && j < numy )
sig[i][j] = max ( 0.0, sig[i][j] - c );
}
void Signal::dec ( float x, float y, float c ) {
int i = row(x), j = col(y);
if ( i >=0 && i<numx && j >=0 && j < numy )
sig[i][j] = max ( 0.0, sig[i][j] - c );
}
float Signal::get ( int i, int j ) {
if ( i >=0 && i<numx && j >=0 && j < numy )
return sig[i][j];
else
return 0.0f;
}
float Signal::get ( float x, float y ) {
int i = row(x), j = col(y);
if ( i >=0 && i<numx && j >=0 && j < numy )
return sig[i][j];
else
return 0.0f;
}
void Signal::set_rect ( float x1, float y1, float x2, float y2, float c ) {
int X1 = row(x1), Y1 = col(y1),
X2 = row(x2), Y2 = col(y2);
for ( int i = X1; i<=X2; i++ )
for ( int j = Y1; j<Y2; j++ )
set(i,j,c);
}