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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseMono_tool.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/tlbase/tlbaseMono_tool.c,v $
 37  * Date    :  $Date: 2009/05/13 15:38:15 $
 38  * Version :  $Revision: 1.8 $
 39  * CVS Id  :  $Id: tlbaseMono_tool.c,v 1.8 2009/05/13 15:38:15 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes : most basic tv_screen level code for managing mono resources and data
 44  *  structures.
 45  * 
 46  * deals with file based i/o as well as display selection
 47  *
 48  *********
 49 */
 50 
 51 #include "tlbaseMono_tool.h"
 52 
 53 #if HAVE_CONFIG_H
 54 #include <config.h>
 55 #endif
 56 
 57 #include <stdio.h>
 58 #include <sys/param.h>
 59 #include <string.h>
 60 #include <stdlib.h>
 61 
 62 #include <tina/sys/sysDef.h>
 63 #include <tina/sys/sysPro.h>
 64 #include <tina/image/imgPro.h>
 65 #include <tina/file/fileUtil_name.h>
 66 #include <tina/file/fileUtil_util.h>
 67 #include <tinatool/tlbase/tlbaseMono_file.h>
 68 #include <tinatool/draw/drawDef.h>
 69 #include <tinatool/draw/drawPro.h>
 70 #include <tinatool/wdgts/wdgtsDef.h>
 71 #include <tinatool/wdgts/wdgtsPro.h>
 72 #include <tinatool/tlbase/tlbase_InfrDef.h>
 73 #include <tinatool/tlbase/tlbase_InfrPro.h>
 74 #include <tinatool/tlbase/tlbase_ImcDef.h>
 75 #include <tinatool/tlbase/tlbase_ImcPro.h>
 76 #include <tinatool/tlbase/tlbaseMono_view.h>
 77 
 78 /* STATIC GLOBALS */
 79 static char directory_name[MAXPATHLEN];
 80 static char base_name[MAXPATHLEN];
 81 static char file_name[MAXPATHLEN];
 82 static void *pdir=NULL, *pfile=NULL;
 83 static int file_type = 0;
 84 static void *pframe;
 85 static int fnum = 0;
 86 
 87 /*mjs 25/11/05 added scale factor flag variables and functions so user can choose which scale 
 88  factors to use when loading DICOM data*/
 89 static int mono_scale_factor_flag = 0;
 90 
 91 int get_mono_scale_factor_flag()
 92 {
 93   return(mono_scale_factor_flag);
 94 }
 95 
 96 static void set_mono_scale_factor_flag(int flag)
 97 {
 98   mono_scale_factor_flag = flag;
 99   return;
100 }
101 
102 
103 
104 /* CALLBACK FUNCTIONS */
105 
106 static void    mono_draw(Tv *tv)
107 {
108     if(tv!=NULL)
109     {
110         tv_free_background(tv);
111         tv_repaint(tv);
112     }
113 }
114 
115 static void tv_proc(void)
116 {
117     mono_tv_set(mono_tv_make());
118     tv_set_next(mono_tv());
119 }
120 
121 
122 /* Push / Pop callbacks */
123 static void push_proc(void)
124 {
125     Imrect *im;
126 
127     im = im_copy(mono_image());
128     stack_push((void *) im, IMRECT, im_free);
129     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
130     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
131     image_choice_reset();
132 }
133 
134 static void pop_proc(void)
135 {
136     int     type;
137 
138     if (stack_check_types(IMRECT, NULL) == false)
139         if (stack_check_types(EDGERECT, NULL) == false)
140             error("pop_proc: wrong type on stack", warning);
141         else
142             mono_edges_set((Imrect *) stack_pop(&type)); 
143     else
144         mono_image_set((Imrect *) stack_pop(&type));
145     mono_draw(mono_tv_get());
146     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
147     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
148     image_choice_reset();
149 }
150 
151 /* Mouse function callbacks */
152 static void mono_mouse_proc(Tv_mouse(*func) ( /* ??? */ ))
153 {
154     tv_set_mouse(mono_tv(), (*func) ());
155     (void) tv_set_activity(mono_tv(), MOUSE);
156 }
157 
158 /* Mono check callback */
159 #define IMAGE_MASK  1
160 #define EDGE_MASK   2
161 #define CORNER_MASK 4
162 #define STRING_MASK 8
163 #define POLY_MASK   16
164 #define OTHER_MASK  32
165 
166 static void mono_check_proc(int val)
167 {
168     mono_image_on((Bool) (val & IMAGE_MASK));
169     mono_edges_on((Bool) (val & EDGE_MASK));
170     mono_corners_on((Bool) (val & CORNER_MASK));
171     mono_strings_on((Bool) (val & STRING_MASK));
172     mono_poly_on((Bool) (val & POLY_MASK));
173 }
174 
175 /* Choice item callbacks */
176 
177 /* File choice callback */
178 static void file_choice_proc(int val)
179 {
180     file_type = val;
181 }
182 
183 /* input / output callbacks */
184 static void input_proc(void)
185 {
186     char  *pfname[1];
187     
188     parse_fname(base_name, file_name, fnum);
189     *pfname = file_name;
190     if (strchr(file_name, '*') && !fname_resolve(directory_name, file_name, pfname))
191     {
192        error("mono input: no such file or filename", warning);
193        return;
194     }
195     mono_input(directory_name, *pfname, file_type);
196     mono_draw(mono_tv_get());
197 }
198 
199 static void output_proc(void)
200 {
201     parse_fname(base_name, file_name, fnum);
202     if (strchr(file_name, '*'))
203     {
204       error("mono output: cannot output to wildcard name", warning);
205       return;
206     }
207     mono_output(directory_name, file_name, file_type);
208 }
209 
210 
211 /* Tv list choice proc */
212 /* ARGSUSED quieten lint */
213 static void tv_choice_proc(int val)
214 {
215     tv_set_next(mono_tv());
216 }
217 
218 static void inc_fnum_proc(void)
219 {
220   fnum++;
221   tw_iglobal_reset(pframe);
222 }
223 
224 static void dec_fnum_proc(void)
225 {
226   fnum--;
227   tw_iglobal_reset(pframe);
228 }
229 
230 static void scan_proc(void)
231 {
232    scan_files(directory_name, base_name);
233    tw_sglobal_reset(pdir);
234    tw_sglobal_reset(pfile);
235 }
236 
237 
238 /* Tool creation */
239 void    mono_tool(int x, int y)
240 {
241     Tv_mouse null_mouse();
242     Tv_mouse pos_mouse();
243     Tv_mouse mono_grey_mouse();
244     Tv_mouse pixel_mouse();
245 
246     static void *tv_screen = NULL;
247 
248     if (tv_screen)
249     {
250         tw_show_tool(tv_screen);
251         return;
252     }
253 
254     tv_proc();
255 
256     tv_screen = tw_tool("Mono Tool", x, y);
257 
258 
259     tw_choice("Tv : ", tv_choice_proc, 0, "mono", NULL);
260 
261     tw_menubar("Mouse: ",
262                "Mono",
263                "null", mono_mouse_proc, null_mouse,
264                "pos", mono_mouse_proc, pos_mouse,
265                "grey", mono_mouse_proc, mono_grey_mouse,
266                "pixel", mono_mouse_proc, pixel_mouse,
267                NULL,
268                NULL);
269 
270     tw_help_button("mono_tool");
271 
272     tw_newrow();
273 
274     tw_check("Mono:       ", mono_check_proc, 1,
275              "image", "edges", "corner", "strings", "geom",
276              NULL);
277 
278     tw_newrow();
279 
280     tw_choice("File:", file_choice_proc, 0,
281               "AIFF", "PGM", "RAD", "EDGE", "POLY", "CAM", "WISP",
282               "RAS", "DICOM", NULL);
283     tw_menubar("", "DICOM (re)scale?", 
284              "Rescale", set_mono_scale_factor_flag, 0,
285              "Scale", set_mono_scale_factor_flag, 1,
286              NULL, NULL);
287     tw_newrow();
288 
289     tw_button("input", input_proc, NULL);
290     tw_button("output", output_proc, NULL);
291     pframe = (void *)tw_iglobal(" Frame Number (#):", &fnum, 5);
292     tw_button("<", dec_fnum_proc, NULL);
293     tw_button(">", inc_fnum_proc, NULL);
294 
295     tw_newrow();
296 
297     pdir = (void *) tw_sglobal("Directory Name:", directory_name, 32);
298     tw_button("scan", scan_proc, NULL);
299 
300     tw_newrow();
301 
302     pfile = (void *) tw_sglobal("Base Name:     ", base_name, 32);
303 
304     tw_newrow();
305 
306     tw_button("push", push_proc, NULL);
307     tw_button("pop", pop_proc, NULL);
308 
309     tw_end_tool();
310 }
311 

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