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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseHist_tool.c

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

  1 /**********
  2  *
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc.,
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  *
 21  * Program :   TINA
 22  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseHist_tool.c,v $
 23  * Date    :  $Date: 2008/10/02 11:57:24 $
 24  * Version :  $Revision: 1.1 $
 25  * CVS Id  :  $Id: tlbaseHist_tool.c,v 1.1 2008/10/02 11:57:24 neil Exp $
 26  *
 27  * Notes : written by Simon Crossley 2002 and put in libraries by NAT 6 years later
 28  *
 29  *
 30  *
 31  *********
 32 */
 33 #include "tlbaseHist_tool.h"
 34 
 35 #if HAVE_CONFIG_H
 36 #include <config.h>
 37 #endif
 38 
 39 #include <math.h>
 40 #include <stdio.h>
 41 #include <limits.h>
 42 #include <string.h>
 43 #include <tina/sys/sysDef.h>
 44 #include <tina/sys/sysPro.h>
 45 #include <tina/math/mathDef.h>
 46 #include <tina/math/mathPro.h>
 47 #include <tina/file/fileDef.h>
 48 #include <tina/file/filePro.h>
 49 #include <tina/image/imgDef.h>
 50 #include <tina/image/imgPro.h>
 51 #include <tinatool/wdgts/wdgtsDef.h>
 52 #include <tinatool/wdgts/wdgtsPro.h>
 53 #include <tinatool/draw/drawDef.h>
 54 #include <tinatool/draw/drawPro.h>
 55 #include <tinatool/tlbase/tlbaseDef.h>
 56 #include <tinatool/tlbase/tlbasePro.h>
 57 
 58 #define MAXPATHLEN 200
 59 
 60 static void *pframe2 = NULL;
 61 static int hnum = 0;
 62 static void *pframe3 = NULL;
 63 static char name_str[256] = "";
 64 static double cut1 = 5.0,  cut2 = 3.0;
 65 
 66 static Tv *graph_tv = NULL;
 67 static void *graph_tool = NULL;
 68 
 69 static shistogram **hist;
 70 
 71 static void update_name_str(void)
 72 {
 73   if (hist[hnum]== NULL)
 74     {
 75       strcpy(name_str, "");
 76       tw_sglobal_reset(pframe3);
 77       return;
 78     }
 79 
 80   strcpy((char *)&name_str[0], hist[hnum]->title);
 81   tw_sglobal_reset(pframe3);
 82 }
 83 
 84 static void graph_tv_proc(void)
 85 {
 86   extern void *display_tool();
 87 
 88 
 89   graph_tool = (void *)display_tool(100, 200, 400, 256);
 90   graph_tv = tv_create("histogram");
 91   tv_install(graph_tv, graph_tool);
 92   tv_set_next(graph_tv);
 93 }
 94 
 95 static void plot_hist_proc(void)
 96 {
 97   char temp[256];
 98   Imrect *histim;
 99   int i, j;
100   shistogram *ph;
101 
102   if ((hnum < 0) || (hnum >= NHIST))
103     return;
104   ph = hist[hnum];
105 
106   if (ph == NULL)
107   {
108       error("plot_hist_proc: histogram not in use", warning);
109       return;
110   }
111   update_name_str();
112 
113   if (ph->type == 2)
114   {
115       histim = im_alloc(ph->ybins,ph->xbins,NULL,float_v);
116       for (j = 0; j < ph->ybins; j++)
117       { 
118           for (i = 0; i < ph->xbins; i++)
119                   IM_PIX_SET(histim, j, i, ph->array[j][i]);
120       }
121       stack_push(histim,IMRECT,im_free);
122       format("2D histogram pushed to Imcalc Tool\n");
123 
124       return;
125   }
126 
127   if (graph_tool == NULL)
128     {
129       error("plot_hist_proc: no histogram TV", warning);
130       return;
131     }
132   tv_erase(graph_tv);
133 
134   strcpy(temp, hist[hnum]->title);
135 
136   plot(PL_INIT,
137        
138        PL_TV, graph_tv,
139        PL_AXIS_COLOR, black,
140        PL_TITLE, temp,
141        
142        PL_COLOR, red,
143        PL_HIST, hist[hnum],
144        
145        PL_PLOT,
146        NULL);
147 }
148 
149 static void hist_stats_proc(void)
150 {
151   float std_dev;
152 
153   if ((hnum < 0) || (hnum >= NHIST))
154     return;
155 
156   if (hist[hnum] == NULL)
157     {
158       error("hist_stats_proc: current histogram not in use", warning);
159       return;
160     }
161 
162   std_dev = (float)sqrt(fabs(hist[hnum]->mean2 - hist[hnum]->mean *
163                              hist[hnum]->mean));
164   format("histogram: %s\n", hist[hnum]->title);
165   format("mean = %e = %f\nstd_dev = %e = %f\n", hist[hnum]->mean,
166          hist[hnum]->mean, std_dev, std_dev);
167   format("entries = %d\noverflows = %f\nunderflows = %f\n",
168          hist[hnum]->entries, hist[hnum]->over, hist[hnum]->under);
169   format("xmin = %f\nxmax = %f\nno. of bins = %d\n",
170          hist[hnum]->xmin, hist[hnum]->xmax, hist[hnum]->xbins);
171 }
172 
173 static void inc_hist_num_proc(void)
174 {
175   if (hnum <0 ) hnum =0;
176   if (hnum >NHIST) hnum = NHIST-1;
177   while(hnum < NHIST-1 && hist[++hnum] == NULL);
178   tw_iglobal_reset(pframe2);
179 
180   update_name_str();
181 }
182 
183 static void integf_hist_proc(void)
184 {
185     if (hnum >= 0 && hnum < NHIST && hist[hnum]!=NULL)
186     {
187        hintegf(hist[hnum]);
188        update_name_str();
189     }
190 }
191 
192 static void dec_hist_num_proc(void)
193 {
194   if (hnum <0 ) hnum =0;
195   if (hnum >NHIST) hnum = NHIST-1;
196   while (hnum > 0 && hist[--hnum] ==NULL);
197 
198   tw_iglobal_reset(pframe2);
199 
200   update_name_str();
201 }
202 
203 void ecd_proc( void )
204 {   
205    int i;
206    float x, *memVeca, *memVecb, *memVec2, *inc; 
207    double maxdiff = 0.0, prob;
208 
209    memVeca = (float *)ralloc(50*sizeof(float));
210    memVecb = (float *)ralloc(50*sizeof(float));
211    memVec2 = (float *)ralloc(50*sizeof(float));
212    inc = (float *)ralloc(50*sizeof(float));
213    if( graph_tv!=NULL )
214    {
215     memVeca[0] = 0.0;
216     memVecb[0] = 0.0;
217     memVec2[0] = 0.0;
218     inc[0] = 0; 
219     x = cut1/100;
220 
221     for ( i = 1; i < 50; i++ )
222     {
223 
224         prob =  (-exp( -x ) + 1.0) ;
225         memVeca[i] = prob + 3.0*sqrt(prob-prob*prob)/sqrt(hist[hnum]->entries);
226         memVecb[i] = prob - 3.0*sqrt(prob-prob*prob)/sqrt(hist[hnum]->entries);
227         memVec2[i] =  hfill1(hist[hnum],x,0.0)/hist[hnum]->entries;
228         inc[i] = x;
229         x += cut1/50.0; 
230         if (fabs(prob-memVec2[i])>maxdiff ) maxdiff = fabs(prob-memVec2[i]);
231     }
232 
233     tv_erase(graph_tv);
234     plot(PL_INIT,
235          PL_TV, graph_tv,
236          PL_AXIS_COLOR, black,
237          PL_TITLE, "cumDistExpFunc",
238          PL_X_RANGE, 0.0, cut1, 1.0,
239          PL_Y_RANGE, 0.0, 1.1, 1.0,
240          PL_STYLE, PL_LINE,            
241          PL_COLOR, black,
242          PL_GRAPH_DATA, i, inc, memVeca,  
243          PL_COLOR, black,
244          PL_GRAPH_DATA, i, inc, memVecb,  
245          PL_COLOR, red,
246          PL_GRAPH_DATA, i, inc, memVec2,
247          PL_PLOT,
248          NULL);
249    }
250    format("maximum difference = %f \n", maxdiff);
251    rfree((void *)memVeca);
252    rfree((void *)memVecb);
253    rfree((void *)memVec2);
254    rfree((void *)inc);
255 }
256 
257 void ncd_proc( void )
258 {   
259    int i;
260    float x, *memVeca, *memVecb, *memVec2, *inc;
261    double maxdiff = 0.0, prob;
262 
263    memVeca = (float *)ralloc(50*sizeof(float));
264    memVecb = (float *)ralloc(50*sizeof(float));
265    memVec2 = (float *)ralloc(50*sizeof(float));
266    inc = (float *)ralloc(50*sizeof(float));
267    if( graph_tv!=NULL )
268    {
269     memVeca[0] = 0.0;
270     memVecb[0] = 0.0;
271     memVec2[0] = 0.0;
272     inc[0] = 0;
273     x = cut2/100;
274 
275     for ( i = 1; i < 50; i++ )
276     {
277         prob = erf( x/sqrt(2.0) );
278         memVeca[i] = prob + 3.0*sqrt(prob-prob*prob)/sqrt(hist[hnum]->entries);
279         memVecb[i] = prob - 3.0*sqrt(prob-prob*prob)/sqrt(hist[hnum]->entries);
280         memVec2[i] = hfill1(hist[hnum],x,0.0)/hist[hnum]->entries;
281         inc[i] = x; 
282         x += cut2/50.0;
283         if (fabs(prob-memVec2[i])>maxdiff ) maxdiff = fabs(prob-memVec2[i]);
284     }
285 
286     tv_erase(graph_tv);
287     plot(PL_INIT,
288          PL_TV, graph_tv,
289          PL_AXIS_COLOR, black,
290          PL_TITLE, "cumDistNormFunc",
291          PL_X_RANGE, 0.0, cut2, 1.0,
292          PL_Y_RANGE, 0.0, 1.1, 1.0,
293          PL_STYLE, PL_LINE,
294          PL_COLOR, black,
295          PL_GRAPH_DATA, i, inc, memVeca,
296          PL_COLOR, black,
297          PL_GRAPH_DATA, i, inc, memVecb,
298          PL_COLOR, red,
299          PL_GRAPH_DATA, i, inc, memVec2,
300          PL_PLOT,
301          NULL);
302    }
303    format("maximum difference = %f \n", maxdiff);
304    rfree((void *)memVeca);
305    rfree((void *)memVecb);
306    rfree((void *)memVec2);
307    rfree((void *)inc);
308 }
309 
310 void hist_tool(int x, int y)
311 {
312   static void *tool = NULL;
313 
314   if (tool)
315     {
316       tw_show_tool(tool);
317       return;
318     }
319   hist = hist_vec();
320 
321 
322   tool = (void *)tw_tool("Histogram Tool", x, y);
323 
324   tw_button("graph TV", graph_tv_proc, NULL);
325   tw_newrow();
326   pframe2 = (void *)tw_iglobal("Current Histogram:", &hnum, 5);
327   tw_button("<", dec_hist_num_proc, NULL);
328   tw_button(">", inc_hist_num_proc, NULL);
329   tw_newrow();
330   pframe3 = (void *)tw_sglobal("Name: ", name_str, 30);
331   tw_newrow();
332   tw_button("plot hist", plot_hist_proc, NULL);
333   tw_button("hist stats", hist_stats_proc, NULL);
334   tw_button("integrate hist", integf_hist_proc, NULL);
335   tw_newrow();
336   tw_button("expCDF",  ecd_proc, NULL );
337   tw_button("normCDF",  ncd_proc, NULL );
338 
339   tw_end_tool();
340 
341   update_name_str();
342 }
343 

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