1 |
– |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
2 |
– |
|
1 |
|
#ifndef lint |
2 |
< |
static char SCCSid[] = "$SunId$ SGI"; |
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 unsigned long gridhash(void *gp); |
37 |
+ |
static lut_hashf_t gridhash; |
38 |
+ |
static int new3dgrid(WARP3D *wp); |
39 |
+ |
static void done3dgrid(struct grid3d *gp); |
40 |
|
|
41 |
+ |
|
42 |
|
double |
43 |
< |
wpdist2(p1, p2) /* compute square of distance between points */ |
44 |
< |
register W3VEC p1, p2; |
43 |
> |
wpdist2( /* compute square of distance between points */ |
44 |
> |
register W3VEC p1, |
45 |
> |
register W3VEC p2 |
46 |
> |
) |
47 |
|
{ |
48 |
|
double d, d2; |
49 |
|
|
55 |
|
|
56 |
|
|
57 |
|
int |
58 |
< |
warp3d(po, pi, wp) /* warp 3D point according to the given map */ |
59 |
< |
W3VEC po, pi; |
60 |
< |
register WARP3D *wp; |
58 |
> |
warp3d( /* warp 3D point according to the given map */ |
59 |
> |
W3VEC po, |
60 |
> |
W3VEC pi, |
61 |
> |
register WARP3D *wp |
62 |
> |
) |
63 |
|
{ |
64 |
|
int rval = W3OK; |
65 |
|
GNDX gi; |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
< |
int |
85 |
< |
gridpoint(ndx, rem, ipt, gp) /* compute grid position for ipt */ |
86 |
< |
GNDX ndx; |
87 |
< |
W3VEC rem, ipt; |
88 |
< |
register struct grid3d *gp; |
84 |
> |
static int |
85 |
> |
gridpoint( /* compute grid position for ipt */ |
86 |
> |
GNDX ndx, |
87 |
> |
W3VEC rem, |
88 |
> |
W3VEC ipt, |
89 |
> |
register struct grid3d *gp |
90 |
> |
) |
91 |
|
{ |
92 |
|
int rval = W3OK; |
93 |
|
register int i; |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
< |
int |
112 |
< |
get3dgpt(ov, ndx, wp) /* get value for voxel */ |
113 |
< |
W3VEC ov; |
114 |
< |
GNDX ndx; |
115 |
< |
register WARP3D *wp; |
111 |
> |
static int |
112 |
> |
get3dgpt( /* get value for voxel */ |
113 |
> |
W3VEC ov, |
114 |
> |
GNDX ndx, |
115 |
> |
register WARP3D *wp |
116 |
> |
) |
117 |
|
{ |
118 |
|
W3VEC gpt; |
119 |
|
register LUENT *le; |
144 |
|
} |
145 |
|
|
146 |
|
|
147 |
< |
int |
148 |
< |
get3dgin(ov, ndx, rem, wp) /* interpolate from warp grid */ |
149 |
< |
W3VEC ov, rem; |
150 |
< |
GNDX ndx; |
151 |
< |
WARP3D *wp; |
147 |
> |
static int |
148 |
> |
get3dgin( /* interpolate from warp grid */ |
149 |
> |
W3VEC ov, |
150 |
> |
GNDX ndx, |
151 |
> |
W3VEC rem, |
152 |
> |
WARP3D *wp |
153 |
> |
) |
154 |
|
{ |
155 |
|
W3VEC cv[8]; |
156 |
|
GNDX gi; |
170 |
|
} |
171 |
|
|
172 |
|
|
173 |
< |
l3interp(vo, cl, dv, n) /* trilinear interpolation (recursive) */ |
174 |
< |
W3VEC vo, *cl, dv; |
175 |
< |
int n; |
173 |
> |
static void |
174 |
> |
l3interp( /* trilinear interpolation (recursive) */ |
175 |
> |
W3VEC vo, |
176 |
> |
W3VEC *cl, |
177 |
> |
W3VEC dv, |
178 |
> |
int n |
179 |
> |
) |
180 |
|
{ |
181 |
|
W3VEC v0, v1; |
182 |
|
register int i; |
193 |
|
} |
194 |
|
|
195 |
|
|
196 |
< |
int |
197 |
< |
warp3dex(ov, pi, wp) /* compute warp using 1/r^2 weighted avg. */ |
198 |
< |
W3VEC ov, pi; |
199 |
< |
register WARP3D *wp; |
196 |
> |
static int |
197 |
> |
warp3dex( /* compute warp using 1/r^2 weighted avg. */ |
198 |
> |
W3VEC ov, |
199 |
> |
W3VEC pi, |
200 |
> |
register WARP3D *wp |
201 |
> |
) |
202 |
|
{ |
203 |
|
double d2, w, wsum; |
204 |
|
W3VEC vt; |
225 |
|
|
226 |
|
|
227 |
|
WARP3D * |
228 |
< |
new3dw(flgs) /* allocate and initialize WARP3D struct */ |
229 |
< |
int flgs; |
228 |
> |
new3dw( /* allocate and initialize WARP3D struct */ |
229 |
> |
int flgs |
230 |
> |
) |
231 |
|
{ |
232 |
|
register WARP3D *wp; |
233 |
|
|
248 |
|
|
249 |
|
|
250 |
|
WARP3D * |
251 |
< |
load3dw(fn, wp) /* load 3D warp from file */ |
252 |
< |
char *fn; |
253 |
< |
WARP3D *wp; |
251 |
> |
load3dw( /* load 3D warp from file */ |
252 |
> |
char *fn, |
253 |
> |
WARP3D *wp |
254 |
> |
) |
255 |
|
{ |
256 |
|
FILE *fp; |
257 |
|
W3VEC inp, outp; |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
< |
int |
283 |
< |
set3dwfl(wp, flgs) /* reset warp flags */ |
284 |
< |
register WARP3D *wp; |
285 |
< |
int flgs; |
282 |
> |
extern int |
283 |
> |
set3dwfl( /* reset warp flags */ |
284 |
> |
register WARP3D *wp, |
285 |
> |
int flgs |
286 |
> |
) |
287 |
|
{ |
288 |
|
if (flgs == wp->grid.flags) |
289 |
|
return(0); |
298 |
|
|
299 |
|
|
300 |
|
int |
301 |
< |
add3dpt(wp, pti, pto) /* add 3D point pair to warp structure */ |
302 |
< |
register WARP3D *wp; |
303 |
< |
W3VEC pti, pto; |
301 |
> |
add3dpt( /* add 3D point pair to warp structure */ |
302 |
> |
register WARP3D *wp, |
303 |
> |
W3VEC pti, |
304 |
> |
W3VEC pto |
305 |
> |
) |
306 |
|
{ |
307 |
|
double d2; |
308 |
|
register W3VEC *na; |
319 |
|
W3VCPY(wp->ulim, pti); |
320 |
|
} else { |
321 |
|
if (wp->npts % AHUNK == 0) { /* allocate another hunk */ |
322 |
< |
na = (W3VEC *)realloc((char *)wp->ip, |
322 |
> |
na = (W3VEC *)realloc((void *)wp->ip, |
323 |
|
(wp->npts+AHUNK)*sizeof(W3VEC)); |
324 |
|
if (na == NULL) return(0); |
325 |
|
wp->ip = na; |
326 |
< |
na = (W3VEC *)realloc((char *)wp->ov, |
326 |
> |
na = (W3VEC *)realloc((void *)wp->ov, |
327 |
|
(wp->npts+AHUNK)*sizeof(W3VEC)); |
328 |
|
if (na == NULL) return(0); |
329 |
|
wp->ov = na; |
352 |
|
} |
353 |
|
|
354 |
|
|
355 |
< |
free3dw(wp) /* free WARP3D data */ |
356 |
< |
register WARP3D *wp; |
355 |
> |
extern void |
356 |
> |
free3dw( /* free WARP3D data */ |
357 |
> |
register WARP3D *wp |
358 |
> |
) |
359 |
|
{ |
360 |
|
done3dgrid(&wp->grid); |
361 |
< |
free((char *)wp->ip); |
362 |
< |
free((char *)wp->ov); |
363 |
< |
free((char *)wp); |
361 |
> |
free((void *)wp->ip); |
362 |
> |
free((void *)wp->ov); |
363 |
> |
free((void *)wp); |
364 |
|
} |
365 |
|
|
366 |
|
|
367 |
< |
unsigned long |
368 |
< |
gridhash(gp) /* hash a grid point index */ |
369 |
< |
GNDX gp; |
367 |
> |
static unsigned long |
368 |
> |
gridhash( /* hash a grid point index */ |
369 |
> |
//GNDX gp |
370 |
> |
void *gp |
371 |
> |
) |
372 |
|
{ |
373 |
< |
return(((unsigned long)gp[0]<<GNBITS | gp[1])<<GNBITS | gp[2]); |
373 |
> |
//return(((unsigned long)gp[0]<<GNBITS | gp[1])<<GNBITS | gp[2]); |
374 |
> |
return(((unsigned long)((unsigned char*)gp)[0]<<GNBITS | ((unsigned char*)gp)[1])<<GNBITS | ((unsigned char*)gp)[2]); |
375 |
|
} |
376 |
|
|
377 |
|
|
378 |
< |
int |
379 |
< |
new3dgrid(wp) /* initialize interpolating grid for warp */ |
380 |
< |
register WARP3D *wp; |
378 |
> |
static int |
379 |
> |
new3dgrid( /* initialize interpolating grid for warp */ |
380 |
> |
register WARP3D *wp |
381 |
> |
) |
382 |
|
{ |
383 |
|
W3VEC gmax; |
384 |
|
double gridstep, d; |
424 |
|
} |
425 |
|
|
426 |
|
|
427 |
< |
done3dgrid(gp) /* free interpolating grid for warp */ |
428 |
< |
register struct grid3d *gp; |
427 |
> |
static void |
428 |
> |
done3dgrid( /* free interpolating grid for warp */ |
429 |
> |
register struct grid3d *gp |
430 |
> |
) |
431 |
|
{ |
432 |
|
if (gp->gn[0] == 0) |
433 |
|
return; |