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

Linux Cross Reference
Tina6/tina-tools/tinatool/wdgts/gtk2/wdgtsGtk_tw_curve.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    :  
 37  * Date    :  
 38  * Version :  
 39  * CVS Id  :  
 40  *
 41  * Notes :
 42  *
 43  * Extra widgets for the mousetool: curve widget based on the GTK+ curve widget
 44  *
 45  *********
 46 */
 47 /**
 48  *  @file  wdgtsGtk_tw_curve.c
 49  *  @brief Define and create curve widget and some associated buttons.
 50  *
 51  *  Curve widget:
 52  *
 53  *  Functions to create a GTK curve widget and to define its use by linking it into the TINA callback 
 54  *  system using a Tw_callback struct.  Also defines a set of buttons to change the curve type to a 
 55  *  spline, piecewise linear, and to reset to a linear ramp.  The Gtk curve widget has no "changed"
 56  *  signal, and so a fourth button ("apply") is defined to return the current curve to the application
 57  *  by calling the "set" function.
 58  * 
 59  *  Note: there are a couple of problems with this widget, largely due to the limitations of Gtk.  First,
 60  *  the size of the widget is linked to the specified x and y ranges of the curve.  Therefore, although 
 61  *  the y range for most purposes should be 0 to 1, the range used by Gtk has been specified to be 0 to 
 62  *  100, necessitating some multiplication and division of the data vector as it is passed around and 
 63  *  and printed to macros.  Second, when the curve is reset by the application or via a macro, the curve 
 64  *  type is set to freehand: this results in some loss of accuracy.  There is no function to get the 
 65  *  current curve type from the curve widget, so this cannot be easily fixed.
 66  *
 67  *  UPDATE 29/01/2010: The GtkCurve structure contains two representations of the curve: a set of control
 68  *  points used by the spline and linear curve types, and a set of points that interpolate between the 
 69  *  control points or are used in drawing freehand curves.  There is no direct mechanism to get or set 
 70  *  the control points: the gtk_curve_get/set_vector functions use the whole curve, and the set function 
 71  *  changes the curve type to freehand.  Switching from freehand to spline or linear uses exactly the nine 
 72  *  most significant points on the curve as control points.  The result of this is that a curve cannot be 
 73  *  accurately saved and then reset.  So, curve_apply_cmnd and curve_apply_prnt work by using a 256-element 
 74  *  vector of floats representing the curve and saving/reading the whole thing to/from the macro file, 
 75  *  leaving the curve type as freehand.  Switching this back to a spline or linear type results in a curve 
 76  *  with nine control points, regardless of the number of control points in the original.  
 77  *
 78  *  As a work-around, short_curve_apply_cmnd and short_curve_apply_prnt read/write the control point array 
 79  *  of the GtkCurve structure directly.  In order to get Gtk to redraw the curve, gtk_curve_set_curve_type 
 80  *  is used: if the curve type in the macro is spline, the curve type of the widget is set to linear before 
 81  *  reading, then the control point array is modified, and finally the curve type is set to spline (opposite 
 82  *  way around for linear type).  This will eventually allow curves to be stored and recalled, so that one
 83  *  curve widget can control multiple lookup tables for use in full colour rendering.
 84  *
 85  *  For this mechanism to work, it is vital that the curve type never becomes freehand.
 86  *
 87  */
 88 
 89 
 90 #include <gtk/gtk.h>
 91 
 92 #include <stdio.h>
 93 #include <gtk/gtk.h>
 94 #include <tina/sys/sysDef.h>
 95 #include <tina/sys/sysPro.h>
 96 #include <tinatool/tlbase/tlbaseDef.h>
 97 #include <tinatool/tlbase/tlbasePro.h>
 98 #include <tinatool/wdgts/gtk2/wdgts_GtkDef.h>
 99 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_tool.h>
