Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

tlbaseDisp_tool.c

Go to the documentation of this file.
00001 /**********
00002  * 
00003  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
00004  * University of Manchester, UK.  All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without modification, 
00007  * are permitted provided that the following conditions are met:
00008  * 
00009  *   . Redistributions of source code must retain the above copyright notice, 
00010  *     this list of conditions and the following disclaimer.
00011  *    
00012  *   . Redistributions in binary form must reproduce the above copyright notice,
00013  *     this list of conditions and the following disclaimer in the documentation 
00014  *     and/or other materials provided with the distribution.
00015  * 
00016  *   . Neither the name of the University of Manchester nor the names of its
00017  *     contributors may be used to endorse or promote products derived from this 
00018  *     software without specific prior written permission.
00019  * 
00020  * 
00021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00031  * POSSIBILITY OF SUCH DAMAGE.
00032  *
00033  **********
00034  * 
00035  * Program :    TINA
00036  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseDisp_tool.c,v $
00037  * Date    :  $Date: 2008/12/02 22:04:19 $
00038  * Version :  $Revision: 1.6 $
00039  * CVS Id  :  $Id: tlbaseDisp_tool.c,v 1.6 2008/12/02 22:04:19 paul Exp $
00040  *
00041  * Author  :  Legacy TINA
00042  *
00043  * Notes : Tv Tool creation function and associated tv_screen procs (for XView & Motif).
00044  *
00045  *********
00046 */
00047 
00048 #include "tlbaseDisp_tool.h"
00049 
00050 #if HAVE_CONFIG_H
00051 #    include <config.h>
00052 #endif
00053 
00054 #include <stdio.h>
00055 #include <math.h>
00056 #include <tina/sys/sysDef.h>
00057 #include <tina/sys/sysPro.h>
00058 #include <tina/math/mathDef.h>
00059 #include <tina/math/mathPro.h>
00060 #include <tinatool/draw/drawDef.h>
00061 #include <tinatool/draw/drawPro.h>
00062 #include <tinatool/wdgts/wdgtsDef.h>
00063 #include <tinatool/wdgts/wdgtsPro.h>
00064 #include <tinatool/gphx/gphxDef.h>
00065 #include <tinatool/gphx/gphxPro.h>
00066 
00067 
00068 #define simple_pair_make(p1, p2) pair_make((void*) p1, 0, (void*) p2, 0)
00069 #define ERASE_TV 3
00070 
00073 static void button_repaint_proc(void *tv_screen)
00074 {
00075   Tv *tv;
00076 
00077   if (tv_screen == NULL)
00078     return;
00079 
00080   tv = tv_screen_tv_get(tv_screen);
00081 
00082   if (tv == NULL)
00083     return;
00084   tv_free_background(tv);
00085   tv_repaint(tv);
00086 }
00087 
00088 static void size_proc(Pair * pair)
00089 {
00090   int size = (int) pair->to1;
00091   void *tv_screen = (void *) pair->to2;
00092 
00093   if (tv_screen == NULL)
00094     return;
00095 
00096   tv_screen_set_size(tv_screen, size, size);
00097 }
00098 
00099 static void activity_proc(Pair * pair)
00100 {
00101   int activity = (int) pair->to1;
00102   void *tv_screen = (void *) pair->to2;
00103 
00104   if (tv_screen == NULL)
00105     return;
00106   (void) tv_set_activity(tv_screen_tv_get(tv_screen), activity);
00107 }
00108 
00109 static void proj_proc(Pair * pair)
00110 {
00111   int proj = (int) pair->to1;
00112   void *tv_screen = (void *) pair->to2;
00113   Tv *tv;
00114 
00115   if (tv_screen == NULL)
00116     return;
00117 
00118   tv = tv_screen_tv_get(tv_screen);
00119 
00120   if (tv == NULL)
00121     return;
00122 
00123   tv_set_proj3(tv, proj);
00124   tv_repaint(tv);
00125 }
00126 
00127 static void paint_proc(Pair * pair)
00128 {
00129   int mode = (int) pair->to1;
00130   void *tv_screen = (void *) pair->to2;
00131   Tv *tv;
00132 
00133   if (tv_screen == NULL)
00134     return;
00135 
00136   tv = tv_screen_tv_get(tv_screen);
00137 
00138   if (tv == NULL)
00139     return;
00140 
00141   if (mode == ERASE_TV)
00142     tv_erase(tv);
00143   else
00144     tv_set_paint_mode(tv, mode);
00145 
00146   if (mode == FULL_PAINT)
00147     tv_repaint(tv);
00148 }
00149 
00150 /*
00151  * Button procedures are applied to current tv_screen: Since a button
00152  * * has been hit, a tv_screen window has been entered and the current
00153  * * tv_screen has been set. 
00154  */
00155 
00156 static void install_proc(Pair * pair)
00157 {
00158   Tv *tv;
00159   int *label = (void *) pair->to1;
00160   void *tv_screen = (void *) pair->to2;
00161   void tw_label_reset();
00162   void tw_tool_title_reset();
00163 
00164   if (tv_screen == NULL)
00165     return;
00166 
00167   tv_install(tv_get_next(), tv_screen);
00168   tv = tv_screen_tv_get(tv_screen);
00169   tv_message_function_set(tv, tw_label_reset, (void *) *label);
00170 }
00171 
00172 static void clone_proc(Pair * pair)
00173 {
00174   Tv *tv;
00175   int *label = (void *) pair->to1;
00176   void *tv_screen = (void *) pair->to2;
00177   void tw_label_reset();
00178   void tw_tool_title_reset();
00179 
00180   if (tv_screen == NULL)
00181     return;
00182   tv_install_clone(tv_get_next(), tv_screen);
00183   tv = tv_screen_tv_get(tv_screen);
00184   tv_message_function_set(tv, tw_label_reset, (void *) *label);
00185 }
00186 
00187 static void init_proc(void *tv_screen)
00188 {
00189   if (tv_screen == NULL || tv_screen_tv_get(tv_screen) == NULL)
00190     return;
00191   tv_init(tv_screen_tv_get(tv_screen));
00192 }
00193 
00194 static void invert_2d_proc(void *tv_screen)
00195 {
00196   Tv *tv = tv_screen_tv_get(tv_screen);
00197 
00198   if (tv == NULL)
00199     return;
00200   tv_rot2(tv, PI);
00201   tv_free_background(tv);
00202   tv_repaint(tv);
00203 }
00204 
00205 static void invert_3d_proc(void *tv_screen)
00206 {
00207   Tv *tv = tv_screen_tv_get(tv_screen);
00208 
00209   if (tv == NULL)
00210     return;
00211   tv_rot3(tv, PI);
00212   tv->axis = vec3_minus(tv->axis);
00213   tv_free_background(tv);
00214   tv_repaint(tv);
00215 }
00216 
00217 void *tv_tool_remote(int x, int y, char *display_name)
00218 {
00219   char name[64];
00220   int canvas;
00221   int owner;
00222   int *label = ralloc(sizeof(int));
00223   static int no = 0;
00224   void canvas_upgrade();
00225   void *tv_screen = tv_screen_struct_create();
00226 
00227   ++no;                         /*
00228                                  * a new tool name number 
00229                                  */
00230 
00231   (void) sprintf(name, "Tv Tool %d", no);
00232 
00233   owner = (int) tw_tool_remote(name, x, y, display_name);
00234 
00235   tw_menubar("",
00236              "Size",
00237              "256", size_proc, simple_pair_make(256, tv_screen),
00238              "512", size_proc, simple_pair_make(512, tv_screen),
00239              "768", size_proc, simple_pair_make(768, tv_screen),
00240              NULL,
00241              "Mouse",
00242              "null", activity_proc, simple_pair_make(NULL, tv_screen),
00243              "zoom", activity_proc, simple_pair_make(ZOOM, tv_screen),
00244              "pick", activity_proc, simple_pair_make(PICK, tv_screen),
00245              "mouse", activity_proc, simple_pair_make(MOUSE, tv_screen),
00246              NULL,
00247              "ROI",
00248              "rect", activity_proc, simple_pair_make(ROI, tv_screen),
00249              "poly", activity_proc, simple_pair_make(POLYROI, tv_screen),
00250              "point", activity_proc, simple_pair_make(POINT, tv_screen),
00251              "global", activity_proc, simple_pair_make(GLOBAL, tv_screen),
00252              NULL,
00253              "Proj",
00254              "orth", proj_proc, simple_pair_make(ORTH, tv_screen),
00255              "persp", proj_proc, simple_pair_make(PERSP, tv_screen),
00256              "invert 2D", invert_2d_proc, tv_screen,
00257              "invert 3D", invert_3d_proc, tv_screen,
00258              NULL,
00259              NULL);
00260 
00261   tw_newrow();
00262   tw_button("install", install_proc, (void *) simple_pair_make((void *) label, tv_screen));
00263   tw_button(" clone ", clone_proc, (void *) simple_pair_make((void *) label, tv_screen));
00264   tw_button(" init  ", init_proc, (void *) tv_screen);
00265   tw_button("repaint", button_repaint_proc, (void *) tv_screen);
00266 
00271   tw_newrow();
00272   *label = (int) tw_label("null");
00273 
00274   tw_newrow();
00275   canvas = (int) tw_canvas(256, 256);   /*
00276                                          * Returns XV Canvas NOT paint
00277                                          * * window 
00278                                          */
00279 
00280   tw_end_tool();
00281 
00282   canvas_upgrade(canvas, owner, tv_screen);     /*
00283                                                  * sets window, screen &
00284                                                  * * visual 
00285                                                  */
00286 
00287   tv_screen_set_size(tv_screen, 256, 256);
00288   return (tv_screen);
00289 }
00290 
00291 void *tv_tool(int x, int y)
00292 {
00293   return tv_tool_remote(x, y, (char *) NULL);
00294 }

Generated on Thu Nov 12 02:20:47 2009 for Tools by doxygen 1.3.6