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.4 by gwlarson, Wed Sep 2 18:41:44 1998 UTC vs.
Revision 3.11 by greg, Sat Dec 28 18:05:14 2019 UTC

# Line 1 | Line 1
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>
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 25 | Line 25 | typedef struct {
25  
26   #define AHUNK   24              /* number of points to allocate at a time */
27  
28 #ifndef malloc
29 extern char     *malloc(), *realloc();
30 #endif
31 extern void     free();
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 >        register W3VEC  p1,
43 >        register W3VEC  p2
44 > )
45   {
46          double  d, d2;
47  
# Line 45 | 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 >        register WARP3D *wp
60 > )
61   {
62          int     rval = W3OK;
63          GNDX    gi;
# Line 69 | 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 >        register struct grid3d  *gp
88 > )
89   {
90          int     rval = W3OK;
91          register int    i;
# Line 94 | 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 >        register WARP3D *wp
114 > )
115   {
116          W3VEC   gpt;
117          register LUENT  *le;
# Line 129 | 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;
# Line 153 | 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;
# Line 172 | 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 >        register WARP3D *wp
199 > )
200   {
201          double  d2, w, wsum;
202          W3VEC   vt;
# Line 202 | 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;
231  
# Line 224 | 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 254 | 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 >        register WARP3D *wp,
283 >        int     flgs
284 > )
285   {
286          if (flgs == wp->grid.flags)
287                  return(0);
# Line 272 | 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 >        register WARP3D *wp,
301 >        W3VEC   pti,
302 >        W3VEC   pto
303 > )
304   {
305          double  d2;
306          register W3VEC  *na;
# Line 291 | 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 324 | 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 >        register WARP3D *wp
356 > )
357   {
358          done3dgrid(&wp->grid);
359 <        free((char *)wp->ip);
360 <        free((char *)wp->ov);
361 <        free((char *)wp);
359 >        free((void *)wp->ip);
360 >        free((void *)wp->ov);
361 >        free((void *)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 >        register WARP3D *wp
377 > )
378   {
379          W3VEC   gmax;
380          double  gridstep, d;
# Line 390 | 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 >        register struct grid3d  *gp
426 > )
427   {
428          if (gp->gn[0] == 0)
429                  return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines