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

Linux Cross Reference
Tina6/tina-tools/tinatool/draw/drawPlot_cntr.c

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

  1 /**********
  2  *
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  *
 35  * Program :    TINA
 36  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawPlot_cntr.c,v $
 37  * Date    :  $Date: 2003/10/01 16:02:47 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: drawPlot_cntr.c,v 1.2 2003/10/01 16:02:47 tony Exp $
 40  *
 41  * Author  : Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "drawPlot_cntr.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 
 55 #include <stdio.h>
 56 #include <math.h>
 57 #include <tina/sys/sysDef.h>
 58 #include <tina/sys/sysPro.h>
 59 #include <tina/math/mathDef.h>
 60 #include <tina/math/mathPro.h>
 61 #include <tina/geometry/geomDef.h>
 62 #include <tinatool/draw/draw_TvDef.h>
 63 #include <tinatool/draw/draw_TvPro.h>
 64 #include <tinatool/draw/draw_PlotDef.h>
 65 #include <tinatool/draw/draw_PlotPro.h>
 66 
 67 static double min3(double a, double b, double c)
 68 {
 69     double  m;
 70 
 71     m = a;
 72     if (m > b)
 73         m = b;
 74     if (m > c)
 75         m = c;
 76     return (m);
 77 }
 78 
 79 static double max3(double a, double b, double c)
 80 {
 81     double  m;
 82 
 83     m = a;
 84     if (m < b)
 85         m = b;
 86     if (m < c)
 87         m = c;
 88     return (m);
 89 }
 90 
 91 static double min4(double a, double b, double c, double d)
 92 {
 93     double  m;
 94 
 95     m = a;
 96     if (m > b)
 97         m = b;
 98     if (m > c)
 99         m = c;
100     if (m > d)
101         m = d;
102     return (m);
103 }
104 
105 static double max4(double a, double b, double c, double d)
106 {
107     double  m;
108 
109     m = a;
110     if (m < b)
111         m = b;
112     if (m < c)
113         m = c;
114     if (m < d)
115         m = d;
116     return (m);
117 }
118 
119 static int between(double x, double a, double b)
120 {
121     return (((a < x) && (x < b)) || ((a > x) && (x > b)));
122 }
123 
124 static void upper_tri(Tv * tv, int i, int j, float *x, float *y, float **z, float c)
125 {
126     double  x1, x2, x3;
127     double  y1, y2, y3;
128     double  z1, z2, z3;
129     double  a1 = 0.0;
130     double  a2 = 0.0;
131     double  b1 = 0.0;
132     double  b2 = 0.0;
133     double  k;
134     int     ncut = 0;
135 
136     x1 = x2 = x[i];
137     x3 = x[i + 1];
138     y1 = y[j];
139     y2 = y3 = y[j + 1];
140     z1 = z[i][j];
141     z2 = z[i][j + 1];
142     z3 = z[i + 1][j + 1];
143 
144     if (c < min3(z1, z2, z3))
145         return;
146     if (c > max3(z1, z2, z3))
147         return;
148 
149     if (c == z1 && c == z2)
150         tv_line2(tv, vec2(x1, y1), vec2(x2, y2));
151     if (c == z2 && c == z3)
152         tv_line2(tv, vec2(x2, y2), vec2(x3, y3));
153     if (c == z3 && c == z1)
154         tv_line2(tv, vec2(x3, y3), vec2(x1, y1));
155 
156     if (between(c, z1, z2))
157     {
158         k = (c - z1) / (z2 - z1);
159         a1 = x1 + k * (x2 - x1);
160         b1 = y1 + k * (y2 - y1);
161         ncut = 1;
162     }
163     if (between(c, z2, z3))
164     {
165         if (ncut == 0)
166         {
167             k = (c - z2) / (z3 - z2);
168             a1 = x2 + k * (x3 - x2);
169             b1 = y2 + k * (y3 - y2);
170             ncut = 1;
171         } else
172         {
173             k = (c - z2) / (z3 - z2);
174             a2 = x2 + k * (x3 - x2);
175             b2 = y2 + k * (y3 - y2);
176             ncut = 2;
177         }
178     }
179     if (between(c, z3, z1) && ncut == 1)
180     {
181         k = (c - z3) / (z1 - z3);
182         a2 = x3 + k * (x1 - x3);
183         b2 = y3 + k * (y1 - y3);
184         ncut = 2;
185     }
186     if (ncut == 2)
187         tv_line2(tv, vec2(a1, b1), vec2(a2, b2));
188 }
189 
190 void    lower_tri(Tv * tv, int i, int j, float *x, float *y, float **z, float c)
191 {
192     float   x1, x2, x3;
193     float   y1, y2, y3;
194     float   z1, z2, z3;
195     float   a1 = (float)0.0;
196     float   b1;
197     float   a2 = (float)0.0;
198     float   b2;
199     float   k;
200     int     ncut = 0;
201 
202     x1 = x[i];
203     x2 = x3 = x[i + 1];
204     y1 = y2 = y[j];
205     y3 = y[j + 1];
206     z1 = z[i][j];
207     z2 = z[i + 1][j];
208     z3 = z[i + 1][j + 1];
209 
210     if (c < min3(z1, z2, z3))
211         return;
212     if (c > max3(z1, z2, z3))
213         return;
214 
215     if (c == z1 && c == z2)
216         tv_line2(tv, vec2(x1, y1), vec2(x2, y2));
217     if (c == z2 && c == z3)
218         tv_line2(tv, vec2(x2, y2), vec2(x3, y3));
219     if (c == z3 && c == z1)
220         tv_line2(tv, vec2(x3, y3), vec2(x1, y1));
221 
222     if (between(c, z1, z2))
223     {
224         k = (c - z1) / (z2 - z1);
225         a1 = x1 + k * (x2 - x1);
226         b1 = y1 + k * (y2 - y1);
227         ncut = 1;
228     }
229     if (between(c, z2, z3))
230     {
231         if (ncut == 0)
232         {
233             k = (c - z2) / (z3 - z2);
234             a1 = x2 + k * (x3 - x2);
235             b1 = y2 + k * (y3 - y2);
236             ncut = 1;
237         } else
238         {
239             k = (c - z2) / (z3 - z2);
240             a2 = x2 + k * (x3 - x2);
241             b2 = y2 + k * (y3 - y2);
242             ncut = 2;
243         }
244     }
245     if (between(c, z3, z1) && ncut == 1)
246     {
247         k = (c - z3) / (z1 - z3);
248         a2 = x3 + k * (x1 - x3);
249         b2 = y3 + k * (y1 - y3);
250         ncut = 2;
251     }
252     if (ncut == 2)
253         tv_line2(tv, vec2(a1, b1), vec2(a2, b2));
254 }
255 
256 void    pl_ctr_plot(Tv * tv, Pl_ctr * ctr)
257 {
258     int     i, j, k;
259     double  cmax, cmin, cinc, dummy;
260     float  *x, *y, **z;
261 
262     if (tv == NULL || ctr == NULL)
263         return;
264 
265     z = ctr->z;
266     x = ctr->x;
267     y = ctr->y;
268 
269     if (ctr->cscale == false)
270     {
271         cmax = ctr->cmax;
272         cmin = ctr->cmin;
273         cinc = ctr->cinc;
274     } else
275     {
276         farray_bounds(z, 0, 0, ctr->nx, ctr->ny, &cmin, &cmax);
277         pl_scale(&cmin, &cmax, &cinc, &dummy);
278     }
279 
280     x = ctr->x;
281     y = ctr->y;
282     z = ctr->z;
283     tv_set_color(tv, ctr->color);
284 
285     for (i = 0; i < ctr->nx - 1; i++)
286         for (j = 0; j < ctr->ny - 1; j++)
287         {
288             double  zmin =
289             min4(z[i][j], z[i + 1][j], z[i][j + 1], z[i + 1][j + 1]);
290             double  zmax =
291             max4(z[i][j], z[i + 1][j], z[i][j + 1], z[i + 1][j + 1]);
292 
293             for (k = (int)((zmin - cmin) / cinc); k <= 1.0 + (zmax - cmin) / cinc; k++)
294             {
295                 double  c = cmin + k * cinc;
296 
297                 upper_tri(tv, i, j, x, y, z, (float)c);
298                 lower_tri(tv, i, j, x, y, z, (float)c);
299             }
300         }
301 }
302 

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