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.5 by greg, Sat Feb 22 02:07:28 2003 UTC vs.
Revision 3.12 by greg, Thu Feb 22 17:45:27 2024 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines