// interfaz con Clasificacion para clasificar la imagen m_Milimagen (ya cargada y perteneciente a ControlImagen) // devuelve false, si ha habido un error o si ya se habia clasificado y unicamente se ha mostrado la imagen ya clasificada bool ControlImagenes::Clasificar(CStatic* pDisplay, list<CMineralClasificado> &listClasificados, unsigned int& nCountOscuros, CRect* pRect, double dRefMin) { if (M_Clasificacion == M_NULL) // hace falta clasificar de nuevo, no se hizo con anterioridad if (!theApp.clasificacion.CargarImagenes(&m_Milimagen[1],m_numImagenes,pRect)) // nos saltamos la banda pancromatica (no usada) return false; if (pDisplay!=NULL) { MIL_ID selected; MdispInquire(m_Mildisplay,M_SELECTED,&selected); if (selected!=M_NULL) MdispDeselect(m_Mildisplay,selected); DisplayBits(8); //para que el display muestre las imagenes de la profundidad leida if (!theApp.clasificacion.InicializaDisplay(pDisplay,m_Mildisplay,M_Clasificacion,M_Confiabilidad,M_Distancia)) { ASSERT(m_bufClasificacionSelectiva != NULL); return false; } if (m_bufClasificacionSelectiva == NULL) m_bufClasificacionSelectiva = new BYTE[m_nAnchoImagen*m_nAltoImagen];//buffer para la imagen de salida (clasificada selectivamente) } if (!theApp.clasificacion.Clasificar(listClasificados,nCountOscuros,theApp.m_dEscalaReflectancia, theApp.m_nBitsProfundidad, dRefMin)) return false; return true; }
void ControlImagenes::Confiabilidad(CStatic& m_control) { MIL_ID selected; MdispInquire(m_Mildisplay,M_SELECTED,&selected); if (selected!=M_NULL) MdispDeselect(m_Mildisplay,selected); DisplayBits(8); //para que el display muestre las imagenes en profundidad 8 bit MdispSelectWindow(m_Mildisplay, M_Confiabilidad, m_control); }
// Se presenta la imagen (previamente cargada) correspondiente al numero de Filtro "numFIltro" bool ControlImagenes::MostrarImagen(int numFiltro, CStatic& m_control) { MIL_ID selected; MdispInquire(m_Mildisplay,M_SELECTED,&selected); if (selected!=M_NULL) MdispDeselect(m_Mildisplay,selected); DisplayBits(theApp.m_nBitsProfundidad); //para que el display muestre las imagenes de la profundidad de la imagen (puede que no estuviese si se estaba presentando la imagen de clasificacion) MdispSelectWindow(m_Mildisplay,m_Milimagen[numFiltro-1],m_control); return true; }
GRenderWinG::~GRenderWinG() { if (LocalBitmap) { if (HaveRenderedSomething) // We're not clean - flush bitmap to screen DisplayBits(); // FreeLPBits( lpBitmapInfo, lpBits ); FreeOffscreenState(); lpBitmapInfo = NULL; lpBits = NULL; } // will call GRenderRegions destructor here }
int DisplayBitmap( PBITMAP pBmp, char *filename ) { int scrn; XVisualInfo *visi = NULL; XSetWindowAttributes xwndsetattr; XWindowAttributes xwndattr; Colormap clrmap; XSizeHints szhints; XEvent event; GLXContext glctx; Atom wm_delete_window; XWMHints hints; Pixmap icon; char *s; if (!pBmp) { fprintf( stderr, "Can't read %s\n", filename ); return 1; } if ( pBmp->sampleformat!=BITMAP_UINT8 && pBmp->sampleformat!=BITMAP_IEEE ) { fprintf( stderr, "Can't display %s: not 8 bits or IEEE 32 bits per sample.\n", filename ); return 1; } if ( pBmp->nsamples!=1 && pBmp->nsamples!=3 && pBmp->nsamples!=4 ) { fprintf( stderr, "Can't display %s: not an 8, 24, or 32 bit per pixel image.\n", filename ); return 1; } dspy = XOpenDisplay( 0 ); if (!dspy) { fprintf( stderr, "Error connecting to X server\n" ); exit( -1 ); } scrn = DefaultScreen( dspy ); visi = glXChooseVisual( dspy, scrn, attributeListSgl ); if ( !visi ) { visi = glXChooseVisual( dspy, scrn, attributeListDbl ); switchbuffer = 1; } glctx = glXCreateContext( dspy, visi, 0, GL_TRUE ); clrmap = XCreateColormap( dspy, RootWindow(dspy, visi->screen ), visi->visual, AllocNone ); xwndsetattr.colormap = clrmap; xwndsetattr.border_pixel = 0; xwndsetattr.event_mask = StructureNotifyMask; wnd = XCreateWindow( dspy, RootWindow( dspy, visi->screen ), 0, /* x */ 0, /* y */ pBmp->xres, /* width */ pBmp->yres, /* height */ 0, visi->depth, InputOutput, visi->visual, CWBorderPixel | CWColormap | CWEventMask, &xwndsetattr ); XGetWindowAttributes( dspy, wnd, &xwndattr ); /* OpenGL likes the bitmap data to have the bottom row first, not the * top row. Note the left most column is the first column. */ pBmp = OrientBitmap( pBmp, BITMAP_BOTLEFT ); /* Get a hook in on the user quitting the app. This will prevent * that annoying "X connection to 0:0 broken" message. */ wm_delete_window = XInternAtom( dspy, "WM_DELETE_WINDOW", False ); (void) XSetWMProtocols( dspy, wnd, &wm_delete_window, 1 ); s = strrchr( filename, '/' ); if (!s) s = filename; else s++; XStoreName( dspy, wnd, s ); icon = XCreateBitmapFromData( dspy, wnd, (const char *)affine_bits, affine_width, affine_height ); hints.icon_pixmap = icon; hints.flags = IconPixmapHint; XSetWMHints( dspy, wnd, &hints ); szhints.flags = PMinSize | PMaxSize; szhints.min_width = pBmp->xres; szhints.max_width = pBmp->xres; szhints.min_height = pBmp->yres; szhints.max_height = pBmp->yres; XSetNormalHints( dspy, wnd, &szhints ); XMapWindow( dspy, wnd ); /* Connect the context to the window. */ glXMakeCurrent(dspy, wnd, glctx); glShadeModel(GL_FLAT); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); glViewport(0,0,pBmp->xres,pBmp->yres); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0,pBmp->xres,0.0,pBmp->yres,-1.0,1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); XSelectInput( dspy, wnd, ExposureMask | StructureNotifyMask ); for (;;) { XNextEvent( dspy, &event ); switch (event.type) { case MapNotify: DisplayBits( pBmp, 0, 0, pBmp->xres, pBmp->yres ); break; case Expose: if ( event.xexpose.window == wnd ) DisplayBits( pBmp, event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ClientMessage: if (event.xclient.data.l[0] == wm_delete_window && event.xclient.window == wnd ) goto Exit; break; } } Exit: if (wnd) XDestroyWindow( dspy, wnd ); if (visi) XFree(visi); if (pBmp) DestroyBitmap( pBmp ); return 0; }
// Calcula las imagenes monocromas para R, G y B segun los porcentajes dados, // reservando memoria y presentando la imagen RGB // Devuelve true si se ha realizado el calculo, false si no (porque ya se realizó antes) bool ControlImagenes::MostrarImagenRGB(int arrFiltroPorcentajesR[MAX_NUM_IMAGENES], int arrFiltroPorcentajesG[MAX_NUM_IMAGENES], int arrFiltroPorcentajesB[MAX_NUM_IMAGENES], CStatic& m_control, int nTotalR,int nTotalG,int nTotalB, bool bModificado) { MIL_ID selected; MdispInquire(m_Mildisplay,M_SELECTED,&selected); if (selected!=M_NULL) MdispDeselect(m_Mildisplay,selected); DisplayBits(8); //para que el display muestre las imagenes en profundidad 8 bit // Si es la primera vez, reservar la memoria de la imagen RGB if (m_MilRGB == M_NULL) MbufAllocColor(M_DEFAULT_HOST, 3, m_nAnchoImagen, m_nAltoImagen, 8+M_UNSIGNED, M_IMAGE+M_DISP, &m_MilRGB); //16 por si las imagenes estan en 16bit else if (!bModificado) { MdispSelectWindow(m_Mildisplay,m_MilRGB,m_control); return false; } unsigned short* pBuffImagen; //auxiliar para volcar cada imagen de cada filtro, 16 bit unsigned char* pRed; // auxiliar para calcular la banda de color (8 bit) unsigned char* pGreen; // auxiliar para calcular la banda de color (8 bit) unsigned char* pBlue; // auxiliar para calcular la banda de color (8 bit) pBuffImagen = (unsigned short*)calloc(m_nAnchoImagen*m_nAltoImagen, sizeof(unsigned short)); pRed = (unsigned char*)calloc(m_nAnchoImagen*m_nAltoImagen, sizeof(unsigned char)); pGreen = (unsigned char*)calloc(m_nAnchoImagen*m_nAltoImagen, sizeof(unsigned char)); pBlue = (unsigned char*)calloc(m_nAnchoImagen*m_nAltoImagen, sizeof(unsigned char)); for (int i= 0; i<MAX_NUM_IMAGENES;i++) { // Cargar buffers de filtros solo si se necesita en alguna de las bandas if (arrFiltroPorcentajesR[i] != 0 || arrFiltroPorcentajesG[i] != 0 || arrFiltroPorcentajesB[i] != 0) { MbufGet(m_Milimagen[i],pBuffImagen); //Acumular el pocentaje adecuado de este filtro en cada color if(arrFiltroPorcentajesR[i] != 0) { Acumular(pRed, pBuffImagen, ((double)arrFiltroPorcentajesR[i])/nTotalR, m_nAnchoImagen*m_nAltoImagen); } if(arrFiltroPorcentajesG[i] != 0) { Acumular(pGreen, pBuffImagen, ((double)arrFiltroPorcentajesG[i])/nTotalG, m_nAnchoImagen*m_nAltoImagen); } if(arrFiltroPorcentajesB[i] != 0) { Acumular(pBlue, pBuffImagen, ((double)arrFiltroPorcentajesB[i])/nTotalB, m_nAnchoImagen*m_nAltoImagen); } } } // Volcar el array auxiliar calculado al color correspondiente MbufPutColor(m_MilRGB,M_SINGLE_BAND,M_BLUE/*2*/,pBlue); MbufPutColor(m_MilRGB,M_SINGLE_BAND,M_GREEN/*1*/,pGreen); MbufPutColor(m_MilRGB,M_SINGLE_BAND,M_RED/*0*/,pRed); free(pBuffImagen); free(pBlue); free(pGreen); free(pRed); // Mostar la imagen en color MdispSelectWindow(m_Mildisplay,m_MilRGB,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 // y porque puede ser que no se haya hecho al cargar las imagenes pancromaticas (en el caso // de que la primera imagen mostrada sea la pancromatica, ver CAnalisisDlg::AbrirTodas y CargarImagen) if (M_overlay_normal==NULL) { MdispInquire(m_Mildisplay, M_OVERLAY_ID, &M_overlay_normal); // Relleno el buffer overlay con el color TRANSPARENTE MbufClear(M_overlay_normal, TRANSPARENTE ); } return true; }