00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include <stdio.h>
00029 #include "imcore.h"
00030 #include "util.h"
00031
00034
00073
00074
00075 void apline(ap_t *ap, float dat[], float conf[], float smoothed[],
00076 float smoothedc[], int j, unsigned char *bpm) {
00077 int i,i1,loop,nn;
00078 int is;
00079 int ip;
00080 int ib;
00081 float i2compare,icompare;
00082 unsigned char *mflag;
00083
00084 i2compare = ap->thresh;
00085 icompare = i2compare * ap->multiply;
00086 mflag = ap->mflag;
00087
00088 for (i = 0; i < ap->lsiz; i++) {
00089 if (smoothedc[i] > icompare && conf[i] != 0) {
00090
00091
00092
00093 is = ap->lastline[i];
00094 ip = ap->lastline[i + 1];
00095 if (ip == 0) {
00096
00097
00098
00099 if (is == 0) {
00100
00101
00102
00103 ip = ap->pstack[ap->ipstack++];
00104 ap->parent[ip].first = ap->bstack[ap->ibstack];
00105 ap->parent[ip].pnop = 0;
00106 ap->parent[ip].pnbp = 0;
00107 ap->parent[ip].growing = 0;
00108 if (j == 0)
00109
00110
00111
00112 ap->parent[ip].touch = 1;
00113 else
00114 ap->parent[ip].touch = 0;
00115
00116
00117
00118 if (ip > ap->maxip)
00119 ap->maxip = ip;
00120 } else {
00121
00122
00123
00124 ip = is;
00125 }
00126 } else if ((ip > 0 && is > 0) && (ip != is)) {
00127
00128
00129
00130 ap->blink[ap->parent[ip].last] = ap->parent[is].first;
00131
00132
00133
00134 ap->parent[ip].last = ap->parent[is].last;
00135 ap->parent[ip].pnop += ap->parent[is].pnop;
00136 ap->parent[ip].pnbp += ap->parent[is].pnbp;
00137
00138
00139
00140 ib = ap->parent[is].first;
00141 loop = 1;
00142 while (loop) {
00143 i1 = ap->plessey[ib].x;
00144 if (ap->lastline[i1 + 1] == is)
00145 ap->lastline[i1 + 1] = ip;
00146 if (ap->parent[is].last == ib)
00147 loop = 0;
00148 else
00149 ib = ap->blink[ib];
00150 }
00151
00152
00153
00154 ap->parent[is].pnop = -1;
00155 ap->parent[is].pnbp = -1;
00156
00157
00158
00159 ap->pstack[--ap->ipstack] = is;
00160 }
00161
00162
00163
00164 ib = ap->bstack[ap->ibstack++];
00165
00166
00167
00168 if (ap->parent[ip].pnop > 0)
00169 ap->blink[ap->parent[ip].last] = ib;
00170
00171
00172
00173 ap->parent[ip].last = ib;
00174
00175
00176
00177 ap->plessey[ib].x = i;
00178 ap->plessey[ib].y = j;
00179 ap->plessey[ib].z = dat[i];
00180 nn = j*ap->lsiz + i;
00181 if (mflag[nn] != MF_SATURATED)
00182 ap->plessey[ib].zsm = MIN(ap->saturation,smoothed[i]);
00183 else
00184 ap->plessey[ib].zsm = ap->saturation;
00185 mflag[nn] = MF_POSSIBLEOBJ;
00186
00187
00188
00189 ap->parent[ip].pnop++;
00190 if (bpm != NULL)
00191 ap->parent[ip].pnbp += bpm[i];
00192
00193
00194
00195 ap->lastline[i + 1] = ip;
00196
00197 } else {
00198
00199
00200
00201 ap->lastline[i + 1] = 0;
00202 }
00203 }
00204
00205
00206
00207
00208 if(ap->lastline[1] > 0 )
00209 ap->parent[ap->lastline[1]].touch |= 2;
00210 if(ap->lastline[ap->lsiz] > 0)
00211 ap->parent[ap->lastline[ap->lsiz]].touch |= 4;
00212 }
00213
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238