1 |
– |
/* Copyright (c) 1997 Regents of the University of California */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ LBL"; |
2 |
> |
static const char RCSid[] = "$Id$"; |
3 |
|
#endif |
6 |
– |
|
4 |
|
/* |
5 |
|
* 3D warping routines. |
6 |
|
*/ |
7 |
|
|
8 |
|
#include <stdio.h> |
9 |
+ |
#include <stdlib.h> |
10 |
|
#include <math.h> |
11 |
+ |
|
12 |
+ |
#include "rterror.h" |
13 |
+ |
#include "rtio.h" |
14 |
|
#include "fvect.h" |
15 |
|
#include "warp3d.h" |
16 |
|
|
26 |
|
|
27 |
|
#define AHUNK 24 /* number of points to allocate at a time */ |
28 |
|
|
28 |
– |
#ifndef malloc |
29 |
– |
extern char *malloc(), *realloc(); |
30 |
– |
#endif |
31 |
– |
extern void free(); |
29 |
|
|
30 |
+ |
double wpdist2(W3VEC p1, W3VEC p2); |
31 |
+ |
static int gridpoint(GNDX ndx, W3VEC rem, W3VEC ipt, struct grid3d *gp); |
32 |
+ |
static int get3dgpt(W3VEC ov, GNDX ndx, WARP3D *wp); |
33 |
+ |
static int get3dgin(W3VEC ov, GNDX ndx, W3VEC rem, WARP3D *wp); |
34 |
+ |
static void l3interp(W3VEC vo, W3VEC *cl, W3VEC dv, int n); |
35 |
+ |
static int warp3dex(W3VEC ov, W3VEC pi, WARP3D *wp); |
36 |
+ |
static lut_hashf_t gridhash; |
37 |
+ |
static int new3dgrid(WARP3D *wp); |
38 |
+ |
static void done3dgrid(struct grid3d *gp); |
39 |
|
|
40 |
+ |
|
41 |
|
double |
42 |
< |
wpdist2(p1, p2) /* compute square of distance between points */ |
43 |
< |
register W3VEC p1, p2; |
42 |
> |
wpdist2( /* compute square of distance between points */ |
43 |
> |
register W3VEC p1, |
44 |
> |
register W3VEC p2 |
45 |
> |
) |
46 |
|
{ |
47 |
|
double d, d2; |
48 |
|
|
54 |
|
|
55 |
|
|
56 |
|
int |
57 |
< |
warp3d(po, pi, wp) /* warp 3D point according to the given map */ |
58 |
< |
W3VEC po, pi; |
59 |
< |
register WARP3D *wp; |
57 |
> |
warp3d( /* warp 3D point according to the given map */ |
58 |
> |
W3VEC po, |
59 |
> |
W3VEC pi, |
60 |
> |
register WARP3D *wp |
61 |
> |
) |
62 |
|
{ |
63 |
|
int rval = W3OK; |
64 |
|
GNDX gi; |
80 |
|
} |
81 |
|
|
82 |
|
|
83 |
< |
int |
84 |
< |
gridpoint(ndx, rem, ipt, gp) /* compute grid position for ipt */ |
85 |
< |
GNDX ndx; |
86 |
< |
W3VEC rem, ipt; |
87 |
< |
register struct grid3d *gp; |
83 |
> |
static int |
84 |
> |
gridpoint( /* compute grid position for ipt */ |
85 |
> |
GNDX ndx, |
86 |
> |
W3VEC rem, |
87 |
> |
W3VEC ipt, |
88 |
> |
register struct grid3d *gp |
89 |
> |
) |
90 |
|
{ |
91 |
|
int rval = W3OK; |
92 |
|
register int i; |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
< |
int |
111 |
< |
get3dgpt(ov, ndx, wp) /* get value for voxel */ |
112 |
< |
W3VEC ov; |
113 |
< |
GNDX ndx; |
114 |
< |
register WARP3D *wp; |
110 |
> |
static int |
111 |
> |
get3dgpt( /* get value for voxel */ |
112 |
> |
W3VEC ov, |
113 |
> |
GNDX ndx, |
114 |
> |
register WARP3D *wp |
115 |
> |
) |
116 |
|
{ |
117 |
|
W3VEC gpt; |
118 |
|
register LUENT *le; |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
< |
int |
147 |
< |
get3dgin(ov, ndx, rem, wp) /* interpolate from warp grid */ |
148 |
< |
W3VEC ov, rem; |
149 |
< |
GNDX ndx; |
150 |
< |
WARP3D *wp; |
146 |
> |
static int |
147 |
> |
get3dgin( /* interpolate from warp grid */ |
148 |
> |
W3VEC ov, |
149 |
> |
GNDX ndx, |
150 |
> |
W3VEC rem, |
151 |
> |
WARP3D *wp |
152 |
> |
) |
153 |
|
{ |
154 |
|
W3VEC cv[8]; |
155 |
|
GNDX gi; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
< |
l3interp(vo, cl, dv, n) /* trilinear interpolation (recursive) */ |
173 |
< |
W3VEC vo, *cl, dv; |
174 |
< |
int n; |
172 |
> |
static void |
173 |
> |
l3interp( /* trilinear interpolation (recursive) */ |
174 |
> |
W3VEC vo, |
175 |
> |
W3VEC *cl, |
176 |
> |
W3VEC dv, |
177 |
> |
int n |
178 |
> |
) |
179 |
|
{ |
180 |
|
W3VEC v0, v1; |
181 |
|
register int i; |
192 |
|
} |
193 |
|
|
194 |
|
|
195 |
< |
int |
196 |
< |
warp3dex(ov, pi, wp) /* compute warp using 1/r^2 weighted avg. */ |
197 |
< |
W3VEC ov, pi; |
198 |
< |
register WARP3D *wp; |
195 |
> |
static int |
196 |
> |
warp3dex( /* compute warp using 1/r^2 weighted avg. */ |
197 |
> |
W3VEC ov, |
198 |
> |
W3VEC pi, |
199 |
> |
register WARP3D *wp |
200 |
> |
) |
201 |
|
{ |
202 |
|
double d2, w, wsum; |
203 |
|
W3VEC vt; |
224 |
|
|
225 |
|
|
226 |
|
WARP3D * |
227 |
< |
new3dw(flgs) /* allocate and initialize WARP3D struct */ |
228 |
< |
int flgs; |
227 |
> |
new3dw( /* allocate and initialize WARP3D struct */ |
228 |
> |
int flgs |
229 |
> |
) |
230 |
|
{ |
231 |
|
register WARP3D *wp; |
232 |
|
|
247 |
|
|
248 |
|
|
249 |
|
WARP3D * |
250 |
< |
load3dw(fn, wp) /* load 3D warp from file */ |
251 |
< |
char *fn; |
252 |
< |
WARP3D *wp; |
250 |
> |
load3dw( /* load 3D warp from file */ |
251 |
> |
char *fn, |
252 |
> |
WARP3D *wp |
253 |
> |
) |
254 |
|
{ |
255 |
|
FILE *fp; |
256 |
|
W3VEC inp, outp; |
278 |
|
} |
279 |
|
|
280 |
|
|
281 |
< |
int |
282 |
< |
set3dwfl(wp, flgs) /* reset warp flags */ |
283 |
< |
register WARP3D *wp; |
284 |
< |
int flgs; |
281 |
> |
extern int |
282 |
> |
set3dwfl( /* reset warp flags */ |
283 |
> |
register WARP3D *wp, |
284 |
> |
int flgs |
285 |
> |
) |
286 |
|
{ |
287 |
|
if (flgs == wp->grid.flags) |
288 |
|
return(0); |
297 |
|
|
298 |
|
|
299 |
|
int |
300 |
< |
add3dpt(wp, pti, pto) /* add 3D point pair to warp structure */ |
301 |
< |
register WARP3D *wp; |
302 |
< |
W3VEC pti, pto; |
300 |
> |
add3dpt( /* add 3D point pair to warp structure */ |
301 |
> |
register WARP3D *wp, |
302 |
> |
W3VEC pti, |
303 |
> |
W3VEC pto |
304 |
> |
) |
305 |
|
{ |
306 |
|
double d2; |
307 |
|
register W3VEC *na; |
318 |
|
W3VCPY(wp->ulim, pti); |
319 |
|
} else { |
320 |
|
if (wp->npts % AHUNK == 0) { /* allocate another hunk */ |
321 |
< |
na = (W3VEC *)realloc((char *)wp->ip, |
321 |
> |
na = (W3VEC *)realloc((void *)wp->ip, |
322 |
|
(wp->npts+AHUNK)*sizeof(W3VEC)); |
323 |
|
if (na == NULL) return(0); |
324 |
|
wp->ip = na; |
325 |
< |
na = (W3VEC *)realloc((char *)wp->ov, |
325 |
> |
na = (W3VEC *)realloc((void *)wp->ov, |
326 |
|
(wp->npts+AHUNK)*sizeof(W3VEC)); |
327 |
|
if (na == NULL) return(0); |
328 |
|
wp->ov = na; |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
< |
free3dw(wp) /* free WARP3D data */ |
355 |
< |
register WARP3D *wp; |
354 |
> |
extern void |
355 |
> |
free3dw( /* free WARP3D data */ |
356 |
> |
register WARP3D *wp |
357 |
> |
) |
358 |
|
{ |
359 |
|
done3dgrid(&wp->grid); |
360 |
< |
free((char *)wp->ip); |
361 |
< |
free((char *)wp->ov); |
362 |
< |
free((char *)wp); |
360 |
> |
free((void *)wp->ip); |
361 |
> |
free((void *)wp->ov); |
362 |
> |
free((void *)wp); |
363 |
|
} |
364 |
|
|
365 |
|
|
366 |
< |
long |
367 |
< |
gridhash(gp) /* hash a grid point index */ |
368 |
< |
GNDX gp; |
366 |
> |
static unsigned long |
367 |
> |
gridhash( /* hash a grid point index */ |
368 |
> |
const char *gp |
369 |
> |
) |
370 |
|
{ |
371 |
< |
return(((unsigned long)gp[0]<<GNBITS | gp[1])<<GNBITS | gp[2]); |
371 |
> |
return(((unsigned long)((const unsigned char*)gp)[0]<<GNBITS | ((const unsigned char*)gp)[1])<<GNBITS | ((const unsigned char*)gp)[2]); |
372 |
|
} |
373 |
|
|
374 |
|
|
375 |
< |
int |
376 |
< |
new3dgrid(wp) /* initialize interpolating grid for warp */ |
377 |
< |
register WARP3D *wp; |
375 |
> |
static int |
376 |
> |
new3dgrid( /* initialize interpolating grid for warp */ |
377 |
> |
register WARP3D *wp |
378 |
> |
) |
379 |
|
{ |
380 |
|
W3VEC gmax; |
381 |
|
double gridstep, d; |
421 |
|
} |
422 |
|
|
423 |
|
|
424 |
< |
done3dgrid(gp) /* free interpolating grid for warp */ |
425 |
< |
register struct grid3d *gp; |
424 |
> |
static void |
425 |
> |
done3dgrid( /* free interpolating grid for warp */ |
426 |
> |
register struct grid3d *gp |
427 |
> |
) |
428 |
|
{ |
429 |
|
if (gp->gn[0] == 0) |
430 |
|
return; |