~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/terrain/grimson.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #include <stdio.h>
  2 #include <sys/param.h>
  3 #include <string.h>
  4 #include <tina/all_tina.h>
  5 
  6 extern Imrect *im_zeropad(Imrect *im, int pad_depth);
  7 
  8 Imrect *grimson_proc(Imrect *im, int max_count)
  9 {
 10   Imrect *disp = NULL;       /* displacement vector image */
 11   Imrect *dispmask = NULL;   /* fixed displacement points mask */
 12   Imrect *new_im = NULL;     /* image returned to stack */
 13   Imrect *im2;               
 14 
 15   Imregion *roi;             /* roi of the original data */
 16   int width, height;         /* width and height of original data */
 17   int shiftx, shifty;        /* offsets used in barrel shifting */
 18 
 19   int loop, row, col;        /* loop variables */
 20   int pad_depth;             /* parameter required by the convolution process */
 21 
 22   /* surface depth constraint parameters */
 23   /* float im_max, im_min; */
 24 
 25   char pathname[MAXPATHLEN]; /* name and location of the interpolation kernel */
 26   Imrect *kernel = NULL;     /* interpolation kernel */
 27   float gr_array[5][5] = {{0.0, 0.0, 0.03125, 0.0, 0.0},
 28                           {0.0, 0.0625, -0.25, 0.0625, 0.0},
 29                           {0.03125, -0.25, 0.625, -0.25, 0.031250},
 30                           {0.0, 0.0625, -0.25, 0.0625, 0.0},
 31                           {0.0, 0.0, 0.03125, 0.0, 0.0}};
 32 
 33   if (im->vtype!=float_v)
 34     {
 35       im2 = im_cast(im, float_v);
 36       im_free(im);
 37       im = im2;
 38     }
 39 
 40   /* create a new image of same size and roi as matrix */
 41 
 42   kernel = im_alloc(5, 5, NULL, float_v);
 43 
 44   /* copy matrix elements into new image */
 45 
 46   FOR_IM(kernel->region, row, col) 
 47     IM_FLOAT(kernel, row, col) = gr_array[row][col];
 48 
 49   /* copy the original image parameters */
 50 
 51   roi = roi_copy(im->region);
 52   height = im->height;
 53   width = im->width;
 54 
 55   /* quad and shift the image to buffer the image with reflections of itself */
 56 
 57   shiftx = (int)(abs(im->region->ux-im->region->lx)/2);
 58   shifty = (int)(abs(im->region->uy-im->region->ly)/2);
 59   im = im_quad(im);
 60   im2 = im_bshift(im, shifty, shiftx);
 61   im_free(im);
 62   im = im2;
 63 
 64   /* alloc storage for the displacement values */
 65 
 66   disp = im_alloc(im->height, im->width, im->region, im->vtype);
 67 
 68   /* generate the displacement point mask, 0 for a fixed value, 1 for not */
 69 
 70   dispmask = im_alloc(im->height, im->width, im->region, im->vtype);
 71 
 72   FOR_IM(im->region, row, col) IM_FLOAT(dispmask, row, col) =
 73     ((IM_FLOAT(im, row, col)==0.0) ? 1.0 : 0.0);
 74 
 75   /* fireburn the initial image */
 76 
 77   im = im_fireburn(im, 0.0, 0.0);
 78 
 79   /* set the minimum and maximum height thresholds for the output image */
 80 
 81 
 82   pad_depth = MAX((abs(kernel->region->ux-kernel->region->lx)/2),
 83                   (abs(kernel->region->uy-kernel->region->ly)/2));
 84   im = im_zeropad(im, pad_depth);
 85 
 86   for (loop=0; loop<max_count; loop++)
 87     {
 88       /* convolve data with interpolation kernel */
 89 
 90       im_convolve(disp, im, kernel);
 91 
 92           /* remove the known disparity point values then
 93              subtract the displacement values to obtain new surface */
 94 
 95       FOR_IM(disp->region, row, col)
 96         {
 97           IM_FLOAT(disp, row, col) *= IM_FLOAT(dispmask, row, col);
 98           IM_FLOAT(im, row, col) -= IM_FLOAT(disp, row, col);
 99         }
100     }
101   
102   /* extract just the orig data plus interpolated data */
103 
104   im2 = im_bshift(im, -shifty, -shiftx);
105   im_free(im);
106   im = im2;
107   new_im = im_subim(im, roi);
108   
109   new_im->height = height;
110   new_im->width = width;
111   
112   im_free(im);
113   im_free(disp);
114   im_free(dispmask);
115   im_free(kernel);
116   rfree((void *)roi);
117 
118   return (new_im);
119 }
120 
121 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.