📄 histogram.cpp
字号:
m_stScroll.nRangeMinOut = pScroll->nRangeMinOut; m_stScroll.nRangeMaxOut = pScroll->nRangeMaxOut; m_stScroll.nRangeMinIn = pScroll->nRangeMinIn; m_stScroll.nRangeMaxIn = pScroll->nRangeMaxIn; SetScroll(pScroll->nPoMin, pScroll->nPoMax);}void RxHistogram::SetScroll(int nMin, int nMax, BOOL bRedraw){ int nWidth = PiToPoH(m_stScroll.nMinSize, m_stScroll.nRangeMinOut, m_stScroll.nRangeMaxOut); if(nMin <= m_stScroll.nRangeMinOut) nMin = m_stScroll.nRangeMinOut; if(nMax >= m_stScroll.nRangeMaxOut) nMax = m_stScroll.nRangeMaxOut; if(nMin + nWidth > nMax) { nMax = nMin+nWidth; if(nMax >= m_stScroll.nRangeMaxOut) { nMin = m_stScroll.nRangeMaxOut-nWidth; nMax = m_stScroll.nRangeMaxOut; } } m_stScroll.nPoMin = nMin; m_stScroll.nPoMax = nMax; RecalcScroll(); RecalcOTFPolygon(FALSE); if(bRedraw) RedrawWnd();}void RxHistogram::RecalcScroll(){ m_stScroll.nPiMin = PoToPiH(m_stScroll.nPoMin, m_stScroll.nRangeMinOut, m_stScroll.nRangeMaxOut); m_stScroll.nPiMax = PoToPiH(m_stScroll.nPoMax, m_stScroll.nRangeMinOut, m_stScroll.nRangeMaxOut);}/////////////////////////////////////////////////////////////////////////////void RxHistogram::SetHistogram(UINT *pHistogram, int nSize, int nMaxMagnitude){ if(m_stHistogram.pHistogram != NULL) delete [](m_stHistogram.pHistogram); m_stHistogram.nSize = nSize; m_stHistogram.pHistogram = new UINT[nSize]; m_stHistogram.nMaxMagnitude = nMaxMagnitude; memcpy(m_stHistogram.pHistogram, pHistogram, nSize*sizeof(UINT));}void RxHistogram::RemoveHistogram(){ if(m_stHistogram.pHistogram != NULL) delete [](m_stHistogram.pHistogram); m_stHistogram.nMaxMagnitude = 0; m_stHistogram.nSize = 0; m_stHistogram.pHistogram = NULL;}/////////////////////////////////////////////////////////////////////////////void RxHistogram::SetWindowing(int nLevel, int nWidth){ m_stWindowing.nLevel = nLevel; m_stWindowing.nWidth = nWidth; int nCenter = nWidth/2; if(nLevel-nCenter < m_stScroll.nPoMin || m_stScroll.nPoMax < nLevel+nCenter) { int nScrollMin, nScrollMax; nScrollMin = m_stScroll.nPoMin; nScrollMax = m_stScroll.nPoMax; if(nLevel-nCenter < m_stScroll.nPoMin) nScrollMin = nLevel-nCenter; if(nCenter+nLevel > m_stScroll.nPoMax) nScrollMax = nLevel+nCenter; SetScroll(nScrollMin, nScrollMax); } else RedrawWnd(); UpdateWindowingTable();}void RxHistogram::SetWindowingLevel(int nLevel){ m_stWindowing.nLevel = nLevel; int nCenter = m_stWindowing.nWidth/2; if(nLevel-nCenter < m_stScroll.nPoMin || m_stScroll.nPoMax < nLevel+nCenter) { int nScrollMin, nScrollMax; nScrollMin = m_stScroll.nPoMin; nScrollMax = m_stScroll.nPoMax; if(nLevel-nCenter < m_stScroll.nPoMin) nScrollMin = nLevel-nCenter; if(nLevel+nCenter > m_stScroll.nPoMax) nScrollMax = nLevel+nCenter; UpdateWindowingTable(); SetScroll(nScrollMin, nScrollMax); } else RedrawWnd(); UpdateWindowingTable();}void RxHistogram::SetWindowingWidth(int nWidth){ m_stWindowing.nWidth = nWidth; int nCenter = nWidth/2; if(m_stWindowing.nLevel-nCenter < m_stScroll.nPoMin || m_stScroll.nPoMax < m_stWindowing.nLevel+nCenter) { int nScrollMin, nScrollMax; nScrollMin = m_stScroll.nPoMin; nScrollMax = m_stScroll.nPoMax; if(m_stWindowing.nLevel-nCenter < m_stScroll.nPoMin) nScrollMin = m_stWindowing.nLevel-nCenter; if(nCenter+m_stWindowing.nLevel > m_stScroll.nPoMax) nScrollMax = m_stWindowing.nLevel+nCenter; SetScroll(nScrollMin, nScrollMax); } else RedrawWnd(); UpdateWindowingTable();}_WINDOWING* RxHistogram::GetWindowing(){ return &m_stWindowing;}void RxHistogram::SetWindowingVisible(BOOL bShow){ m_stWindowing.bVisible = bShow; RedrawWnd();}BOOL RxHistogram::GetWindowingVisible(){ return m_stWindowing.bVisible;}void RxHistogram::UpdateWindowingTable(){ int nWindowingHigh = 1300;// int nWindowingHigh = m_stWindowing.nLevel + 1024 + m_stWindowing.nWidth/2; int nWindowingLow = 800;// int nWindowingLow = m_stWindowing.nLevel + 1024 - m_stWindowing.nWidth/2; int nMin = max( 0, nWindowingLow); int nMax = min(4095, nWindowingHigh); int i; for(i = 0; i < nMin; i++) m_stWindowing.byTable[i] = 0; for(i = nMin; i < nMax; i++)// m_stWindowing.byTable[i] = (BYTE)(255. * (i-nWindowingLow) / m_stWindowing.nWidth); m_stWindowing.byTable[i] = (BYTE)(255. * (i-nWindowingLow) / 500); for(i = nMax; i < 4096; i++) m_stWindowing.byTable[i] = 255; m_stWindowing.byTable[4096] = 0; //dummy value}/////////////////////////////////////////////////////////////////////////////void RxHistogram::AddOTFPolygon(int *nPoint, COLORREF *crPoint, float fOpacity, BOOL bEnable){ // 器牢飘 蜡瓤己 八荤饶 犁炼沥 // // Scroll scale 犁炼沥茄促. int nOldMin = m_stScroll.nPoMin; int nOldMax = m_stScroll.nPoMax; if(m_stScroll.nPoMax - m_stScroll.nPoMin < nPoint[3] - nPoint[0]) m_stScroll.nPoMax = m_stScroll.nPoMin + nPoint[3] - nPoint[0]; if(m_stScroll.nPoMin > nPoint[0]) m_stScroll.nPoMin = nPoint[0]; if(m_stScroll.nPoMax < nPoint[3]) m_stScroll.nPoMax = nPoint[3]; if(nOldMin != m_stScroll.nPoMin || nOldMax != m_stScroll.nPoMax) SetScroll(m_stScroll.nPoMin, m_stScroll.nPoMax, FALSE); // fill the structure _OTF_POLYGON *pOTFPolygon = new _OTF_POLYGON; pOTFPolygon->bEnable = bEnable; for(int i = 0; i < 4; i++) { pOTFPolygon->nPointPoX[i] = nPoint[i]; pOTFPolygon->nPointPiX[i] = PoToPiH(pOTFPolygon->nPointPoX[i], m_stScroll.nPoMin, m_stScroll.nPoMax, FALSE); pOTFPolygon->crPoint[i] = crPoint[i]; } pOTFPolygon->fOpacityPo = fOpacity; pOTFPolygon->nPointPiY[0] = pOTFPolygon->nPointPiY[3] = m_szWindow.cy - (HGSZ_OTF_BMARGIN+HGSZ_SPECTRUM); pOTFPolygon->nPointPiY[1] = pOTFPolygon->nPointPiY[2] = PoToPiO(pOTFPolygon->fOpacityPo); m_ArrayOTFPolygon.Add(pOTFPolygon); m_nActiveOTF = m_ArrayOTFPolygon.GetSize() - 1; UpdateSpectrum(); RedrawWnd();}int RxHistogram::GetOTFCount(){ return m_ArrayOTFPolygon.GetSize();}_OTF_POLYGON* RxHistogram::GetOTFPolygon(int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return NULL; return (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex);}void RxHistogram::RemoveOTFPolygon(int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return; _OTF_POLYGON *pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex); delete pOTFPolygon; m_ArrayOTFPolygon.RemoveAt(nIndex); m_nActiveOTF = m_ArrayOTFPolygon.GetSize() - 1; UpdateSpectrum(); RedrawWnd();}void RxHistogram::RemoveAllOTFPolygon(){ int nOTFCount = m_ArrayOTFPolygon.GetSize(); _OTF_POLYGON *pOTFPolygon; for(int i = 0; i < nOTFCount; i++) { pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(i); delete pOTFPolygon; } m_ArrayOTFPolygon.RemoveAll(); m_nActiveOTF = -1;}void RxHistogram::EnableOTFPolygon(BOOL bEnable, int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return; _OTF_POLYGON *pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex); pOTFPolygon->bEnable = bEnable; RedrawWnd();}BOOL RxHistogram::IsEnableOTFPolygon(int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return FALSE; _OTF_POLYGON *pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex); return pOTFPolygon->bEnable;}void RxHistogram::SetOTFPointX(WORD wArg, int nPt1, int nPt2, int nPt3, int nPt4, int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return; _OTF_POLYGON *pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex); if(wArg & HGARG_1) { pOTFPolygon->nPointPoX[0] = nPt1; pOTFPolygon->nPointPiX[0] = PoToPiH(nPt1, m_stScroll.nPoMin, m_stScroll.nPoMax); } if(wArg & HGARG_2) { pOTFPolygon->nPointPoX[1] = nPt2; pOTFPolygon->nPointPiX[1] = PoToPiH(nPt2, m_stScroll.nPoMin, m_stScroll.nPoMax); } if(wArg & HGARG_3) { pOTFPolygon->nPointPoX[2] = nPt3; pOTFPolygon->nPointPiX[2] = PoToPiH(nPt3, m_stScroll.nPoMin, m_stScroll.nPoMax); } if(wArg & HGARG_4) { pOTFPolygon->nPointPoX[3] = nPt4; pOTFPolygon->nPointPiX[3] = PoToPiH(nPt4, m_stScroll.nPoMin, m_stScroll.nPoMax); } UpdateSpectrum(); RedrawWnd();}void RxHistogram::SetOTFOpacity(float fOpacity, int nIndex){ if(nIndex < 0) nIndex = m_nActiveOTF; if(nIndex < 0 || nIndex >= m_ArrayOTFPolygon.GetSize()) return; _OTF_POLYGON *pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(nIndex); pOTFPolygon->fOpacityPo = fOpacity; pOTFPolygon->nPointPiY[1] = pOTFPolygon->nPointPiY[2] = PoToPiO(fOpacity); UpdateSpectrum(); RedrawWnd();}// 龋免登绢 瘤绰 矫扁 : WM_SIZE and Scroll position changing(and Adding OTF)void RxHistogram::RecalcOTFPolygon(BOOL bWithHeight){ int nOTFCount = m_ArrayOTFPolygon.GetSize(); _OTF_POLYGON *pOTFPolygon; for(int i = 0; i < nOTFCount; i++) { pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(i); for(int j = 0; j < 4; j++) pOTFPolygon->nPointPiX[j] = PoToPiH(pOTFPolygon->nPointPoX[j], m_stScroll.nPoMin, m_stScroll.nPoMax, FALSE); if(bWithHeight) { pOTFPolygon->nPointPiY[0] = pOTFPolygon->nPointPiY[3] = m_szWindow.cy - (HGSZ_OTF_BMARGIN+HGSZ_SPECTRUM); pOTFPolygon->nPointPiY[1] = pOTFPolygon->nPointPiY[2] = PoToPiO(pOTFPolygon->fOpacityPo); } }}/////////////////////////////////////////////////////////////////////////////void* RxHistogram::GetSpectrumMPR(){ return m_SpectrumTable.m_pMPRTable;}void* RxHistogram::GetSpectrum(){ return m_SpectrumTable.m_pTable;}// 龋免登绢瘤绰 矫扁 : Add/Del OTF, Moving OTF, Changing point color, Enable/Disable OTFvoid RxHistogram::UpdateSpectrum(){ int nOTFCount = m_ArrayOTFPolygon.GetSize(); if(nOTFCount <= 0) return; m_SpectrumTable.Initialize(0, 4095); _OTF_POLYGON *pOTFPolygon; short nPointX[4]; float fColor[13]; for(int i = 0; i < nOTFCount ; i++) { pOTFPolygon = (_OTF_POLYGON *)m_ArrayOTFPolygon.GetAt(i); if(pOTFPolygon->bEnable) { for(int j = 0; j < 4; j++) { // 0 base肺 傈券 nPointX[j] = pOTFPolygon->nPointPoX[j] - m_stScroll.nRangeMinIn; fColor[j*3+0] = ((pOTFPolygon->crPoint[j] & 0x00ff0000 ) >> 16) / 255.0f; //b fColor[j*3+1] = ((pOTFPolygon->crPoint[j] & 0x0000ff00 ) >> 8) / 255.0f; //g fColor[j*3+2] = ((pOTFPolygon->crPoint[j] & 0x000000ff )) / 255.0f; //r } fColor[12] = pOTFPolygon->fOpacityPo; m_SpectrumTable.SetVolumeInfo(nPointX, fColor); } } m_SpectrumTable.MakeDensityTable();}/////////////////////////////////////////////////////////////////////////////void RxHistogram::SendMessageToOwner(WORD wMessage){ _NMHISTO_CTRL hdrHisto; hdrHisto.hdr.hwndFrom = m_hWnd; hdrHisto.hdr.idFrom = GetDlgCtrlID(); hdrHisto.hdr.code = wMessage; hdrHisto.nCurOTF = m_nActiveOTF; hdrHisto.pHistogram = this; CWnd* pOwner = GetOwner(); if (pOwner) pOwner->SendMessage(WM_NOTIFY, hdrHisto.hdr.idFrom, (LPARAM)&hdrHisto);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -