Example #1
0
void gui_siesta_mode_show(GtkWidget *w, gpointer dialog)
{
    gint i, atom, state;
    gdouble scale, x1[3], x2[3], colour[3];
    gpointer button, spin;
    GSList *list;
    struct core_pak *core;
    struct spatial_pak *spatial;
    struct model_pak *model;

    g_assert(dialog != NULL);

    model = dialog_model(dialog);
    g_assert(model != NULL);

    button = dialog_child_get(dialog, "phonon_toggle");
    g_assert(button != NULL);

    spatial_destroy_by_label("siesta_phonons", model);

    state = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
    if (!state)
    {
        redraw_canvas(SINGLE);
        return;
    }

    spin = dialog_child_get(dialog, "phonon_scaling");
    scale = SPIN_FVAL(spin);

    /* create & init the spatial object */
    spatial = spatial_new("siesta_phonons", SPATIAL_VECTOR, 2, TRUE, model);

    atom = 0;
    /* get eigenvectors from all atoms */
    for (list=model->cores ; list; list=g_slist_next(list))
    {
        core = list->data;
        ARR3SET(x1, core->x);

        /* get current eigenvector */
        i = model->siesta.sorted_eig_values[model->siesta.current_animation];
        x2[0] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom, i);
        x2[1] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom+1, i);
        x2[2] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom+2, i);
        atom++;

        /* compute coords */
        VEC3MUL(x2, scale);
        vecmat(model->ilatmat, x2);
        ARR3ADD(x2, x1);
        /* add to spatial */
        spatial_vertex_add(x2, colour, spatial);
        spatial_vertex_add(x1, colour, spatial);
    }

    /* drawing update */
    coords_compute(model);
    redraw_canvas(SINGLE);
}
Example #2
0
void MainWindow::start_game(QString music_name)
{
    cur_scene = game;

    sound_menu->stop();
    Phonon::MediaObject *sound_start = new Phonon::MediaObject(this);
    createPath(sound_start, new Phonon::AudioOutput(Phonon::MusicCategory, this));
    sound_start->setCurrentSource(Phonon::MediaSource(":/sound/start.mp3"));
    sound_start->play();

    QDir dir_music(QDir::home().absoluteFilePath(QString(".musicman/songs/%1/").arg(music_name)));

    music_guitar = new Phonon::MediaObject(this);
    music_guitar->setCurrentSource(Phonon::MediaSource(dir_music.absoluteFilePath("guitar.mp3")));
    music_guitar_output =
        new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(music_guitar, music_guitar_output);

    music_song = new Phonon::MediaObject(this);
    music_song->setCurrentSource(Phonon::MediaSource(dir_music.absoluteFilePath("song.mp3")));
    music_song_output =
        new Phonon::AudioOutput(Phonon::MusicCategory, this);
    Phonon::createPath(music_song, music_song_output);

    canvas = new Canvas(this);
    Midi midi(dir_music.absoluteFilePath("notes.musicman").toStdString());
    midi.parse();
    canvas->setMidi(midi);
    canvas->setTotalTime(music_song->totalTime());
    canvas->resize(this->size());
    canvas->show();

    connect(timer, SIGNAL(timeout()), SLOT(redraw_canvas()));
    timer->start(20);
}
Example #3
0
void select_frame(GtkWidget *w, struct model_pak *model)
{
    FILE *fp=NULL;

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

#if DEBUG_SELECT_FRAME
    printf("request frame: %d, model: %p\n", model->cur_frame, model);
#endif

    /* FIXME - better way to cope with transform animations */
    if (!model->transform_list)
        fp = fopen(model->filename, "r");

    read_frame(fp, model->cur_frame, model);

    meas_graft_model(model);

    gui_active_refresh();

    redraw_canvas(SINGLE);

    if (!model->transform_list)
        fclose(fp);
}
Example #4
0
void gtk_refresh_images(GtkWidget *w, gpointer dummy)
{
struct model_pak *model;

model = sysenv.active_model;
g_assert(model != NULL);

/* atom colour/display updates */
space_make_images(CREATE, model);
coords_init(CENT_COORDS, model);
redraw_canvas(SINGLE);
}
Example #5
0
void camera_rotate_animate(gint axis, gdouble *angle, gint overwrite, struct model_pak *model)
{
gdouble a, radian[3];
GSList *journey;
struct camera_pak *camera;

g_assert(model != NULL);

dialog_destroy_type(ANIM);

/* TODO - angle checks */
ARR3SET(radian, angle);
VEC3MUL(radian, D2R);

journey = NULL;
for (a=radian[0] ; a<radian[1]+0.5*radian[2] ; a+=radian[2])
  {
  camera = camera_dup(model->camera);
  switch (axis)
    {
    case 1:
      quat_concat_euler(camera->q, ROLL, a);
      break;

    case 2:
      quat_concat_euler(camera->q, YAW, a);
      break;

    default:
      quat_concat_euler(camera->q, PITCH, a);
    }
  journey = g_slist_prepend(journey, camera);
  }

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
void gui_phonon_cleanup(struct model_pak *model)
{
GSList *list;
struct core_pak *core;

g_assert(model != NULL);

/* reset offsets */
for (list=model->cores ; list; list=g_slist_next(list))
  {
  core = list->data;
  VEC3SET(core->offset, 0.0, 0.0, 0.0);
  }
model->animating = FALSE;

/* recalc coords and adjust bond orientations */
coords_compute(model);
connect_midpoints(model);
redraw_canvas(SINGLE);
}
Example #7
0
void cb_make_asymmetric(GtkWidget *w, gpointer dummy)
{
GSList *list;
struct core_pak *core;
struct shel_pak *shel;
struct model_pak *model;

model = sysenv.active_model;

g_assert(model != NULL);

if (model->periodic)
  {
  for (list=model->cores ; list ; list=g_slist_next(list))
    {
    core = list->data;
    if (core->primary)
      continue;

    if (model->asym_on)
      core->status |= HIDDEN;
    else
      core->status &= ~HIDDEN;
    }
  for (list=model->shels ; list ; list=g_slist_next(list))
    {
    shel = list->data;
    if (shel->primary)
      continue;
    if (model->asym_on)
      shel->status |= HIDDEN;
    else
      shel->status &= ~HIDDEN;
    }
  }

/* update */
coords_compute(model);
redraw_canvas(SINGLE);
}
Example #8
0
void cb_space_image_spinner(GtkWidget *w, gpointer data)
{
gint i;
struct model_pak *model;

model = sysenv.active_model;
if (!model)
  return;

/* alter the spinner value */
i = GPOINTER_TO_INT(data);
g_assert(i >= 0);
g_assert(i < 6);
model->image_limit[i] = SPIN_FVAL(GTK_SPIN_BUTTON(w));

/* update only if this is a genuine call for perioidic image creation */
if (image_update)
  {
  space_make_images(CREATE, model);
  coords_init(CENT_COORDS, model);
  redraw_canvas(SINGLE);
  }
}
Example #9
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 #10
0
gint gui_phonon_loop(void)
{
gint current_phonon;
gdouble f;
gpointer ptr;
GSList *list, *xlist, *ylist, *zlist;
struct core_pak *core, *prim;
struct model_pak *model;

model = tree_model_get();
if (!model)
  return(FALSE);
if (!model->animating)
  {
  gui_phonon_cleanup(model);
  return(FALSE);
  }

//current_phonon = displayed_phonon;
current_phonon = model->current_phonon;

/* NB: list numbering starts from 0 */
ptr = g_slist_nth_data(model->phonons, current_phonon-1);
if (!ptr)
  {
#if DEBUG_PHONON_LOOP
printf("Bad phonon %d/%d\n",  current_phonon, g_slist_length(model->phonons));
#endif
  gui_phonon_cleanup(model);
  return(FALSE);
  }
if (!model->pulse_direction)
  {
  gui_phonon_cleanup(model);
  return(FALSE);
  }

/* setup scaling for this step */
model->pulse_count += model->pulse_direction;
if (model->pulse_count <= -sysenv.render.phonon_resolution)
  {
  model->pulse_count = -sysenv.render.phonon_resolution;
  model->pulse_direction = 1;
  }
if (model->pulse_count >= sysenv.render.phonon_resolution)
  {
  model->pulse_count = sysenv.render.phonon_resolution;
  model->pulse_direction = -1;
  }

f = sysenv.render.phonon_scaling;
f *= (gdouble) model->pulse_count;
f /= sysenv.render.phonon_resolution;

/* get eigenvectors from all atoms */
for (list=model->cores ; list; list=g_slist_next(list))
  {
  core = list->data;

/* get eigenvector list */
  if (core->primary)
    {
    xlist = core->vibx_list; 
    ylist = core->viby_list; 
    zlist = core->vibz_list; 
    }
  else
    {
    prim = core->primary_core;
    xlist = prim->vibx_list; 
    ylist = prim->viby_list; 
    zlist = prim->vibz_list; 
    }
  g_assert(xlist != NULL);
  g_assert(ylist != NULL);
  g_assert(zlist != NULL);

/* vibrational eigenvector */
  ptr = g_slist_nth_data(xlist, current_phonon-1);
  if (!ptr)
    {
    gui_phonon_cleanup(model);
    return(FALSE);
    }
  core->offset[0] = *((gdouble *) ptr);

  ptr = g_slist_nth_data(ylist, current_phonon-1);
  if (!ptr)
    {
    gui_phonon_cleanup(model);
    return(FALSE);
    }
  core->offset[1] = *((gdouble *) ptr);

  ptr = g_slist_nth_data(zlist, current_phonon-1);
  if (!ptr)
    {
    gui_phonon_cleanup(model);
    return(FALSE);
    }
  core->offset[2] = *((gdouble *) ptr);

/* pulse offset scaling */
  VEC3MUL(core->offset, f);
  vecmat(model->ilatmat, core->offset);

/* TODO - shell also? */
  }

/* recalc coords and adjust bond orientations */
coords_compute(model);
connect_midpoints(model);
redraw_canvas(SINGLE);

return(TRUE);
}
Example #11
0
gint anim_next_frame(struct model_pak *model)
{
    gulong time;
    gchar *text, *name;

    g_assert(model != NULL);

    /* increment and test if should we return to the start */
    model->cur_frame += model->anim_step;
    if (model->cur_frame >= model->num_frames)
        if (model->anim_loop)
            model->cur_frame = 1;

    /* continue until we run out of frames (or a stop is flagged) */
    if (model->cur_frame < model->num_frames && model->animating)
    {
#if DEBUG_DISPLAY_NEXT_FRAME
        printf("displaying [%d]\n", model->cur_frame);
#endif

        time = mytimer();

        /* if a dialog exists - update via the current frame spinner */
        if (dialog_exists(ANIM, model))
            gui_relation_update(model);
        else
        {
            /* otherwise, update manually */
            read_frame(model->afp, model->cur_frame, model);
            meas_graft_model(model);
            gui_active_refresh();
            redraw_canvas(SINGLE);
        }

        /* animation adjusted redraw time */
        time = mytimer() - time;
        model->redraw_cumulative += time;

        /* NEW - render to file */
        if (sysenv.render.animate)
        {
            text = g_strdup_printf("%s_%06d.pov", sysenv.render.animate_file, model->cur_frame);
            name = g_build_filename(sysenv.cwd, text, NULL);

            write_povray(name, model);

            /* NB: added this as jago keeps locking up on multi-frame renders */
            if (!sysenv.render.no_povray_exec)
                povray_exec(name);

            g_free(text);
            g_free(name);
        }

        return(TRUE);
    }

    /* FIXME - find a better way to do this... */
    if (!model->transform_list)
        fclose(model->afp);

    /* done animation */
    model->animating = FALSE;
    model->cur_frame--;

    /* create movie? */
    if (sysenv.render.animate && !sysenv.render.no_povray_exec)
    {
        text = NULL;
        switch (sysenv.render.animate_type)
        {
        case ANIM_GIF:
            text = g_strdup_printf("%s -delay %d %s_*.tga %s.gif",
                                   sysenv.convert_path,
                                   (gint) sysenv.render.delay,
                                   sysenv.render.animate_file, sysenv.render.animate_file);
            break;

        case ANIM_MPEG:
            text = g_strdup_printf("%s -quality %d -delay %d %s_*.tga %s.mpg",
                                   sysenv.convert_path, (gint) sysenv.render.mpeg_quality,
                                   (gint) sysenv.render.delay,
                                   sysenv.render.animate_file, sysenv.render.animate_file);
            break;
        }

        if (text)
        {
            system(text);
            g_free(text);
            gui_text_show(DEFAULT, "Completed movie creation.\n");
        }
    }

    /* cleanup */
    if (sysenv.render.no_keep_tempfiles)
    {
#ifndef __WIN32
        text = g_strdup_printf("rm -rf %s_*.pov", sysenv.render.animate_file);
        system(text);
        g_free(text);
        text = g_strdup_printf("rm -rf %s_*.tga", sysenv.render.animate_file);
        system(text);
        g_free(text);
#endif
        /* TODO - windows equivalents */
    }

    /* done - return FALSE to terminate the timer */
    return(FALSE);
}
Example #12
0
gint siesta_phonon_timer(gpointer dialog)
{
    static gint count=0;
    gint atom, mode;
    gchar *text, *name;
    gdouble f, x1[3];
    gpointer spin;
    GSList *list;
    struct core_pak *core;
    struct model_pak *model;

    /* checks */
    if (!dialog_valid(dialog))
        return(FALSE);

    model = dialog_model(dialog);
    g_assert(model != NULL);

    /* stop animation? */
    if (!model->pulse_direction)
    {
        siesta_phonon_cleanup(model);
        coords_compute(model);
        redraw_canvas(SINGLE);
        return(FALSE);
    }

    /* setup animation resolution */
    spin = dialog_child_get(dialog, "phonon_resolution");
    model->pulse_max = SPIN_FVAL(spin);

    /* setup scaling for this step */
    model->pulse_count += model->pulse_direction;
    if (model->pulse_count <= -model->pulse_max)
    {
        model->pulse_count = -model->pulse_max;
        model->pulse_direction = 1;
    }
    if (model->pulse_count >= model->pulse_max)
    {
        model->pulse_count = model->pulse_max;
        model->pulse_direction = -1;
    }

    spin = dialog_child_get(dialog, "phonon_scaling");
    f = SPIN_FVAL(spin);
    f *= (gdouble) model->pulse_count;
    f /= model->pulse_max;

    atom = 0;

    mode = model->siesta.sorted_eig_values[model->siesta.current_animation];

    /* get eigenvectors from all atoms */
    for (list=model->cores ; list; list=g_slist_next(list))
    {
        core = list->data;
        ARR3SET(x1, core->x);

//get x,y,z for given freq.
        core->offset[0] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom, mode);
        core->offset[1] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom+1, mode);
        core->offset[2] = mesch_me_get(model->siesta.eigen_xyz_atom_mat, 3*atom+2, mode);
        atom++;

        /* pulse offset scaling */
        VEC3MUL(core->offset, f);
        vecmat(model->ilatmat, core->offset);
    }

    /* recalc coords */
    coords_compute(model);

    /* CURRENT - output to povray for movie rendering */
    if (model->phonon_movie)
    {
        if (!model->pulse_count && model->pulse_direction==1)
        {
            model->phonon_movie = FALSE;
            count=0;

            text = g_strdup_printf("%s -delay 20 %s_*.tga %s.%s",
                                   sysenv.convert_path, model->phonon_movie_name,
                                   model->phonon_movie_name, model->phonon_movie_type);

            system(text);
            g_free(text);

            return(FALSE);
        }
        else
        {
            text = g_strdup_printf("%s_%06d.pov", model->phonon_movie_name, count++);
            name = g_build_filename(sysenv.cwd, text, NULL);
            write_povray(name, model);

            povray_exec(sysenv.cwd, name);

            g_free(text);
            g_free(name);
        }

    }
    else
        redraw_canvas(SINGLE);

    return(TRUE);
}