📄 marki.cpp
字号:
return nrows;}//-----------------------------------------------------------------------------static void SaveState (void){char sHeader[SLEN];CreateMarkedFile();CreateTaggedFile();fgMarkedFilesUpToDate = true;fgTaggedFilesUpToDate = true;lprintf("Creating \"%s\" ", sgNewShapeFile);lprintf("(%d landmarks per shape) ", ngPoints);if (fgOnlySelectedFiles) { sprintf(sHeader, "created by %s from %s (AdjLandmark %d)", sgProgramName, sgShapeFile, igLandmark); WriteShapeFile(sgNewShapeFile, gShapes, gTagStrings, ngImages, ngPoints, sHeader, sgImageDirs); }else { sprintf(sHeader, "Modified by %s from %s (AdjLandmark %d)", sgProgramName, sgShapeFile, igLandmark); UpdateShapeFile(sgNewShapeFile, sgShapeFile, gShapes, gTagStrings, ngImages, ngPoints, sHeader); }}//-----------------------------------------------------------------------------static void UpdateDlgWnd (void){char s[SLEN];sprintf(s, "%d", igImage);SetDlgItemText(hgDlgWnd, IDC_IMAGE_NBR, s);sprintf(s, "of %d", ngImages);SetDlgItemText(hgDlgWnd, IDC_NBR_IMAGES, s);sprintf(s, "%d", igLandmark);SetDlgItemText(hgDlgWnd, IDC_LANDMARK, s);sprintf(s, "of %d", ngPoints);SetDlgItemText(hgDlgWnd, IDC_NBR_LANDMARKS, s);char *sMarked = "";//TODO it would be nice to get rid of this loopfor (int iPoint = 0; iPoint < ngPoints; iPoint++) if (fPointMarked(igImage, iPoint)) { sMarked = "MARKED "; break; }char *sStat = "";eImageStatus eStat = gImageStatus[igImage];if (eStat) sStat = sgImageStatus[eStat];char *sAttr = "";if (gTagStrings.size()) // initialized? { unsigned int Attr; const char *sTag = gTagStrings[igImage].c_str(); if (1 != sscanf(sTag, "%x", &Attr)) SysErr("Can't convert first part of tag %s to a hex number", sTag); sAttr = sGetAtFaceString(Attr); }sprintf(s, "%s%s%s%s", sMarked, sStat, ((sMarked[0]||sStat[0])? " ":""), sAttr);SetDlgItemText(hgDlgWnd, IDC_MARKED, s);SetDlgItemText(hgDlgWnd, IDC_SAVED, ((fgMarkedFilesUpToDate && fgTaggedFilesUpToDate)? "": "Changes not saved"));if (gTagStrings.size() > igImage) { sprintf(s, "%s ", gTagStrings[igImage].c_str()); SetDlgItemText(hgDlgWnd, IDC_FILE_NAME, s); }}//-----------------------------------------------------------------------------BOOL CALLBACK DlgProc (HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam){char s[SLEN];switch (msg) { case WM_INITDIALOG: { // Move the dialog window to the right place // It's actually a top level window so we need to position wrt the screen RECT RectWorkArea; SystemParametersInfo(SPI_GETWORKAREA, 0, &RectWorkArea, 0); #define CONF_nDlgWidth 180 #define CONF_nDlgHeight 190 MoveWindow(hDlg, xgDlg, ygDlg, CONF_nDlgWidth, CONF_nDlgHeight+30, true); SendDlgItemMessage(hDlg, IDC_IMAGE_NBR, EM_LIMITTEXT, SLEN, 0); SendDlgItemMessage(hDlg, IDC_LANDMARK, EM_LIMITTEXT, SLEN, 0); SetWindowText(hDlg, sgProgramName); UpdateDlgWnd(); return false; } case WM_COMMAND: //TODO need to fix edit box to allow tab and return (current dialog modelled on petzold/strprog.c) if (wParam == IDOK) { bool fLoad = false; int iInput = -1; GetDlgItemText(hDlg, IDC_LANDMARK, s, SLEN); if (1 != sscanf(s, "%d", &iInput) || iInput < 0 || iInput > ngPoints) Err("Bad landmark specified \"%s\", allowed range is 0 to %d", s, ngPoints-1); else { if (iInput != igLandmark) { igLandmark = iInput; fLoad = true; lprintf("New landmark %d\n", igLandmark, igImage); } GetDlgItemText(hDlg, IDC_IMAGE_NBR, s, SLEN); if (1 != sscanf(s, "%d", &iInput) || iInput < 0 || iInput >= INT_MAX-10) Err("Bad image index \"%s\"", s); else { if (iInput > ngImages-1) iInput = ngImages-1; if (iInput != igImage) { igImage = iInput; fLoad = true; lprintf("New image index %d \"%s\"\n", igImage, gTagStrings[igImage].c_str()); } } } if (fLoad) { sLoadCurrentImage(MA_SHOW_ERR); InvalidateRect(hgMainWnd, NULL, false); // force repaint of entire window } return true; } }return false;}//-----------------------------------------------------------------------------static void AdjustTagBit (int iImage, unsigned iBit, bool fSet){if (iBit) { unsigned Attr; const char *sTag = gTagStrings[igImage].c_str(); if (1 != sscanf(sTag, "%x", &Attr)) SysErr("Can't convert first part of tag %s to a hex number", sTag); else { if (fSet) Attr |= iBit; else Attr &= ~iBit; char s[SLEN]; sprintf(s, "%4.4x %s", Attr, gTagStrings[iImage].c_str() + FNAME_OFFSET); gTagStrings[iImage] = s; } }}//-----------------------------------------------------------------------------static bool fAcceptCmd (void){bool fLoad = false;gImageStatus[igImage] = ST_ACCEPT;AdjustTagBit(igImage, gRejectBit, false);lprintf("ACCEPT %s\n", gTagStrings[igImage].c_str());if (fgAutoNext) { IdmNext(); fLoad = true; }fgTaggedFilesUpToDate = false;return fLoad;}//-----------------------------------------------------------------------------static bool fRejectCmd (void){bool fLoad = false;gImageStatus[igImage] = ST_REJECT;AdjustTagBit(igImage, gRejectBit, true);lprintf("REJECT %s\n", gTagStrings[igImage].c_str());if (fgAutoNext) { IdmNext(); fLoad = true; }fgTaggedFilesUpToDate = false;return fLoad;}//-----------------------------------------------------------------------------void WmCommand (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam){fgChug = false; // any command turns off chuggingbool fLoad = false;switch (wParam) { case IDM_Save:#if 0 // alway save if (!fgMarkedFilesUpToDate || !fgTaggedFilesUpToDate)#endif SaveState(); break; case IDM_AutoNext: fgAutoNext ^= 1; // Tell the button to display itself as depresed or not, depending on value of fgAutoNext SendMessage(hgToolbar, TB_CHECKBUTTON, IDM_AutoNext, (LPARAM)MAKELONG(fgAutoNext, 0)); break; case IDM_Equalize: fgEqualize ^= 1; SendMessage(hgToolbar, TB_CHECKBUTTON, IDM_Equalize, (LPARAM)MAKELONG(fgEqualize, 0)); fLoad = true; break; case IDM_ConnectDots: fgConnectDots ^= 1; SendMessage(hgToolbar, TB_CHECKBUTTON, IDM_ConnectDots, (LPARAM)MAKELONG(fgConnectDots, 0)); fLoad = true; break; case IDM_EraseLandmark: lprintf("Erased iLandmark %d image %s\n", igLandmark, gTagStrings[igImage].c_str()); gShapes[igImage](igLandmark, VX) = 0; gShapes[igImage](igLandmark, VY) = 0; fgMarkedFilesUpToDate = false; fLoad = true; if (fgAutoNext) IdmNext(); break; case IDM_Crop: if (++igCrop > CONF_nMaxCrop) igCrop = 0; fLoad = true; break; case IDM_Prev: IdmPrev(); fLoad = true; break; case IDM_Next: IdmNext(); fLoad = true; break; case IDM_Accept: fLoad = fAcceptCmd(); break; case IDM_Reject: fLoad = fRejectCmd(); break; default: SysErr("WmCommand bad param %u", wParam); break; }if (fLoad) sLoadCurrentImage(MA_SHOW_ERR);InvalidateRect(hgMainWnd, NULL, false); // force repaint of entire window}//-----------------------------------------------------------------------------static void Wm_LButtonDown (LPARAM lParam){int ix, iy;int xMouse = LOWORD(lParam);int yMouse = HIWORD(lParam);#if 1ix = ((double)xMouse * gImg.width) / ngMaiwidth - 1;iy = gImg.height - ((double)yMouse * gImg.height) / ngMaiheight - 1;#else // code before changes to DrawShapeix = ((double)xMouse * gImg.width) / ngMaiwidth;iy = gImg.height - ((double)yMouse * gImg.height) / ngMaiheight;#endifif (ix || iy) // never use 0,0 value, that's our special "unused" value { // update screen image with this mark tRGB *p = &gImg(ix, iy); p->Red = 0; p->Green = 255; p->Blue = 255; // cyan ix = igLeftCrop + ix - (gImg.width + igLeftCrop + igRightCrop)/2; // screen to shape coords iy = igBottomCrop - (gImg.height + igBottomCrop + igTopCrop)/2 + iy; lprintf("Mark %s %d %d (was %g %g)\n", gTagStrings[igImage].c_str(), ix, iy, gShapesOrg[igImage](igLandmark, VX), gShapesOrg[igImage](igLandmark, VY)); gShapes[igImage](igLandmark, VX) = ix; gShapes[igImage](igLandmark, VY) = iy; // make sure coords aren't 0,0 because that means "unused landmark" if (gShapes[igImage](igLandmark, VX) == 0 && gShapes[igImage](igLandmark, VY) == 0) gShapes[igImage](igLandmark, VX) = 0.1; fgMarkedFilesUpToDate = false; if (fgAutoNext) IdmNext(); sLoadCurrentImage(MA_SHOW_ERR); InvalidateRect(hgMainWnd, NULL, false); // force repaint of entire window }SetCursor(LoadCursor (NULL, IDC_CROSS)); // this is needed, not sure why}//-----------------------------------------------------------------------------static void CheckSaveState (void){if ((!fgMarkedFilesUpToDate || !fgTaggedFilesUpToDate) && fYesNoMsg(true, "Save state?\n\nFiles:\n%c %s\n%c %s\n%c %s\n%c %s", (fgMarkedFilesUpToDate? ' ': '*'), sgNewShapeFile, (fgMarkedFilesUpToDate? ' ': '*'), sgMarkedFile, (fgTaggedFilesUpToDate? ' ': '*'), sgTagged, (fgTaggedFilesUpToDate? ' ': '*'), sgUmSed)) { SaveState(); }}//-----------------------------------------------------------------------------static void WmPaint (HWND hWnd){HDC hdc;PAINTSTRUCT ps;// display the image -- magnify it so it fills windowBITMAPINFO BmInfo;memset(&BmInfo.bmiHeader, 0, sizeof(BmInfo.bmiHeader));BmInfo.bmiHeader.biSize = 40;BmInfo.bmiHeader.biWidth = gImg.width;BmInfo.bmiHeader.biHeight = gImg.height;BmInfo.bmiHeader.biPlanes = 1;BmInfo.bmiHeader.biBitCount = 24;hdc = BeginPaint(hWnd, &ps);StretchDIBits(hdc, 0, 0, ngMaiwidth, ngMaiheight, 0, 0, gImg.width, gImg.height, // xSrcLowerLeft, ySrcLowerLeft, SrcWidth, SrcHeight gImg.buf, // lpBits (LPBITMAPINFO)&BmInfo, // lpBitsInfo DIB_RGB_COLORS, // wUsage SRCCOPY); // raser operation codeEndPaint(hWnd, &ps);UpdateDlgWnd();}//-----------------------------------------------------------------------------static void WmTimer (void){fgChug = true;IdmNext();sLoadCurrentImage(MA_SHOW_ERR);SetTimer(hgMainWnd, IdTimer_Chug, igChugDelay, NULL);InvalidateRect(hgMainWnd, NULL, false); // force repaint of entire window}//-----------------------------------------------------------------------------static void WmKeydown (HWND hWnd, WPARAM wParam){bool fLoad = true;bool fTempChug = fgChug; // any key stops chugging but we have tofgChug = false; // make sure pushing 'C' toggles chugging tooswitch (wParam) { case ' ': // space case VK_NEXT: // page down IdmNext(); break; case VK_PRIOR: // page up IdmPrev(); break; case VK_HOME: // goto first image igImage = 0; break; case VK_END: // goto last image igImage = ngImages-1; break; case 'C': // chug mode if (!fTempChug) WmTimer(); break; case 'A': // accept fLoad = fAcceptCmd(); break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -