| 18 |
|
#include <string.h> |
| 19 |
|
#include <math.h> |
| 20 |
|
#include "bsdfrep.h" |
| 21 |
+ |
|
| 22 |
+ |
#ifndef NEIGH_FACT2 |
| 23 |
+ |
#define NEIGH_FACT2 0.2 /* empirical neighborhood distance weight */ |
| 24 |
+ |
#endif |
| 25 |
|
/* number of processes to run */ |
| 26 |
|
int nprocs = 1; |
| 27 |
|
/* number of children (-1 in child) */ |
| 139 |
|
|
| 140 |
|
#endif /* ! _WIN32 */ |
| 141 |
|
|
| 142 |
+ |
/* Compute normalized distribution scattering functions for comparison */ |
| 143 |
+ |
static void |
| 144 |
+ |
compute_nDSFs(const RBFNODE *rbf0, const RBFNODE *rbf1) |
| 145 |
+ |
{ |
| 146 |
+ |
const double nf0 = (GRIDRES*GRIDRES) / rbf0->vtotal; |
| 147 |
+ |
const double nf1 = (GRIDRES*GRIDRES) / rbf1->vtotal; |
| 148 |
+ |
int x, y; |
| 149 |
+ |
FVECT dv; |
| 150 |
+ |
|
| 151 |
+ |
for (x = GRIDRES; x--; ) |
| 152 |
+ |
for (y = GRIDRES; y--; ) { |
| 153 |
+ |
ovec_from_pos(dv, x, y); |
| 154 |
+ |
dsf_grid[x][y].val[0] = nf0 * eval_rbfrep(rbf0, dv); |
| 155 |
+ |
dsf_grid[x][y].val[1] = nf1 * eval_rbfrep(rbf1, dv); |
| 156 |
+ |
} |
| 157 |
+ |
} |
| 158 |
+ |
|
| 159 |
+ |
/* Compute neighborhood distance-squared (dissimilarity) */ |
| 160 |
+ |
static double |
| 161 |
+ |
neighborhood_dist2(int x0, int y0, int x1, int y1) |
| 162 |
+ |
{ |
| 163 |
+ |
int rad = GRIDRES>>5; |
| 164 |
+ |
double sum2 = 0.; |
| 165 |
+ |
double d; |
| 166 |
+ |
int p[4]; |
| 167 |
+ |
int i, j; |
| 168 |
+ |
|
| 169 |
+ |
if ((x0 == x1) & (y0 == y1)) |
| 170 |
+ |
return(0.); |
| 171 |
+ |
/* check radius */ |
| 172 |
+ |
p[0] = x0; p[1] = y0; p[2] = x1; p[3] = y1; |
| 173 |
+ |
for (i = 4; i--; ) { |
| 174 |
+ |
if (p[i] < rad) rad = p[i]; |
| 175 |
+ |
if (GRIDRES-1-p[i] < rad) rad = GRIDRES-1-p[i]; |
| 176 |
+ |
} |
| 177 |
+ |
for (i = -rad; i <= rad; i++) |
| 178 |
+ |
for (j = -rad; j <= rad; j++) { |
| 179 |
+ |
d = dsf_grid[x0+i][y0+j].val[0] - |
| 180 |
+ |
dsf_grid[x1+i][y1+j].val[1]; |
| 181 |
+ |
sum2 += d*d; |
| 182 |
+ |
} |
| 183 |
+ |
return(sum2 / (4*rad*(rad+1) + 1)); |
| 184 |
+ |
} |
| 185 |
+ |
|
| 186 |
|
/* Comparison routine needed for sorting price row */ |
| 187 |
|
static int |
| 188 |
|
msrt_cmp(void *b, const void *p1, const void *p2) |
| 203 |
|
FVECT *vto = (FVECT *)malloc(sizeof(FVECT) * to_rbf->nrbf); |
| 204 |
|
int i, j; |
| 205 |
|
|
| 206 |
+ |
compute_nDSFs(from_rbf, to_rbf); |
| 207 |
|
pm->nrows = from_rbf->nrbf; |
| 208 |
|
pm->ncols = to_rbf->nrbf; |
| 209 |
|
pm->price = (float *)malloc(sizeof(float) * pm->nrows*pm->ncols); |
| 229 |
|
d = Acos(DOT(vfrom, vto[j])); |
| 230 |
|
pm->prow[j] = d*d; |
| 231 |
|
d = R2ANG(to_rbf->rbfa[j].crad) - from_ang; |
| 232 |
< |
pm->prow[j] += d*d; |
| 232 |
> |
pm->prow[j] += d*d; |
| 233 |
> |
/* neighborhood difference */ |
| 234 |
> |
pm->prow[j] += NEIGH_FACT2 * neighborhood_dist2( |
| 235 |
> |
from_rbf->rbfa[i].gx, from_rbf->rbfa[i].gy, |
| 236 |
> |
to_rbf->rbfa[j].gx, to_rbf->rbfa[j].gy ); |
| 237 |
|
srow[j] = j; |
| 238 |
|
} |
| 239 |
|
qsort_r(srow, pm->ncols, sizeof(short), pm, &msrt_cmp); |