Example #1
0
/* NB: returns -1, 0, 1 if value is less, within, or outside the count range */
gint count_insert(gdouble value, gpointer data)
{
gint n;
gdouble offset;
struct count_pak *count = data;

g_assert(count != NULL);

if (value < count->start)
  return(-1);
if (value > count->stop)
  return(1);

offset = value - count->start;
offset /= count->step;

n = nearest_int(offset);

g_assert(n >= 0);

if (n >= count->size)
  {
printf("BAD VALUE = %f : size = %d\n", value, n);
  }

g_assert(n < count->size);

*(count->bins+n) += 1; 

return(0);
}
Example #2
0
gpointer count_new(gdouble start, gdouble stop, gdouble step)
{
struct count_pak *count;

g_assert(stop > step);
g_assert(stop-step >= step);
g_assert(step >= 0.0);

count = g_malloc(sizeof(struct count_pak));

/* copy extents */
count->start = start;
count->stop = stop;
count->step = step;

/* compute and allocate bin array */
count->size = nearest_int (0.5 + ((stop-start) / step) );
count->bins = g_malloc0(count->size * sizeof(gint));

#if DEBUG_COUNT_NEW
printf("new count from: %f - %f, step: %f, size: %d\n", start, stop, step, count->size); 
#endif

return(count);
}
Example #3
0
void gui_siesta_slider_changed(GtkWidget *w, gpointer dialog)
{
    gint m;
    struct model_pak *model;

    g_assert(w != NULL);
    g_assert(dialog != NULL);

    model = dialog_model(dialog);

    m = nearest_int(gtk_range_get_value(GTK_RANGE(w)));
    model->siesta.current_animation = m-1;   /* 1..n range -> 0..n-1 */

    gui_siesta_frequency_set(dialog);
    gui_siesta_mode_show(NULL, dialog);
}
Example #4
0
/* NB: returns -1, 0, 1 if value is less, within, or outside the count range */
gint count_insert(gdouble value, gpointer data)
{
gint n;
gdouble offset;
struct count_pak *count = data;

g_assert(count != NULL);

if (value < count->start)
  return(-1);
if (value > count->stop)
  return(1);

offset = value - count->start;
offset /= count->step;

n = nearest_int(offset);

/*
g_assert(n >= 0);
g_assert(n < count->size);
if (n >= count->size)
  printf("BAD VALUE = %f : size = %d (max=%d)\n", value, n, count->size);
*/
/* n can be == count->size if user gives a mismatched interval */
/* eg a step size that doesnt fit nicely between start and stop */

/* CURRENT - ignore if it doesnt fit into a bin */
if (n >= 0 && n < count->size)
  {
  *(count->bins+n) += 1; 
  count->sum++;
  }

return(0);
}
Example #5
0
void camera_waypoint_animate(gint frames, gint overwrite, struct model_pak *model)
{
gint i;
gdouble a, af, v[3], e[3], o[3], tmp[3];
gdouble jf, jv[3], x[3], mat[9];
GSList *list, *journey;
struct camera_pak *cam, *cam1, *cam2;

/* checks */
g_assert(model != NULL);
g_assert(frames > 0);
if (g_slist_length(model->waypoint_list) < 2)
  {
  gui_text_show(ERROR, "You need to make at least 2 waypoint.\n");
  return;
  }

/* close any active animation dialog */
dialog_destroy_type(ANIM);

#if DEBUG_CAMERA_ANIMATE
printf("frames for each traversal: %d\n", frames);
#endif

list = model->waypoint_list;
cam1 = list->data;
list = g_slist_next(list);

/* create the camera journey */
journey = NULL;
while (list)
  {
  cam2 = list->data;

/* setup camera journey vector */
  ARR3SET(jv, cam2->x);
  ARR3SUB(jv, cam1->x);

/* add starting camera over journey leg */
  for (i=0 ; i<frames ; i++)
    {
/* journey fraction */
    jf = i;
    jf /= frames;

    ARR3SET(x, jv);
    VEC3MUL(x, jf);    

    cam = camera_dup(cam1);
    ARR3ADD(cam->x, x);

    journey = g_slist_prepend(journey, cam);
    }
 
/* approx 5 degrees */
#define ROTATION_INCREMENT 0.08727
/* (v x e plane alignment) */
proj_vop(v, cam2->v, cam1->o);
a = via(v, cam1->v, 3);

/* compute rotation increment */
af = (gint) nearest_int(a / ROTATION_INCREMENT);
if (!af)
  af = 1.0;

/* test rotation sense */
matrix_v_rotation(mat, cam1->o, a);
ARR3SET(tmp, cam1->v);
vecmat(mat, tmp);
if (via(tmp, v, 3) > 0.1)
  a *= -1.0;

/* build rotaton */
matrix_v_rotation(mat, cam1->o, a/af);

/* apply to camera */
ARR3SET(v, cam1->v);
ARR3SET(e, cam1->e);
for (i=af ; i-- ; )
  {
  cam = camera_dup(cam1);
  ARR3SET(cam->x, cam2->x);

  vecmat(mat, v);
  vecmat(mat, e);

  ARR3SET(cam->v, v);
  ARR3SET(cam->e, e);

  journey = g_slist_prepend(journey, cam);
  }

/* TODO - apply elevation to get v in complete coincidence */
/* rotate about e to achieve coincidence */
a = via(v, cam2->v, 3);

/* compute rotation increment */
af = (gint) nearest_int(a / ROTATION_INCREMENT);
if (!af)
  af = 1.0;

/* test rotation sense */
matrix_v_rotation(mat, e, a);
ARR3SET(tmp, v);
vecmat(mat, tmp);
if (via(tmp, cam2->v, 3) > 0.1)
  a *= -1.0;

/* build rotaton */
matrix_v_rotation(mat, e, a/af);

/* apply to camera */
ARR3SET(o, cam1->o);
for (i=af ; i-- ; )
  {
  cam = camera_dup(cam1);
  ARR3SET(cam->x, cam2->x);

  vecmat(mat, v);
  vecmat(mat, o);

  ARR3SET(cam->v, v);
  ARR3SET(cam->o, o);
  ARR3SET(cam->e, e);

  journey = g_slist_prepend(journey, cam);
  }

/* endpoint camera */
  journey = g_slist_prepend(journey, camera_dup(cam2));

/* get next journey leg */
  cam1 = cam2;
  list = g_slist_next(list);
  }
journey = g_slist_reverse(journey);

if (overwrite)
  {
  free_slist(model->transform_list);
  model->transform_list = journey;
  }
else
  model->transform_list = g_slist_concat(model->transform_list, journey);

model->num_frames = g_slist_length(model->transform_list);
model->animation = TRUE;

redraw_canvas(SINGLE);
}
Example #6
0
 const double delta_x( const double x )
 {
   return x - nearest_int(x);
 }
Example #7
0
 const double nearest_even( const double s )
 {
   return 2. * nearest_int( s / 2. );
 }