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

Linux Cross Reference
Tina5/tina-tools/tinatool/draw/drawTv_draw.c

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

  1 /*********
  2  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  3  * University of Manchester, UK.  All rights reserved.
  4  * 
  5  * Redistribution and use in source and binary forms, with or without modification, 
  6  * are permitted provided that the following conditions are met:
  7  * 
  8  *   . Redistributions of source code must retain the above copyright notice, 
  9  *     this list of conditions and the following disclaimer.
 10  *    
 11  *   . Redistributions in binary form must reproduce the above copyright notice,
 12  *     this list of conditions and the following disclaimer in the documentation 
 13  *     and/or other materials provided with the distribution.
 14  * 
 15  *   . Neither the name of the University of Manchester nor the names of its
 16  *     contributors may be used to endorse or promote products derived from this 
 17  *     software without specific prior written permission.
 18  * 
 19  * 
 20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 30  * POSSIBILITY OF SUCH DAMAGE.
 31  *
 32  **********
 33  *
 34  * Program :    TINA
 35  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_draw.c,v $
 36  * Date    :  $Date: 2008/12/02 22:04:19 $
 37  * Version :  $Revision: 1.3 $
 38  * CVS Id  :  $Id: drawTv_draw.c,v 1.3 2008/12/02 22:04:19 paul Exp $
 39  *
 40  * Author  : Legacy TINA
 41  *
 42  * Notes :
 43  *
 44  *********
 45 */
 46 
 47 #include "drawTv_draw.h"
 48 
 49 #if HAVE_CONFIG_H
 50   #include <config.h>
 51 #endif
 52 
 53 #include <tina/sys/sysDef.h>
 54 #include <tina/sys/sysPro.h>
 55 #include <tina/math/mathDef.h>
 56 #include <tina/math/mathPro.h>
 57 #include <tinatool/draw/draw_TvDef.h>
 58 #include <tinatool/draw/draw_TvPro.h>
 59 
 60 /* EXTERNS */
 61 extern void *tw_tool();
 62 extern void tv_screen_point();
 63 extern void tv_screen_line();
 64 extern void tv_screen_point();
 65 extern void tv_screen_raster();
 66 extern void tv_screen_rect();
 67 extern void tv_screen_circle();
 68 extern void tv_screen_erase();
 69 extern void tv_screen_fillrect();
 70 extern void tv_screen_flush();
 71 extern void tv_screen_image();
 72 extern void tv_screen_line();
 73 extern void tv_screen_point();
 74 extern void tv_screen_polyline();
 75 extern void tv_screen_raster();
 76 extern void tv_screen_text();
 77 
 78 Ipos tv_proj2();
 79 Ipos tv_proj3();
 80 Vec2 tv_backproj2();
 81 
 82 void tv_flush(Tv * tv)
 83 {
 84     if (tv == NULL)
 85         return;
 86     tv_screen_flush(tv->tv_screen);
 87 }
 88 
 89 void tv_erase(Tv * tv)
 90 {
 91     if (tv == NULL)
 92         return;
 93     tv_screen_erase(tv->tv_screen);
 94 }
 95 
 96 void tv_point(Tv * tv, Ipos p)
 97 {
 98     if (tv == NULL)
 99         return;
100     tv_screen_point(tv->tv_screen, p);
101 }
102 
103 void tv_pointxy(Tv * tv, int x, int y)
104 {
105     if (tv == NULL)
106         return;
107     tv_screen_point(tv->tv_screen, ipos(x, y));
108 }
109 
110 void tv_point2(Tv * tv, Vec2 p)
111 {
112     if (tv == NULL)
113         return;
114     tv_screen_point(tv->tv_screen, tv_proj2(tv, p));
115 }
116 
117 void tv_point3(Tv * tv, Vec3 p)
118 {
119     if (tv == NULL)
120         return;
121     tv_screen_point(tv->tv_screen, tv_proj3(tv, p));
122 }
123 
124 void tv_line(Tv * tv, Ipos p1, Ipos p2)
125 {
126     if (tv == NULL)
127         return;
128     tv_screen_line(tv->tv_screen, p1, p2);
129 }
130 
131 void tv_linexy(Tv * tv, int x1, int y1, int x2, int y2)
132 {
133     if (tv == NULL)
134         return;
135     tv_screen_line(tv->tv_screen, ipos(x1, y1), ipos(x2, y2));
136 }
137 
138 void tv_line2(Tv * tv, Vec2 p1, Vec2 p2)
139 {
140     if (tv == NULL)
141         return;
142     tv_screen_line(tv->tv_screen, tv_proj2(tv, p1), tv_proj2(tv, p2));
143 }
144 
145 void tv_line3(Tv * tv, Vec3 p1, Vec3 p2)
146 {
147     if (tv == NULL)
148         return;
149     tv_screen_line(tv->tv_screen, tv_proj3(tv, p1), tv_proj3(tv, p2));
150 }
151 
152 void tv_dot(Tv * tv, Ipos p)
153 {
154     int x = ipos_x(p);
155     int y = ipos_y(p);
156     if (tv == NULL)
157         return;
158     tv_screen_fillrect(tv->tv_screen, ipos(x - 1, y - 1), ipos(x + 2, y + 2));
159 }
160 
161 void tv_dotxy(Tv * tv, int x, int y)
162 {
163     tv_dot(tv, ipos(x, y));
164 }
165 
166 void tv_dot2(Tv * tv, Vec2 p)
167 {
168     if (tv == NULL)
169         return;
170     tv_dot(tv, tv_proj2(tv, p));
171 }
172 
173 void tv_dot3(Tv * tv, Vec3 p)
174 {
175     if (tv == NULL)
176         return;
177     tv_dot(tv, tv_proj3(tv, p));
178 }
179 
180 void tv_bigdot(Tv * tv, Ipos p, int n)
181 {
182     int x = ipos_x(p);
183     int y = ipos_y(p);
184     if (tv == NULL)
185         return;
186     tv_screen_fillrect(tv->tv_screen, ipos(x - n, y - n), ipos(x + n + 1, y + n + 1));
187 }
188 
189 void tv_bigdot2(Tv * tv, Vec2 p, int n)
190 {
191     if (tv == NULL)
192         return;
193     tv_bigdot(tv, tv_proj2(tv, p), n);
194 }
195 
196 void tv_bigdot3(Tv * tv, Vec3 p, int n)
197 {
198     if (tv == NULL)
199         return;
200     tv_bigdot(tv, tv_proj3(tv, p), n);
201 }
202 
203 void tv_cross(Tv * tv, Ipos p, int n)
204 {
205     int x0, x1, x2;
206     int y0, y1, y2;
207     if (tv == NULL)
208         return;
209     x1 = ipos_x(p);
210     x0 = x1 - n;
211     x2 = x1 + n;
212     y1 = ipos_y(p);
213     y0 = y1 - n;
214     y2 = y1 + n;
215     tv_line(tv, ipos(x0, y1), ipos(x2, y1));
216     tv_line(tv, ipos(x1, y0), ipos(x1, y2));
217 }
218 
219 void tv_cross2(Tv * tv, Vec2 p, int n)
220 {
221     if (tv == NULL)
222         return;
223     tv_cross(tv, tv_proj2(tv, p), n);
224 }
225 
226 void tv_cross3(Tv * tv, Vec3 p, int n)
227 {
228     if (tv == NULL)
229         return;
230     tv_cross(tv, tv_proj3(tv, p), n);
231 }
232 
233 void tv_vector(Tv * tv, Ipos p, Ipos v)
234 {
235     if (tv == NULL)
236         return;
237     tv_dot(tv, p);
238     tv_line(tv, p, ipos_sum(p, v));
239 }
240 
241 void tv_vector2(Tv * tv, Vec2 p, Vec2 v)
242 {
243     tv_dot2(tv, p);
244     tv_line2(tv, p, vec2_sum(p, v));
245 }
246 
247 void tv_vector3(Tv * tv, Vec3 p, Vec3 v)
248 {
249     tv_dot3(tv, p);
250     tv_line3(tv, p, vec3_sum(p, v));
251 }
252 
253 void tv_polyline(Tv * tv, List * points)
254 {
255     if (tv == NULL)
256         return;
257     tv_screen_polyline(tv->tv_screen, points);
258 }
259 
260 void tv_polyline2(Tv * tv, List * points)
261 {
262     List *ptr;
263     List *ipoints = NULL;
264     List *ref_addtostart();
265     if (tv == NULL)
266         return;
267     for (ptr = points; ptr != NULL; ptr = ptr->next)
268     {
269         Ipos *p = ipos_alloc();
270         *p = tv_proj2(tv, *((Vec2 *) ptr->to));
271         ipoints = ref_addtostart(ipoints, (void *) &p, 0);
272     }
273     tv_screen_polyline(tv->tv_screen, ipoints);
274     list_rm(ipoints, rfree);
275 }
276 
277 void tv_polyline3(Tv * tv, List * points)
278 {
279     List *ptr;
280     List *ipoints = NULL;
281     List *ref_addtostart();
282     if (tv == NULL)
283         return;
284     for (ptr = points; ptr != NULL; ptr = ptr->next)
285     {
286         Ipos *p = ipos_alloc();
287         *p = tv_proj3(tv, *((Vec3 *) ptr->to));
288         ipoints = ref_addtostart(ipoints, (void *) &p, 0);
289     }
290     tv_screen_polyline(tv->tv_screen, ipoints);
291     list_rm(ipoints, rfree);
292 }
293 
294 void tv_quad(Tv * tv, Ipos p1, Ipos p2, Ipos p3, Ipos p4)
295 {
296     tv_line(tv, p1, p2);
297     tv_line(tv, p2, p3);
298     tv_line(tv, p3, p4);
299     tv_line(tv, p4, p1);
300 }
301 
302 void tv_quad2(Tv * tv, Vec2 p1, Vec2 p2, Vec2 p3, Vec2 p4)
303 {
304     tv_line2(tv, p1, p2);
305     tv_line2(tv, p2, p3);
306     tv_line2(tv, p3, p4);
307     tv_line2(tv, p4, p1);
308 }
309 
310 void tv_quad3(Tv * tv, Vec3 p1, Vec3 p2, Vec3 p3, Vec3 p4)
311 {
312     tv_line3(tv, p1, p2);
313     tv_line3(tv, p2, p3);
314     tv_line3(tv, p3, p4);
315     tv_line3(tv, p4, p1);
316 }
317 
318 void tv_rect(Tv * tv, Ipos p1, Ipos p2)
319 {
320     int x1, x2, sx;
321     int y1, y2, sy;
322     if (tv == NULL)
323         return;
324     x1 = ipos_x(p1);
325     x2 = ipos_x(p2);
326     y1 = ipos_y(p1);
327     y2 = ipos_y(p2);
328     if (x1 == x2 || y1 == y2)
329     {
330         if (x1 == x2 && y1 == y2)
331             tv_point(tv, p1);
332         else
333             tv_line(tv, p1, p2);
334         return;
335     }
336     sx = (x1 < x2) ? 1 : -1;
337     sy = (y1 < y2) ? 1 : -1;
338     tv_line(tv, ipos(x1, y1), ipos(x1, y2));
339     tv_line(tv, ipos(x1, y1), ipos(x2, y1));
340     tv_line(tv, ipos(x1 + sx, y2), ipos(x2, y2));
341     tv_line(tv, ipos(x2, y1 + sy), ipos(x2, y2));
342 }
343 
344 void tv_rect2(Tv * tv, Vec2 p1, Vec2 p2)
345 {
346     if (tv == NULL)
347         return;
348     tv_rect(tv, tv_proj2(tv, p1), tv_proj2(tv, p2));
349 }
350 
351 void tv_rect3(Tv * tv, Vec3 p1, Vec3 p2)
352 {
353     if (tv == NULL)
354         return;
355     tv_rect(tv, tv_proj3(tv, p1), tv_proj3(tv, p2));
356 }
357 
358 void tv_fillrect(Tv * tv, Ipos p1, Ipos p2)
359 {
360     if (tv == NULL)
361         return;
362     tv_screen_fillrect(tv->tv_screen, p1, p2);
363 }
364 
365 void tv_fillrectxy(Tv * tv, int x1, int y1, int x2, int y2)
366 {
367     if (tv == NULL)
368         return;
369     tv_screen_fillrect(tv->tv_screen, ipos(x1, y1), ipos(x2, y2));
370 }
371 
372 void tv_fillrect2(Tv * tv, Vec2 p1, Vec2 p2)
373 {
374     if (tv == NULL)
375         return;
376     tv_screen_fillrect(tv->tv_screen, tv_proj2(tv, p1), tv_proj2(tv, p2));
377 }
378 
379 void tv_fillrect3(Tv * tv, Vec3 p1, Vec3 p2)
380 {
381     if (tv == NULL)
382         return;
383     tv_screen_fillrect(tv->tv_screen, tv_proj3(tv, p1), tv_proj3(tv, p2));
384 }
385 
386 void tv_text(Tv * tv, char *string, Ipos p)
387 {
388     if (tv == NULL)
389         return;
390     tv_screen_text(tv->tv_screen, string, p);
391 }
392 
393 void tv_textxy(Tv * tv, char *string, int x, int y)
394 {
395     if (tv == NULL)
396         return;
397     tv_screen_text(tv->tv_screen, string, ipos(x, y));
398 }
399 
400 void tv_text2(Tv * tv, char *string, Vec2 p)
401 {
402     if (tv == NULL)
403         return;
404     tv_screen_text(tv->tv_screen, string, tv_proj2(tv, p));
405 }
406 
407 void tv_text3(Tv * tv, char *string, Vec3 p)
408 {
409     if (tv == NULL)
410         return;
411     tv_screen_text(tv->tv_screen, string, tv_proj3(tv, p));
412 }
413 
414 void tv_offset_text(Tv * tv, char *string, Ipos p, int offx, int offy)
415 {
416     if (tv == NULL)
417         return;
418     p.x += offx;
419     p.y += offy;
420     tv_screen_text(tv->tv_screen, string, p);
421 }
422 
423 void tv_offset_text2(Tv * tv, char *string, Vec2 p, int offx, int offy)
424 {
425     if (tv == NULL)
426         return;
427     tv_offset_text(tv, string, tv_proj2(tv, p), offx, offy);
428 }
429 
430 void tv_offset_text3(Tv * tv, char *string, Vec3 p, int offx, int offy)
431 {
432     if (tv == NULL)
433         return;
434     tv_offset_text(tv, string, tv_proj3(tv, p), offx, offy);
435 }
436 
437 void tv_pixel2(Tv * tv, Vec2 p)
438 {
439     Ipos pos1 = {Ipos_id};
440     Ipos pos2 = {Ipos_id};
441     if (tv == NULL)
442         return;
443 
444     vec2_x(p) = (float)(tina_int(vec2_x(p)));
445     vec2_y(p) = (float)(tina_int(vec2_y(p)));
446     pos1 = tv_proj2(tv, p);
447 
448     vec2_x(p) += (float)1.0;
449     vec2_y(p) += (float)1.0;
450     pos2 = tv_proj2(tv, p);
451 
452     if (ipos_equal(pos1, pos2))
453     {
454         tv_screen_point(tv->tv_screen, pos1);
455         return;
456     }
457     if (ipos_x(pos2) == ipos_x(pos1))
458     {
459         ipos_y(pos2) -= 1;
460 
461         if (ipos_equal(pos1, pos2))
462             tv_screen_point(tv->tv_screen, pos1);
463         tv_screen_line(tv->tv_screen, pos1, pos2);
464         return;
465     }
466     if (ipos_y(pos2) == ipos_y(pos1))
467     {
468         ipos_x(pos2) -= 1;
469         if (ipos_equal(pos1, pos2))
470             tv_screen_point(tv->tv_screen, pos1);
471         tv_screen_line(tv->tv_screen, pos1, pos2);
472         return;
473     }
474     ipos_x(pos2) -= 1;
475     ipos_y(pos2) -= 1;
476 
477     if (ipos_equal(pos1, pos2))
478         tv_screen_point(tv->tv_screen, pos1);
479     else
480         tv_screen_rect(tv->tv_screen, pos1, pos2);
481 }
482 
483 void tv_fillpixel2(Tv * tv, Vec2 p)
484 {
485     Ipos pos1 = {Ipos_id};
486     Ipos pos2 = {Ipos_id};
487     if (tv == NULL)
488         return;
489 
490     vec2_x(p) = (float)(tina_int(vec2_x(p)));
491     vec2_y(p) = (float)(tina_int(vec2_y(p)));
492     pos1 = tv_proj2(tv, p);
493 
494     vec2_x(p) += (float)1.0;
495     vec2_y(p) += (float)1.0;
496     pos2 = tv_proj2(tv, p);
497 
498     if (ipos_equal(pos1, pos2))
499     {
500         tv_screen_point(tv->tv_screen, pos1);
501         return;
502     }
503     ipos_x(pos2) -= 1;
504     ipos_y(pos2) -= 1;
505 
506     tv_screen_fillrect(tv->tv_screen, pos1, pos2);
507 }
508 
509 void tv_circle(Tv * tv, Ipos centre, int radius)
510 {
511     if (tv == NULL)
512         return;
513     tv_screen_circle(tv->tv_screen, centre, radius);
514 }
515 
516 void tv_circle2(Tv * tv, Vec2 centre, double radius)
517 {
518     extern void tv_screen_circle();
519     Ipos c = {Ipos_id};
520     int r;
521     if (tv == NULL)
522         return;
523     c = tv_proj2(tv, centre);
524     r = (int) (radius * tv->scalex);    /** what about scalex != scaley ? **/
525     tv_screen_circle(tv->tv_screen, c, r);
526 }
527 
528 void tv_raster(Tv * tv, int x1, int x2, int y, char *raster)
529 {
530     /* assumes grey level conversion complete */
531     if (tv == NULL)
532         return;
533     tv_screen_raster(tv->tv_screen, x1, x2, y, raster + x1);
534 }
535 
536 /*
537 may not work with 16 bit colormaps 
538 void tv_raster2(Tv * tv, int c1, int c2, int r, char *raster)
539 
540 
541 {
542     Ipos ll = {Ipos_id};
543     Ipos ur = {Ipos_id};        
544     int lx, ly, ux, uy;
545     float sx, imx;
546     char *tv_screen_rast;
547     int i;
548     Vec2 v2 = {Vec2_id};
549     if (tv == NULL || tv->tv_screen == NULL)
550         return;
551 
552     ll = tv_proj2(tv, vec2((float) c1, (float) r));
553     ur = tv_proj2(tv, vec2((float) c2, r + 1.0));
554 
555     lx = MAX(0, ipos_x(ll));
556     ux = MIN(tv->width, ipos_x(ur));
557     ly = MAX(0, ipos_y(ll));
558     uy = MIN(tv->height, ipos_y(ur));
559 
560     if (ly == uy)
561         ++uy;
562 
563     if (ux < 0 || lx >= tv->width || uy < 0 || ly >= tv->height)
564         return;
565 
566     sx = (float)(1.0 / tv->scalex);
567     v2 = tv_backproj2(tv, ipos(lx, ly));
568     imx = vec2_x(v2);
569 
570     while (imx < c1)
571     {
572         ++lx;
573         imx += sx;
574     }
575 
576     tv_screen_rast = cvector_alloc(lx, ux);
577 
578     for (i = lx; i < ux; ++i)
579     {
580         tv_screen_rast[i] = raster[(int) imx];
581         imx += sx;
582     }
583 
584     for (i = ly; i < uy; ++i)
585         tv_screen_raster(tv->tv_screen, lx, ux, i, tv_screen_rast + lx);
586 
587     cvector_free((void *) tv_screen_rast, lx);
588 }
589 */
590 

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