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

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

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

  1 /*
  2  * ims_draw.c
  3  *
  4  * imstack graphics functions
  5  *
  6  */
  7 
  8 #include <tina/all_tina.h>
  9 #include <tina/brain.h>
 10 #include <tina/brainfuncs.h>
 11 
 12 static int oldvoi = 0;
 13 
 14 void ims_sagit_tube_draw(Tv *tv)
 15 {
 16     int z;
 17     Tube *tube;
 18     Imstack *ims = ims_imstack_get();
 19     if(ims == NULL)
 20         return;
 21     if((tube = ims->tube) == NULL)
 22         return;
 23     tv_color_set(tv, red);
 24     for(z = tube->z1; z < tube->z2-1; z++)
 25     {
 26         double y1 = vec2_y(tube->p1[z]);
 27         double y2 = vec2_y(tube->p1[z+1]);
 28         tv_line2(tv, vec2(y1, z+0.5), vec2(y2, z+1.5));
 29     }
 30     tv_color_set(tv, red);
 31     for(z = tube->z1; z < tube->z2-1; z++)
 32     {
 33         double y1 = vec2_y(tube->p2[z]);
 34         double y2 = vec2_y(tube->p2[z+1]);
 35         tv_line2(tv, vec2(y1, z+0.5), vec2(y2, z+1.5));
 36     }
 37 }
 38 
 39 void ims_all_vois_draw(Tv * tv, void (*func) ())
 40 {
 41     int i;
 42     if (ims_imstack_get() == NULL)
 43         return;
 44     oldvoi = ims_nvoi_get();
 45     tv_save_draw(tv);
 46     for (i = 0; i < NVOI; i++)
 47     {
 48         tv_color_set(tv, magenta+i);
 49         ims_nvoi_set(i);
 50         func(tv);
 51     }
 52     ims_nvoi_set(oldvoi);
 53     tv_save_draw(tv);
 54 }
 55 
 56 double ims_all_vois_area()
 57 {
 58     Imstack *ims = ims_imstack_get();
 59     Tstring *string;
 60     int z, zold;
 61     double total=0.0;
 62 
 63     if (ims == NULL)
 64         return(0.0);
 65 
 66     zold = ims_z_get();
 67 
 68     for (z = ims->lz; z < ims->uz; z++)
 69     {
 70         ims_z_set(z);
 71         string = ims_string_get();
 72         if (string!=NULL) total += str2_area(string);
 73     }
 74     ims_z_set(zold);
 75     return(total);
 76 }
 77 
 78 void ims_spline_draw(Tv * tv)
 79 {
 80     int color;
 81     color = tv_get_color(tv);
 82     if (ims_nvoi_get() == oldvoi)
 83         tv_color_set(tv,red);
 84     spline_draw(tv, ims_spline_get());
 85     tv_color_set(tv,color);
 86 }
 87 
 88 void ims_all_splines_draw(Tv * tv)
 89 {
 90     ims_all_vois_draw(tv, ims_spline_draw);
 91 }
 92 
 93 void ims_snake_draw(Tv * tv)
 94 {
 95     int color;
 96     color = tv_get_color(tv);
 97     if (ims_nvoi_get() == oldvoi)
 98         tv_color_set(tv,red);
 99     snake_draw(tv, ims_snake_get());
100     tv_color_set(tv,color);
101 }
102 
103 void ims_all_snakes_draw(Tv * tv)
104 {
105     ims_all_vois_draw(tv, ims_snake_draw);
106 }
107 
108 void ims_string_draw(Tv * tv)
109 {
110     int color;
111     color = tv_get_color(tv); 
112     if (ims_nvoi_get() == oldvoi)
113         tv_color_set(tv,red);
114     str2_draw(tv, ims_string_get());
115     tv_color_set(tv,color);
116 }
117 
118 void ims_all_strings_draw(Tv * tv)
119 {
120     ims_all_vois_draw(tv, ims_string_draw);
121 }
122 
123 void ims_str2_draw3(Tv * tv)
124 {
125     Imstack *ims = ims_imstack_get();
126     if (ims != NULL)
127         str2_draw3(tv, ims_string_get(), SLICE(ims)->z);
128 }
129 
130 void ims_strings_draw3(Tv * tv)
131 {
132     int z, zold;
133     int color;
134     Imstack *ims = ims_imstack_get();
135 
136     if (ims == NULL)
137         return;
138 
139     tv_save_draw(tv);
140     zold = ims_z_get();
141     color = tv_get_color(tv);
142 
143     /** draw furthest first **/
144     if (vec3_z(tv->ez3) < 0.0)
145     {
146         for (z = ims->lz; z < ims->uz; z++)
147         {
148             ims_z_set(z);
149             if (z == zold && ims_nvoi_get() == oldvoi)
150             {
151                 tv_color_set(tv, red);
152                 ims_str2_draw3(tv);
153                 tv_color_set(tv, color);
154             } else
155                 ims_str2_draw3(tv);
156         }
157     } else
158     {
159         for (z = ims->uz - 1; z >= ims->lz; z--)
160         {
161             ims_z_set(z);
162             if (z == zold && ims_nvoi_get() == oldvoi)
163             {
164                 tv_color_set(tv, red);
165                 ims_str2_draw3(tv);
166                 tv_color_set(tv, color);
167             } else
168                 ims_str2_draw3(tv);
169         }
170     }
171 
172     ims_z_set(zold);
173     tv_reset_draw(tv);
174 }
175 
176 void ims_all_strings_draw3(Tv * tv)
177 {
178     ims_all_vois_draw(tv, ims_strings_draw3);
179 }
180 
181 /*
182 void ims_surf_draw3(Tv * tv)
183 {
184     void *surf;
185 
186     tv_save_draw(tv);
187     surf = ims_surf_make();
188     surface_shade(tv, surf);
189     surface_free(surf);
190     tv_reset_draw(tv);
191 }
192 */
193 
194 void ims_string_sagit_draw3(Tv * tv)
195 {
196     Imstack *ims = ims_imstack_get();
197     if (ims != NULL)
198         string_sagit_draw3(tv, ims_string_get(), ims->z);
199 }
200 
201 void ims_strings_sagit_draw3(Tv * tv)
202 {
203     int z, zold, color;
204     Imstack *ims = ims_imstack_get();
205 
206     if (ims == NULL)
207         return;
208 
209     tv_save_draw(tv);
210     tv_set_linewidth(tv, 2);
211     zold = ims_z_get();
212     color = tv_color_get(tv);
213 
214     for (z = ims->lz; z < ims->uz; z++)
215     {
216         ims_z_set(z);
217         if (z == zold && color == red)
218         {
219             tv_color_set(tv, red);
220             ims_string_sagit_draw3(tv);
221             tv_color_set(tv, magenta);
222         } else
223             ims_string_sagit_draw3(tv);
224     }
225     ims_z_set(zold);
226     tv_reset_draw(tv);
227 }
228 
229 void ims_all_strings_sagit_draw3(Tv * tv)
230 {
231     ims_all_vois_draw(tv, ims_strings_sagit_draw3);
232 }
233 
234 void ims_string_front_draw3(Tv * tv)
235 {
236     Imstack *ims = ims_imstack_get();
237     if (ims != NULL)
238         string_front_draw3(tv, ims_string_get(), ims->z);
239 }
240 
241 void ims_strings_front_draw3(Tv * tv)
242 {
243     int z, zold, color;
244     Imstack *ims = ims_imstack_get();
245 
246     if (ims == NULL)
247         return;
248 
249     tv_save_draw(tv);
250     tv_set_linewidth(tv, 2);
251     zold = ims_z_get();
252 
253     for (z = ims->lz; z < ims->uz; z++)
254     {
255         ims_z_set(z);
256         if (z == zold && color == red)
257         {
258             tv_color_set(tv, red);
259             ims_string_front_draw3(tv); /* NAT 27/2/2000 */
260             tv_color_set(tv, magenta);
261         } else
262             ims_string_front_draw3(tv); /* NAT 27/2/2000 */
263     }
264     ims_z_set(zold);
265     tv_reset_draw(tv);
266 }
267 
268 void ims_all_strings_front_draw3(Tv * tv)
269 {
270     ims_all_vois_draw(tv, ims_strings_front_draw3);
271 }
272 
273 void ims_string_skeldraw3(Tv * tv, int space)
274 {
275     Imstack *ims = ims_imstack_get();
276     if (ims != NULL)
277         string_skeldraw3(tv, ims_string_get(), SLICE(ims)->z, space);
278 }
279 
280 void ims_strings_skeldraw3(Tv * tv, int space, int maxnum)
281 {
282     int z, zold, dz;
283     Imstack *ims = ims_imstack_get();
284 
285     if (ims == NULL)
286         return;
287     zold = ims_z_get();
288     dz = (ims->uz - ims->lz) / (double) maxnum;
289     dz = MAX(1.0, dz);
290     for (z = ims->lz; z < ims->uz; z += dz)
291     {
292         ims_z_set(z);
293         ims_string_skeldraw3(tv, space);
294     }
295     ims_z_set(zold);
296 }
297 
298 static void face(Tv * tv, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4, Vec3 c, double s)
299 {
300     Vec3 n, dc;
301 
302     n = vec3_cross(vec3_diff(p2, p1), vec3_diff(p3, p1));
303     dc = vec3_diff(c, p1);
304     if (s * vec3_dot(n, tv->ez3) * vec3_dot(n, dc) > 0.0)
305         return;
306     tv_line3(tv, p1, p2);
307     tv_line3(tv, p2, p3);
308     tv_line3(tv, p3, p4);
309     tv_line3(tv, p4, p1);
310 }
311 
312 void ims_box_draw3(Tv * tv, double s)
313 {
314     Imstack *ims = ims_imstack_get();
315     Vec3 p1, p2, p3, p4;
316     Vec3 q1, q2, q3, q4;
317     Vec3 c;
318     double lx, ly, lz;
319     double ux, uy, uz;
320 
321     if (ims == NULL)
322         return;
323     lx = ims->lx;
324     ly = ims->ly;
325     lz = imstack_zscaled(ims, ims->lz - 1);
326     ux = ims->ux;
327     uy = ims->uy;
328     uz = imstack_zscaled(ims, ims->uz);
329 
330     tv_save_draw(tv);
331     tv_color_set(tv, gold);
332     p1 = vec3(lx, ly, lz);
333     p2 = vec3(ux, ly, lz);
334     p3 = vec3(ux, uy, lz);
335     p4 = vec3(lx, uy, lz);
336     q1 = vec3(lx, ly, uz);
337     q2 = vec3(ux, ly, uz);
338     q3 = vec3(ux, uy, uz);
339     q4 = vec3(lx, uy, uz);
340     c = vec3_midpoint(p1, q3);
341 
342     face(tv, p1, p2, p3, p4, c, s);
343     face(tv, q1, q2, q3, q4, c, s);
344     face(tv, p1, p2, q2, q1, c, s);
345     face(tv, p2, p3, q3, q2, c, s);
346     face(tv, p3, p4, q4, q3, c, s);
347     face(tv, p4, p1, q1, q4, c, s);
348     tv_reset_draw(tv);
349 }
350 
351 void ims_tube_draw(Tv *tv)
352 {
353     Imstack *ims = ims_imstack_get();
354     if(ims == NULL || ims->tube == NULL)
355         return;
356     tv_set_color(tv, red);
357     tv_bigdot2(tv, ims->tube->p1[ims->z], 2);
358     tv_set_color(tv, green);
359     tv_bigdot2(tv, ims->tube->p2[ims->z], 2);
360 }
361 
362 void ims_camera2(Tv * tv)
363 {
364     Imstack *ims = ims_imstack_get();
365     if (ims != NULL)
366         tv_camera2_roi(tv, ims_roi_get());
367 }
368 
369 void ims_image_draw(Tv * tv)
370 {
371     Imstack *ims = ims_imstack_get();
372     if (ims != NULL)
373         slice_image_draw(tv, SLICE(ims));
374 }
375 
376 void ims_pot_draw(Tv * tv)
377 {
378     Imstack *ims = ims_imstack_get();
379     if (ims != NULL)
380         slice_pot_draw(tv, SLICE(ims));
381 }
382 
383 void ims_loop_draw(Tv * tv)
384 {
385     int z, oldz;
386     void timer_handler_install(long int length);
387     Imstack *ims = ims_imstack_get();
388 
389     if (ims == NULL)
390         return;
391     oldz = ims_z_get();
392     tv_start_movie(tv);
393     for (z = ims->lz; z < ims->uz; z++)
394     {
395         ims_z_set(z);
396         tv_free_background(tv);
397         tv_repaint(tv);
398         tv_make_movie(tv);
399     }
400     timer_handler_install(500000); /* NAT 27/2/2000 */
401     tv_loop_movie(tv, 4);
402     timer_handler_uninstall();
403     ims_z_set(oldz);
404 }
405 

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