100 #include <tinatool/wdgts/gtk2/wdgtsGtk_tw_command.h>
101 
102 #include "wdgtsGtk_tw_curve.h"
103 
104 #if HAVE_CONFIG_H
105 #   include <config.h>
106 #endif
107 
108 
109 /**
110  * @brief Call the function to set or reset the curve type.
111  * @param twc Pointer to Tw_callback associated with the curve widget.
112  *
113 */
114 static void curve_button_call(Tw_callback *twc)
115 {
116   tw_set_tool((GtkWidget *)twc->data2);
117   (*twc->func)(twc->data1);
118 }
119 
120 
121 /**
122  * @brief Replay curve type button press from macro file.
123  * @param twc Pointer to Tw_callback associated with the curve widget.
124  *
125 */
126 static void curve_button_cmnd(Tw_callback *twc)
127 {
128   tw_set_tool((GtkWidget *)twc->data2);
129   (*twc->func)(twc->data1);
130 }
131 
132 
133 /**
134  * @brief Record curve type button press in macro file.
135  * @param twc Pointer to Tw_callback associated with the curve widget.
136  *
137 */
138 static void curve_button_prnt(FILE * fp, Tw_callback *twc)
139 {
140   (void) fprintf(fp, "%s\n", twc->name);
141 }
142 
143 
144 /**
145  * @brief Pass the current curve to the application via the setting function.
146  * @param twc Pointer to Tw_callback associated with the curve widget.
147  *
148  * Notes: memory is allocated here, and so should be freed by the caller.
149  *
150 */
151 static void curve_apply_call(Tw_callback * twc)
152 {
153   float  *x;
154   int i, xlen;
155   void   (*set)() = (void (*) ()) twc->func;
156 
157   xlen = *((int *)twc->data1);
158   x = fvector_alloc(0, xlen);
159   gtk_curve_get_vector(GTK_CURVE(twc->widget), xlen, x);
160   for(i=0; i<xlen; i++)
161   {
162     x[i] = x[i]/100.0;
163   }
164   (*set) (x, xlen);
165 }
166 
167 
168 /**
169  * @brief Reset the curve from a macro file (as a long freehand curve).
170  * @param twc   Pointer to Tw_callback associated with the apply button.
171  * @param args  Pointer to required data, stored in the macro file.
172  *
173  * Note: curve length will be 256 for macro purposes.
174  *
175  * Note: gtk_curve_set_vector sets the curve type to freehand
176  *
177 */
178 static void curve_apply_cmnd(Tw_callback * twc, char *args)
179 {
180   char   name[64];
181   int    i, xlen=256, n;
182   float  *x = fvector_alloc(0, xlen);
183 
184   (void) sscanf(args, "%s%n", name, &n);
185   args += n;
186   for(i=0; i<xlen; i++)
187   {
188     (void)sscanf(args, "%f%n", &x[i], &n);
189     args += n;
190   }
191   gtk_curve_set_vector(GTK_CURVE(twc->widget), xlen, x);
192   fvector_free(x, 0);
193 
194   curve_apply_call(twc);
195 }
196 
197 
198 /**
199  * @brief Record the current curve in a macro file (as a long freehand curve).
200  * @param fp    Pointer to the macro file.
201  * @param twc   Pointer to Tw_callback associated with the apply button.
202  *
203  * Notes: curve length will be 256 for macro purposes.
204  *
205 */
206 static void curve_apply_prnt(FILE * fp, Tw_callback * twc)
207 {
208   int    i, xlen = 256;
209   float  *x = fvector_alloc(0, xlen);
210 
211   (void) fprintf(fp, "%s ", twc->name);
212   gtk_curve_get_vector(GTK_CURVE(twc->widget), xlen, x);
213 
214   for(i=0; i<xlen; i++)
215   {
216     (void) fprintf(fp, "%f ", x[i]);
217   }
218   (void) fprintf(fp, " \n");
219 
220   fvector_free(x, 0);
221 }
222 
223 
224 /**
225  * @brief Reset the curve from a macro file (as a control point array).
226  * @param twc   Pointer to Tw_callback associated with the apply button.
227  * @param args  Pointer to required data, stored in the macro file.
228  *
229  * Notes: this version of the function accesses the control points of the 
230  * GtkCurve structure directly in order to avoid the limitations of Gtk
231  * (see comments at the top of the file).
232  *
233 */
234 static void short_curve_apply_cmnd(Tw_callback * twc, char *args)
235 {
236   GtkCurve *c = GTK_CURVE(twc->widget);
237   char   name[64];
238   int num, type, i, n;
239   float x, y;
240 
241   (void) sscanf(args, "%s%n", name, &n);
242   args += n;
243   (void) sscanf(args, "%d%n", &num, &n);
244   args += n;
245   (void) sscanf(args, "%d%n", &type, &n);
246   args += n;
247 
248   if(type==GTK_CURVE_TYPE_SPLINE)
249   {
250     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_LINEAR);
251   }
252   else
253   {
254     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_SPLINE);
255   }
256 
257   g_free (c->ctlpoint);
258   c->num_ctlpoints = num;
259   c->ctlpoint = g_malloc (num * sizeof (c->ctlpoint[0]));
260 
261   for(i=0; i<num; i++)
262   {
263     (void) sscanf(args, "%f%n", &x, &n);
264     args += n;
265     (void) sscanf(args, "%f%n", &y, &n);
266     args += n;
267     c->ctlpoint[i][0] = x;
268     c->ctlpoint[i][1] = y;
269   }
270 
271   if(type==GTK_CURVE_TYPE_SPLINE)
272   {
273     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_SPLINE);
274   }
275   else
276   {
277     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_LINEAR);
278   }
279 
280   curve_apply_call(twc);
281 }
282 
283 
284 /**
285  * @brief Record the current curve in a macro file (as a control point array).
286  * @param fp    Pointer to the macro file.
287  * @param twc   Pointer to Tw_callback associated with the apply button.
288  *
289  * Notes: this version of the function accesses the control points of the
290  * GtkCurve structure directly in order to avoid the limitations of Gtk
291  * (see comments at the top of the file).
292  *
293  * Data stored to the macro file:
294  *
295  * - name of the widget
296  * - number of control points (int)
297  * - type of curve
298  * - vector of control points (x0, y0, x1, y1,..., x(n-1), y(n-1); n=number of control points)
299  *
300 */
301 static void short_curve_apply_prnt(FILE * fp, Tw_callback * twc)
302 {
303   GtkCurve *c = GTK_CURVE(twc->widget);
304   int i;
305 
306   (void) fprintf(fp, "%s %d %d ", twc->name, c->num_ctlpoints, c->curve_type);
307 
308   for(i=0; i<c->num_ctlpoints; i++)
309   {
310     (void) fprintf(fp, "%f %f ", c->ctlpoint[i][0], c->ctlpoint[i][1]);
311   }
312   (void) fprintf(fp, " \n");
313 }
314 
315 
316 /**
317  * @brief Set the curve type to spline.
318  * @param curve the curve to which the type change will be applied.
319  *
320 */
321 static void set_curve_spline(void *curve)
322 {
323    gtk_curve_set_curve_type(GTK_CURVE(curve), GTK_CURVE_TYPE_SPLINE);
324 }
325 
326 
327 /**
328  * @brief Set the curve type to piecewise linear.
329  * @param curve the curve to which the type change will be applied.
330  *
331 */
332 static void set_curve_linear(void *curve)
333 {
334    gtk_curve_set_curve_type(GTK_CURVE(curve), GTK_CURVE_TYPE_LINEAR);
335 }
336 
337 
338 /**
339  * @brief Reset the curve to a linear ramp.
340  * @param curve the curve to which the change will be applied.
341  *
342 */
343 static void set_curve_reset(void *curve)
344 {
345    gtk_curve_reset(GTK_CURVE(curve));
346 }
347 
348 
349 /**
350  * @brief Create a Gtk curve widget and some associated buttons to set the curve type.
351  * @param  name    String to be used as curve widget identifier and label.
352  * @param  set()   Pointer to the function to be called when "apply" is clicked.
353  * @param  length  Length of the vector used to contain the curve data.
354  * @return Tw_callback  Pointer to new Tw_callback associated with the apply button for this curve.
355  *
356  * Create a Gtk curve widget, contained within a labelled frame, and some associated 
357  * buttons to set the curve type to spline, piecewise linear, or to reset to a linear 
358  * ramp.  There is no "changed" signal for the Gtk curve widget, and so the effects of
359  * changes to the curve are enforced by clicking the "apply" button, which passes a 
360  * float vector of length "length" to the function "set".
361  * 
362  * For macro purposes, the current curve is recorded in a macro file only when the "apply" 
363  * button is pressed.  The callback is also associated with the "apply" button rather than 
364  * the curve itself.
365  *
366 */
367 Tw_callback *tw_curve(char *name, void (*set)(), int length)
368 {
369   Tw_callback  *twc_spline, *twc_linear, *twc_reset, *twc_apply;
370   GtkWidget   *tool = tw_get_tool();
371   GtkWidget   *panel = tw_get_panel();
372   GtkWidget   *curve;
373   GtkWidget   *cbox;
374   GtkWidget   *curve_frame;
375   GtkWidget   *buttox;
376   GtkWidget   *spline_button;
377   GtkWidget   *linear_button;
378   GtkWidget   *reset_button;
379   GtkWidget   *apply_button;
380   char        *fullname = tw_extend_fullname(tw_get_toolname(), name);
381   char        *spline_fullname = tw_extend_fullname(fullname, "spline");
382   char        *linear_fullname = tw_extend_fullname(fullname, "linear");
383   char        *reset_fullname = tw_extend_fullname(fullname, "reset");
384   char        *apply_fullname = tw_extend_fullname(fullname, "apply");
385 
386   int *xlen = ivector_alloc(0, 1);
387   xlen[0] = length;
388 
389   curve_frame = gtk_frame_new(name);
390   gtk_container_set_border_width(GTK_CONTAINER(curve_frame), 0);
391   gtk_box_pack_start(GTK_BOX(panel), curve_frame, FALSE, FALSE, 0);
392 
393   cbox = gtk_hbox_new(FALSE, 0);
394   gtk_container_add(GTK_CONTAINER(curve_frame), cbox);
395 
396   curve = gtk_curve_new();
397   gtk_curve_set_range(GTK_CURVE(curve), 0.0, 256.0, 0.0, 100.0);
398   gtk_box_pack_start(GTK_BOX(cbox), curve, FALSE, FALSE, 0);
399 
400   buttox = gtk_vbox_new(FALSE, 0);
401   gtk_box_pack_end(GTK_BOX(cbox), buttox, FALSE, FALSE, 0);
402 
403   /* Add some buttons like the ones for gtk_gamma_curve, to set the curve type and reset the curve */
404 
405   spline_button = gtk_button_new_with_label("spline");
406   gtk_box_pack_start(GTK_BOX(buttox), spline_button, FALSE, FALSE, 0);
407   gtk_widget_show(spline_button);
408   twc_spline = tw_callback_make(spline_fullname, spline_button, curve_button_call, curve_button_cmnd, curve_button_prnt,
409                                 set_curve_spline, (void *)curve, (void *)tool);
410   gtk_signal_connect(GTK_OBJECT(spline_button), "clicked", GTK_SIGNAL_FUNC(tw_gtk_callback), (gpointer)twc_spline);
411 
412   linear_button = gtk_button_new_with_label("linear");
413   gtk_box_pack_start(GTK_BOX(buttox), linear_button, FALSE, FALSE, 0);
414   gtk_widget_show(linear_button);
415   twc_linear = tw_callback_make(linear_fullname, linear_button, curve_button_call, curve_button_cmnd, curve_button_prnt,
416                                 set_curve_linear, (void *)curve, (void *)tool);
417   gtk_signal_connect(GTK_OBJECT(linear_button), "clicked", GTK_SIGNAL_FUNC(tw_gtk_callback), (gpointer)twc_linear);
418 
419   reset_button = gtk_button_new_with_label("reset");
420   gtk_box_pack_start(GTK_BOX(buttox), reset_button, FALSE, FALSE, 0);
421   gtk_widget_show(reset_button);
422   twc_reset = tw_callback_make(reset_fullname, reset_button, curve_button_call, curve_button_cmnd, curve_button_prnt,
423                                 set_curve_reset, (void *)curve, (void *)tool);
424   gtk_signal_connect(GTK_OBJECT(reset_button), "clicked", GTK_SIGNAL_FUNC(tw_gtk_callback), (gpointer)twc_reset);
425 
426   /* Changes to the curve do not result in a signal, and so we need an extra button to call the function 
427      associated with the curve widget */
428 
429   apply_button = gtk_button_new_with_label("apply");
430   gtk_box_pack_start(GTK_BOX(buttox), apply_button, FALSE, FALSE, 0);
431   gtk_widget_show(apply_button);
432 
433   twc_apply = tw_callback_make(apply_fullname, curve, curve_apply_call, short_curve_apply_cmnd, 
434                                short_curve_apply_prnt, (void *)set, (void *)xlen, NULL);
435 
436   gtk_signal_connect(GTK_OBJECT(apply_button), "clicked", GTK_SIGNAL_FUNC(tw_gtk_callback), (gpointer) twc_apply);
437 
438   /* Show the remaining widgets */
439 
440   gtk_widget_show(buttox);
441   gtk_widget_show(curve);
442   gtk_widget_show(cbox);
443   gtk_widget_show(curve_frame);
444 
445   cvector_free(fullname, 0);
446   return twc_apply;
447 }
448 
449 
450 /**
451  * @brief Set a curve widget to a user-specified curve (from a float vector).
452  * @param Tw_callback The callback associated with the "apply" button of the curve widget.
453  * @param x           A float vector of length xlen containing the curve to set in the widget.
454  * @param xlen        The length of the vector x.
455  *
456  * Notes: this function does not call the apply function, in order to avoid the potential 
457  * memory leak (the apply function allocates memory, which will not be needed as a vector 
458  * has already been allocated to be the x argument to this function).
459  *
460 */
461 void tw_curve_set_vector(Tw_callback * twc, float *x, int xlen)
462 {
463   int i;
464   float *xb = fvector_alloc(0, xlen);
465 
466   if(twc==NULL) return;
467 
468   for(i=0; i<xlen; i++)
469   {
470     xb[i] = x[i]*100.0;
471   }
472 
473   gtk_curve_set_vector(GTK_CURVE(twc->widget), xlen, xb);
474   fvector_free(xb, 0);
475 }
476 
477 
478 /*
479  *
480  * Note: the next five functions allow curves to be stored/reset from/to a curve widget, so that
481  *       one widget can be used to control multiple lookup tables.
482  *
483 */
484 
485 
486 /**
487  * @brief Return a float vector representation of the curve.
488  * @param twc Pointer to Tw_callback associated with the curve widget.
489  *
490  * Notes: memory is allocated here, and so should be freed by the caller.
491  *
492 */
493 float  *tw_curve_get_vector(Tw_callback * twc)
494 {
495   float  *x;
496   int i, xlen;
497 
498   xlen = *((int *)twc->data1);
499   x = fvector_alloc(0, xlen);
500   gtk_curve_get_vector(GTK_CURVE(twc->widget), xlen, x);
501   for(i=0; i<xlen; i++)
502   {
503     x[i] = x[i]/100.0;
504   }
505   return x;
506 }
507 
508 
509 
510 /**
511  * @brief Free a Tw_curve_store structure.
512  * @param Tw_curve_store The Tw_curve_store structure to free.
513  *
514 */
515 void tw_curve_store_free(Tw_curve_store *curve_store)
516 {
517     if(curve_store==NULL) return;
518 
519     if(curve_store->points != NULL) farray_free(curve_store->points, 0, 0, curve_store->npoints, 2);
520     rfree(curve_store);
521 }
522 
523 
524 /**
525  * @brief Return the control points and type of a curve widget.
526  * @param Tw_callback The callback associated with the "apply" button of the curve widget.
527  * @return Tw_curve_store A structure containing the control points etc. of the curve.
528  *
529  * Note: memory is allocated here, and will have to be freed by the caller.
530  *
531 */
532 Tw_curve_store *tw_curve_get(Tw_callback * twc)
533 {
534     Tw_curve_store *curve_store=NULL;
535     GtkCurve *c = NULL;
536     int i, num;
537 
538     if(twc==NULL) return NULL;
539     c = GTK_CURVE(twc->widget);
540 
541     curve_store = ralloc(sizeof(Tw_curve_store));
542     num = curve_store->npoints = c->num_ctlpoints;
543     if(c->curve_type==GTK_CURVE_TYPE_SPLINE)
544     {
545         curve_store->type = 0;
546     }
547     else /* Assuming linear */
548     {
549         curve_store->type = 1;
550     }
551 
552     curve_store->points = farray_alloc(0, 0, num, 2);
553     for(i=0; i<num; i++)
554     {
555         curve_store->points[i][0] = c->ctlpoint[i][0];
556         curve_store->points[i][1] = c->ctlpoint[i][1];
557     }
558 
559     return curve_store;
560 }
561 
562 
563 /**
564  * @brief Set a curve widget to a user-specified curve (from control points).
565  * @param Tw_callback The callback associated with the "apply" button of the curve widget.
566  * @param curve_store A Tw_curve_store structure containing the control points etc. of the curve.
567  *
568  * Note that this does not free the stored curve, and does not call the apply function, as it is
569  * intended to allow storage and display of multiple curves on a single curve widget.
570  *
571 */
572 void tw_curve_set(Tw_callback * twc, Tw_curve_store *curve_store)
573 {
574   GtkCurve *c=NULL;
575   int i;
576 
577   if(twc==NULL) return;
578   c = GTK_CURVE(twc->widget);
579 
580   if(curve_store->type==0)
581   {
582     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_LINEAR);
583   }
584   else
585   {
586     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_SPLINE);
587   }
588 
589   g_free (c->ctlpoint);
590   c->num_ctlpoints = curve_store->npoints;
591   c->ctlpoint = g_malloc (curve_store->npoints * sizeof (c->ctlpoint[0]));
592 
593   for(i=0; i<curve_store->npoints; i++)
594   {
595     c->ctlpoint[i][0] = curve_store->points[i][0];
596     c->ctlpoint[i][1] = curve_store->points[i][1];
597   }
598 
599   if(curve_store->type==0)
600   {
601     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_SPLINE);
602   }
603   else
604   {
605     gtk_curve_set_curve_type(c, GTK_CURVE_TYPE_LINEAR);
606   }
607 }
608 
609 
610 /**
611  * @brief Set a curve widget to a user-specified curve (from control points).
612  * @param Tw_callback The callback associated with the "apply" button of the curve widget.
613  *
614  * Note: the above functions are designed to allow multiple curves to be displayed
615  * using a single curve widget, in which case the curve should be redisplayed without
616  * calling its apply function.  However, in order to allow the control points of a 
617  * curve to be saved to a file and reloaded (in the options saver for the volume
618  * renderer options dialog box) we need a way to call the apply function once a 
619  * curve had been loaded.  The "apply" function itself is not suitable as it does 
620  * not check its parameters (they are correct by default if it is called via the
621  * "apply" button of the curve widget).  Therefore, this function provides a 
622  * wrapper with checks for the parameters.
623  *
624 */
625 void tw_curve_apply(Tw_callback * twc)
626 {
627   if(twc!=NULL)
628   {
629     curve_apply_call(twc);
630   }
631 }
632 

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