예제 #1
0
void MdispGtkView::GraphicsAnnotations( bool on )
   {
   if(m_MilDisplay)
      {
      m_isGraphicsAnnotationsEnabled = on;
      
      if(m_isGraphicsAnnotationsEnabled)
         {
         if(!m_MilGraphContext && !m_MilGraphList)
            {
            MIL_INT BufSizeX  = 0, BufSizeY = 0;
            MIL_INT LogoCellSize = 12;
            MIL_INT LogoSize  = 6 * LogoCellSize;
            MIL_INT Offset    = 10;

            MgraAlloc(((MdispGtkApp*)dispGtkApp())->m_MilSystem, &m_MilGraphContext);
            MgraAllocList(((MdispGtkApp*)dispGtkApp())->m_MilSystem, M_DEFAULT, &m_MilGraphList);
            MdispControl(m_MilDisplay, M_DISPLAY_GRAPHIC_LIST, m_MilGraphList);

            MdispControl(m_MilDisplay, M_UPDATE_GRAPHIC_LIST, M_DISABLE);
            MbufInquire(m_MilImage, M_SIZE_X, &BufSizeX);
            MbufInquire(m_MilImage, M_SIZE_Y, &BufSizeY);

            MgraClear(m_MilGraphContext, m_MilGraphList);

            GraphicLogo(Offset                 , Offset           , LogoCellSize);
            GraphicLogo(BufSizeX - (LogoSize/2), Offset           , LogoCellSize);
            GraphicLogo(Offset                 , BufSizeY + Offset, LogoCellSize);

            MgraColor(m_MilGraphContext, M_COLOR_LIGHT_BLUE);
            MgraLine(m_MilGraphContext, m_MilGraphList, Offset + (LogoSize/2), Offset + LogoSize, Offset + LogoSize/2, BufSizeY + Offset);
            MgraLine(m_MilGraphContext, m_MilGraphList, Offset + LogoSize,  Offset + (LogoSize/2), BufSizeX - (LogoSize/2), Offset + (LogoSize/2));

            MgraColor(m_MilGraphContext, M_COLOR_GRAY);
            MgraText(m_MilGraphContext, m_MilGraphList, Offset, (2*Offset)+LogoSize, MT("Mil Graphic"));
            MgraText(m_MilGraphContext, m_MilGraphList, Offset, (4*Offset)+LogoSize, MT("Annotations"));

            MdispControl(m_MilDisplay, M_UPDATE_GRAPHIC_LIST, M_ENABLE);
            }
         }
      else
         {
         MdispControl(m_MilDisplay, M_DISPLAY_GRAPHIC_LIST, M_NULL);
         
         if(m_MilGraphList)
            {
            MgraFree(m_MilGraphList);
            m_MilGraphList = M_NULL;
            }
         if(m_MilGraphContext)
            {
            MgraFree(m_MilGraphContext);
            m_MilGraphContext = M_NULL;
            }
         }
      }
   }
