Download document (10.35 MB) - Escuela Superior de Informática ...

Download document (10.35 MB) - Escuela Superior de Informática ... Download document (10.35 MB) - Escuela Superior de Informática ...

11.07.2015 Views

156 Capítulo D. Código fuente473 * Salidas: puntero a GdkPixbuf.474 ****************************************************************/475 GdkPixbuf* getImagePixbufOpencvExample(const char* filename){476477 IplImage *imgPix = cvLoadImage(filename, CV_LOAD_IMAGE_COLOR);478 gchar *archivoVideo = g_strdup(filename);479480 GdkPixbuf *pix_src, *pix_dst;481 pix_src = gdk_pixbuf_new_from_data((guchar*)imgPix->imageData,482 GDK_COLORSPACE_RGB, FALSE,483 imgPix->depth, imgPix->width,484 imgPix->height, imgPix->widthStep,485 NULL, NULL);486487 archivoVideo = strrchr(archivoVideo,’.’);488489 if(strcmp(archivoVideo,".png") != 0) {490 pix_dst = gdk_pixbuf_scale_simple(pix_src, imgPix->width/10,491 imgPix->height/10, GDK_INTERP_BILINEAR);492 }493 else {494 pix_dst = gdk_pixbuf_scale_simple(pix_src, imgPix->width,495 imgPix->height, GDK_INTERP_BILINEAR);496 }497 cvReleaseImage( &imgPix );498499 return pix_dst;500 }501502 /***********************************************************************503 * Funcion: motion_notify_event504 * Descripcion: Manejador del evento de arrastrar el raton en el Widget505 * Entradas: widget --> Puntero al widget GtkGlExt506 * event --> Puntero con caracteristicas del evento ocurrido507 * data --> Puntero con datos que se le pasan como parametros508 * Salidas: Devuelve TRUE si no se produjo error.509 ***********************************************************************/510 gboolean motion_notify_event (GtkWidget *widget, GdkEventButton *event,511 gpointer data)512 {513 int x, y, dx, dy;514 GdkModifierType state = 0;515 GtkWidget *boton_play;516517 x = event->x;518 y = event->y;519520 dx = x - inicioX;521 dy = y - inicioY;522 state = event->state;523524 /* Rotamos con el arrastre del boton izquierdo... */525 if (state & GDK_BUTTON1_MASK) { /* Boton izquierdo pulsado */526 rotx = getModulo(inicioRotX + factorRotacion*dy,360);527 rotz = getModulo(inicioRotZ + factorRotacion*dx,360);528 calculaVistaModelo();529530 } else if (state && GDK_BUTTON2_MASK) { /* Boton central pulsado */531 trans[0] = inicioTransX- factorTrans*dx;532 trans[1] = inicioTransY+ factorTrans*dy;

D.2. Código fuente de los módulos más relevantes. 157533 calculaVistaModelo();534 //˜ calculaProyeccion();535 }536537 boton_play = glade_xml_get_widget(gxml,"boton_play");538539 /* Si el boton del play no esta activo, redibujamos540 (si esta activo, el redibujado es automatico). */541 if ((gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(boton_play))542 ==FALSE) && (state)) {543 dibujar_gl (widget, NULL, NULL);544 }545546 return TRUE;547 }548549 /*********************************************************************550 * Funcion: button_press_event551 * Descripcion: Manejador del evento de pinchar con el raton en el Widget552 * Entradas: widget --> Puntero al widget GtkGlExt553 * event --> Puntero con caracteristicas del evento ocurrido554 * data --> Puntero con datos que se le pasan como parametros555 * Salidas: Devuelve TRUE si no se produjo error.556 ********************************************************************/557 gboolean button_press_event (GtkWidget *widget, GdkEventButton *event,558 gpointer data)559 {560 inicioRotX = rotx;561 inicioRotY = roty;562 inicioRotZ = rotz;563564 inicioX = event->x;565 inicioY = event->y;566567 inicioTransX = trans[0];568 inicioTransY = trans[1];569570 return TRUE;571 }572573 /*********************************************************************574 * Funcion: scroll_event575 * Descripcion: Manejador del evento de rueda del raton en el Widget576 * Entradas: widget --> Puntero al widget GtkGlExt577 * event --> Puntero con caracteristicas del evento ocurrido578 * data --> Puntero con datos que se le pasan como parametros579 * Salidas: Devuelve TRUE si no se produjo error.580 ********************************************************************/581 gboolean scroll_event (GtkRange *range, GdkEventScroll *event,582 gpointer data){583 if (event->direction == GDK_SCROLL_DOWN)584 escala-=0.01;585 if (event->direction == GDK_SCROLL_UP)586 escala+=0.01;587 gtk_widget_queue_draw(GTK_WIDGET((GtkWidget *)data));588589 return TRUE;590 }591592 /*********************************************************************

D.2. Código fuente <strong>de</strong> los módulos más relevantes. 157533 calculaVistaMo<strong>de</strong>lo();534 //˜ calculaProyeccion();535 }536537 boton_play = gla<strong>de</strong>_xml_get_widget(gxml,"boton_play");538539 /* Si el boton <strong>de</strong>l play no esta activo, redibujamos540 (si esta activo, el redibujado es automatico). */541 if ((gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(boton_play))542 ==FALSE) && (state)) {543 dibujar_gl (widget, NULL, NULL);544 }545546 return TRUE;547 }548549 /*********************************************************************550 * Funcion: button_press_event551 * Descripcion: Manejador <strong>de</strong>l evento <strong>de</strong> pinchar con el raton en el Widget552 * Entradas: widget --> Puntero al widget GtkGlExt553 * event --> Puntero con caracteristicas <strong>de</strong>l evento ocurrido554 * data --> Puntero con datos que se le pasan como parametros555 * Salidas: Devuelve TRUE si no se produjo error.556 ********************************************************************/557 gboolean button_press_event (GtkWidget *widget, GdkEventButton *event,558 gpointer data)559 {560 inicioRotX = rotx;561 inicioRotY = roty;562 inicioRotZ = rotz;563564 inicioX = event->x;565 inicioY = event->y;566567 inicioTransX = trans[0];568 inicioTransY = trans[1];569570 return TRUE;571 }572573 /*********************************************************************574 * Funcion: scroll_event575 * Descripcion: Manejador <strong>de</strong>l evento <strong>de</strong> rueda <strong>de</strong>l raton en el Widget576 * Entradas: widget --> Puntero al widget GtkGlExt577 * event --> Puntero con caracteristicas <strong>de</strong>l evento ocurrido578 * data --> Puntero con datos que se le pasan como parametros579 * Salidas: Devuelve TRUE si no se produjo error.580 ********************************************************************/581 gboolean scroll_event (GtkRange *range, GdkEventScroll *event,582 gpointer data){583 if (event->direction == GDK_SCROLL_DOWN)584 escala-=0.01;585 if (event->direction == GDK_SCROLL_UP)586 escala+=0.01;587 gtk_widget_queue_draw(GTK_WIDGET((GtkWidget *)data));588589 return TRUE;590 }591592 /*********************************************************************

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!