ControlImagenes::ControlImagenes()
{
    //Inicilizacion
//    m_Milsistema        = M_NULL;
    m_Milaplicacion     = M_NULL;
    m_Mildisplay        = M_NULL;
    m_Miloverlay        = M_NULL;
    m_lut_overlay       = M_NULL;
    m_numImagenes       = 0;
    m_nAnchoImagen      = -1;
    m_nAltoImagen       = -1;
    for (int i=0;i<MAX_NUM_IMAGENES;i++)
        m_Milimagen[i]  = M_NULL;        
    m_MilRGB            = M_NULL;
    M_Clasificacion     = M_NULL;
    m_bufClasificacionSelectiva = NULL;
    m_bDefiniendoArea   = false;
    m_bPintandoRect     = false;


	MappAlloc(M_DEFAULT, &m_Milaplicacion);	// Selecciono la aplicación MIL.
	if ( m_Milaplicacion == M_NULL ) {
        AfxMessageBox("Error: No se pudo inicilizar MIL", MB_ICONERROR | MB_OK);
	}

	//	Pregunto al sistema la versión de la librería de control de proceso de imagen
	//MappInquire(M_VERSION, &m_Milversion);

    // pruebas MIL 8
//	MsysAlloc(M_SYSTEM_METEOR_II_1394, M_DEV0, M_DEFAULT, &M_sistema);	// Selecciono un sistema hardware

//	if ( M_sistema == M_NULL )  {
//        AfxMessageBox("Error: No se pudo inicilizar MIL", MB_ICONERROR | MB_OK);
//	}

    //	Display normal para las imágenes adquiridas y procesadas. 
	MdispAlloc(M_DEFAULT_HOST, M_DEFAULT, "M_DEFAULT", M_WINDOWED + M_GDI_OVERLAY, &m_Mildisplay);
	if ( m_Mildisplay == M_NULL )  {
        AfxMessageBox("Error: No se pudo inicilizar MIL", MB_ICONERROR | MB_OK);
	}

	// El texto tiene color de fondo transparente
    MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);

    // OVERLAY (diferente para MIL 8 y anteriores
    if (M_MIL_CURRENT_VERSION >= 8.0)
    {
        // Inicializar colores para pintar areas
        m_listaColor[NEGRO_POS] =     M_RGB888(NEGRO_R,NEGRO_G,NEGRO_B);
        m_listaColor[MARRON_POS] =     M_RGB888(MARRON_R,MARRON_G,MARRON_B);
        m_listaColor[ROJO_POS] =     M_RGB888(ROJO_R,ROJO_G,ROJO_B);
        m_listaColor[CYAN_POS] =     M_RGB888(CYAN_R,CYAN_G,CYAN_B);
        m_listaColor[NARANJA_POS] =     M_RGB888(NARANJA_R,NARANJA_G,NARANJA_B);
        m_listaColor[VERDE_POS] =     M_RGB888(VERDE_R,VERDE_G,VERDE_B);
        m_listaColor[AZUL_POS] =     M_RGB888(AZUL_R,AZUL_G,AZUL_B);
        m_listaColor[MORADO_POS] =     M_RGB888(MORADO_R,MORADO_G,MORADO_B);
        m_listaColor[GRIS_POS] =     M_RGB888(GRIS_R,GRIS_G,GRIS_B);
        m_listaColor[ORO_POS] =     M_RGB888(ORO_R,ORO_G,ORO_B);
        m_listaColor[ROSA_POS] =    M_RGB888(ROSA_R,ROSA_G,ROSA_B);

        MdispControl(m_Mildisplay, M_OVERLAY, M_ENABLE);

        // Establezco TRANSPARENTE como color transparente
        MdispControl(m_Mildisplay, M_TRANSPARENT_COLOR, TRANSPARENTE);

        //Tipo de interpolacion para el redimensionamiento de la imagen en el display
        //Si se activa en MIL 8, quedan lineas de color transparernte en el overlay cuando el zoom no es 1
        //MdispControl(m_Mildisplay, M_INTERPOLATION_MODE, M_NEAREST_NEIGHBOR);
    }
    else
    {
        // Inicializar colores para pintar areas
        m_listaColor[0] =     NEGRO   ;
        m_listaColor[1] =     ROJO_OSC  ;
        m_listaColor[2] =     ROJO    ;
        m_listaColor[3] =     CYAN ;
        m_listaColor[4] =     AMARILLO;
        m_listaColor[5] =     VERDE   ;
        m_listaColor[6] =     AZUL    ;
        m_listaColor[7] =     MAGENTA_OSC  ;
        m_listaColor[8] =     GRIS    ;
        m_listaColor[9] =     AMARILLO_OSC     ;
        m_listaColor[10] =    GRIS_CLA   ;

        // LUT
	    MbufAllocColor(M_DEFAULT_HOST, 3L, 256L, 1L, 8L+M_UNSIGNED, M_LUT, &m_lut_overlay);
	    if ( m_lut_overlay == M_NULL)  {
            AfxMessageBox("Error: No se pudo inicilizar MIL", MB_ICONERROR | MB_OK);
	    }
    
	    crea_LUT_overlay(m_lut_overlay, 0);	// Genera LUT color y corrección de gamma
	    configura_overlay(m_Mildisplay, M_NULL, &m_Miloverlay, 1); // repartido entre aqui y CargarImagen // M_NULL, antes ponia M_imagen1 que ya no esta disponible en Analisis, seguramente falle

        //	Asocio la LUT de pseudo-color al display de overlay
	    MdispControl(m_Mildisplay, M_OVERLAY_LUT, m_lut_overlay);


	    //	Modifico la configuración del display: m_Mildisplay_normal.
	    //		- Deshabilito el menú de tareas.
	    //		- Deshabilito la barra del título.
	    //	    - Fijo la posición de la ventana en 0,0. 
	    MdispControl(m_Mildisplay, M_WINDOW_MENU_BAR, M_DISABLE);
	    MdispControl(m_Mildisplay, M_WINDOW_TITLE_BAR, M_DISABLE);
	    MdispControl(m_Mildisplay, M_WINDOW_INITIAL_POSITION_X, 0 );
	    MdispControl(m_Mildisplay, M_WINDOW_INITIAL_POSITION_Y, 0 );

        // Establezco TRANSPARENTE como color transparente
		MdispOverlayKey(m_Mildisplay, M_KEY_ON_COLOR, M_EQUAL, 0xff, TRANSPARENTE);
    }

    // Bitmap de fondo para poner siempre que no haya mas imagenes
    BYTE bBits[] = {0xd8,0xe9,0xec};
    m_backgound_bitmap.CreateBitmap(1,1,1,32,bBits);        
}
Esempio n. 2
0
void MdispGtkView::InitializeOverlay()
   {
   MIL_TEXT_CHAR chText[80]; 

   // Initialize overlay if not already done
   if ((!m_isOverlayInitialized) && (m_MilDisplay))
      {
      //Only do it on a valid windowed display [CALL TO MIL]
      if (m_MilImage && m_MilDisplay )
         {
         // Prepare overlay buffer //
         ////////////////////////////

         // Enable display overlay annotations.
         MdispControl(m_MilDisplay, M_OVERLAY, M_ENABLE);

         // Inquire the Overlay buffer associated with the displayed buffer [CALL TO MIL]
         MdispInquire(m_MilDisplay, M_OVERLAY_ID, &m_MilOverlayImage);

         // Clear the overlay to transparent.
         MdispControl(m_MilDisplay, M_OVERLAY_CLEAR, M_DEFAULT);
         
         // Disable the overlay display update to accelerate annotations.
         MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_DISABLE);


         // Draw MIL monochrome overlay annotation *
         //*****************************************

         // Inquire MilOverlayImage size x and y [CALL TO MIL]
         long imageWidth  = MbufInquire(m_MilOverlayImage,M_SIZE_X,M_NULL);
         long imageHeight = MbufInquire(m_MilOverlayImage,M_SIZE_Y,M_NULL);

         // Set graphic text to transparent background. [CALL TO MIL]
         MgraControl(M_DEFAULT, M_BACKGROUND_MODE, M_TRANSPARENT);

         // Set drawing color to white. [CALL TO MIL]
         MgraColor(M_DEFAULT, M_COLOR_WHITE);

         // Print a string in the overlay image buffer. [CALL TO MIL]
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5,    " -------------------- ");
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+25, " - MIL Overlay Text - ");
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth/9, imageHeight/5+50, " -------------------- ");

         // Print a green string in the green component overlay image buffer. [CALL TO MIL]
         MgraColor(M_DEFAULT, M_COLOR_GREEN);
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5,    " -------------------- ");
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+25, " - MIL Overlay Text - ");
         MgraText(M_DEFAULT, m_MilOverlayImage, imageWidth*11/18, imageHeight/5+50, " -------------------- ");

         // Draw GDI color overlay annotation *
         //************************************

         // Disable hook to MIL error because control might not be supported
         MappControl(M_ERROR_HOOKS, M_DISABLE);

         // Create a device context to draw in the overlay buffer with GDI.  [CALL TO MIL]
         MbufControl(m_MilOverlayImage, M_XPIXMAP_ALLOC, M_COMPENSATION_ENABLE);

         // Reenable hook to MIL error
         MappControl(M_ERROR_HOOKS, M_ENABLE);

         // Retrieve the XPIXMAP of the overlay [CALL TO MIL]
         Pixmap XPixmap = (Pixmap)MbufInquire(m_MilOverlayImage, M_XPIXMAP_HANDLE, M_NULL);

         /* convert it to gdkpixmap */
         GdkPixmap *gdkpixmap = gdk_pixmap_foreign_new(XPixmap);
            
         if(gdkpixmap)
            {
            GdkPoint Hor[2];
            GdkPoint Ver[2];
            GdkColor color[3];               
            GdkFont *font = NULL;
            font = gdk_font_load ("-misc-*-*-r-*-*-*-140-*-*-*-*-*-1");
            int i;
            
            /* get graphic context from pixmap*/
            GdkGC *gc = gdk_gc_new(gdkpixmap);
            
            /* allocate colors */
            gdk_color_parse("blue",&color[0]);
            gdk_color_parse("red",&color[1]);
            gdk_color_parse("yellow",&color[2]);
            for(i=0;i<3;i++)
               gdk_color_alloc(gdk_colormap_get_system(), &color[i]);
            
            /* set the foreground to our color */
            gdk_gc_set_foreground(gc, &color[0]);
            // Draw a blue cross in the overlay buffer.
            Hor[0].x = 0;
            Hor[0].y = imageHeight/2;
            Hor[1].x = imageWidth;
            Hor[1].y = imageHeight/2;
            gdk_draw_lines(gdkpixmap,gc,Hor,2);
            
            Ver[0].x = imageWidth/2;
            Ver[0].y = 0;
            Ver[1].x = imageWidth/2;
            Ver[1].y = imageHeight;
            gdk_draw_lines(gdkpixmap,gc,Ver,2);
            

            // Write Red text in the overlay buffer. 
            MosStrcpy(chText, 80, "X Overlay Text "); 
            gdk_gc_set_foreground(gc, &color[1]);
            gdk_draw_string(gdkpixmap, 
                            font,
                            gc, 
                            imageWidth*3/18,
                            imageHeight*4/6,
                            chText);
            
            // Write Yellow text in the overlay buffer. 
            gdk_gc_set_foreground(gc, &color[2]);
            gdk_draw_string(gdkpixmap, 
                            font,
                            gc, 
                            imageWidth*12/18,
                            imageHeight*4/6,
                            chText);
            
            /* flush */
            gdk_display_flush(gdk_display_get_default());
            
            /* Free graphic context.*/
            g_object_unref(gc);

            // Delete created Pixmap.  [CALL TO MIL]
            MbufControl(m_MilOverlayImage, M_XPIXMAP_FREE, M_DEFAULT);
            
            // Signal MIL that the overlay buffer was modified. [CALL TO MIL]
            MbufControl(m_MilOverlayImage, M_MODIFIED, M_DEFAULT);
            }

         // Now that overlay buffer is correctly prepared, we can show it [CALL TO MIL]
         MdispControl(m_MilDisplay, M_OVERLAY_SHOW, M_ENABLE);

         // Overlay is now initialized
         m_isOverlayInitialized = true;
         }
      }
   }