/* EXPORT-> MakeXGraf: Create and open window, initialization */ void MakeXGraf(char *wname, int x, int y, int w, int h, int bw) /* WIN32: bw is ignored. */ { WNDCLASS WindowClass; char sbuf[256], *hgraf = "HGraf"; HDC dc; if (winCreated) HError(6870, "MakeXGraf: Attempt to recreate the graphics window"); WindowClass.hInstance = GetModuleHandle(NULL); WindowClass.lpszClassName = hgraf; WindowClass.lpfnWndProc = HGWinFunc; WindowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; WindowClass.hIcon = NULL; WindowClass.hCursor = LoadCursor(NULL,IDC_ARROW); WindowClass.lpszMenuName = NULL; WindowClass.cbClsExtra = 0; WindowClass.cbWndExtra = 0; WindowClass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH); RegisterClass(&WindowClass); strcpy(sbuf, hgraf); strcat(sbuf, ": "); strcat(sbuf, wname); theWindow = CreateWindow(hgraf, sbuf, WS_OVERLAPPEDWINDOW | WS_VISIBLE, x,y, w,h, HWND_DESKTOP, NULL, WindowClass.hInstance, NULL); /* adjust window size so that the client rectangle is the size requested */ /* by the caller of MakeXGraf() --- Win32 interprets w and h as the dimensions */ /* of the overall window. */ GetClientRect(theWindow,&ClientRect); MoveWindow(theWindow,x,y,w+w-ClientRect.right,h+h-ClientRect.bottom,TRUE); GetClientRect(theWindow,&ClientRect); /* Obtain and initialize device contexts */ dc = GetDC(theWindow); memDC = CreateCompatibleDC(dc); SetArcDirection(memDC,AD_COUNTERCLOCKWISE); SetArcDirection(dc,AD_COUNTERCLOCKWISE); SetPolyFillMode(memDC,WINDING); SetPolyFillMode(memDC,WINDING); SetTextAlign(memDC,TA_BASELINE | TA_LEFT); SetTextAlign(dc,TA_BASELINE | TA_LEFT); SetBkMode(memDC,TRANSPARENT); SetBkMode(dc,TRANSPARENT); theBitmap = CreateCompatibleBitmap(dc,w,h); SelectObject(memDC,theBitmap); ReleaseDC(theWindow,dc); CreateHeap(&btnHeap, "Button heap", MHEAP, sizeof(HButton), 1.0, 100, 100); InitGlobals(); InstallColours(); winCreated = TRUE; HSetColour(WHITE); HFillRectangle(0,0,ClientRect.right,ClientRect.bottom); }
// Initialise sizes for display window void ARec::InitDrawRD() { const int margin = 4; int textheight; int nlines; textheight = HTextHeight(win,"ABCD"); x0 = margin; y0 = margin; x1 = width-margin; x2 = x0 + HTextWidth(win,"Status") + 2; x3 = x2+20; x4 = x3+ 2*margin; x5 = x4 + HTextWidth(win,"Time") + 2; x6 = x5 + HTextWidth(win,"9999.9s") + 2; x7 = x6 + HTextWidth(win,"Score") + 2; x8 = x7 + 40; x9 = x8 + 4*margin; x10 = x9 + HTextWidth(win,"HMM") + 4; x11 = x10 + HTextWidth(win,"aa-yy+bb") + 4; x12 = x11 + HTextWidth(win,"Nact") + 6; x13 = x12 + HTextWidth(win,"9999") + 6; x14 = x13 + HTextWidth(win,"Mode") + 4; y9 = height - margin; y8 = y9 - margin; y5 = y8 - margin; y4 = y5 - textheight - 1; y3 = y4 - margin; y6 = (int) (y3 - textheight*1.5); y1 = y6 - margin; y7 = y1 - margin-2; HSetFontSize(win,-14); textheight = HTextHeight(win,"ABCD"); rdlyinc = textheight+2; HSetFontSize(win,0); nlines = (y7-y0) / rdlyinc; --nlines; rdly = y7 - nlines*rdlyinc; // paint background HSetGrey(win,PANELGREY2); HFillRectangle(win,0,0,width,height); // paint output panel HDrawPanel(win,x0,y0,x1,y1,PANELGREY1); // paint traceback panel HDrawPanel(win,x0,y6,x1,y3,PANELGREY1); // write labels HSetGrey(win,PANELGREY0); HPrintf(win,x0,y5,"Status"); HPrintf(win,x4,y5,"Time"); HPrintf(win,x6,y5,"Score"); HPrintf(win,x9,y5,"HMM"); HPrintf(win,x11,y5,"NAct"); HPrintf(win,x13,y5,"Mode"); }
void ARec::ScrollOutBox() { int w,h; if ( (rdly+rdlyinc) > y7) { // scroll h = y7-(y0+1)-rdlyinc+3; w = x1-x0-2; HCopyArea(win,x0+1,rdly+3-h,w,h,x0+1,y0+1); HSetGrey(win,PANELGREY1); HFillRectangle(win,x0+1,y1-rdlyinc-1,x1-1,y1-1); rdly = y7; } else rdly += rdlyinc; }
// Draw current status void ARec::DrawStatus() { if (laststate != runstate){ switch(runstate){ case WAIT_STATE: HSetColour(win,RED); break; case PRIME_STATE: HSetColour(win,ORANGE); break; case FLUSH_STATE: HSetColour(win,YELLOW); break; case RUN_STATE: HSetColour(win,DARK_GREEN); break; case ANS_STATE: HSetColour(win,MAUVE); break; } HFillRectangle(win,x2,y4+4,x3,y5+1); laststate = runstate; } int npkts = in->NumPackets(); if (npkts != inlevel){ inlevel = npkts; int x = npkts+x0; if (x>x1) x = x1; HSetGrey(win,PANELGREY1); HFillRectangle(win,x0,y8,x1,y9); HSetColour(win,RED); HFillRectangle(win,x0+1,y8,x,y9); } }
// Do traceback and if showRD then update display void ARec::TraceBackRecogniser() { int i,st,en; char *p,buf[10]; MLink m; Path *pp; float tnow,confidence,ac; int iscore; PartialPath pptb,ppcb; ppcb = CurrentBestPath(pri); // get the word that the current best path is within p=""; if (ppcb.node!=NULL && ppcb.node->wordset!=NULL) p = ppcb.node->wordset->name; // update time tnow = float((pri->frame*sampPeriod + stTime)/1e7); if (showRD){ HSetColour(win,BLACK); HSetGrey(win,PANELGREY2); HFillRectangle(win,x5-1,y4-1,x6+1,y5+1); HSetColour(win,BLACK); HPrintf(win,x5,y5,"%.1fs",tnow); } // update HMM, nactive, and score (but ignore silence) if (showRD){ m=FindMacroStruct(hset,'h',pri->genMaxNode->info.hmm); assert(m!=NULL); if (strcmp(m->id->name,"sil") != 0 && strcmp(m->id->name,"sp") != 0) { st = trbakFrame; en = pri->frame; ac = float(pri->genMaxTok.like - trbakAc); confidence = GetConfidence(pri,st+1,en,ac,""); //printf("CONFA %d->%d = %f [%f - %f = %f]\n",st,en,confidence,pri->genMaxTok.like,trbakAc,ac); trbakFrame = pri->frame; trbakAc = float(pri->genMaxTok.like); iscore = (int) (float(x7) + confidence*float(x8-x7)); if (iscore<=x7) { HSetColour(win,RED); HFillRectangle(win,x7,y4+4,x8,y5+1); }else if (iscore>=x8) { HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,x8,y5+1); }else { HSetColour(win,RED); HFillRectangle(win,iscore,y4+4,x8,y5+1); HSetColour(win,DARK_GREEN); HFillRectangle(win,x7,y4+4,iscore,y5+1); } } // update HMM HSetGrey(win,PANELGREY2); HFillRectangle(win,x10,y4-1,x11,y5+3); HSetColour(win,BLACK); HPrintf(win,x10,y5,"%s",m->id->name); // update nactive HSetGrey(win,PANELGREY2); HFillRectangle(win,x12,y4-1,x13,y5+1); HSetColour(win,BLACK); HPrintf(win,x12,y5,"%d", pri->nact); // update mode HSetGrey(win,PANELGREY2); HFillRectangle(win,x14,y4-1,x1,y5+1); HSetColour(win,BLACK); strcpy(buf," "); if (runmode&ONESHOT_MODE) buf[0] = '1'; if (runmode&CONTINUOUS_MODE) buf[0] = 'C'; if (runmode&RUN_IMMED) buf[1] = 'I'; if (runmode&FLUSH_TOMARK) buf[1] = 'M'; if (runmode&FLUSH_TOSPEECH) buf[1] = 'S'; if (runmode&STOP_IMMED) buf[2] = 'I'; if (runmode&STOP_ATMARK) buf[2] = 'M'; if (runmode&STOP_ATSIL) buf[2] = 'S'; if (runmode&RESULT_ATEND) buf[3] = 'E'; if (runmode&RESULT_IMMED) buf[3] = 'I'; if (runmode&RESULT_ASAP) buf[3] = 'A'; if ((runmode&RESULT_ALL) == RESULT_ALL) buf[3] = 'X'; HPrintf(win,x14,y5,"%s",buf); } // if showRD do full traceback if (showRD){ string s = p; char buf[256],*bp; for (pp = ppcb.path; pp!=NULL; pp=pp->prev){ if (pp->owner->node->info.pron != NULL) // it might be a !NULL tag s = string(pp->owner->node->info.pron->word->wordName->name) + string(" ") + s; } if (s != trbak){ int w = x1-x0-8,txtw; trbak = s; HSetGrey(win,PANELGREY1); strcpy(buf,s.c_str()); bp = buf; txtw = HTextWidth(win,bp); while (txtw>w) txtw = HTextWidth(win,++bp); HFillRectangle(win,x0+1,y6+2,x0+trbakLastWidth+5,y3-2); HSetColour(win,BLACK); HPrintf(win,x0+4,y3-4,"%s",bp); trbakLastWidth = txtw; } } // runmode is RESULT_ASAP, see if anything more can be disambiguated if (runmode&RESULT_ASAP){ pptb = DoTraceBack(pri); if (pptb.n>0){ if (trace&T_PAN) { printf(" traceback at frame %.1f\n",tnow); PrintPartialPath(pptb,FALSE); } for (i=1; i<=pptb.n; i++) OutPathElement(i,pptb); } } // runmode is RESULT_IMMED, output any new words regardless if ((runmode&RESULT_IMMED) && (ppcb.n>0)){ if (trace&T_IAN) { printf(" current best at frame %.1f\n",tnow); PrintPartialPath(ppcb,FALSE); } for (i=1; i<=ppcb.n; i++) OutPathElement(i,ppcb); } }