📄 fmwnd3dmpr.cpp
字号:
// FMWnd3DMPR.cpp : implementation file////////////////////////////////////////////////////////////////////////// Title: Interface for MPR window control//////////////////////////////////////////////////////////////////////////// Author: H.Lee// 138-dong 417-ho Seoul National University// San 56-1 Shinlim-dong Kwanak-gu Seoul, Korea// Email. //// Date : 2002/11/20// Update :////////////////////////////////////////////////////////////////////////#include "stdafx.h"#include "fusion.h"#include "FMDocVR.h"#include "FMWnd3DMPR.h"#include "FusionGlobal.h"#include "fusiondefine.h"#include "Filters.h"#include <math.h>#include "Histogram.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#define ID_CASE_NONE 0#define ID_CASE_HORIZONTAL 1#define ID_CASE_VERTICAL 2#define ID_CASE_SLANT 3#define ID_CASE_CIRCLE 4#define VERTICAL 0#define HORIZONTAL 1#define MPR_MODE_RAYSUM 0#define MPR_MODE_MIP 1#define MPR_MODE_MINIP 2#define WINDOW_MARGIN 100.f#define WINDOW_MARGIN_FIT 100.f#define LERP(a,l,h) ((l)+(((h)-(l))*(a)))#define INRANGE(X, Y, Z) \ ((X) >= 0 && (X) < xsize-1 && \ (Y) >= 0 && (Y) < ysize-1 && \ (Z) >= 0 && (Z) < zsize-1)#define INCROPRANGE(X, Y, Z) \ ((X) >= ixMin && (X) < ixMax && \ (Y) >= iyMin && (Y) < iyMax && \ (Z) >= izMin && (Z) < izMax)#define DENS(X, Y, Z) OriginalVolume[(X)+(xsize)*((Y)+(ysize)*(Z))]CEvent g_MPRThreadKillEvent(FALSE,TRUE);CCriticalSection g_3DMPRCS[3];extern void Zoom(BYTE *in_image, int in_width, int in_height, unsigned char *out_image, int out_width, int out_height, int color);extern BOOL FusionImages(BYTE *pBackgroundImage, BYTE *pForegroundImage, BYTE *pOutputImage, CSize szImage, float fBackWeight, float fFrontWeight);extern BOOL GetDIBColor(unsigned short *pSrc, unsigned int *pDst, __m128 *pPallete, int nPixelNum, float fWeight);extern BOOL MultiplyScale(BYTE *pInputImage, BYTE *pOutputImage, CSize szImage, float fWeight);/////////////////////////////////////////////////////////////////////////////// RxFMWnd3DMPRRxFMWnd3DMPR::RxFMWnd3DMPR(UINT nSeries) : RxFMWnd(nSeries){ m_bUpdateMPR = FALSE;// m_pnRawMPRImage = NULL; m_iMPRThickness = 1; m_iZoomFactor = 100; RxGetFrameBottom()->GetWindowing(RXSERIES_REF, m_iWindowingLevel, m_iWindowingWidth); m_pDib = NULL; m_ptPanOffset = CPoint(0,0); m_szWindow = CSize(-1,-1); m_fRatioRef = 0.5;}RxFMWnd3DMPR::~RxFMWnd3DMPR(){ RemoveSamplePt(); if(m_pDib) delete m_pDib;// if(m_pnRawMPRImage) delete []m_pnRawMPRImage;}BEGIN_MESSAGE_MAP(RxFMWnd3DMPR, RxFMWnd) //{{AFX_MSG_MAP(RxFMWnd3DMPR) ON_WM_CREATE() ON_WM_PAINT() ON_WM_SIZE() ON_WM_MOUSEMOVE() ON_WM_RBUTTONDOWN() ON_WM_RBUTTONUP() ON_WM_SETCURSOR() ON_WM_LBUTTONDOWN() ON_WM_LBUTTONUP() //}}AFX_MSG_MAP ON_COMMAND(IDFM_LOCAL_BTN_MIN, OnBtnMin)END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// RxFMWnd3DMPR message handlersint RxFMWnd3DMPR::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (RxFMWnd::OnCreate(lpCreateStruct) == -1) return -1; AddButton(IDFM_LOCAL_BTN_MIN, IDB_FMWND_BTN_MIN, RXCBS_VISIBLE|RXCBS_NORMAL); return 0;}void RxFMWnd3DMPR::OnBtnMin(){ RxGetFrameMain()->Frame3DF_Local_Nor();}void RxFMWnd3DMPR::OnPaint() { CPaintDC dc(this); // device context for painting RedrawWnd(m_bUpdateMPR);}void RxFMWnd3DMPR::RedrawWnd(BOOL bUpdateMPR, BOOL bUpdateZoom){ if(m_bUpdateMPR) { bUpdateZoom = TRUE; m_bUpdateMPR = FALSE; } if(bUpdateMPR) UpdateMPRImage(bUpdateZoom); CDC *pDC = GetDC(); CDC dcMem; dcMem.CreateCompatibleDC(pDC); CBitmap bmpMem, *pOldBitmap; bmpMem.CreateCompatibleBitmap(pDC, m_szWindow.cx, m_szWindow.cy); pOldBitmap = dcMem.SelectObject(&bmpMem); CBrush brush, *pOldBrush; brush.CreateSolidBrush(RGB( 0, 0, 0)); pOldBrush = dcMem.SelectObject(&brush); dcMem.PatBlt(0, 0, m_szWindow.cx, m_szWindow.cy, PATCOPY); dcMem.SelectObject(pOldBrush); brush.DeleteObject(); if(m_pDib) { CPoint ptOrigin = CalcuPtOrigin(); CSingleLock lockDib(&g_3DMPRCS[m_nSeries]); lockDib.Lock(); m_pDib->Draw(&dcMem, ptOrigin, m_szDIB); lockDib.Unlock(); } pDC->BitBlt(0, 0, m_szWindow.cx, m_szWindow.cy, &dcMem, 0, 0, SRCCOPY); dcMem.SelectObject(pOldBitmap); bmpMem.DeleteObject(); dcMem.DeleteDC(); ReleaseDC(pDC);}/////////////////////////////////////////////////////////////////////////////void RxFMWnd3DMPR::Init_ZoomFactor(CSize& szMPRImage){ m_iZoomFactor = __min(int(100.* (m_szWindow.cy - WINDOW_MARGIN)/szMPRImage.cy), int(100.*(m_szWindow.cx - WINDOW_MARGIN)/szMPRImage.cx)); m_iZoomFactor = min(MAX_ZOOM, max(MIN_ZOOM, m_iZoomFactor)); }BOOL RxFMWnd3DMPR::UpdateMPRImage(BOOL bUpdateZoom){ int iMPRThickness = m_iMPRThickness; CSize szMPRImage = m_szWindow; if(m_szWindow.cx == -1 && m_szWindow.cy == -1) return FALSE; int iResetMode = 0; RxFMWndVR* pFMWndVR = RxGetFrameMain()->m_pFMWndVR[m_nSeries]; if(pFMWndVR == NULL) return NULL; double uMin = (double)pFMWndVR->m_iUMin; double uMax = (double)pFMWndVR->m_iUMax; double vMin = (double)pFMWndVR->m_iVMin; double vMax = (double)pFMWndVR->m_iVMax; int wMin = pFMWndVR->m_iWMin; int wMax = pFMWndVR->m_iWMax; RxRayCastingCommonInfo *pVRInfo; int xStride, yStride; BOOL bRotated = FALSE; BOOL bXMirror = FALSE, bYMirror = FALSE; if(m_nSeries== RXSERIES_FLT || m_nSeries == RXSERIES_REF){ if(m_nSeries == RXSERIES_FLT){ pVRInfo = pFMWndVR->m_pVRFltInfo;} else if(m_nSeries == RXSERIES_REF){ pVRInfo = pFMWndVR->m_pVRRefInfo;} double fRatioZ = RxGetVolumeData(m_nSeries)->m_fRatioZ; unsigned short *pRawMPRImage = (unsigned short*)(GetRawMPRImage(pVRInfo->m_mxInvViewing, uMin, uMax, vMin, vMax, wMin, wMax, fRatioZ, iMPRThickness, iResetMode, szMPRImage, MPR_MODE_RAYSUM, DOWNSIZE_ONCE, xStride, yStride, bRotated, bXMirror, bYMirror)); CSingleLock lockMPR(&g_3DMPRCS[m_nSeries]); lockMPR.Lock(); m_szMPRImage = szMPRImage; lockMPR.Unlock(); unsigned char *pWindowingTable; if (m_iMPRThickness == 1) { RxGetFrameBottom()->GetWindowing(m_nSeries, m_iWindowingLevel, m_iWindowingWidth); pWindowingTable = RxGetFrameTuning()->GetWindowingTable(m_nSeries); } CSingleLock lock3DMPR(&g_3DMPRCS[m_nSeries]); lock3DMPR.Lock(); if(m_pDib) delete m_pDib; //m_szDIB甫 拌魂秦辑 逞败霖促.. if(bUpdateZoom) Init_ZoomFactor(szMPRImage); m_pDib = (RxDib*)RxRawImgToDIB(pRawMPRImage, szMPRImage, m_szDIB, m_iZoomFactor, pWindowingTable, FALSE); if(pRawMPRImage){ delete []pRawMPRImage; pRawMPRImage = NULL; } lock3DMPR.Unlock(); } else if(m_nSeries == RXSERIES_COM){ CSize szFittedCombineImg; CSize szTransformedCombineImg; double fRefRatioZ = RxGetVolumeData(RXSERIES_REF)->m_fRatioZ; pVRInfo = pFMWndVR->m_pVRRefInfo; unsigned short *pRefRawMPRImage = (unsigned short*)(GetRawMPRImage(pVRInfo->m_mxInvViewing, uMin, uMax, vMin, vMax, wMin, wMax, fRefRatioZ, iMPRThickness, iResetMode, szTransformedCombineImg, MPR_MODE_RAYSUM, DOWNSIZE_ONCE, xStride, yStride, bRotated, bXMirror, bYMirror)); double fFltRatioZ = RxGetVolumeData(RXSERIES_FLT)->m_fRatioZ; unsigned short *pFltRawMPRImage = (unsigned short*)(GetFittedFltData(pFMWndVR->m_pVRFltInfo, pFMWndVR->m_pVRRefInfo, &m_apSamplePt, wMin, wMax, fFltRatioZ, fRefRatioZ, iMPRThickness, m_szOriginal, szTransformedCombineImg, MPR_MODE_RAYSUM, DOWNSIZE_ONCE, xStride, yStride, bRotated, bXMirror, bYMirror)); //Fitting size for 4byte szFittedCombineImg.cx = (szTransformedCombineImg.cx + 7) / 8 * 8; szFittedCombineImg.cy = szTransformedCombineImg.cy; int iSize = szFittedCombineImg.cx * szFittedCombineImg.cy; unsigned short* pFittedFltMap = new unsigned short[iSize]; memset(pFittedFltMap, 0x00, sizeof(unsigned short)*iSize); unsigned short* pFittedRefMap = new unsigned short[iSize]; memset(pFittedRefMap, 0x00, sizeof(unsigned short)*iSize); int nMargin = szFittedCombineImg.cx - szTransformedCombineImg.cx; for(int nY = 0 ; nY< szFittedCombineImg.cy ; nY++){ memcpy(&(pFittedFltMap[nY*szFittedCombineImg.cx]), &(pFltRawMPRImage[nY*szTransformedCombineImg.cx]), sizeof(unsigned short)*szTransformedCombineImg.cx); for(int nX = 0 ; nX<nMargin ; nX++){ pFittedFltMap[nY*szFittedCombineImg.cx+szTransformedCombineImg.cx +nX] = 0; } memcpy(&(pFittedRefMap[nY*szFittedCombineImg.cx]), &(pRefRawMPRImage[nY*szTransformedCombineImg.cx]), sizeof(unsigned short)*szTransformedCombineImg.cx); for(nX = 0 ; nX<nMargin ; nX++){ pFittedRefMap[nY*szFittedCombineImg.cx+szTransformedCombineImg.cx +nX] = 0; } } BOOL bFrameInterleaving = TRUE; if (bFrameInterleaving){ // for gray unsigned char *pWTRef; if (m_iMPRThickness == 1) { RxGetFrameBottom()->GetWindowing(RXSERIES_REF, m_iWindowingLevel, m_iWindowingWidth); pWTRef = RxGetFrameTuning()->GetWindowingTable(RXSERIES_REF); } //Reference unsigned int* lpTemp = new unsigned int[iSize]; DWORD wht = 0x00010101; for(int i = 0 ; i < szFittedCombineImg.cy; i++){ for(int j=0; j< szFittedCombineImg.cx; j++){ lpTemp[i*szFittedCombineImg.cx+j] = wht * pWTRef[(int)pFittedRefMap[i*szFittedCombineImg.cx+j]]; } } m_szDIB = m_szMPRImage = szFittedCombineImg; if(bUpdateZoom) Init_ZoomFactor(szFittedCombineImg); MakeMixedDibForFusion(lpTemp, pFittedFltMap, szFittedCombineImg, m_szDIB); delete[] lpTemp; } else{ // edge interleaving RxxFilters Filter; LPBYTE pbyCanny; pbyCanny = Filter.CannyProcessing(pFittedRefMap, szFittedCombineImg.cx, szFittedCombineImg.cy); //Reference unsigned int* lpTemp = new unsigned int[iSize]; DWORD wht = 0x00010101; for (int j = 0; j< szFittedCombineImg.cy; j++){ for (int i = 0; i< szFittedCombineImg.cx; i++){ int iIndex = j*szFittedCombineImg.cx+i; if (pbyCanny[iIndex]) lpTemp[iIndex] = wht * pbyCanny[iIndex]; else lpTemp[iIndex] = 0; } } m_szDIB = szFittedCombineImg; m_szMPRImage = szFittedCombineImg; if(bUpdateZoom) Init_ZoomFactor(szFittedCombineImg); MakeMixedDibForFusion(lpTemp, pFittedFltMap, szFittedCombineImg, m_szDIB); delete[] lpTemp; delete[] pbyCanny; } delete[] pFittedRefMap; delete[] pFittedFltMap; if(pFltRawMPRImage){ delete[] pFltRawMPRImage; pFltRawMPRImage=NULL;} if(pRefRawMPRImage){ delete[] pRefRawMPRImage; pRefRawMPRImage=NULL;} } return TRUE;}void RxFMWnd3DMPR::OnActivateWnd(BOOL bActivate, CWnd *pCurWnd, CWnd *pOldWnd){ RxFMWnd::OnActivateWnd(bActivate, pCurWnd, pOldWnd); if (bActivate) { int nTBCurMode = RxGetFrameMain()->GetTBCurMode(); if(nTBCurMode == BTN_MEASURE_DISTANCE || nTBCurMode == BTN_MEASURE_AREA || nTBCurMode == BTN_MEASURE_VOLUME) RxGetFrameMain()->SetTBCurMode(BTN_ZOOM); }}void RxFMWnd3DMPR::OnSize(UINT nType, int cx, int cy) { RxFMWnd::OnSize(nType, cx, cy); if(cx <= 0 || cy <= 0) return; m_szWindow.cx = cx; m_szWindow.cy = cy; m_bUpdateMPR = TRUE;}BOOL RxFMWnd3DMPR::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { if(pWnd->GetSafeHwnd() == GetSafeHwnd() && nHitTest == HTCLIENT) { int nTBCurMode = RxGetFrameMain()->GetTBCurMode(); if(nTBCurMode == BTN_PAN) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_PAN)); return TRUE; } else if(nTBCurMode == BTN_ZOOM) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_ZOOM)); return TRUE; } else if(nTBCurMode == BTN_WINDOWING) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_WINDOWING)); return TRUE; } } return RxFMWnd::OnSetCursor(pWnd, nHitTest, message);}void RxFMWnd3DMPR::OnLButtonDown(UINT nFlags, CPoint point) { SetCapture(); m_ptOld = point; RxFMWnd::OnLButtonDown(nFlags, point);}void RxFMWnd3DMPR::OnLButtonUp(UINT nFlags, CPoint point) { if(GetCapture() == this) ReleaseCapture(); RxFMWnd::OnLButtonUp(nFlags, point);}void RxFMWnd3DMPR::OnRButtonDown(UINT nFlags, CPoint point) { SetCursor(AfxGetApp()->LoadCursor(IDC_CURSOR_WINDOWING)); SetCapture(); m_ptOld = point; RxFMWnd::OnRButtonDown(nFlags, point);}void RxFMWnd3DMPR::OnRButtonUp(UINT nFlags, CPoint point) { if(GetCapture() == this) ReleaseCapture(); RxFMWnd::OnRButtonUp(nFlags, point);}void RxFMWnd3DMPR::OnMouseMove(UINT nFlags, CPoint point) { if(GetCapture() != this) { RxFMWnd::OnMouseMove(nFlags, point); return; } CPoint ptDiff = point - m_ptOld; if(ptDiff.x == 0 && ptDiff.y == 0) { RxFMWnd::OnMouseMove(nFlags, point); return; } if(nFlags & MK_LBUTTON) { int nTBCurMode = RxGetFrameMain()->GetTBCurMode(); switch(nTBCurMode) { case BTN_PAN: m_ptPanOffset += ptDiff; RedrawWnd(FALSE); break; case BTN_ZOOM: if(ptDiff.y != 0) ChangeZoomFactorByDiff(ptDiff.y); break; case BTN_WINDOWING: PerformWindowingByOffset(ptDiff); break; } } else if(nFlags & MK_RBUTTON){ PerformWindowingByOffset(ptDiff); } m_ptOld = point; RxFMWnd::OnMouseMove(nFlags, point);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -