ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/px/warp3d.c
(Generate patch)

Comparing ray/src/px/warp3d.c (file contents):
Revision 3.3 by greg, Wed Feb 5 17:18:07 1997 UTC vs.
Revision 3.10 by greg, Fri Feb 18 00:40:25 2011 UTC

# Line 1 | Line 1
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  
# Line 25 | Line 26 | typedef struct {
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  
# Line 45 | Line 54 | register W3VEC p1, p2;
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;
# Line 69 | Line 80 | register WARP3D        *wp;
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;
# Line 94 | Line 107 | register struct grid3d *gp;
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;
# Line 129 | Line 143 | register WARP3D        *wp;
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;
# Line 153 | Line 169 | WARP3D *wp;
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;
# Line 172 | Line 192 | int    n;
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;
# Line 202 | Line 224 | register WARP3D        *wp;
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  
# Line 224 | Line 247 | int    flgs;
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;
# Line 254 | Line 278 | cleanup:
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);
# Line 272 | Line 297 | int    flgs;
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;
# Line 291 | Line 318 | W3VEC  pti, pto;
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;
# Line 324 | Line 351 | W3VEC  pti, pto;
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;
# Line 390 | Line 421 | register WARP3D        *wp;
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;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines