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/tlbaseView_tool.c,v $
37 * Date : $Date: 2007/02/15 01:55:50 $
38 * Version : $Revision: 1.4 $
39 * CVS Id : $Id: tlbaseView_tool.c,v 1.4 2007/02/15 01:55:50 paul Exp $
40 *
41 * Author : Legacy TINA
42 *
43 * Notes : tool for setting standard view and dump parameters for tina view tools
44 *
45 *********
46 */
47
48 #if HAVE_CONFIG_H
49 #include <config.h>
50 #endif
51
52
53 /* view_tool.c
54 *
55 * tool for setting standard view and dump parameters for tina view tools
56 */
57
58 #define VIEW_TOOL_INCLUDED
59
60 #include <math.h>
61 #include <string.h>
62
63 #include <tina/sys/sysDef.h>
64 #include <tina/sys/sysPro.h>
65 #include <tina/math/mathDef.h>
66 #include <tina/math/mathPro.h>
67 #include <tina/image/imgDef.h>
68 #include <tina/image/imgPro.h>
69
70 #include <tinatool/draw/drawDef.h>
71 #include <tinatool/draw/drawPro.h>
72 #include <tinatool/gphx/gphxPro.h>
73 #include <tinatool/wdgts/wdgtsDef.h>
74 #include <tinatool/wdgts/wdgtsPro.h>
75 #include <tinatool/tlbase/tlbase_DispPro.h>
76 #include <tinatool/tlbase/tlbase_InfrPro.h>
77 #include <tinatool/tlbase/tlbaseView_display.h>
78
79 static int bkgrnd_val = 0;
80
81 /* FORWARD REFS */
82 static void bkgrnd_choice_proc (int value);
83 void cmap_choice_proc (int value);
84 static void dim_set (double d);
85 static double dim_get (void);
86 static void *currenttv;
87 static char tv_namestr[256] = "";
88 static int fspeed = 100;
89 static int fcount = 4;
90 static double x_rot = 0;
91 static double y_rot = 0.5;
92 static int count = 10;
93
94 /* EXTERNS */
95
96 static void bkgrnd_choice_proc (int value)
97 {
98 Tv *tv = tv_get_next ();
99
100 if (tv == NULL || tv->cmap_data_visible == NULL || tv->cmap_data_visible->std_lut==NULL) return;
101 switch (value)
102 {
103 case 0:
104 tv_reset_color (tv, bkgrnd, 255, 255, 255);
105 break;
106 case 1:
107 tv_reset_color (tv, bkgrnd, 180, 180, 180);
108 break;
109 case 2:
110 tv_reset_color (tv, bkgrnd, 96, 96, 96);
111 break;
112 case 3:
113 tv_reset_color (tv, bkgrnd, 0, 0, 0);
114 break;
115 case 4:
116 tv_reset_color (tv, bkgrnd, 0, 0, 255);
117 break;
118 }
119 bkgrnd_val = value;
120 tv_screen_background_set(tv->tv_screen, tv->cmap_data_visible->std_lut[bkgrnd]);
121 tv_free_background (tv);
122 tv_repaint (tv);
123 }
124
125 static void col_choice_proc(int value)
126 {
127 switch (value)
128 {
129 case 0:
130 tv_set_color(tv_get_next(), black);
131 break;
132 case 1:
133 tv_set_color(tv_get_next(), blue);
134 break;
135 case 2:
136 tv_set_color(tv_get_next(), white);
137 break;
138 case 3:
139 tv_set_color(tv_get_next(), red);
140 break;
141 }
142 tv_repaint(tv_get_next());
143 }
144
145 void cmap_choice_proc (int value)
146 {
147 extern void tv_screen_cmap_find_and_install ();
148 Tv *tv = tv_get_next ();
149 static Bool first_time = true;
150
151 if (tv && tv->tv_screen && !first_time)
152 {
153 Bool (*cmap_create_fn) () = NULL;
154 extern void tv_cmap_create_fn_set ();
155
156 switch (value)
157 {
158 case 0:
159 cmap_create_fn = tv_standard_cmap_create;
160 break;
161 case 1:
162 cmap_create_fn = tv_grey_cmap_create;
163 break;
164 case 2:
165 cmap_create_fn = tv_anag_cmap_create;
166 break;
167 case 3:
168 cmap_create_fn = tv_false_cmap_create;
169 break;
170 default:
171 break;
172 }
173 tv->cmap_create_fn = cmap_create_fn;
174 tv_screen_cmap_find_and_install (tv, tv->tv_screen);
175 tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
176 bkgrnd_choice_proc(bkgrnd_val);
177 }
178 first_time = false;
179 }
180
181 void cmap_show_proc (void)
182 {
183 Tv *tv = tv_get_next ();
184
185 static void *tv_screen = NULL;
186
187 if (tv)
188 {
189 static Tv *cmap_tv = NULL;
190 int width = 768;
191 int height = 768;
192 if (tv_screen)
193 {
194 tw_show_tool(tv_screen_owner_get (tv_screen)); /* popup tool */
195 }
196 else
197 { /* Create & popup tool to display colormap */
198 cmap_tv = tv_create ("Colormap tool");
199 tv_screen = display_tool (0, 0, width, height);
200 tv_install (cmap_tv, tv_screen);
201 }
202 cmap_show (tv->cmap_data_visible, cmap_tv);
203 }
204 }
205
206 void push_tv_screen(void)
207 {
208 Imrect *tv_screen2imrect();
209
210 stack_push(tv_screen2imrect(), IMRECT, im_free);
211 }
212
213
214 static void cmap_lookup_show_proc (void)
215 {
216 Tv *tv = tv_get_next ();
217
218 if (tv)
219 {
220 tv_cmap_lookup_print (tv);
221 }
222 }
223
224 static double dim = 4.0;
225
226 static void dim_set (double d)
227 {
228 dim = d;
229 }
230
231 static double dim_get (void)
232 {
233 return (dim);
234 }
235
236 static void dump_proc (void)
237 {
238 void dump_tool();
239 dump_tool();
240 }
241
242
243 static void line_width_choice_proc (int value)
244 {
245 Tv *tv = tv_get_next ();
246
247 (void) tv_set_linewidth (tv, value);
248 }
249
250 void viewtool_tv_update(void)
251 {
252 Tv *tv = tv_get_next ();
253
254 if (tv!=NULL) strcpy(tv_namestr, tv->label);
255 (void)tw_sglobal_reset(currenttv);
256 }
257
258 static void set_bigtolittle_proc (void)
259 {
260 void toggle_bigtolittle(void);
261 toggle_bigtolittle();
262 }
263
264 static void movie_manual_start (void)
265 {
266 tv_start_movie (tv_get_next ());
267 }
268
269 static void movie_manual_next (void)
270 {
271 tv_make_movie (tv_get_next ());
272 }
273
274 static void show_movie_proc (void)
275 {
276 Tv *tv = tv_get_next ();
277 void timer_handler_install(long int length);
278 int i;
279
280 if (tv == NULL || tv->tv_screen == NULL)
281 return;
282 if (fspeed < 1) fspeed = 1;
283 timer_handler_install(10000*fspeed);
284
285 tv_loop_movie (tv, fcount);
286 timer_handler_uninstall();
287 }
288
289 static void make_movie_proc (void)
290 {
291 Tv *tv = tv_get_next ();
292 double theta;
293 Vec3 v =
294 {Vec3_id};
295 int i;
296
297 if (tv == NULL || tv->tv_screen == NULL)
298 return;
299
300 if (tv->zoomlevel != ZOOM4 && tv->zoomlevel != ZOOM3 && tv->zoomlevel != ZOOMGR)
301 return;
302
303 if (tv->zoomlevel == ZOOMGR)
304 { /* can only rotate about z axis */
305 v = vec3_ez ();
306 theta = sqrt (x_rot * x_rot + y_rot * y_rot);
307 if (theta == 0.0)
308 return;
309
310 }
311 else
312 {
313 v = vec3_sum (vec3_times (x_rot / count, tv->ex3),
314 vec3_times (y_rot / count, tv->ey3));
315 theta = vec3_mod (v);
316 if (theta == 0.0)
317 return;
318 v = vec3_times (1 / theta, v); /* to make it unit */
319 }
320
321 tv_start_movie (tv);
322 tv_repaint (tv);
323 tv_make_movie (tv);
324 for (i = 0; i < count; ++i)
325 {
326 tv_twist (tv, theta, v);
327 tv_repaint (tv);
328 tv_make_movie (tv);
329 }
330 }
331
332 static void rand_movie_proc (void)
333 {
334 Tv *tv = tv_get_next ();
335 void timer_handler_install(long int length);
336 int i;
337
338 if (tv == NULL || tv->tv_screen == NULL)
339 return;
340 if (fspeed < 1) fspeed = 1;
341 timer_handler_install(10000*fspeed);
342
343 tv_random_movie (tv, fcount);
344 timer_handler_uninstall();
345 }
346
347
348 void view_tool (int x, int y)
349 {
350 static void *tool = NULL;
351 char *default_font_get ();
352 void default_font_set ();
353
354 if (tool)
355 {
356 tw_show_tool (tool);
357 return;
358 }
359 tool = tw_tool ("View Tool", x, y);
360
361 currenttv = tw_sglobal("Current TV: ", tv_namestr, 20);
362 set_view_tool_func((void (*) ())viewtool_tv_update);
363 tw_button ("dump", dump_proc, NULL);
364 tw_label(" ");
365 tw_help_button("view_tool");
366
367 tw_newrow();
368 tw_choice ("Bkgrnd ", bkgrnd_choice_proc, bkgrnd_val,
369 "white", "light grey", "dark grey", "black", "blue", NULL);
370 tw_newrow ();
371 tw_choice ("Line ", line_width_choice_proc, 0, "", "1", "2", "3", NULL);
372 tw_choice("Color", col_choice_proc, 0, "black", "blue", "white", "red", NULL);
373 tw_newrow();
374 tw_choice ("Colormap", cmap_choice_proc, 0, "Standard", "Greyscale",
375 "Anaglyph", "False colour", NULL);
376 tw_newrow ();
377 (void) tw_ivalue ("default colors:", ndefault_colors_get,
378 (void (*)()) ndefault_colors_set, 3);
379 (void) tw_svalue ("Default Font : ", default_font_get, default_font_set, 10);
380 tw_button("endian", set_bigtolittle_proc, NULL);
381 tw_newrow ();
382 tw_button ("Show cmap", cmap_show_proc, NULL);
383 tw_button ("Show tv`s cmap_lookup", cmap_lookup_show_proc, NULL);
384 tw_button ("Push tv screen", push_tv_screen, NULL);
385
386 tw_newrow ();
387
388 (void) tw_label ("Movie");
389 tw_button ("init", movie_manual_start, NULL);
390 tw_button ("add one", movie_manual_next, NULL);
391 tw_button ("make seq", make_movie_proc, NULL);
392 tw_button ("show", show_movie_proc, NULL);
393 tw_button ("random", rand_movie_proc, NULL);
394
395 tw_newrow ();
396
397 (void) tw_fglobal ("Rot x:", &x_rot, 10);
398 (void) tw_fglobal ("Rot y:", &y_rot, 10);
399 (void) tw_iglobal ("Steps:", &count, 5);
400
401 tw_newrow ();
402 tw_iglobal("Timer (0.01 sec):", &fspeed, 5);
403 tw_iglobal(" Count :", &fcount, 5);
404 tw_end_tool ();
405
406 viewtool_tv_update();
407 }
408
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.