// Se reserva memoria, se carga y se presenta la imagen "nomFich"
// Se presupone que no hay otra imagen cargada con el mismo numero de filtro ("numFiltro")
//  m_control es el control al dialogo
//  bMostrar indica si debe de mostrarse la imagen en pantalla o solo cargar la imagen en memoria
// Se inicializa M_overlay_normal
// Se deja el zoom a 0.5
bool ControlImagenes::CargarImagen(char* nomFich, CStatic&	m_control, int numFiltro, bool bMostrar)
{

	// Comprobaciones
	struct stat stFileInfo;
	if (stat(nomFich,&stFileInfo) != 0)
		return false;
    if (m_Milimagen[numFiltro-1] != NULL)
        return false;

    long lSizeX, lSizeY;
    MbufDiskInquire(nomFich,M_SIZE_X, &lSizeX);
    MbufDiskInquire(nomFich,M_SIZE_Y, &lSizeY);
    MbufAlloc2d(M_DEFAULT_HOST, lSizeX,lSizeY, 16 + M_UNSIGNED, M_IMAGE + M_DISP + M_PROC, &m_Milimagen[numFiltro-1]);
    if (MbufImport(nomFich,M_TIFF,M_LOAD,M_NULL,&m_Milimagen[numFiltro-1]) == M_NULL)
//    if (MbufImport(nomFich,M_TIFF,M_RESTORE,M_DEFAULT_HOST,&m_Milimagen[numFiltro-1]) == M_NULL)
        return false;
    if (m_Milimagen[numFiltro-1] == NULL)
        return false;

    m_numImagenes++;

	if (bMostrar)
	{
		MdispSelectWindow(m_Mildisplay,m_Milimagen[numFiltro-1],m_control);
		// Inicializar Overlay la primera vez que se carga una imagen
		// Esto se hace aqui porque no funciona si no hay un buffer asociado con el display
		// ha de usarse la variable global M_overlay_normal para que funcionen las funciones graficas
		if (M_overlay_normal == M_NULL)
		{
			MdispInquire(m_Mildisplay, M_OVERLAY_ID, &M_overlay_normal);

			// Relleno el buffer overlay con el color TRANSPARENTE
//			MbufClear(M_overlay_normal, TRANSPARENTE );
		}
        // TRUCO para evitar que los rectangulos se pinten con un reborde negro. Pero la carga de imagenes es mas lenta
        // Se deja el zoom a 0.5
        // Los rectangulos se pintan con un reborde negro cuando el zoom esta entre 0.5 y 1 en MIL 8
        // por razones desconocidas. Este truco funciona, pero tampoco se sabe porque
//        MdispZoom(m_Mildisplay, 0.5, 0.5);
        //En la funcion llamante, se debe actualizar correctamente el zoom
	}
    // Solo una vez cada vez que se cargan todas las imagenes
    if (numFiltro == 2)
    {
        // Recuperamos las dimensiones de la imagen
        MbufInquire(m_Milimagen[1],M_SIZE_X,&m_nAnchoImagen);
        MbufInquire(m_Milimagen[1],M_SIZE_Y,&m_nAltoImagen);
	}

    return true;
}
예제 #3
0
bool MdispGtkView::newDoc()
   {
    // Set buffer attributes
   if(((MdispGtkApp*)dispGtkApp())->m_numberOfDigitizer)
      {
      m_bufferAttributes=M_IMAGE+M_DISP+M_GRAB+M_PROC;
      m_imageSizeX = ((MdispGtkApp*)dispGtkApp())->m_digitizerSizeX;
      m_imageSizeY = ((MdispGtkApp*)dispGtkApp())->m_digitizerSizeY;
      m_NbBands    = ((MdispGtkApp*)dispGtkApp())->m_digitizerNbBands;

      // Allocate a buffer [CALL TO MIL]
      MbufAllocColor(((MdispGtkApp*)dispGtkApp())->m_MilSystem,
                     m_NbBands,
                     m_imageSizeX,
                     m_imageSizeY,
                     M_DEF_IMAGE_TYPE,
                     m_bufferAttributes,
                     &m_MilImage);

      // Clear the buffer [CALL TO MIL] 
      MbufClear(m_MilImage,M_COLOR_BLACK);
      }
   else
      {
      //Import image in buffer [CALL TO MIL]
      MbufImport(IMAGE_FILE,M_DEFAULT,M_RESTORE,((MdispGtkApp*)dispGtkApp())->m_MilSystem,&m_MilImage);

      // Set SizeX and SizeY variable to the size of the buffer [CALL TO MIL]
      if (m_MilImage) 
         {
         m_imageSizeX   = MbufInquire(m_MilImage, M_SIZE_X, M_NULL);
         m_imageSizeY   = MbufInquire(m_MilImage, M_SIZE_Y, M_NULL);
         m_NbBands      = MbufInquire(m_MilImage, M_SIZE_BAND, M_NULL);
         }
      }

   UpdateContentSize();

   // If not able to allocate a buffer, do not create a new document
   if(!m_MilImage)
      return false;

   Initialize();

   return true;
   }
