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

drawTv_tv.c

Go to the documentation of this file.
00001 /*********
00002  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
00003  * University of Manchester, UK.  All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  * 
00008  *   . Redistributions of source code must retain the above copyright notice, 
00009  *     this list of conditions and the following disclaimer.
00010  *    
00011  *   . Redistributions in binary form must reproduce the above copyright notice,
00012  *     this list of conditions and the following disclaimer in the documentation 
00013  *     and/or other materials provided with the distribution.
00014  * 
00015  *   . Neither the name of the University of Manchester nor the names of its
00016  *     contributors may be used to endorse or promote products derived from this 
00017  *     software without specific prior written permission.
00018  * 
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  **********
00033  *
00034  * Program :    TINA
00035  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_tv.c,v $
00036  * Date    :  $Date: 2008/12/02 22:04:19 $
00037  * Version :  $Revision: 1.3 $
00038  * CVS Id  :  $Id: drawTv_tv.c,v 1.3 2008/12/02 22:04:19 paul Exp $
00039  *
00040  * Author  : Legacy TINA
00041  *
00042  * Notes :
00043  * Tv ('logical' display device) creation & installation
00044  * Basic tv creation and installation on tv_screens.
00045  *
00046  *
00047  *********
00048 */
00049 
00050 #include "drawTv_tv.h"
00051 
00052 #if HAVE_CONFIG_H
00053   #include <config.h>
00054 #endif
00055 
00056 #include <stdio.h>
00057 #include <string.h>
00058 #include <tina/sys/sysDef.h>
00059 #include <tina/sys/sysPro.h>
00060 #include <tina/math/mathDef.h>
00061 #include <tina/math/mathPro.h>
00062 #include <tina/geometry/geomDef.h>
00063 #include <tina/geometry/geomPro.h>
00064 #include <tinatool/draw/draw_TvDef.h>
00065 #include <tinatool/draw/draw_TvPro.h>
00066 #include <tinatool/gphx/gphxPro.h>
00067 #include <tinatool/wdgts/wdgtsPro.h>
00068 
00069 /* EXTERNS
00070 extern void picture_free();
00071 extern void tv_screen_cmap_find_and_install();
00072 extern void tv_screen_named_font_set();
00073 extern void tv_screen_set_op();
00074 extern void tv_screen_set_linewidth();
00075 extern void tv_screen_save_size();
00076 extern void tv_screen_tv_set();
00077 extern void tv_screen_background_set();
00078 extern void tw_tool_title_reset();
00079 */
00080 
00081 void    tv_free_background(Tv * tv)
00082 {
00083     if (tv == NULL)
00084         return;
00085     if (tv->backsave)
00086     {
00087         picture_free(tv->background);
00088         tv->background = NULL;
00089     }
00090 }
00091 
00092 void    tv_repaint(Tv * tv)
00093 {
00094     if (tv == NULL || tv->tv_screen == NULL)
00095         return;
00096 
00097     if (tv->backsave && tv->paint_mode == FULL_PAINT)
00098     {
00099         if (tv->background == NULL)
00100         {
00101             tv_erase(tv);
00102             tv->backdraw(tv, tv->drawdata);
00103             tv->background = tv_get_picture(tv);
00104         } else
00105             tv_show_picture(tv, tv->background);
00106     } else
00107         tv_erase(tv);
00108 
00109     switch (tv->paint_mode)
00110     {
00111     case FULL_PAINT:
00112         tv->fulldraw(tv, tv->drawdata);
00113         break;
00114     case SKEL_PAINT:
00115         tv->skeldraw(tv, tv->drawdata);
00116         break;
00117     }
00118 }
00119 
00120 Tv     *tv_create(char *label)
00121 {
00122     Tv     *tv = ts_ralloc(Tv);
00123 
00124     (void) strcpy(tv->label, label);
00125 
00126     tv->clone = 0;
00127 
00128     tv->tv_screen = NULL;
00129     tv->width = tv->height = 256;
00130     tv->init = null_function;
00131 
00132     tv->overlay_on = false;
00133     tv->color = black;          /* index into
00134                                  * tv->cmap_data_visible->std_lut[] */
00135     tv->op = rop_copy;
00136     tv->linewidth = 0;
00137     tv->linestyle = line_solid;
00138     *tv->font_name = '\0';      /* length STRING128 */
00139     tv->draw = NULL;
00140 
00141     tv->activity = 0;
00142     tv->proj3type = ORTH;
00143     tv->paint_mode = FULL_PAINT;
00144     tv->mouse = null_mouse();
00145     tv->mouse_reset = null_function;
00146     tv->pick = null_pick();
00147     tv->pick_reset = null_function;
00148     tv->backdraw = tv->fulldraw = tv->skeldraw = null_function;
00149     tv->drawdata = NULL;
00150     tv->backsave = false;
00151     tv->background = NULL;
00152 
00153     tv->ul = vec2_zero();
00154     tv->lr = vec2((float) tv->width, (float) tv->height);
00155 
00156     tv->movie = NULL;
00157 
00158     tv_camera3(tv, vec3_zero(), 1.0, 3.0, vec3_ez(), vec3_ey());
00159     tv->axis_set = false;
00160     tv_set_proj3_orth(tv);
00161     tv_camera2(tv, vec2(128.0, 128.0), 128.0, vec2_ey());
00162     tv_set_proj2(tv);
00163 
00164     /* tv's colormap info. */
00165     tv->cmap_data_visible = NULL;
00166     tv->cmap_create_fn = tv_standard_cmap_create;
00167 
00168     /* zbuffering option * */
00169     tv->zbuff = NULL;
00170 
00171     return (tv);
00172 }
00173 
00174 Tv     *tv_clone(Tv * tv)
00175 {
00176     char    clone[16];
00177     Tv     *tv_new;
00178 
00179     if (tv == NULL)
00180         return (NULL);
00181 
00182     tv_new = ts_ralloc(Tv);
00183     *tv_new = *tv;
00184     tv_new->pick.picklist = NULL;
00185     tv_new->clone = ++(tv->clone);
00186     (void) sprintf(clone, "%-8d", tv_new->clone);
00187     (void) string_append(tv_new->label, tv->label, " clone ", clone, NULL);
00188     tv_new->tv_screen = NULL;
00189     tv_new->movie = NULL;
00190     tv_new->background = NULL;
00191     tv_new->zbuff = NULL;
00192     tv_new->message_fn = NULL;
00193     tv_new->message_data = NULL;
00194     tv_new->header_fn = NULL;
00195     tv_new->header_data = NULL;
00196     return (tv_new);
00197 }
00198 
00199 void    tv_install(Tv * tv, void *tv_screen)
00200 {
00201     void   *owner;
00202     Tv     *tv_screen_tv_get();
00203     void   *tv_screen_owner_get();
00204 
00205     if (tv && tv_screen)
00206     {
00207         /* Uninstall OLD tv_screen (loses link to its tv) */
00208         if (tv->tv_screen)
00209         {
00210             tv_set_header(tv, "uninstalled");
00211             tv_set_message(tv, "null");
00212             tv_header_function_set(tv, NULL, NULL);
00213             tv_message_function_set(tv, (void (*) ()) NULL, NULL);
00214             tv_screen_tv_set(tv->tv_screen, (Tv *) NULL);
00215         }
00216         if (tv_screen_tv_get(tv_screen))
00217         {
00218             (tv_screen_tv_get(tv_screen))->tv_screen = NULL;
00219         }
00220         tv_screen_save_size(tv_screen);
00221 
00222         tv->tv_screen = tv_screen;
00223         tv_screen_tv_set(tv_screen, tv);
00224 
00225         owner = tv_screen_owner_get(tv_screen);
00226         tv_header_function_set(tv, (void (*) ()) tw_tool_title_reset, owner);
00227 
00228         tv_screen_cmap_find_and_install(tv, tv_screen);
00229         tv_screen_color_set(tv->tv_screen, tv->cmap_data_visible->std_lut[tv->color]);
00230         tv_screen_background_set(tv->tv_screen, tv->cmap_data_visible->std_lut[bkgrnd]);
00231 
00232         (void) tv_screen_set_op(tv->tv_screen, tv->op);
00233         tv_screen_set_linewidth(tv->tv_screen, tv->linewidth);
00234         tv_screen_set_linestyle(tv->tv_screen, tv->linestyle);
00235         tv_screen_named_font_set(tv->tv_screen, tv->font_name);
00236         tv_set_proj3(tv, tv->proj3type);
00237         (void) tv_set_activity(tv, tv->activity);       /* sets message */
00238         tv_rescale(tv);
00239         tv_free_background(tv); /* Ie image */
00240         if(tv->zbuff)
00241             tv_set_zbuff(tv, tv->zbuff->zmin, tv->zbuff->zmax);
00242         tv_repaint(tv);
00243     }
00244 }
00245 
00246 void    tv_install_clone(Tv * tv, void *tv_screen)
00247 {
00248     Tv     *tv_new;
00249 
00250     if (tv && tv_screen)
00251     {
00252         tv_new = tv_clone(tv);
00253         tv_install(tv_new, tv_screen);
00254     }
00255 }
00256 
00257 void    tv_set_message(Tv * tv, char *name)
00258 {
00259     if (tv == NULL || tv->message_fn == NULL)
00260         return;
00261 
00262     tv->message_fn(tv->message_data, name);
00263 }
00264 
00265 void    tv_message_function_set(Tv * tv, void (*func) ( /* ??? */ ), void *data)
00266 {
00267     if (tv == NULL)
00268         return;
00269     tv->message_fn = func;
00270     tv->message_data = data;
00271     (void) tv_set_activity_message(tv);
00272 }
00273 
00274 void    tv_set_header(Tv * tv, char *name)
00275 {
00276     if (tv == NULL || tv->header_fn == NULL)
00277         return;
00278 
00279     tv->header_fn(tv->header_data, name);
00280 }
00281 
00282 void    tv_header_function_set(Tv * tv, void (*func) ( /* ??? */ ), void *data)
00283 {
00284     if (tv == NULL)
00285         return;
00286     tv->header_fn = func;
00287     tv->header_data = data;
00288     tv_set_header(tv, tv->label);
00289 }
00290 
00291 Tv     *tv_open(void *tv_screen, char *label)
00292 {
00293     Tv     *tv = NULL;
00294 
00295     if (tv_screen)
00296     {
00297         tv = tv_create(label);
00298         tv_install(tv, tv_screen);
00299     }
00300     return (tv);
00301 }
00302 
00303 static void tv_dummy_calls(void)
00304 {                               /* for separate library complilation */
00305     Tv     *tv = (Tv *) NULL;
00306     double  zoom = 0.0;
00307 
00308     tv_zoom(tv, zoom);
00309     (void) tv_cmap_create(tv);
00310     (void) tv_get_im_roi(tv);
00311     (void) tv_get_next();
00312     tv_init(tv);
00313 }

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