www.pudn.com > 医学图像处理示例源代码.rar > CommonProc.cpp
#include "stdafx.h" #include#include #include "resource.h" #include "CommonProc.h" #include CIni::CIni() { csLineEnd = "\r\n"; } CIni::~CIni() { Clear(); } bool CIni::Read(const char * cFileName) { Clear(); char buf[1024]; ifstream ifs(cFileName); while (ifs.good()) { ifs.getline(buf, 1023); CString cs(buf); csList.Add(cs); } return true; } bool CIni::Write(const char * cFileName) { ASSERT(cFileName); ofstream ofs(cFileName); int t, max = csList.GetSize(); for (t = 0; t < max; t++) { ofs << csList.GetAt(t) << "\n"; } return true; } // ********************************************************************************** void CIni::Clear() { csList.RemoveAll(); } // ********************************************************************************** int CIni::FindSection(const char * cSection) { int t, max = csList.GetSize(); CString csSection; csSection.Format("[%s]", cSection); for (t = 0; t < max; t++) if (csList.GetAt(t) == csSection) return t; return -1; } int CIni::InsertSection(const char * cSection) { ASSERT(cSection); if (!cSection) return -1; int idx = FindSection(cSection); if (idx < 0) { CString csSection; csSection.Format("[%s]", cSection); idx = csList.Add(csSection); } return idx; } int CIni::FindItem(const int iSection, const char * cItem, CString &csVal) { ASSERT(iSection >= 0); ASSERT(cItem); int max = csList.GetSize(), t; CString csItem(cItem), csLook; csItem += " = "; int iLen = csItem.GetLength(); for (t = iSection; t < max; t++) { if (!IsSection(t)) { csLook = csList.GetAt(t); if (csLook.GetLength() >= iLen) { if (csLook.Left(iLen) == csItem) { if (csLook.GetLength() == iLen) csVal = ""; else csVal = csLook.Right(csLook.GetLength() - iLen); return t; } } } else return -1; } return -1; } int CIni::FindMultiItem(const int iSection, const char * cItem, CString &csVal) { ASSERT(iSection >= 0); ASSERT(cItem); int max = csList.GetSize(), t, i; CString csItem(cItem), csLook; csItem += " = \""; int iLen = csItem.GetLength(); for (t = iSection; t < max; t++) { if (!IsSection(t)) { csLook = csList.GetAt(t); if (csLook == csItem) { csVal = ""; for (i = t + 1; i < max; i++) { csLook = csList.GetAt(i); if (csLook == '\"' || IsSection(i)) { i = max; } else { if (csVal != "") csVal += csLineEnd; csVal += csLook; } } return t; } } else return -1; } return -1; } bool CIni::IsSection(const int iSection) { ASSERT(iSection >= 0 && iSection < csList.GetSize()); if (iSection >= 0 && iSection < csList.GetSize()) { CString csItem = csList.GetAt(iSection); if (csItem.GetLength() > 2 && csItem.Left(1) == '[' && csItem.Right(1) == ']') return true; } return false; } bool CIni::RemoveSection(const char * cSection) { int idx = FindSection(cSection); if (idx >= 0) { for (;;) { csList.RemoveAt(idx); if (idx >= csList.GetSize()) return true; if (IsSection(idx)) return true; } } return true; } void CIni::RemoveMultiLineItem(const int idx) { int max = csList.GetSize(), t; CString csLook; for (t = idx; t < max; t++) { if (!IsSection(t)) { csLook = csList.GetAt(t); if (csLook == '\"') { csList.RemoveAt(t); return; } csList.RemoveAt(t); } else return; } } // ********************************************************************************** bool CIni::SetValue(const char * cSection, const char * cItem, const bool bVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %s", cItem, bVal ? "true" : "false"); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const COLORREF crVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %d", cItem, (DWORD) crVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const char * cVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %s", cItem, cVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const double dbVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %20.20f", cItem, dbVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const float fVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %f", cItem, fVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const long lVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %d", cItem, lVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const int iVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %d", cItem, iVal); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetMultiValue(const char * cSection, const char * cItem, const char * cVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %s", cItem, cVal); char * c = csVal.LockBuffer(); int i = csVal.Find('\r'); while (i >= 0) { c[i] = '}'; i = csVal.Find('\r'); } i = csVal.Find('\n'); while (i >= 0) { c[i] = '|'; i = csVal.Find('\n'); } csVal.UnlockBuffer(); if (iIdx >= 0) csList.SetAt(iIdx, csVal);//how else csList.InsertAt(idx+1, csVal); return true; } return false; } /*bool CIni::SetHospitalValue(const char * cSection, const char * cItem, const char * cVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = %s", cItem, cVal); char * c = csVal.LockBuffer(); int i = csVal.Find('\r'); while (i >= 0) { c[i] = '}'; i = csVal.Find('\r'); } i = csVal.Find('\n'); while (i >= 0) { c[i] = '|'; i = csVal.Find('\n'); } csVal.UnlockBuffer(); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; }*/ bool CIni::SetValue(const char * cSection, const char * cItem, const CRect rcVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = RECT(%d,%d,%d,%d)", cItem, rcVal.left, rcVal.top, rcVal.right, rcVal.bottom); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } bool CIni::SetValue(const char * cSection, const char * cItem, const CPoint ptVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; int iIdx = FindItem(idx+1, cItem, csVal); csVal.Format("%s = POINT(%d,%d)", cItem, ptVal.x, ptVal.y); if (iIdx >= 0) csList.SetAt(iIdx, csVal); else csList.InsertAt(idx+1, csVal); return true; } return false; } // ********************************************************************************** bool CIni::GetValue(const char * cSection, const char * cItem, COLORREF &crVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { crVal = (COLORREF) (DWORD) atol(csVal); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, bool &bVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { if (csVal.Find("true") >= 0) bVal = true; else bVal = false; return true; } } return false; } bool CIni::GetMultiValue(const char * cSection, const char * cItem, CString &cVal) { int idx = FindSection(cSection); if (idx >= 0) { if (FindItem(idx+1, cItem, cVal) > 0) { char * ch = cVal.LockBuffer(); int i = cVal.Find('}'); while (i >= 0) { ch[i] = '\r'; i = cVal.Find('}'); } i = cVal.Find('|'); while (i >= 0) { ch[i] = '\n'; i = cVal.Find('|'); } cVal.UnlockBuffer(); return true; } } return false; } /*bool CIni::GetHospitalValue(const char * cSection, const char * cItem, CString &cVal) { int idx = FindSection(cSection); if (idx >= 0) { if (FindItem(idx+1, cItem, cVal) > 0) { char * ch = cVal.LockBuffer(); int i = cVal.Find('}'); while (i >= 0) { ch[i] = '\r'; i = cVal.Find('}'); } i = cVal.Find('|'); while (i >= 0) { ch[i] = '\n'; i = cVal.Find('|'); } cVal.UnlockBuffer(); return true; } } return false; }*/ bool CIni::GetValue(const char * cSection, const char * cItem, CString &cVal) { int idx = FindSection(cSection); if (idx >= 0) { if (FindItem(idx+1, cItem, cVal) > 0) return true; } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, double &dbVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { dbVal = atof(csVal); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, float &fVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { fVal = (float) atof(csVal); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, long &lVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { lVal = (long) atol(csVal); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, int &iVal) { int idx = FindSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { iVal = (int) atoi(csVal); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, CRect &rcVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { char * pt = csVal.LockBuffer(); int pf, t = 0, l = 0, r = 0, b = 0; pf = sscanf(csVal, "RECT(%d,%d,%d,%d)", &l, &t, &r, &b); ASSERT(pf == 4); csVal.UnlockBuffer(); rcVal.SetRect(l, t, r, b); return true; } } return false; } bool CIni::GetValue(const char * cSection, const char * cItem, CPoint &ptVal) { int idx = InsertSection(cSection); if (idx >= 0) { CString csVal; if (FindItem(idx+1, cItem, csVal) > 0) { char * pt = csVal.LockBuffer(); int pf, x = 0, y = 0; pf = sscanf(csVal, "POINT(%d,%d)", &x, &y); ASSERT(pf == 2); csVal.UnlockBuffer(); ptVal.x = x; ptVal.y = y; return true; } } return false; } ///////////////////////////////////////////////////////////////////////////// // CProgressDlg dialog CProgressDlg::CProgressDlg(UINT nCaptionID) { m_nCaptionID = CG_IDS_PROGRESS_CAPTION; if (nCaptionID != 0) m_nCaptionID = nCaptionID; m_bCancel=FALSE; m_nLower=0; m_nUpper=100; m_nStep=10; //{{AFX_DATA_INIT(CProgressDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_bParentDisabled = FALSE; } CProgressDlg::~CProgressDlg() { if(m_hWnd!=NULL) DestroyWindow(); } BOOL CProgressDlg::DestroyWindow() { ReEnableParent(); return CDialog::DestroyWindow(); } void CProgressDlg::ReEnableParent() { if(m_bParentDisabled && (m_pParentWnd!=NULL)) m_pParentWnd->EnableWindow(TRUE); m_bParentDisabled=FALSE; } BOOL CProgressDlg::Create(CWnd *pParent) { // Get the true parent of the dialog m_pParentWnd = CWnd::GetSafeOwner(pParent); // m_bParentDisabled is used to re-enable the parent window // when the dialog is destroyed. So we don't want to set // it to TRUE unless the parent was already enabled. if((m_pParentWnd!=NULL) && m_pParentWnd->IsWindowEnabled()) { m_pParentWnd->EnableWindow(FALSE); m_bParentDisabled = TRUE; } if(!CDialog::Create(CProgressDlg::IDD,pParent)) { ReEnableParent(); return FALSE; } return TRUE; } void CProgressDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CProgressDlg) DDX_Control(pDX, CG_IDC_PROGDLG_PROGRESS, m_Progress); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CProgressDlg, CDialog) //{{AFX_MSG_MAP(CProgressDlg) //}}AFX_MSG_MAP END_MESSAGE_MAP() void CProgressDlg::SetStatus(LPCTSTR lpszMessage) { ASSERT(m_hWnd); // Don't call this _before_ the dialog has // been created. Can be called from OnInitDialog CWnd *pWndStatus = GetDlgItem(CG_IDC_PROGDLG_STATUS); // Verify that the static text control exists ASSERT(pWndStatus!=NULL); pWndStatus->SetWindowText(lpszMessage); } void CProgressDlg::OnCancel() { m_bCancel=TRUE; } void CProgressDlg::SetRange(int nLower,int nUpper) { m_nLower = nLower; m_nUpper = nUpper; m_Progress.SetRange(nLower,nUpper); } int CProgressDlg::SetPos(int nPos) { PumpMessages(); int iResult = m_Progress.SetPos(nPos); UpdatePercent(nPos); return iResult; } int CProgressDlg::SetStep(int nStep) { m_nStep = nStep; // Store for later use in calculating percentage return m_Progress.SetStep(nStep); } int CProgressDlg::OffsetPos(int nPos) { PumpMessages(); int iResult = m_Progress.OffsetPos(nPos); UpdatePercent(iResult+nPos); return iResult; } int CProgressDlg::StepIt() { PumpMessages(); int iResult = m_Progress.StepIt(); UpdatePercent(iResult+m_nStep); return iResult; } void CProgressDlg::PumpMessages() { // Must call Create() before using the dialog ASSERT(m_hWnd!=NULL); MSG msg; // Handle dialog messages while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if(!IsDialogMessage(&msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } } BOOL CProgressDlg::CheckCancelButton() { // Process all pending messages PumpMessages(); // Reset m_bCancel to FALSE so that // CheckCancelButton returns FALSE until the user // clicks Cancel again. This will allow you to call // CheckCancelButton and still continue the operation. // If m_bCancel stayed TRUE, then the next call to // CheckCancelButton would always return TRUE BOOL bResult = m_bCancel; m_bCancel = FALSE; return bResult; } void CProgressDlg::UpdatePercent(int nNewPos) { CWnd *pWndPercent = GetDlgItem(CG_IDC_PROGDLG_PERCENT); int nPercent; int nDivisor = m_nUpper - m_nLower; ASSERT(nDivisor>0); // m_nLower should be smaller than m_nUpper int nDividend = (nNewPos - m_nLower); ASSERT(nDividend>=0); // Current position should be greater than m_nLower nPercent = nDividend * 100 / nDivisor; // Since the Progress Control wraps, we will wrap the percentage // along with it. However, don't reset 100% back to 0% if(nPercent!=100) nPercent %= 100; // Display the percentage CString strBuf; strBuf.Format(_T("%d%c"),nPercent,_T('%')); CString strCur; // get current percentage pWndPercent->GetWindowText(strCur); if (strCur != strBuf) pWndPercent->SetWindowText(strBuf); } ///////////////////////////////////////////////////////////////////////////// // CProgressDlg message handlers BOOL CProgressDlg::OnInitDialog() { CDialog::OnInitDialog(); m_Progress.SetRange(m_nLower,m_nUpper); m_Progress.SetStep(m_nStep); m_Progress.SetPos(m_nLower); CString strCaption; VERIFY(strCaption.LoadString(m_nCaptionID)); SetWindowText(strCaption); return TRUE; } CString GetNextSerialFilename(CString Filename) { CString ReturnString = Filename; int count = Filename.GetLength(); int StartPos = count-4; if(Filename.GetAt(StartPos)!='.') { AfxMessageBox("wrong in filename!"); return "haha"; } BOOL ok = FALSE; BYTE tChar; while(!ok) { StartPos--; if(StartPos<=0) ok = TRUE; tChar = Filename.GetAt(StartPos) - '0'; if(tChar>=0&&tChar<9) { tChar = tChar + 1 + '0'; ReturnString.SetAt(StartPos,tChar); ok = TRUE; } else { if(tChar==9) ReturnString.SetAt(StartPos,'0'); else ok = TRUE; } } return ReturnString; } CString GetPrevSerialFilename(CString Filename) { CString ReturnString = Filename; int count = Filename.GetLength(); int StartPos = count-4; if(Filename.GetAt(StartPos)!='.') { AfxMessageBox("wrong in filename!"); return "haha"; } BOOL ok = FALSE; BYTE tChar; while(!ok) { StartPos--; if(StartPos<=0) ok = TRUE; tChar = Filename.GetAt(StartPos) - '0'; if(tChar>0&&tChar<=9) { tChar = tChar - 1 + '0'; ReturnString.SetAt(StartPos,tChar); ok = TRUE; } else { if(tChar==0) ReturnString.SetAt(StartPos,'9'); else ok = TRUE; } } return ReturnString; } CString GetNameformFullPathName(CString FullPathName) { int count1 = FullPathName.ReverseFind('\\'); int count2 = FullPathName.GetLength(); count2 -= (count1 + 1); CString RV= "", FileName; FileName = FullPathName.Right(count2); if( count2 > 4 ) { RV = FileName.Left(count2- 4); } return RV; } CString GetCurrentDirectory() { int drive = _getdrive(); char path[256]; _getdcwd(drive,path,256); return path; } BOOL IsExistFile(CString Filename) { struct _finddata_t c_file; long hFile; if( (hFile = _findfirst(Filename, &c_file )) != -1L ) return TRUE; else return FALSE; } BOOL FindNextFile(CString &Filename) { int count1 = Filename.ReverseFind('\\'); //TRACE("The Filename is %s\n",Filename); CString Path = Filename.Left(count1+1); CString FileExtname = Path + "*" + Filename.Right(4); //TRACE("The FileExtname is %s\n",FileExtname); CString LastFilename ; struct _finddata_t c_file; long hFile; BOOL OK = FALSE; if( (hFile = _findfirst(FileExtname, &c_file )) != -1L ) { LastFilename = Path + c_file.name; //TRACE("next image filename is %s\n",LastFilename); while( _findnext( hFile, &c_file ) == 0 ) { if(LastFilename == Filename) OK=TRUE; if(OK) { Filename = Path + c_file.name; return TRUE; } LastFilename = Path + c_file.name; } } _findclose( hFile ); return FALSE; } BOOL FindPrevFile(CString &Filename) { int count1 = Filename.ReverseFind('\\'); //TRACE("The Filename is %s\n",Filename); CString Path = Filename.Left(count1+1); CString FileExtname = Path + "*" + Filename.Right(4); //TRACE("The FileExtname is %s\n",FileExtname); CString LastFilename ; struct _finddata_t c_file; long hFile; BOOL OK = FALSE; if( (hFile = _findfirst(FileExtname, &c_file )) != -1L ) { LastFilename = Path + c_file.name; //TRACE("next image filename is %s\n",LastFilename); while( _findnext( hFile, &c_file ) == 0 ) { CString Nowfile = Path + c_file.name; if(Nowfile == Filename) OK=TRUE; if(OK) { Filename = LastFilename; return TRUE; } LastFilename = Nowfile; } } _findclose( hFile ); return FALSE; } void L_TraceRect(CString VarName, CRect rect) { TRACE("%s LeftUp point is (%d ,%d) , RightBottom point is (%d ,%d) w,h = (%d ,%d)\n",\ VarName, rect.left, rect.top, rect.right, rect.bottom, rect.Width(), rect.Height()); } void pIntBubble(BYTE *p,int n) { int m,k,j,i; BYTE d; k=0; m=n-1; while (k p[i+1]) { d=p[i]; p[i]=p[i+1]; p[i+1]=d; m=i;} j=k+1; k=0; for (i=m; i>=j; i--) if (p[i-1]>p[i]) { d=p[i]; p[i]=p[i-1]; p[i-1]=d; k=i;} } } void IntSplit(BYTE *p,int n,int *m) { int i,j,k,l; BYTE t; i=0; j=n-1; k=(i+j)/2; if ((p[i]>=p[j])&&(p[j]>=p[k])) l=j; else if ((p[i]>=p[k])&&(p[k]>=p[j])) l=k; else l=i; t=p[l]; p[l]=p[i]; while (i!=j) { while ((i =t)) j=j-1; if (i 10) { IntSplit(p,n,i); m=i0; IntQuickSort(p,m); s=p+(i0+1); m=n-(i0+1); IntQuickSort(s,m); } else pIntBubble(p,n); } void int_to_uchar(int *r,BYTE *in,int size) { int i, max_r=r[0], min_r=r[0]; double fTemp; for (i=1; i max_r ) max_r=r[i]; else if ( r[i] < min_r ) min_r=r[i]; } max_r-=min_r; if(max_r!=0) { for (i=0; i max_r ) max_r=r[i]; else if ( r[i] < min_r ) min_r=r[i]; } max_r-=min_r; if(max_r!=0) { for (i=0; i 0.0) ? discrim : -discrim; if (abs_discrim < 0.01) // case III { d1 = (float)sqrt(b / (2.0 * a)); d2 = 1.0f/ d1; gN0 = 0.5f* maxresponse/ b; gD0 = 0.5f* d1 * maxresponse / b; for(lpDmask[hM] = 0.0f, i = -hM; i < 0; i++) { lpDmask[hM+ i] = float( gD0 * i * exp(i* d1) ); lpDmask[hM- i] = -lpDmask[hM+ i]; } if( lpmask != NULL ) { for(lpDmask[hM] = gN0, i = -hM; i < 0; i++) lpmask[hM+ i] = lpmask[hM- i] = float( gN0 * exp(i* d1) * ( d2 - i) ); } } else if (fabs(a) < 0.000001) // case V - membrane { d1 = (float)sqrt(b); gN0 = maxresponse / d1; gD0 = maxresponse / b; for(lpDmask[hM] = 0.0f, i = -hM; i < 0; i++) { lpDmask[hM+ i] = -float( gD0 * exp(i/ d1) ); lpDmask[hM- i] = -lpDmask[hM+ i]; } if( lpmask != NULL ) { for(lpDmask[hM] = gN0, i = -hM; i < 0; i++) lpmask[hM+ i] = lpmask[hM- i] = float( gN0 * exp(i/ d1) ); } } else if (fabs(b) < 0.000001) // case IV - Plate { dSqrt = (float)sqrt(a); d2 = (float)sqrt(dSqrt); d1 = 1.0f / (float)( sqrt(2.0) * d2); gN0 = maxresponse / (4.0f * dSqrt * d1); gD0 = maxresponse / (2.0f * dSqrt); for(lpDmask[hM] = 0.0f, x= -d1, i = 1; i <= hM; i++, x -= d1) { lpDmask[hM- i] = float( gD0 * exp(x)* sin(x) ); lpDmask[hM+ i] = -lpDmask[hM- i]; } if( lpmask != NULL ) { for(lpDmask[hM] = gN0, x= -d1, i = 1; i <= hM; i++, x -= d1) lpmask[hM+ i] = lpmask[hM- i] = float( gN0 * exp(x)* (cos(x) - sin(x)) ); } } else if (discrim > 0.0 ) // case I { d1 = (float)sqrt((b + sqrt(discrim))/(2.0 * a)); d2 = (float)sqrt((b - sqrt(discrim))/(2.0 * a)); gN0 = 1.0f * maxresponse/(2.0f* a* (d2* d2 - d1* d1)); gD0 = gN0; for(lpDmask[hM] = 0.0f, i = -hM; i < 0; i++) { lpDmask[hM+ i] = -float( gD0 * (exp(i* d2) - exp(i* d1)) ); lpDmask[hM- i] = -lpDmask[hM+ i]; } if( lpmask != NULL ) { for(lpDmask[hM] = gN0, i = -hM; i < 0; i++) lpmask[hM+ i] = lpmask[hM- i] = float( gN0 * ( exp(i* d1)/ d1 - exp(i* d2)/ d2 ) ); } } else if (discrim < 0.0) // case II { dSqrt = (float)sqrt(a); quarta = (float)sqrt(dSqrt); d1 = (float)( cos(0.5* atan(sqrt(4.0*a/(b*b) - 1)))) / quarta ; d2 = (float)( sin(0.5* atan(sqrt(4.0*a/(b*b) - 1)))) / quarta ; gN0 = maxresponse/ (4.0f * dSqrt); gD0 = maxresponse/ (4.0f * a * d1 * d2); for(lpDmask[hM] = 0.0f, i = -hM; i < 0; i++) { lpDmask[hM+ i] = float( gD0 * exp(i* d2) * sin(i* d1) ); lpDmask[hM- i] = -lpDmask[hM+ i]; } if( lpmask != NULL ) { for(lpDmask[hM] = gN0, i = -hM; i < 0; i++) lpmask[hM+ i] = lpmask[hM- i] = float( gN0 * exp(i* d2)*( cos(i* d1)/ d2 + sin(i* d1)/ d1 ) ); } } } int GetDriveCount() { int i, iDriveType, cDrives = 0; char szDrive[] = "x:\\\0"; for (szDrive[0]='C'; szDrive[0] <= 'Z'; szDrive[0]++) { i = (int) (szDrive[0] - 'C'); iDriveType = ::GetDriveType( szDrive ); if (iDriveType == DRIVE_FIXED || iDriveType == DRIVE_REMOTE || iDriveType == DRIVE_RAMDISK) { cDrives++; } } return cDrives; }