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

Linux Cross Reference
Tina6/tina-tools/tinatool/draw/drawPaint_line3.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/drawPaint_line3.c,v $
 37  * Date    :  $Date: 2003/10/01 16:02:47 $
 38  * Version :  $Revision: 1.2 $
 39  * CVS Id  :  $Id: drawPaint_line3.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 "drawPaint_line3.h"
 49 
 50 #if HAVE_CONFIG_H
 51   #include <config.h>
 52 #endif
 53 
 54 #include <math.h>
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/math/mathDef.h>
 57 #include <tina/math/mathPro.h>
 58 #include <tina/geometry/geomDef.h>
 59 #include <tinatool/draw/draw_TvDef.h>
 60 #include <tinatool/draw/draw_TvPro.h>
 61 #include <tinatool/draw/draw_PaintDef.h>
 62 #include <tinatool/draw/draw_PaintPro.h>
 63 
 64 double  ipos_dist_seg();
 65 
 66 void    line3_draw(Tv * tv, Line3 * line)
 67 {
 68     if (line == NULL)
 69         return;
 70     tv_line3(tv, line->p1, line->p2);
 71 }
 72 
 73 void    line3_draw_directed(Tv * tv, Line3 * line, int direction)
 74 {
 75     Ipos    p1 = {Ipos_id};
 76     Ipos    p2 = {Ipos_id};
 77     Ipos    tv_proj3();
 78     float   ydir, xdir, mag;
 79     float   hl, hw;             /* head length and width */
 80 
 81     if (line == NULL)
 82         return;
 83 
 84     switch (direction)
 85     {
 86     case NEGATIVE:
 87         p2 = tv_proj3(tv, line->p1);
 88         p1 = tv_proj3(tv, line->p2);
 89         break;
 90     case POSITIVE:
 91     default:
 92         p1 = tv_proj3(tv, line->p1);
 93         p2 = tv_proj3(tv, line->p2);
 94         break;
 95     }
 96 
 97     if (p2.x == p1.x && p2.y == p1.y)
 98         return;
 99 
100     tv_line(tv, p1, p2);
101     xdir = (float)(p2.x - p1.x);
102     ydir = (float)(p2.y - p1.y);
103     mag = (float)sqrt(SQR(xdir) + SQR(ydir));
104     xdir /= mag;
105     ydir /= mag;
106 
107     hl = mag / 10;
108     if (hl > 10)
109         hl = (float)10.0;
110     hw = hl / 3;
111 
112     p1.x = (int)(p2.x - hl * xdir);
113     p1.y = (int)(p2.y - hl * ydir);
114 
115     tv_line(tv, ipos((int) (p1.x - ydir * hw), (int) (p1.y + xdir * hw)), p2);
116     tv_line(tv, ipos((int) (p1.x + ydir * hw), (int) (p1.y - xdir * hw)), p2);
117 }
118 
119 void    line3_draw_with_arrow(Tv * tv, Line3 * line)
120 {
121     Ipos    p1 = {Ipos_id};
122     Ipos    p2 = {Ipos_id};
123     Ipos    tv_proj3();
124     float   ydir, xdir, mag;
125     float   hl, hw;             /* head length and width */
126 
127     if (line == NULL)
128         return;
129 
130     p1 = tv_proj3(tv, line->p1);
131     p2 = tv_proj3(tv, line->p2);
132 
133     if (p2.x == p1.x && p2.y == p1.y)
134         return;
135 
136     tv_line(tv, p1, p2);
137     xdir = (float)(p2.x - p1.x);
138     ydir = (float)(p2.y - p1.y);
139     mag = (float)sqrt(SQR(xdir) + SQR(ydir));
140     xdir /= mag;
141     ydir /= mag;
142 
143     hl = mag / 10;
144     if (hl > 10)
145         hl = (float)10.0;
146     hw = hl / 3;
147 
148     p1.x = (int)(p2.x - hl * xdir);
149     p1.y = (int)(p2.y - hl * ydir);
150 
151     tv_line(tv, ipos((int) (p1.x - ydir * hw), (int) (p1.y + xdir * hw)), p2);
152     tv_line(tv, ipos((int) (p1.x + ydir * hw), (int) (p1.y - xdir * hw)), p2);
153 }
154 
155 
156 double  pick_line3_dist(Tv * tv, Ipos pos, Line3 * line)
157 {
158     Ipos    p1 = {Ipos_id};
159     Ipos    p2 = {Ipos_id};
160 
161     p1 = tv_proj3(tv, line->p1);
162     p2 = tv_proj3(tv, line->p2);
163     return (ipos_dist_seg(pos, p1, p2));
164 }
165 

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