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

Linux Cross Reference
Tina4/src/snake/aivru_voi.c

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

  1 /** @(#)Aivru/Covira interface. (ie Aivru_Voi_edit functions)
  2  */
  3 
  4 #include <stdio.h>
  5 #include <tina/sys.h>
  6 #include <tina/sysfuncs.h>
  7 #include <tina/math.h>
  8 #include <tina/mathfuncs.h>
  9 #include <tina/vision.h>
 10 #include <tina/visionfuncs.h>
 11 #include <tina/cvr.h>
 12 #include <tina/snakefuncs.h>
 13 
 14 /* FORWARD REFS  */
 15 static Vec2 button_down_notify(Vec2 mouse_pos);
 16 
 17 /* STATICS */
 18 static  Vec2(*kw_button_down_function) () = NULL;       /* Function called on
 19                                                          * button down */
 20 static void (*kw_snake_run_function) () = NULL; /* Function called when
 21                                                  * snake is run */
 22 static void (*contour_changed_fn) () = NULL;    /* Function called on
 23                                                  * snake changes */
 24 
 25 /* GLOBALS */
 26 
 27 /* EXTERNS */
 28 
 29 /* Provide the Aivru module with a callback function to notify of a
 30  * change (which may lead to interactive display updates) of the
 31  * current contour */
 32 void    Aivru_Voi_edit_contour_changed_fn_set(void (*function_new) ( /* ??? */ ))
 33 {
 34     /* Set the function to be called when the snake changes */
 35     contour_changed_fn = function_new;
 36 }
 37 
 38 /* Construct IcContour from current snake model */
 39 IcContour *Aivru_Voi_edit_contour_get(void)
 40 {
 41     /* Get iccontour as Tina Ddlist of Vec2 (edge string) */
 42     Kwsnake *kwsnake = kwsnake_get();
 43     Tstring *edge_string = es_of_kwsnake(kwsnake);
 44     IcContour *iccontour = edge_string_to_iccontour(edge_string);
 45 
 46     return iccontour;
 47 }
 48 
 49 /* Take a look at the current selected Aivru contour, represented as an
 50  * IcContour spline.  It is owned by the Aivru modules.  Facilitates
 51  * efficicent display. Copy the contour for a permanent record. */
 52 IcContour *Aivru_Voi_edit_contour_peek(void)
 53 {
 54     /* Get iccontour as kwsnake */
 55     return (IcContour *) kwsnake_get();
 56 }
 57 
 58 /* Pass a selected contour to the Aivru modules */
 59 void    Aivru_Voi_edit_contour_set(IcContour * iccontour)
 60 {
 61     Tstring *edge_string = iccontour_to_edge_string(iccontour);
 62 
 63     snake_create(edge_string);  /* Create & set current snake */
 64 }
 65 
 66 /* Pass image slices to Aivru modules & initialise. */
 67 void    Aivru_Voi_edit_image_init(IcImage * icimage)
 68 {
 69     Imstack *imstack = icimage_to_imstack(icimage);
 70 
 71     imstack_set(imstack);
 72 }
 73 
 74 /* Set current working slice. (If slice < first or slice >= end, then
 75  * do nowt) */
 76 void    Aivru_Voi_edit_image_select(int slice)
 77 {
 78     Imstack *imstack = imstack_get();
 79 
 80     if (imstack && imstack->first <= slice && slice < imstack->end)
 81     {
 82         imstack->slice = slice;
 83     }
 84 }
 85 
 86 /* Set mode in which AIVRU module is to interpret contour editing
 87  * events */
 88 void    Aivru_Voi_edit_interact_mode_set(int mode)
 89 {
 90     /* Set the function called on button down */
 91     switch (mode)
 92     {
 93         case PULL_CONTOUR:
 94         kw_button_down_function = kw_attract;
 95         break;
 96     case PUSH_CONTOUR:
 97         kw_button_down_function = kw_repel;
 98         break;
 99     default:
100         format("Aivru_Voi_edit_interact_mode_set: unknown mode: %d\n", mode);
101         break;
102     }
103 }
104 
105 /* Returns the exact position of the control point closest to the point
106  * given (which may be a point chosen by the user with the mouse). NB
107  * THIS FUNCTIONALITY NOT YET IMPLEMENTED. Currently it calls the
108  * button down function set by Aivru_Voi_edit_interact_mode_set. */
109 IcPoint Aivru_Voi_edit_position_down(IcPoint icpoint)
110 {
111     Vec2    vec2 = {Vec2_id};
112 
113     ICPOINT_TO_VEC2(icpoint, vec2);
114     vec2 = button_down_notify(vec2);
115     VEC2_TO_ICPOINT(vec2, icpoint);
116 
117     return icpoint;
118 }
119 
120 /* Used for real time graphic interaction only. */
121 IcPoint Aivru_Voi_edit_position_drag(IcPoint icpoint)
122 {
123     format("Aivru_Voi_edit_position_drag: incomplete\n");
124     return icpoint;
125 }
126 
127 /* Returns the exact position of the mouse up */
128 IcPoint Aivru_Voi_edit_position_up(IcPoint icpoint)
129 {
130     format("Aivru_Voi_edit_position_up: incomplete\n");
131     return icpoint;
132 }
133 
134 /* Quit Aivru modules & free all associated memory. (Does NOT free
135  * image data) */
136 void    Aivru_Voi_edit_quit(void)
137 {
138     format("Aivru_Voi_edit_quit: incomplete");
139     /* Destroy contour... */
140 
141     imstack_deep_destroy(imstack_get());        /* Free imstack BUT not
142                                                  * its image data */
143 }
144 
145 /* Set snake behaviour mode */
146 void    Aivru_Voi_edit_snake_mode_set(int mode)
147 {
148     switch (mode)
149     {
150         case SEEK_EDGE:
151         kw_snake_run_function = kw_orth_fn;
152         break;
153     case CORRELATE:
154         kwsnake_temp_fn();      /* Create a temporary snake */
155         kw_snake_run_function = kwsnake_corr_fn;
156         break;
157     case GROW_REGION:
158         kw_snake_run_function = kw_region_fn;
159         break;
160     default:
161         format("Aivru_Voi_edit_snake_mode_set: unknown mode %d\n", mode);
162         break;
163     }
164 }
165 
166 /* Run current active contours as snakes in specified mode. In current
167  * version only a single contour can be defined. */
168 void    Aivru_Voi_edit_snake_run(void)
169 {
170     if (kw_snake_run_function)
171     {
172         kw_snake_run_function();
173     } else
174     {
175         format("Aivru_Voi_edit_snake_run: kw_snake_run_function is NULL\n");
176     }
177 }
178 
179 /* Get snake scale  */
180 double  Aivru_Voi_edit_snake_scale_get(void)
181 {
182     return kw_sigma_get();
183 }
184 
185 /* Set snake scale */
186 void    Aivru_Voi_edit_snake_scale_set(double snake_scale)
187 {
188     kw_sigma_set(snake_scale);
189 }
190 
191 /* Get snake stiffness */
192 double  Aivru_Voi_edit_snake_stiffness_get(void)
193 {
194     return kw_beta_get();
195 }
196 
197 /* Set snake stiffness */
198 void    Aivru_Voi_edit_snake_stiffness_set(double snake_stiffness)
199 {
200     kw_beta_set(snake_stiffness);
201 }
202 
203 /* Get snake tension */
204 double  Aivru_Voi_edit_snake_tension_get(void)
205 {
206     return kw_alpha_get();
207 }
208 
209 /* Set snake tension */
210 void    Aivru_Voi_edit_snake_tension_set(double snake_tension)
211 {
212     kw_alpha_set(snake_tension);
213 }
214 
215 /* Call kw_button_down function  */
216 static Vec2 button_down_notify(Vec2 mouse_pos)
217 {
218     if (kw_button_down_function)
219     {
220         /* In snake edit mode kw_button_down_function is
221          * kw_{attract,repel} */
222         mouse_pos = kw_button_down_function(mouse_pos);
223     }
224     return mouse_pos;
225 }
226 
227 /* Call the snake change function */
228 void    contour_changed_notify(void)
229 {
230     if (contour_changed_fn)
231     {
232         contour_changed_fn();
233     } else
234     {
235         error("contour_changed_notify: contour_changed_fn is NULL\n", warning);
236     }
237 }
238 

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