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

Linux Cross Reference
Tina6/tina-tools/tinatool/tlmedical/tlmedSroi_poly.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    :  
 37  * Date    :  
 38  * Version : 
 39  * CVS Id  : 
 40  *
 41  *********
 42 */
 43 
 44 #include "tlmedSroi_poly.h"
 45 
 46 #if HAVE_CONFIG_H
 47 #   include <config.h>
 48 #endif
 49 
 50 #include <stdio.h>
 51 #include <math.h>
 52 #include <tina/sys/sysDef.h>
 53 #include <tina/sys/sysPro.h>
 54 #include <tina/math/mathDef.h>
 55 #include <tina/math/mathPro.h>
 56 #include <tinatool/draw/drawDef.h>
 57 #include <tinatool/draw/drawPro.h>
 58 #include <tina/image/imgDef.h>
 59 #include <tina/image/imgPro.h>
 60 #include <tina/geometry/geomDef.h>
 61 #include <tina/geometry/geomPro.h>
 62 #include <tinatool/draw/drawDef.h>
 63 #include <tinatool/draw/drawPro.h>
 64 #include <tinatool/wdgts/wdgtsDef.h>
 65 #include <tinatool/wdgts/wdgtsPro.h>
 66 #include <tinatool/tlbase/tlbase_InfrDef.h>
 67 #include <tinatool/tlbase/tlbase_InfrPro.h>
 68 
 69 
 70 static char getfromfile(FILE * fp)
 71 {
 72   char k = getc(fp);
 73 
 74   while ((k == ' ') || (k == '\t') || (k == '\n'))
 75     k = getc(fp);
 76 
 77   return (k);
 78 }
 79 
 80 
 81 static int read_poly_points(FILE * fp, double **el, int m, int n)
 82 {
 83   Vec2    p;
 84   List *roi_poly = NULL;
 85   float   weight;
 86   int     i, j, size;
 87   int     run = 1;
 88   char    c;
 89 
 90   fscanf(fp, "%d", &size);
 91 
 92   for (i = 0; i < size; i++)
 93   {
 94     p.el[0] = 0;
 95     p.el[1] = 0;
 96     while (run == 1)
 97     {
 98       if (fscanf(fp, "%f", &weight) == EOF)
 99       {
100         run = 2;
101         continue;
102       }
103       if ((c = getfromfile(fp)) != ',')
104       {
105         run = 3;
106         continue;
107       }
108       if (fscanf(fp, "%d", &j) == EOF || j < 0 || j > n)
109       {
110         run = 4;
111         continue;
112       }
113       if ((c = getfromfile(fp)) == ';')
114         run = 0;
115       else if (c != ',')
116       {
117         run = 5;
118         continue;
119       }
120       p.el[0] += weight * el[0][j];
121       p.el[1] += weight * el[1][j];
122     }
123 
124     if (run == 0)
125     {
126       roi_poly = dd_ref_addtoend(roi_poly, (void *)vec2_copy(&p), VEC2);
127       run = 1;
128     } else
129     {
130       format("read_poly_points: error %d\n", run);
131       continue;
132     }
133   }
134 
135   tv_poly_set(roi_poly);
136 
137   return (0);
138 }
139 
140 
141 static int sroi_roi_readpnts(FILE * fp, double **pos, int m, int n)
142 {
143   char comm;
144 
145   if ((comm = getfromfile(fp)) == EOF)
146     return (0);
147 
148   switch (comm)
149   {
150   case 'p':
151     read_poly_points(fp, pos, m, n);
152     break;
153 
154   default:
155     break;
156   }
157 
158   return (1);
159 }
160 
161 
162 void sroi_polygon(double **pos, int m, int n, char *config_file)
163 {
164   FILE *fp = NULL;
165 
166   if (pos == NULL || m < 2 || config_file == NULL)
167     return;
168 
169   if ((fp = fopen((const char *)config_file, "r")) == NULL)
170   {
171     error("sroi_polygon: its all gone wrong\n", warning);
172     return;
173   }
174   sroi_roi_readpnts(fp, pos, m, n);
175 
176   fclose(fp);
177 }
178 
179 
180 void sroi_polygon_label(double **pos, int m, int n, Tv * tv)
181 {
182   Vec2  loc;
183   int   i;
184   char  num[4];
185 
186   if (pos == NULL || tv == NULL || m < 2)
187     return;
188 
189   tv_set_color(tv, red);
190 
191   for (i = 0; i < n; i++)
192   {
193     vec2_x(loc) = pos[0][i] + 5.0;
194     vec2_y(loc) = pos[1][i] + 5.0;
195     sprintf(num, "%d", i);
196     tv_text2(tv, num, loc);
197   }
198 }
199 

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