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

Linux Cross Reference
Tina4/src/draw/plot/plot_cntr.c

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

  1 /**@(#)
  2 **/
  3 #include <stdio.h>
  4 #include <math.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 #include <tina/tv.h>
 10 #include <tina/tvfuncs.h>
 11 #include <tina/vision.h>
 12 #include <tina/draw.h>
 13 #include <tina/drawfuncs.h>
 14 
 15 static double min3(double a, double b, double c)
 16 {
 17     double  m;
 18 
 19     m = a;
 20     if (m > b)
 21         m = b;
 22     if (m > c)
 23         m = c;
 24     return (m);
 25 }
 26 
 27 static double max3(double a, double b, double c)
 28 {
 29     double  m;
 30 
 31     m = a;
 32     if (m < b)
 33         m = b;
 34     if (m < c)
 35         m = c;
 36     return (m);
 37 }
 38 
 39 static double min4(double a, double b, double c, double d)
 40 {
 41     double  m;
 42 
 43     m = a;
 44     if (m > b)
 45         m = b;
 46     if (m > c)
 47         m = c;
 48     if (m > d)
 49         m = d;
 50     return (m);
 51 }
 52 
 53 static double max4(double a, double b, double c, double d)
 54 {
 55     double  m;
 56 
 57     m = a;
 58     if (m < b)
 59         m = b;
 60     if (m < c)
 61         m = c;
 62     if (m < d)
 63         m = d;
 64     return (m);
 65 }
 66 
 67 static int between(double x, double a, double b)
 68 {
 69     return (((a < x) && (x < b)) || ((a > x) && (x > b)));
 70 }
 71 
 72 static void upper_tri(Tv * tv, int i, int j, float *x, float *y, float **z, float c)
 73 {
 74     double  x1, x2, x3;
 75     double  y1, y2, y3;
 76     double  z1, z2, z3;
 77     double  a1 = 0.0;
 78     double  a2 = 0.0;
 79     double  b1 = 0.0;
 80     double  b2 = 0.0;
 81     double  k;
 82     int     ncut = 0;
 83 
 84     x1 = x2 = x[i];
 85     x3 = x[i + 1];
 86     y1 = y[j];
 87     y2 = y3 = y[j + 1];
 88     z1 = z[i][j];
 89     z2 = z[i][j + 1];
 90     z3 = z[i + 1][j + 1];
 91 
 92     if (c < min3(z1, z2, z3))
 93         return;
 94     if (c > max3(z1, z2, z3))
 95         return;
 96 
 97     if (c == z1 && c == z2)
 98         tv_line2(tv, vec2(x1, y1), vec2(x2, y2));
 99     if (c == z2 && c == z3)
100         tv_line2(tv, vec2(x2, y2), vec2(x3, y3));
101     if (c == z3 && c == z1)
102         tv_line2(tv, vec2(x3, y3), vec2(x1, y1));
103 
104     if (between(c, z1, z2))
105     {
106         k = (c - z1) / (z2 - z1);
107         a1 = x1 + k * (x2 - x1);
108         b1 = y1 + k * (y2 - y1);
109         ncut = 1;
110     }
111     if (between(c, z2, z3))
112     {
113         if (ncut == 0)
114         {
115             k = (c - z2) / (z3 - z2);
116             a1 = x2 + k * (x3 - x2);
117             b1 = y2 + k * (y3 - y2);
118             ncut = 1;
119         } else
120         {
121             k = (c - z2) / (z3 - z2);
122             a2 = x2 + k * (x3 - x2);
123             b2 = y2 + k * (y3 - y2);
124             ncut = 2;
125         }
126     }
127     if (between(c, z3, z1) && ncut == 1)
128     {
129         k = (c - z3) / (z1 - z3);
130         a2 = x3 + k * (x1 - x3);
131         b2 = y3 + k * (y1 - y3);
132         ncut = 2;
133     }
134     if (ncut == 2)
135         tv_line2(tv, vec2(a1, b1), vec2(a2, b2));
136 }
137 
138 void    lower_tri(Tv * tv, int i, int j, float *x, float *y, float **z, float c)
139 {
140     float   x1, x2, x3;
141     float   y1, y2, y3;
142     float   z1, z2, z3;
143     float   a1 = (float)0.0;
144     float   b1;
145     float   a2 = (float)0.0;
146     float   b2;
147     float   k;
148     int     ncut = 0;
149 
150     x1 = x[i];
151     x2 = x3 = x[i + 1];
152     y1 = y2 = y[j];
153     y3 = y[j + 1];
154     z1 = z[i][j];
155     z2 = z[i + 1][j];
156     z3 = z[i + 1][j + 1];
157 
158     if (c < min3(z1, z2, z3))
159         return;
160     if (c > max3(z1, z2, z3))
161         return;
162 
163     if (c == z1 && c == z2)
164         tv_line2(tv, vec2(x1, y1), vec2(x2, y2));
165     if (c == z2 && c == z3)
166         tv_line2(tv, vec2(x2, y2), vec2(x3, y3));
167     if (c == z3 && c == z1)
168         tv_line2(tv, vec2(x3, y3), vec2(x1, y1));
169 
170     if (between(c, z1, z2))
171     {
172         k = (c - z1) / (z2 - z1);
173         a1 = x1 + k * (x2 - x1);
174         b1 = y1 + k * (y2 - y1);
175         ncut = 1;
176     }
177     if (between(c, z2, z3))
178     {
179         if (ncut == 0)
180         {
181             k = (c - z2) / (z3 - z2);
182             a1 = x2 + k * (x3 - x2);
183             b1 = y2 + k * (y3 - y2);
184             ncut = 1;
185         } else
186         {
187             k = (c - z2) / (z3 - z2);
188             a2 = x2 + k * (x3 - x2);
189             b2 = y2 + k * (y3 - y2);
190             ncut = 2;
191         }
192     }
193     if (between(c, z3, z1) && ncut == 1)
194     {
195         k = (c - z3) / (z1 - z3);
196         a2 = x3 + k * (x1 - x3);
197         b2 = y3 + k * (y1 - y3);
198         ncut = 2;
199     }
200     if (ncut == 2)
201         tv_line2(tv, vec2(a1, b1), vec2(a2, b2));
202 }
203 
204 void    pl_ctr_plot(Tv * tv, Pl_ctr * ctr)
205 {
206     int     i, j, k;
207     double  cmax, cmin, cinc, dummy;
208     float  *x, *y, **z;
209 
210     if (tv == NULL || ctr == NULL)
211         return;
212 
213     z = ctr->z;
214     x = ctr->x;
215     y = ctr->y;
216 
217     if (ctr->cscale == false)
218     {
219         cmax = ctr->cmax;
220         cmin = ctr->cmin;
221         cinc = ctr->cinc;
222     } else
223     {
224         farray_bounds(z, 0, 0, ctr->nx, ctr->ny, &cmin, &cmax);
225         pl_scale(&cmin, &cmax, &cinc, &dummy);
226     }
227 
228     x = ctr->x;
229     y = ctr->y;
230     z = ctr->z;
231     tv_set_color(tv, ctr->color);
232 
233     for (i = 0; i < ctr->nx - 1; i++)
234         for (j = 0; j < ctr->ny - 1; j++)
235         {
236             double  zmin =
237             min4(z[i][j], z[i + 1][j], z[i][j + 1], z[i + 1][j + 1]);
238             double  zmax =
239             max4(z[i][j], z[i + 1][j], z[i][j + 1], z[i + 1][j + 1]);
240 
241             for (k = (int)((zmin - cmin) / cinc); k <= 1.0 + (zmax - cmin) / cinc; k++)
242             {
243                 double  c = cmin + k * cinc;
244 
245                 upper_tri(tv, i, j, x, y, z, (float)c);
246                 lower_tri(tv, i, j, x, y, z, (float)c);
247             }
248         }
249 }
250 

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