HstFunction

HstFunction — a GObject to evaluate a 1D function in a given range

Synopsis


#include <gtk-hst/function.h>


            HstFunction;
            HstFunctionClass;
HstFunction* hst_function_new               (int n,
                                             double xmin,
                                             double xmax,
                                             Hst1DFunction ptr);
double      hst_function_eval               (HstFunction *f,
                                             double x);
int         hst_function_npts               (HstFunction *f);
double      hst_function_xmin               (HstFunction *f);
double      hst_function_xmax               (HstFunction *f);
double      hst_function_step               (HstFunction *f);
int         hst_function_find_bin           (HstFunction *f,
                                             double x);
double      hst_function_bin_center         (HstFunction *f,
                                             int ib);
int         hst_function_resize             (HstFunction *f,
                                             int width,
                                             int height);
gchar*      hst_function_get_name           (HstFunction *f);
void        hst_function_set_name           (HstFunction *f,
                                             gchar *name);
typedef     Tuple;
struct      Tuple_;
typedef     PointList;
struct      PointList_;
double      (*Hst1DFunction)                (double );


Object Hierarchy


  GObject
   +----HstFunction
         +----HstGraph
         +----HstHistogram
         +----HstFunction2D

Properties


  "func"                 gpointer              : Read / Write
  "name"                 gchararray            : Read / Write
  "nx"                   gint                  : Read / Write
  "range"                gpointer              : Read / Write
  "xmax"                 gdouble               : Read / Write
  "xmin"                 gdouble               : Read / Write
  "xstep"                gdouble               : Read / Write

Signals


"range-changed"
            void        user_function      (HstFunction *arg0,
                                            gpointer     user_data)      : Run first

Description

This is an object that wraps a 1D function and a range of validity for that function. The range is defined as an interval of evaluation and the number of points in which the function is evaluated. The range is the basis for defining an axis in a Histogram.

Details

HstFunction

typedef struct _HstFunction HstFunction;

The HstFunction struct contains the following fields. (These fields should be considered read-only. They should never be set by an application.)

double (*func)(double) A pointer to a 1D function
int nbin Number of bins
gdouble xmin Minimum value of the X range
gdouble xmax Maximum value of the X range
gdouble step Step
gchar *name Name of the function


HstFunctionClass

typedef struct {
    GObjectClass parent_class;
    
    double (*eval)(HstFunction *,double);
    void   (*array)(HstFunction *,Tuple *, double, double);
    int    (*resize)(HstFunction *,int w, int h);    

    /* signals */
    
    void (*range_changed)(HstFunction *);
} HstFunctionClass;

A HstFunction implements three methods which are used to evaluate the function, to return an array of points in order to draw the function

GObjectClass parent_class;
eval () This is the method that evaluates the function at the given value
array () Returns a list of points that serve to represent graphically the function
resize () This is the method that changes the size of the graphical representation.
range_changed ()

hst_function_new ()

HstFunction* hst_function_new               (int n,
                                             double xmin,
                                             double xmax,
                                             Hst1DFunction ptr);

This is a convenient function to create a HstFunction and setting its properties in one go.

n : number of bins
xmin : minimum value of the range
xmax : maximum value of the range
ptr : a pointer to a real value function
Returns : a HstFunction object

hst_function_eval ()

double      hst_function_eval               (HstFunction *f,
                                             double x);

f : a HstFunction object
x : value of x at which we want to evaluate the function
Returns : a double. The value of the function at x: f(x)

hst_function_npts ()

int         hst_function_npts               (HstFunction *f);

f : a HstFunction
Returns : the number of points of the function

hst_function_xmin ()

double      hst_function_xmin               (HstFunction *f);

f : a HstFunction
Returns : the lower value of the function range

hst_function_xmax ()

double      hst_function_xmax               (HstFunction *f);

f : a HstFunction
Returns : the upper value of the function range

hst_function_step ()

double      hst_function_step               (HstFunction *f);

f : a HstFunction
Returns : the step or binwidth of the function

hst_function_find_bin ()

int         hst_function_find_bin           (HstFunction *f,
                                             double x);

f : a HstFunction
x : the value
Returns : the bin that includes x

hst_function_bin_center ()

double      hst_function_bin_center         (HstFunction *f,
                                             int ib);

f : a HstFunction
ib : bin number
Returns : the center of the i-th bin

hst_function_resize ()

int         hst_function_resize             (HstFunction *f,
                                             int width,
                                             int height);

This function is used to change the size of the graphical representation of the function

f : a HstFunction object
width : the new width
height : the new height
Returns : an integer

hst_function_get_name ()

gchar*      hst_function_get_name           (HstFunction *f);

f : a HstFunction
Returns : the name of the function

hst_function_set_name ()

void        hst_function_set_name           (HstFunction *f,
                                             gchar *name);

Sets a name for a function

f : a HstFunction
name : the new name for the function

Tuple

typedef struct Tuple_ Tuple;


struct Tuple_

struct Tuple_ {
    int n;
    PointList *P;
};


PointList

typedef struct PointList_ PointList;


struct PointList_

struct PointList_ {
    double x;
    double y;
};


Hst1DFunction ()

double      (*Hst1DFunction)                (double );

Param1 :
Returns :

Property Details

The "func" property

  "func"                 gpointer              : Read / Write

A pointer to a double Hst1DFunction function that is to be evaluated by HstFunction


The "name" property

  "name"                 gchararray            : Read / Write

The name of the function.

Default value: "<unnamed>"


The "nx" property

  "nx"                   gint                  : Read / Write

The number of bins in the X axis

Allowed values: [1,999999]

Default value: 10


The "range" property

  "range"                gpointer              : Read / Write

The range of the funtion represents any of nx, xmin, xmax. If any of those change, there will be a range-change notification.


The "xmax" property

  "xmax"                 gdouble               : Read / Write

The maximum value of X definig the range of validity of the function

Default value: 1


The "xmin" property

  "xmin"                 gdouble               : Read / Write

The minimum value of X definig the range of validity of the function

Default value: 0


The "xstep" property

  "xstep"                gdouble               : Read / Write

step en X.

Default value: 1

Signal Details

The "range-changed" signal

void        user_function                  (HstFunction *arg0,
                                            gpointer     user_data)      : Run first

This signal is emitted whenever any of the properties that define the range of the histogram change. That applies to nx, xmin or xmax.

user_data : user data set when the signal handler was connected.