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

Linux Cross Reference
Tina4/src/covira/snake_draw.c

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

  1 /*@(#)
  2 *
  3 * snake_draw.c
  4 *
  5 * graphics functions for snakes
  6 *
  7 */
  8 
  9 #include <tina/all_tina.h>
 10 #include <tina/brain.h>
 11 #include <tina/brainfuncs.h>
 12 
 13 /*
 14 draw snake to tv, marking knots with bigdots
 15 */
 16 void snake_draw(Tv * tv, Snake * snake)
 17 {
 18     int i, n;
 19 
 20     if (snake == NULL)
 21         return;
 22     n = snake->n;
 23     for (i = 0; i < n - 1; i++)
 24     {
 25         tv_bigdot2(tv, snake->p[i], 2);
 26         tv_line2(tv, snake->p[i], snake->p[i + 1]);
 27     }
 28     tv_bigdot2(tv, snake->p[n - 1], 2);
 29     tv_line2(tv, snake->p[n - 1], snake->p[0]);
 30 }
 31 
 32 /*
 33 return 3D position of snake knot with z-coord given
 34 */
 35 static Vec3 snake_knot3(Snake * snake, double z, int i)
 36 {
 37     return (vec3(vec3_x(snake->p[i]), vec3_y(snake->p[i]), z));
 38 }
 39 
 40 /*
 41 draw z-plane snake to tv with z-coord given
 42 */
 43 void snake_draw3(Tv * tv, Snake * snake, double z)
 44 {
 45     int i, n;
 46 
 47     if (snake == NULL)
 48         return;
 49     n = snake->n;
 50     for (i = 0; i < n - 1; i++)
 51         tv_line3(tv, snake_knot3(snake, z, i), snake_knot3(snake, z, i + 1));
 52     tv_line3(tv, snake_knot3(snake, z, n - 1), snake_knot3(snake, z, 0));
 53 }
 54 
 55 /*
 56 Draw snake forces to tv (normalised so maximum force shown as maxlength).
 57 Actual maximum force is printed at top left of tv.
 58 */
 59 void snake_force_draw(Tv * tv, Snake * snake, double maxlength)
 60 {
 61     int i, n = snake->n;
 62     Vec2 *p = snake->p;
 63     Vec2 *f = snake->f;
 64     double fmax = 0.0;
 65     char string[32];
 66 
 67     for (i = 0; i < n; i++)
 68         fmax = MAX(fmax, vec2_mod(f[i]));
 69     sprintf(string, "maxforce: %12.6f\n", fmax);
 70     tv_textxy(tv, string, 10, 10);
 71 
 72     if (fmax == 0.0)
 73         fmax = 1.0;
 74 
 75     maxlength /= fmax;
 76     tv_save_draw(tv);
 77     tv_color_set(tv, red);
 78     for (i = 0; i < n; i++)
 79         tv_vector2(tv, p[i], vec2_times(maxlength, f[i]));
 80     tv_reset_draw(tv);
 81 }
 82 
 83 /*
 84 graph normal forces
 85 */
 86 static void normal_graph(Tv * tv, Vec2 p, Vec2 n, double h, Imrect * pot,
 87                           int s, double *mask1, double *mask2)
 88 {
 89     int i;
 90     Vec2 *w = tvector_alloc(-s, s + 1, Vec2), t = vec2_perp(n);
 91 
 92     /* draw axes */
 93     tv_color_set(tv, blue);
 94     tv_line2(tv, vec2_sum(p, vec2_times(-h, t)), vec2_sum(p, vec2_times(h, t)));
 95     tv_line2(tv, vec2_sum(p, vec2_times(-s, n)), vec2_sum(p, vec2_times(s, n)));
 96 
 97     for (i = -s; i <= s; i++)
 98     {
 99         Vec2 v = vec2_sum(p, vec2_times(i, n));
100         mask1[i] = im_sub_pixf(pot, vec2_y(v), vec2_x(v));
101     }
102 
103     /* draw grad */
104     smask_smooth(s, mask2, mask1);
105     smask_diff2(s, mask1, mask2);
106     smask_normalise(s, mask1, h);
107     for (i = -s; i <= s; i++)
108         w[i] = vec2_sum3(p, vec2_times(i, n), vec2_times(mask1[i], t));
109     tv_color_set(tv, magenta);
110     for (i = -s; i < s; i++)
111         tv_line2(tv, w[i], w[i + 1]);
112 
113     /* draw diff2 */
114     smask_diff(s, mask1, mask2);
115     smask_normalise(s, mask1, h);
116     for (i = -s; i <= s; i++)
117         w[i] = vec2_sum3(p, vec2_times(i, n), vec2_times(mask1[i], t));
118     tv_color_set(tv, red);
119     for (i = -s; i < s; i++)
120         tv_line2(tv, w[i], w[i + 1]);
121 
122     tvector_free(w, -s, Vec2);
123 }
124 
125 /*
126 draw graphs of snake potential normal to snake
127 */
128 void snake_normal_graphs(Tv * tv, Snake * snake, Imrect * pot)
129 {
130     int i, n = snake->n, s = 10;
131     double *mask1 = tvector_alloc(-s, s + 1, double);
132     double *mask2 = tvector_alloc(-s, s + 1, double);
133     double h;
134 
135     tv_save_draw(tv);
136     tv_set_linewidth(tv, 0);
137     for (i = 0; i < n; i++)
138     {
139         Vec2 nml = snake_perp(snake, i);
140         h = 0.25*(snake_chord(snake, i-1)+snake_chord(snake, i));
141         normal_graph(tv, snake->p[i], nml, h, pot, s, mask1, mask2);
142     }
143     tvector_free(mask1, -s, double);
144     tvector_free(mask2, -s, double);
145     tv_reset_draw(tv);
146 }
147 

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