예제 #4
0
bool MdispGtkView::load(const char *filename)
   {
   //Import image in buffer [CALL TO MIL]
   MbufImport(filename,M_DEFAULT,M_RESTORE,((MdispGtkApp*)dispGtkApp())->m_MilSystem,&m_MilImage);

   // Set SizeX and SizeY variable to the size of the buffer [CALL TO MIL]
   if (m_MilImage)
      {
      Initialize();
      m_imageSizeX = MbufInquire(m_MilImage,M_SIZE_X,M_NULL);
      m_imageSizeY = MbufInquire(m_MilImage,M_SIZE_Y,M_NULL);
      m_filename = g_strdup(g_path_get_basename(filename));
      UpdateContentSize();
      return true;
      }
   else
      {
      return false;
      }
   }
/**************************  graba_imagen_campo  ****************************
   Función para efectuar la grabación en disco de una imagen del campo.
   "nombre" es el nombre del archivo a almacenar.
   "buffer" es el buffer que quiero copiar a disco. Se espera que este buffer
   este en 8 o 16 bits reales (dependiendo de la profundidad de la camara)
   nBits - profundidad en bits en que se grabará la imagen (8,12,16)
****************************************************************************/
int graba_imagen_campo_bits(parametros& param, char *nombre, MIL_ID buffer, int nBits, double dEscala)
{
    int res = 0;

    if (param.Cam.profundidad == 16 && (nBits == 8 || nBits == 12))
    {
        MIL_ID M_buf16;
        long altoImagen,anchoImagen;
        MbufInquire(buffer, M_SIZE_X, &anchoImagen);
        MbufInquire(buffer, M_SIZE_Y, &altoImagen);
		MbufAlloc2d(M_sistema, anchoImagen, altoImagen, 16+M_UNSIGNED,
			M_IMAGE+M_DISP+M_PROC, &M_buf16 );
        if (nBits == 8)
        {
            MIL_ID M_buf8;
		    MbufAlloc2d(M_sistema, anchoImagen, altoImagen, 8+M_UNSIGNED,
			    M_IMAGE+M_DISP+M_PROC, &M_buf8 );
            MimShift(buffer,M_buf16,-8);//conversion a 8 bit 
		    MbufCopy(M_buf16, M_buf8); 
    //        MimShift(buffer,buffer,4);//conversion a 12 bit. Para que luego los histogramas funcionen correctamente

            res = graba_imagen_campo(nombre,M_buf8, nBits, dEscala);
            MbufFree(M_buf8);
        }
        else //nBits==12
        {
            MimShift(buffer,M_buf16,-4);//conversion a 12 bit 
            res = graba_imagen_campo(nombre,M_buf16, nBits, dEscala);
        }
        MbufFree(M_buf16);
    }
    else //Grabar tal cual (imagen origen esta en 8 bit o esta en 16 bit y se quiere dejar en 16 bit)
    {
        res = graba_imagen_campo(nombre,buffer, nBits, dEscala);
    }

    return res;
}
예제 #6
0
/**************************  calcula_valores_linea  *************************
	Calcula los valores de nivel de gris de una determinada línea.
	(horizontal o vertical).
*****************************************************************************/
int calcula_valores_linea(MIL_ID M_fb, int posX, int posY, int linea)
{
	BYTE  val_pixel_h[MAX_ANCHO_IMAGEN], val_pixel_v[MAX_ALTO_IMAGEN];
	int altoImagen, anchoImagen;
	
	MbufCopy(M_fb, M_imagen6);
	
	/*	Compruebo que los valores a calcular no están fuera de los límites definidos por
		el buffer. */

	anchoImagen = MbufInquire(M_imagen6, M_SIZE_X, M_NULL);
	altoImagen = MbufInquire(M_imagen6, M_SIZE_Y, M_NULL);

	posX = (posX < 0)? 0 : posX;
	posX = (posX > anchoImagen)? anchoImagen : posX;
	posY = (posY < 0)? 0 : posY;
	posY = (posY > altoImagen)? altoImagen : posY;

	// Línea horizontal.
	if (linea == L_HORIZ)  {
		MbufGetLine(M_imagen6, 0, posY, anchoImagen-1, posY, M_DEFAULT, M_NULL, &val_pixel_h);
		dibuja_analisis_linea(val_pixel_h, linea, altoImagen, anchoImagen);
	}
	
	// Línea vertical.
	else if (linea == L_VERT)  {
		MbufGetLine(M_imagen6, posX, 0, posX, altoImagen-1, M_DEFAULT, M_NULL, &val_pixel_v);
		dibuja_analisis_linea(val_pixel_v, linea, altoImagen, anchoImagen);
	}
	else  {
		error_leve("calcula_valores_linea", "no se puede mostrar el análisis de la línea");
		return -1;
	}

	return 0;
}
예제 #7
0
/**************************  perfiles  *********************************
   Función para iniciar el proceso de análisis, obteniendo las imágenes
   de disco.
*****************************************************************************/
int perfiles(MIL_ID M_fb, parametros *param)
{
	char mensaje[128];
	int  tecla, posX, posY;
	MIL_ID M_ancho, M_alto;

	posX = param->Cam.anchoImagen / 2;	// Inicio en la posición central de la imagen
	posY = param->Cam.altoImagen / 2;
	
	M_ancho = MbufInquire(M_fb, M_SIZE_X, M_NULL);	// Pregunto sobre el ancho y alto
	M_alto = MbufInquire(M_fb, M_SIZE_Y, M_NULL);	// del buffer seleccionado.

	do {
		sprintf(mensaje, "   - X: %ld.   - Y: %ld.		", posX, posY);
		sendcont(mensaje);
		do {
			dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
			Sleep(200);		// Espera mientras no se pulse una tecla
		} while (!kbhit());
		tecla = getKey();
		switch (tecla) {
			case K_ESC:
				break;
			case K_LEFT:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX - MOV_LENTO;
				posX = (posX < 0)? 0 : posX;
				posY = posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_RIGHT:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);
				
				posX = posX + MOV_LENTO;
				posX = (posX > M_ancho)? M_ancho : posX;
				posY = posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_UP:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX;
				posY = posY - MOV_LENTO;
				posY = (posY < 0)? 0 : posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_DOWN:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX;
				posY = posY + MOV_LENTO;
				posY = (posY > M_alto)? M_alto : posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;

			case K_CR_LEFT:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX - MOVIMIENTO;
				posX = (posX < 0)? 0 : posX;	// Compruebo que no sobrepaso el límite.
				posY = posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_CR_RIGHT:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);
				
				posX = posX + MOVIMIENTO;
				posX = (posX > M_ancho)? M_ancho : posX;
				posY = posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_CR_UP:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX;
				posY = posY - MOVIMIENTO;
				posY = (posY < 0)? 0 : posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case K_CR_DOWN:
				/* borro la anterior linea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 1);

				posX = posX;
				posY = posY + MOVIMIENTO;
				posY = (posY > M_alto)? M_alto : posY;
				/* Dibujo la nueva línea. */
				dibuja_linea_activa(M_overlay_normal, posX, posY, 0);
				break;
			case 'H':
			case 'h':
				if ( calcula_valores_linea(M_imagen1, posX, posY, L_HORIZ) )
					error_leve("perfiles", "No se puede mostrar el análisis solicitado");
				break;
			case 'V':
			case 'v':
				calcula_valores_linea(M_imagen1, posX, posY, L_VERT);
				break;
			default :
				putch('\a');
		}
	} while (tecla != K_ESC);
	MbufClear(M_overlay_normal, TRANSPARENTE);

	return 0;
}
예제 #8
0
파일: milmex.cpp 프로젝트: gbishop/milmex
void mexFunction(int nlhs, mxArray *plhs[],
				 int nrhs, const mxArray *prhs[] )
{
	// validate the command string
	if(nrhs < 1 || mxIsChar(prhs[0]) != 1 || mxGetM(prhs[0]) != 1) {
		mexErrMsgTxt("Missing command string.");
	}

	// get the command
	int cmdlen = mxGetN(prhs[0]) + 1;
	char* command = (char*)mxCalloc(cmdlen, sizeof(char));
	if(mxGetString(prhs[0], command, cmdlen) != 0) {
		mexErrMsgTxt("Get command string failed.");
	}

	// startup 
	if(strcmp(command, "init") == 0) {

		// set things up so a clear will also clean up
		mexAtExit(cleanup);

		if(nrhs > 1) {
			if(!mxIsChar(prhs[1]) || mxGetM(prhs[1]) != 1) {
				mexErrMsgTxt("init argument should be the name of a dcf file.");
			}
			int nmlen = mxGetN(prhs[1]) + 1;
			char* dcfname = (char*)mxCalloc(nmlen, sizeof(char));
			mxGetString(prhs[1], dcfname, nmlen);

			MappAllocDefault(M_SETUP, &MilApplication, &MilSystem,
				M_NULL, M_NULL, M_NULL);
			if(MdigAlloc(MilSystem, M_DEV0, dcfname, M_DEFAULT, &MilDigitizer) == M_NULL) {
				mexErrMsgTxt("init failed.");
			}
		} else {
			/* Allocate defaults. */
			MappAllocDefault(M_SETUP, &MilApplication, &MilSystem,
				M_NULL, &MilDigitizer, M_NULL);
		}
		MBands = (int)MdigInquire(MilDigitizer, M_SIZE_BAND, M_NULL);
		for(int i=0; i<MBands; i++)
			band_is_selected[i] = true;
		bands_selected = MBands;

		MappTimer(M_TIMER_RESET, M_NULL);

		grab_scale_x = grab_scale_y = 1;

		MdigControl(MilDigitizer, M_GRAB_MODE, M_ASYNCHRONOUS);
		MdigControl(MilDigitizer, M_GRAB_SCALE_X, grab_scale_x);
		MdigControl(MilDigitizer, M_GRAB_SCALE_Y, grab_scale_y);
		
	// wrapup
	} else if(strcmp(command, "quit") == 0) {
		cleanup();

	// set the x and y scaling factor
	} else if(strcmp(command, "setscale") == 0) {
		// check the parameters
		if(nrhs != 3 || !mxIsDouble(prhs[1]) || !mxIsDouble(prhs[2])) {
			mexErrMsgTxt("setscale expects 2 arguments.");
		}
		grab_scale_x = mxGetScalar(prhs[1]);
		grab_scale_y = mxGetScalar(prhs[2]);

		MdigControl(MilDigitizer, M_GRAB_SCALE_X, grab_scale_x);
		MdigControl(MilDigitizer, M_GRAB_SCALE_Y, grab_scale_y);

	// select which bands to return for multiband sources
	} else if(strcmp(command, "selectbands") == 0) {
		// check to see if it's legal
		if(MBands == 1) {
			mexErrMsgTxt("selectbands only works for multiband sources.");
		}
		// check the argument
		if(nrhs != 2 || !mxIsDouble(prhs[1]) || mxGetM(prhs[1]) != 1) {
			mexErrMsgTxt("selectbands expects a row vector of band numbers.");
		}
		int nbands = mxGetN(prhs[1]);
		if(nbands == 0 || nbands > MBands) {
			mexErrMsgTxt("selectbands allows only 1 to 3 bands.");
		}
		double* bp = mxGetPr(prhs[1]);
		for(int i=0; i<3; i++) {
			band_is_selected[i] = false;
		}
		bands_selected = 0;
		for(i=0; i<nbands; i++) {
			int bnd = int(bp[i]);
			if(bnd < 0 || bnd > 2) {
				mexErrMsgTxt("selectbands allows bands numbered 0 to 2.");
			}
			if(!band_is_selected[bnd]) {
				band_is_selected[bnd] = true;
				bands_selected++;
			}
		}
		
	// grab a sequence in one call
	} else if(strcmp(command, "grabframes") == 0) {
		// check the parameters
		if(nrhs < 4 || !mxIsDouble(prhs[1]) || !mxIsDouble(prhs[2]) || !mxIsDouble(prhs[3])) {
			mexErrMsgTxt("grabframes expects 3 or 4 arguments.");
		}
		int width = int(mxGetScalar(prhs[1]));
		int height = int(mxGetScalar(prhs[2]));
		int frames = int(mxGetScalar(prhs[3]));

		// indicates whether this is a continuation of a previous grab
		bool grab_continue = false;
		if(nrhs == 5 && mxIsDouble(prhs[4]) && mxGetScalar(prhs[4]) > 0) {
			grab_continue = true;
		}

		// space to record per frame times if requested
		mxArray *time_array = 0;
		double* time_data = 0;
		if(nlhs > 1) {
			time_array = mxCreateDoubleMatrix(frames, 1, mxREAL);
			time_data = mxGetPr(time_array);
		}

		// allocate a matlab multidimensional array to return the image
		int dims[4];
		int ndims = 3;
		dims[0] = height;
		dims[1] = width;
		if(bands_selected > 1) {
			dims[2] = bands_selected;
			dims[3] = frames;
			ndims = 4;
		} else {
			dims[2] = frames;
		}
		mxArray *res = mxCreateNumericArray(ndims, dims, mxUINT8_CLASS, mxREAL);
		int frameelements = width*height*MBands;
		unsigned char* pmat = (unsigned char*)mxGetPr(res);

		// free buffers if they are the wrong size
		if(MilImageX != 0 && (width != MilImageX || height != MilImageY)) {
			MdigGrabWait(MilDigitizer, M_GRAB_END);
			for(int n=0; n<nmilbuff; n++) {
				MbufFree(MilImage[n]);
			}
			MilImageX = MilImageY = 0;
		}
		// allocate a few MIL buffers if we don't already have them
		if(MilImageX == 0) {
			for (int n=0; n<nmilbuff; n++)
			{
				MbufAllocColor(MilSystem,  
					MBands,
					width,
					height,
					8L+M_UNSIGNED, 
					M_IMAGE+M_GRAB, &MilImage[n]);
				if (MilImage[n] == 0)                     
				{
					mexErrMsgTxt("MbufAllocColor failed.");
				}
			}
			MilImageX = width;
			MilImageY = height;
		}

		// grab the frames
		if(!grab_continue) {
			// if you're not continuing a previous grab, then you want a fresh first frame
			MdigGrab(MilDigitizer, MilImage[MilImageNdx]);
		}
		for(int i = 0; i < frames; i++)
		{
			int ndx0 = MilImageNdx;
			MilImageNdx = (MilImageNdx + 1) % nmilbuff;
			MdigGrab(MilDigitizer, MilImage[MilImageNdx]);
			if(time_array)
				MappTimer(M_TIMER_READ, &time_data[i]);
			
			// copy the completed buff to the matlab array
			if(MBands == 1) { // easy
				// get a pointer to the buffer
				unsigned char* pmil;
				MbufInquire(MilImage[ndx0], M_HOST_ADDRESS, &pmil);
				if(pmil == M_NULL) {
					mexErrMsgTxt("no access to mil buffer.");
				}

				// copy the pixels exchanging x and y coordinates to suit matlab
				for(int y=0; y<height; y++) {
					for(int x=0; x<width; x++) {
						pmat[y+x*height] = pmil[x+y*width];
					}
				}
				pmat += width*height;

			} else { // harder
				// I bet there is some smarter way to do this...
				// for each band
				for(int b=0; b<MBands; b++) {
					if(band_is_selected[b]) {
						// allocate a child buffer on the band.
						MIL_ID child = MbufChildColor(MilImage[ndx0], b, M_NULL);
						if(child == M_NULL) {
							mexErrMsgTxt("no child");
						}
						// get a pointer to the child
						unsigned char* pmil;
						MbufInquire(child, M_HOST_ADDRESS, &pmil);
						if(pmil == M_NULL) {
							MbufFree(child);
							mexErrMsgTxt("no access to mil buffer.");
						}
						// do the copy, twizzling the indicies around...
						for(int y=0; y<height; y++) {
							for(int x=0; x<width; x++) {
								pmat[(y + x*height)] = pmil[x+y*width];
							}
						}
						pmat += width*height;

						// release the child
						MbufFree(child);
					}
				}
			}
		}

		plhs[0] = res;
		if(time_array)
			plhs[1] = time_array;

	} else {
		mexErrMsgTxt("Unknown command string.");
	}

}  
/**************************  carga_imagen_campo  ****************************
	Función para efectuar la carga desde disco de una imagen del campo.
	Se le pasan a esta función los siguientes argumentos:
		nombre: nombre del fichero que quiero cargar.
		buffer: le paso el buffer donde quiero almacenar la imagen a cargar.
				Esto define el tamaño del mismo.
        nProfundidad: profundidad (bits) del buffer (8,12,16)
	Esta función únicamente carga la imagen en el buffer seleccionado, no la
	muestra en el display.
    LEE LA PROFUNDIDAD GUARDADA, EL BUFFER ESTA EN nProfundidad
****************************************************************************/
int carga_imagen_campo_bits(char *nombre, MIL_ID buffer, int nProfundidad)
{
    // Leer informacion TIF (escala reflectancia y profundidad)
    int nProfundidadFichero = -1;
    double dEscalaFichero;
    try
    {
        CString csNombreImagen;
        INTERFAZ_LIBTIF::LeerTags(nombre,nProfundidadFichero,dEscalaFichero); //Leemos de la imagen la profundidad en bits y la escala reflectancia-gris
        if (nProfundidadFichero < 0 )
            nProfundidadFichero = 8; // por defecto las imagenes estan en 8 bit
    }
    catch(...)
    {
        nProfundidadFichero = 8;
    }

    if (nProfundidad != nProfundidadFichero) 
    {
        // Buffer auxiliar de 16 es necesario para poder operar (M_PROC)
        MIL_ID M_buf16;
        long altoImagen,anchoImagen;
        MbufInquire(buffer, M_SIZE_X, &anchoImagen);
        MbufInquire(buffer, M_SIZE_Y, &altoImagen);
	    MbufAlloc2d(M_DEFAULT_HOST, anchoImagen, altoImagen, 16+M_UNSIGNED,
		    M_IMAGE+M_DISP+M_PROC, &M_buf16 );
        if (nProfundidad >= 12 && nProfundidadFichero >= 12) 
        {
            if (carga_imagen_campo(nombre,M_buf16))
                return 1;//ERROR
            MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 12 a 16 bit 
        }
        else if (nProfundidadFichero == 8) //nProfundidad>8
        {
            MIL_ID M_buf8;
	        MbufAlloc2d(M_DEFAULT_HOST, anchoImagen, altoImagen, 8+M_UNSIGNED,
		        M_IMAGE+M_DISP+M_PROC, &M_buf8 );

            if (carga_imagen_campo(nombre,M_buf8))
                //ERROR
                return 1;

	        MbufCopy(M_buf8, M_buf16); 
            MbufFree(M_buf8);
            MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 8 a 12 bit 
        }
        else //(nProfundidad == 8 && nProfundidadFichero > 8
        {
            if (carga_imagen_campo(nombre,M_buf16))
                //ERROR
                return 1;

            MimShift(M_buf16,buffer,nProfundidad - nProfundidadFichero);//conversion de 8 a 12 bit 
        }
        MbufFree(M_buf16);
    }
    else
    {
        if (carga_imagen_campo(nombre,buffer))
            //ERROR
            return 1;
    }

	return  0;
}
예제 #10
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;
         }
      }
   }