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

Linux Cross Reference
Tina4/src/vision/improc/im_surf.c

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

  1 /**@(#)
  2 **/
  3 #include <tina/sys.h>
  4 #include <tina/sysfuncs.h>
  5 #include <tina/math.h>
  6 #include <tina/mathfuncs.h>
  7 #include <tina/vision.h>
  8 
  9 void    terrain_data_free(Terrain_data * surf)
 10 {
 11     if (surf == NULL)
 12         return;
 13 
 14     narray_free((char **) surf->data, 0, surf->m, 0, surf->n, sizeof(Vec3));
 15     carray_free(surf->mask, 0, surf->m, 0, surf->n);
 16     rfree((void *) surf);
 17 }
 18 
 19 Terrain_data *terrain_alloc(int type, int m, int n)
 20 {
 21     Terrain_data *surf;
 22 
 23     surf = ts_ralloc(Terrain_data);
 24 #ifdef TSTRUCT
 25     surf->data = ts_narray_alloc(0, 0, m, n, Vec3);
 26 #else
 27     surf->data = (Vec3 **) narray_alloc(0, 0, m, n, sizeof(Vec3));
 28 #endif
 29     surf->mask = carray_alloc(0, 0, m, n);
 30     surf->type = type;
 31     surf->m = m;
 32     surf->n = n;
 33     return (surf);
 34 }
 35 
 36 Terrain_data *terrain_copy(Terrain_data * surf)
 37 {
 38     Terrain_data *copy;
 39     int     m, n, i, j;
 40 
 41     if (surf == NULL)
 42         return (NULL);
 43 
 44     m = surf->m;
 45     n = surf->n;
 46 
 47     copy = terrain_alloc(surf->type, m, n);
 48 
 49     for (i = 0; i < m; ++i)
 50         for (j = 0; j < n; ++j)
 51         {
 52             copy->mask[i][j] = surf->mask[i][j];
 53             copy->data[i][j] = surf->data[i][j];
 54         }
 55 
 56     return (copy);
 57 }
 58 
 59 Terrain_data *terrain_make(Imregion * region, Imrect * mask, int samplex, int sampley)
 60 {
 61     Terrain_data *surf;
 62     int     lx, ly, ux, uy;
 63     int     m, n;               /* mrows and n columns */
 64     int     i, j, r, c;
 65     float   x, y;
 66 
 67     if (region == NULL)
 68         return (NULL);
 69     if (samplex <1 ) samplex = 1;
 70     if (sampley <1 ) sampley = 1;
 71 
 72     lx = region->lx;
 73     ly = region->ly;
 74     ux = region->ux;
 75     uy = region->uy;
 76 
 77     m = (uy - ly) / sampley;
 78     n = (ux - lx) / samplex;
 79 
 80     uy--;
 81     ux--;
 82     surf = terrain_alloc(IMAGE, m + 1, n + 1);
 83 
 84     for (i = 0; i < m; i++)
 85     {
 86         r = ly + i * sampley;
 87         y = (float)r; 
 88         for (j = 0; j < n; ++j)
 89         {
 90             c = lx + j * samplex;
 91             x = (float)c;
 92             surf->data[i][j] = vec3(x, y, 0.0);
 93             if (mask == NULL || im_get_pix(mask, r, c))
 94                 surf->mask[i][j] = 1;
 95         }
 96         surf->data[i][j] = vec3((float) ux, y, 0.0);
 97         if (mask == NULL || im_get_pix(mask, r, ux))
 98             surf->mask[i][j] = 1;
 99     }
100 
101     for (j = 0; j < n; ++j)
102     {
103         c = lx + j * samplex;
104         x = (float)c;
105         surf->data[i][j] = vec3(x, (float) uy, 0.0);
106         if (mask == NULL || im_get_pix(mask, uy, c))
107             surf->mask[i][j] = 1;
108     }
109 
110     surf->data[i][j] = vec3((float) ux, (float) uy, 0.0);
111     if (mask == NULL || im_get_pix(mask, uy, ux))
112         surf->mask[i][j] = 1;
113 
114     return (surf);
115 }
116 
117 Terrain_data *im_surface(Imrect * im, Imrect * mask, int samplex, int sampley, double scale)
118 {
119     Terrain_data *surf;
120     int     lx, ly, ux, uy;
121     int     m, n;               /* mrows and n columns */
122     int     i, j, r, c;
123     float   x, y;
124 
125     if (im == NULL || im->region == NULL)
126         return (NULL);
127     if (samplex <1 ) samplex = 1;
128     if (sampley <1 ) sampley = 1;
129 
130     lx = im->region->lx;
131     ly = im->region->ly;
132     ux = im->region->ux;
133     uy = im->region->uy;
134 
135     m = (uy - ly) / sampley;
136     n = (ux - lx) / samplex;
137 
138     uy--;
139     ux--;
140     surf = terrain_alloc(IMAGE, m + 1, n + 1);
141 
142     for (i = 0; i < m; i++)
143     {
144         r = ly + i * sampley;
145         y = (float) r;
146         for (j = 0; j < n; ++j)
147         {
148             c = lx + j * samplex;
149             x = (float) c;
150             if (mask == NULL || im_get_pix(mask, r, c))
151             {
152                 surf->data[i][j] = vec3(x, y, im_get_pixf(im, r, c) * scale);
153                 surf->mask[i][j] = 1;
154             } else
155                 surf->data[i][j] = vec3(x, y, 0.0);
156         }
157         if (mask == NULL || im_get_pix(mask, r, ux))
158         {
159             surf->data[i][j] = vec3((float) ux, y, im_get_pixf(im, r, ux) * scale);
160             surf->mask[i][j] = 1;
161         } else
162             surf->data[i][j] = vec3((float) ux, y, 0.0);
163     }
164 
165     for (j = 0; j < n; ++j)
166     {
167         c = lx + j * samplex;
168         x = (float) c;
169         if (mask == NULL || im_get_pix(mask, uy, c))
170         {
171             surf->data[i][j] = vec3(x, (float) uy, im_get_pixf(im, uy, c) * scale);
172             surf->mask[i][j] = 1;
173         } else
174             surf->data[i][j] = vec3(x, (float) uy, 0.0);
175     }
176     if (mask == NULL || im_get_pix(mask, uy, ux))
177     {
178         surf->data[i][j] = vec3((float) ux, (float) uy, im_get_pixf(im, uy, ux) * scale);
179         surf->mask[i][j] = 1;
180     } else
181         surf->data[i][j] = vec3((float) ux, (float) uy, 0.0);
182     return (surf);
183 }
184 

~ [ 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.