天天看點

MFC位圖顯示

void CTMVedioShow::ShowCombineFundus()

111

#pragma once
#include "afxwin.h"
#include "utility.h"
#include "UtilityObject.h"
#include "TMVedio.h"

typedef struct _COMBINEFUNDUS_ 
{
	SCANMODE mode;
	//角度
	int nAngle;
	//透明度
	BYTE byAlpha;
	// 中心位置
	DPOINT position;
	//區域寬度
	float nlength;
	//圖像寬度
	long nWidth;
	//圖像高度
	long nHeight;
	//合成眼底圖資料
	BYTE *pBit;
	float nCrossBeamGap;
}COMBINEFUNDUS, *PCOMBINEFUNDUS;

class CTMVedioShow :
	public CStatic
{
	DECLARE_DYNAMIC(CTMVedioShow)
protected:
	DECLARE_MESSAGE_MAP()
private:
	//圖像資料
	BYTE *m_pbyReversebuff;
	//圖像高
	DWORD m_nImgHeight ;
	//圖像寬
	DWORD m_nImgWidth;
	//圖像頭資訊
	BYTE *m_pHeaderBuffer;
	//圖像資訊
	LPBITMAPINFO m_pBitmapInfo;
	//調色闆
	CPalette *m_pPalette;
	//是否反轉圖像
	//BOOL m_bReverse;
	//合成眼底圖資訊
	PCOMBINEFUNDUS m_comfinefundusinfo;
	//合成眼底圖透明度
	BYTE m_byAlpha;
	//掃描線顔色
	const COLORREF m_clScanLine;
	//掃描直線tuodong角度
	float m_nAngle_drag;
	//瞳孔中心點
	DPOINT m_irisCenter;
	DPOINT m_irisCenter1;
	//瞳孔半徑
	UINT m_nRadius;
	//瞳孔中心點 
	CRect m_IrisCenterRect;
protected:
	//顯示合成眼底圖
	void ShowCombineFundus();
public:
	CTMVedioShow(void);
public:
	~CTMVedioShow(void);
public:
	//override
	void PreSubclassWindow();
	//override
	void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
	//設定檔案路徑
	void SetImage(BYTE *pbyBit, BOOL bReverse = FALSE);
	//設定合成眼底圖資訊
	void SetCombineFundusInfo(PCOMBINEFUNDUS pFundusInfo);
	//設定合成眼底圖透明度
	void SetCombineFundusAlpha(BYTE byAlpha);
	//區域掃描線
	void DrawRangle(CDC *pDC);
	//六線掃描
	void DrawSixLine(CDC *pDC);
	//直線掃描
	void DrawLine(CDC *pDC);
	//畫掃描線
	void DrawVirtualScanLine(CDC *pDC);
	void DrawCrossBeam(CDC *pDC);
	/************************************************************************
	* 功能描述: 畫算法定位到的瞳孔圓盤
	* 輸入參數:
	* 輸出參數:
	* 傳回參數:
	* 其它說明:
	************************************************************************/
	void DrawIris(CDC *pDC);
	/************************************************************************
	* 功能描述: 畫瞳孔紅圓圈
	* 輸入參數:
	* 輸出參數:
	* 傳回參數:
	* 其它說明:
	************************************************************************/
	void DrawRedCircle(CDC *pDC, CRect &rt, DPOINT &center, UINT nRadius, COLORREF clColor, BOOL bFill = TRUE);
	void SetIrisCenterAndRadius(POINT* center,int radius);
};
           

222

#include "StdAfx.h"
#include "TMVedioShow.h"
#include "ScanParam.h"
#include "Log.h"

IMPLEMENT_DYNAMIC(CTMVedioShow, CStatic)

BEGIN_MESSAGE_MAP(CTMVedioShow, CStatic)

END_MESSAGE_MAP()

CTMVedioShow::CTMVedioShow(void)
: m_clScanLine(RGB(255, 0, 0))
{
	m_nRadius=0;
#ifndef NEW_OSE2000
	m_nImgHeight =VEDIOHDHEIGHT ;//VEDIOHEIGHT - VEDIO_TOP_CUT - VEDIO_BOTTOM_CUT;
	m_nImgWidth = VEDIOHDWIDTH;//VEDIOWIDTH - VEDIO_LEFT_CUT - VEDIO_RIGHT_CUT;
	CLog::GetInstance()->WriteLog(_T("CTMVedioShow::CTMVedioShow NEW_OSE2000"));
#else
	m_nImgHeight = VEDIOHEIGHT;
	m_nImgWidth = VEDIOWIDTH;
	CLog::GetInstance()->WriteLog(_T("CTMVedioShow::CTMVedioShow 320 240"));
#endif
	CLog::GetInstance()->WriteLog(_T("CTMVedioShow::CTMVedioShow"));

	//randongmei:20180409
	//DWORD nSize = WIDTHBYTES(m_nImgWidth * 8) * m_nImgHeight;
	DWORD nSize = m_nImgWidth *  m_nImgHeight*3;
	m_pbyReversebuff = (BYTE *)malloc(nSize);
	memset(m_pbyReversebuff, 0, nSize);
	CLog::GetInstance()->WriteLog(_T("CUtilityObject::GetInstance()"));

	m_pHeaderBuffer = CUtilityObject::GetInstance()->tmImage.Create8GrayscaleBMPINFO(m_nImgWidth, m_nImgHeight);
	m_pBitmapInfo = (LPBITMAPINFO)m_pHeaderBuffer;
	CLog::GetInstance()->WriteLog(_T("CUtilityObject::GetInstance()"));

	m_pPalette = CUtilityObject::GetInstance()->tmImage.Create8GrayscalePalette();
	//m_comfinefundusinfo = NULL;
	//m_bReverse = FALSE;
	m_nAngle_drag=0.0;
}

CTMVedioShow::~CTMVedioShow(void)
{
	free(m_pbyReversebuff);
	free(m_pHeaderBuffer);
	delete m_pPalette;
}

void CTMVedioShow::PreSubclassWindow()
{
	CLog::GetInstance()->WriteLog(_T("CTMVedioShow::PreSubclassWindow"));

	DWORD dwStyle = GetStyle();
	SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_OWNERDRAW | SS_NOTIFY);
	CStatic::PreSubclassWindow();
	CLog::GetInstance()->WriteLog(_T("CStatic::PreSubclassWindow"));
}

void CTMVedioShow::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	//CLog::GetInstance()->WriteLog(_T("CTMVedioShow::DrawItem"));
	CRect rt;
	GetClientRect(&rt);
	CDC *pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	
	CPalette *oldpalette = pDC->SelectPalette(m_pPalette, TRUE);
	pDC->RealizePalette();

	HDC hdc = pDC->GetSafeHdc();
	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP bmpMem = CreateCompatibleBitmap(hdc, m_nImgWidth, m_nImgHeight);
	HGDIOBJ holdBmp = ::SelectObject(hdcMem, bmpMem);
	//CLog::GetInstance()->WriteLog(_T("::SelectObject(hdcMem, bmpMem)"));
#ifndef NEW_OSE2000
	CRgn rgn;
	rgn.CreateEllipticRgn(0, 0, m_nImgWidth, m_nImgHeight/*rt.Width(), rt.Height()*/);
	//pDC->SelectClipRgn(&rgn);
	SelectClipRgn(hdcMem, rgn);
	CLog::GetInstance()->WriteLog(_T("NEW_OSE2000"));
#endif
	//pDC->SelectClipRgn(&rgn);
	SetStretchBltMode(hdc, COLORONCOLOR);
	SetDIBits(hdcMem, bmpMem, 0, m_nImgHeight, m_pbyReversebuff, m_pBitmapInfo, DIB_RGB_COLORS);
		//CLog::GetInstance()->WriteLog(_T("SetDIBits"));
	StretchBlt(hdc, 0, 0, rt.Width(), rt.Height(), hdcMem, 0, 0, m_nImgWidth, m_nImgHeight, SRCCOPY);
		//CLog::GetInstance()->WriteLog(_T("StretchBlt"));

	pDC->SelectPalette(oldpalette, TRUE);
	TRACE("CTMVedioShow dramitem.\n");
	DeleteObject(hdcMem);
	DeleteObject(holdBmp);
	DeleteObject(bmpMem);
	//DrawVirtualScanLine(pDC);	
	DrawIris(pDC);
	ReleaseDC(pDC);
	//CLog::GetInstance()->WriteLog(_T("ReleaseDC"));
	//ShowCombineFundus();
}

void CTMVedioShow::SetImage(BYTE *pbyBit, BOOL bReverse)
{
	
#ifndef NEW_OSE2000
	memcpy(m_pbyReversebuff,pbyBit,m_nImgWidth*m_nImgHeight);
	CLog::GetInstance()->WriteLog(_T("CTMVedioShow::SetImage NEW_OSE2000"));
#else
 	int nbottom = VEDIOHEIGHT-1;
 	int ntop = 0;
 	int nleft = 0;
 	int nright = VEDIOWIDTH-1;
 	int w = 0, h = 0;
 	for (int i=nbottom; i>=ntop; i--)
 	{
 		w = 0;
 		for (int j=nright; j>=nleft; j--)
 		{
 			m_pbyReversebuff[h * m_nImgWidth + w] = pbyBit[i * VEDIOWIDTH + j];
 			w++;
 		}
 		h++;
 	}
	//m_pbyReversebuff=pbyBit;
	//CLog::GetInstance()->WriteLog(_T("CTMVedioShow::SetImage else for"));

#endif
	
}

void CTMVedioShow::ShowCombineFundus()
{
	if (!(m_comfinefundusinfo->mode == OCT3000_MACULAAREA ||
		m_comfinefundusinfo->mode == OCT3000_GLAUCOMADISC ||
		m_comfinefundusinfo->mode == OCT3000_GLAUCOMAMACULA ||
		m_comfinefundusinfo->mode == OCT3000_MACULAAREAVESSEL ||
		m_comfinefundusinfo->mode == OCT3000_DISCAREAVESSEL)
		)
		return;

	//合成眼底圖資料
	BYTE *pFundus = m_comfinefundusinfo->pBit;
	//圖像寬、高
	int nWidth = m_comfinefundusinfo->nWidth;
	int nHeight = m_comfinefundusinfo->nHeight;
	//虛拟視窗矩形
	CRect rtVirtual;
	GetClientRect(&rtVirtual);
	//實際視窗矩形
	REALSCREEN_RECT rtReal;
	CScanParam *pParam = CScanParam::GetInstance();
	rtReal.left = (float)pParam->GetMinSH();
	rtReal.right = (float)pParam->GetMaxSH();
	rtReal.top = (float)pParam->GetMaxSL();
	rtReal.bottom = (float)pParam->GetMinSL();
	//實際視窗原點
	DPOINT origin;
	//origin.x = (rtReal.left + rtReal.right) / 2;
	//origin.y = (rtReal.top + rtReal.bottom) / 2;

	//虛拟掃描中心點
	DPOINT pos = m_comfinefundusinfo->position;
	//虛拟掃描線長度
	int nLength = m_comfinefundusinfo->nlength;
	//位置
	int nLeft = pos.x - nLength / 2;
	int nTop = pos.y - nLength / 2;
	//重新整理背景
	BYTE *pHeaderBuffer = CUtilityObject::GetInstance()->tmImage.Create8GrayscaleBMPINFO(nWidth, nHeight);
	BITMAPINFO *pBitmapInfo = (LPBITMAPINFO)pHeaderBuffer;
	pBitmapInfo->bmiHeader.biHeight = -nHeight;
	CPalette *pPalette = CUtilityObject::GetInstance()->tmImage.Create8GrayscalePalette();

	CDC *pDC = this->GetDC();
	CPalette *oldpalette = pDC->SelectPalette(pPalette, TRUE);
	pDC->RealizePalette();

	HDC hdc = pDC->GetSafeHdc();
	HDC hdcMem = CreateCompatibleDC(hdc);
	HBITMAP bmpMem = CreateCompatibleBitmap(hdc, nWidth, nHeight);
	HGDIOBJ holdBmp = ::SelectObject(hdcMem, bmpMem);

	SetStretchBltMode(hdc, COLORONCOLOR);
	SetDIBits(hdcMem, bmpMem, 0, nHeight, pFundus, pBitmapInfo, DIB_RGB_COLORS);

	BLENDFUNCTION bf;
	bf.AlphaFormat = 0;   
	bf.BlendFlags = 0;   
	bf.BlendOp = AC_SRC_OVER;
	bf.SourceConstantAlpha = m_byAlpha;
	//顯示半透明圖像
	AlphaBlend(hdc, nLeft, nTop, nLength, nLength, hdcMem, 0, 0, nWidth, nHeight, bf);
	pDC->SelectPalette(oldpalette, TRUE);

	DeleteObject(hdcMem);
	DeleteObject(holdBmp);
	DeleteObject(bmpMem);
	ReleaseDC(pDC);

	free(pHeaderBuffer);
	delete pPalette;
}

void CTMVedioShow::SetCombineFundusInfo(PCOMBINEFUNDUS pFundusInfo)
{
	m_comfinefundusinfo = pFundusInfo;
}

void CTMVedioShow::SetCombineFundusAlpha(BYTE byAlpha)
{
	m_byAlpha = byAlpha;
	Invalidate();
}

void CTMVedioShow::DrawLine(CDC *pDC)
{
	int nAngle =/*180 -  */m_comfinefundusinfo->nAngle;
	float linelength = m_comfinefundusinfo->nlength;
	DPOINT center = m_comfinefundusinfo->position;

	CPen pen, *oldpen;
	pen.CreatePen(PS_SOLID, 1, m_clScanLine);
	oldpen = pDC->SelectObject(&pen);
	CPoint start, end;

	double sina = sin(nAngle / 180.0 * PI);
	double cosa = cos(nAngle / 180.0 * PI);

	start.x = (LONG)(center.x + (linelength / 2) * cosa);
	start.y = (LONG)(center.y - (linelength / 2) * sina);
	// CLog::GetInstance()->WriteLog(_T("start.x %d,center.x %d,linelength %d"),start.x,center.x,linelength);


	end.x = (LONG)(center.x - (linelength / 2) * cosa);
	end.y = (LONG)(center.y + (linelength / 2) * sina);

	pDC->MoveTo(start);
	pDC->LineTo(end);
	//CLog::GetInstance()->WriteLog(_T("Start(%d, %d), End(%d, %d)."), start.x, start.y, end.x, end.y);
	//DrawGreenCircle(pDC, m_LineCenterRect, m_center, m_nInRtLenght, RGB(0, 255, 0), FALSE);

	m_nAngle_drag = m_comfinefundusinfo->nAngle;
	//上肩頭=======begin
	double theta = PI/6;//箭頭兩側直線與所畫直線之間的夾角
	double len = 10.0;//箭頭兩側直線的長度
	double theta1,theta2;//所畫直線與水準方向之間的夾角
	if (m_nAngle_drag <= 90)
	{
		theta1 = atan2 (double (end.y - start.y), double(end.x - start.x));
		pDC->MoveTo(start);
		pDC->LineTo((int)(start.x + len * cos(theta + theta1)), (int)(start.y + len * sin(theta + theta1)));
		pDC->MoveTo(start);
		pDC->LineTo((int)(start.x + len * cos(theta1 - theta)), (int)(start.y + len * sin(theta1 - theta)));
		//CLog::GetInstance()->WriteLog(_T("m_nAngle: 1111111111111111     %lf, %lf"), m_nAngle,m_nAngle_drag);
	}
	else
	{
		theta1 = atan2 (double (end.y - start.y), double(end.x - start.x));
		theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
		pDC->MoveTo(end);
		pDC->LineTo((int)(end.x - len * cos(theta + theta1)), (int)(end.y - len * sin(theta + theta1)));
		pDC->MoveTo(end);
		pDC->LineTo((int)(end.x - len * cos(theta1 - theta)), (int)(end.y - len * sin(theta1 - theta)));
	}
	///=================end  加箭頭
	pDC->SelectObject(oldpen);
}

void CTMVedioShow::DrawRangle(CDC *pDC)
{
	int linelength = m_comfinefundusinfo->nlength;
	DPOINT center = m_comfinefundusinfo->position;

	CRect rt;
	rt.left = center.x - (linelength >> 1);
	rt.top = center.y - (linelength >> 1);
	rt.right = rt.left + linelength;
	rt.bottom = rt.top + linelength;
	rt.InflateRect(1, 1, 1, 1);

	CBrush brush, *oldbrush;
	brush.CreateSolidBrush(m_clScanLine);
	oldbrush = pDC->SelectObject(&brush);
	//矩形
	pDC->FrameRect(&rt, &brush);
	pDC->SelectObject(oldbrush);
}

void CTMVedioShow::DrawSixLine(CDC *pDC)
{
	int linelength = m_comfinefundusinfo->nlength;
	DPOINT center = m_comfinefundusinfo->position;

	double amplitude = linelength >> 1;
	float sin_AOA, cos_AOA;
	const short angle = 30;
	//const double PI = 3.1415926;
	CPen pen, *oldpen;
	pen.CreatePen(PS_SOLID, 1, m_clScanLine);
	oldpen = pDC->SelectObject(&pen);
	CPoint start, end;
	for (int i=0; i<6; i++)
	{
		//起點 
		sin_AOA = (float)(amplitude * sin(i * angle / 180.0 * PI));
		cos_AOA = (float)(amplitude * cos(i * angle / 180.0 * PI));
		start.x = (LONG)(center.x + sin_AOA);
		start.y = (LONG)(center.y + cos_AOA);
		//終點
		sin_AOA = (float)(amplitude * sin((i * angle + 180) / 180.0 * PI));
		cos_AOA = (float)(amplitude * cos((i * angle + 180) / 180.0 * PI));
		end.x = (LONG)(center.x + sin_AOA);
		end.y = (LONG)(center.y + cos_AOA);

		pDC->MoveTo(start);
		pDC->LineTo(end);

		double theta = PI/6;//箭頭兩側直線與所畫直線之間的夾角
		double len = 10.0;//箭頭兩側直線的長度
		double theta1,theta2;//所畫直線與水準方向之間的夾角
		if (i == 0)
		{
			theta1 = atan2 (double (start.y - end.y), double(start.x - end.x));
			//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
			pDC->MoveTo(end);
			pDC->LineTo((int)(end.x + len * cos(theta + theta1)), (int)(end.y + len * sin(theta + theta1)));//point3
			pDC->MoveTo(end);
			pDC->LineTo((int)(end.x + len * cos(theta1 - theta)), (int)(end.y + len * sin(theta1 - theta)));//point4
			continue;
		}
		theta1 = atan2 (double (end.y - start.y), double(end.x - start.x));
		//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
		pDC->MoveTo(start);
		pDC->LineTo((int)(start.x + len * cos(theta + theta1)), (int)(start.y + len * sin(theta + theta1)));//point3
		pDC->MoveTo(start);
		pDC->LineTo((int)(start.x + len * cos(theta1 - theta)), (int)(start.y + len * sin(theta1 - theta)));//point4

	}
	//設定矩形
	//CPoint topleft, bottomright;
	//topleft.x = (LONG)(m_center.x - amplitude);
	//topleft.y = (LONG)(m_center.y - amplitude);
	//bottomright.x = (LONG)(m_center.x + amplitude);
	//bottomright.y = (LONG)(m_center.y + amplitude);
	//m_AreaRect.SetRect(topleft, bottomright);
	pDC->SelectObject(oldpen);
}

void CTMVedioShow::DrawVirtualScanLine(CDC *pDC)
{
	//CLog::GetInstance()->WriteLog(_T("ReleaseDC"));

	switch (m_comfinefundusinfo->mode)
	{
	case OCT3000_SIXLINE:
	case OCT3000_HDSIXLINE:
	case OCT3000_HDSIXLINEDOUBLEEYE:
		DrawSixLine(pDC);
		break;
	case OCT3000_ANTERIORLINE:
	case OCT3000_ANTERIORLINEDCI:
	case OCT3000_MACULALINE:
	case OCT3000_MACULALINE4K:
	case OCT3000_MACULAHDLINE_DPL:
		DrawLine(pDC);
		break;
	case OCT3000_MACULAAREA:
	case OCT3000_DISCAREA:
	case OCT3000_GLAUCOMADISC:
	case OCT3000_GLAUCOMAMACULA:
	case OCT3000_MACULAAREAVESSEL:
	case OCT3000_DISCAREAVESSEL:
		DrawRangle(pDC);
		break;
	case OCT3000_MACULACROSSBEAM:
		DrawCrossBeam(pDC);
	default:
		break;
	}
}


void CTMVedioShow::DrawCrossBeam(CDC *pDC)
{
	//直線
	CPen pen;
	pen.CreatePen(PS_SOLID, 1, RGB(0, 255, 0));
	CPen *oldpen = pDC->SelectObject(&pen);

	float gap= m_comfinefundusinfo->nCrossBeamGap;
	DPOINT center = m_comfinefundusinfo->position;
	int linelength = m_comfinefundusinfo->nlength;
	//從左邊到右,從下到上
	for (int i=-2; i<3; i++)
	{
		if(i !=0 )
		{
			CPoint ptStart, ptEnd;
			//起點
			ptStart.x = center.x - linelength/2;
			ptStart.y = center.y + i * gap;
			//終點
			ptEnd.x = center.x +linelength/2;
			ptEnd.y = center.y + i * gap;
			pDC->MoveTo(ptStart);
			pDC->LineTo(ptEnd);
			//begin  加箭頭
			double theta = PI/6;//箭頭兩側直線與所畫直線之間的夾角
			double len = 10.0;//箭頭兩側直線的長度
			double theta1,theta2;//所畫直線與水準方向之間的夾角
			theta1 = atan2 (double (ptStart.y - ptEnd.y), double(ptStart.x - ptEnd.x));
			//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
			pDC->MoveTo(ptEnd);
			pDC->LineTo((int)(ptEnd.x + len * cos(theta + theta1)), (int)(ptEnd.y + len * sin(theta + theta1)));//point3
			pDC->MoveTo(ptEnd);
			pDC->LineTo((int)(ptEnd.x + len * cos(theta1 - theta)), (int)(ptEnd.y + len * sin(theta1 - theta)));//point4

			///=================end  加箭		

		}

	}
	//豎直線
	for(int i=-2;i<3;i++)
	{
		if(i != 0)
		{
			CPoint ptStart, ptEnd;
			//起點
			ptStart.x = center.x + i*gap;
			ptStart.y = center.y - linelength/2;
			//終點
			ptEnd.x = center.x+ i*gap;
			ptEnd.y = center.y + linelength/2;
			pDC->MoveTo(ptStart);
			pDC->LineTo(ptEnd);
			//begin  加箭頭
			double theta = PI/6;//箭頭兩側直線與所畫直線之間的夾角
			double len = 10.0;//箭頭兩側直線的長度
			double theta1,theta2;//所畫直線與水準方向之間的夾角
			theta1 = atan2 (double (ptEnd.y - ptStart.y), double(ptEnd.x - ptStart.x));
			//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
			pDC->MoveTo(ptStart);
			pDC->LineTo((int)(ptStart.x + len * cos(theta + theta1)), (int)(ptStart.y + len * sin(theta + theta1)));//point3
			pDC->MoveTo(ptStart);
			pDC->LineTo((int)(ptStart.x + len * cos(theta1 - theta)), (int)(ptStart.y + len * sin(theta1 - theta)));//point4
		}	

	}

	//直線
	CPen pen2;
	pen2.CreatePen(PS_SOLID, 1, RGB(255, 0, 0));
	oldpen = pDC->SelectObject(&pen2);
	CPoint ptStart, ptEnd;
	//起點
	ptStart.x = center.x -  linelength/2;
	ptStart.y = center.y ;
	//終點
	ptEnd.x = center.x +linelength/2;
	ptEnd.y = center.y ;
	pDC->MoveTo(ptStart);
	pDC->LineTo(ptEnd);
	//begin  加箭頭
	double theta = PI/6;//箭頭兩側直線與所畫直線之間的夾角
	double len = 10.0;//箭頭兩側直線的長度
	double theta1,theta2;//所畫直線與水準方向之間的夾角
	theta1 = atan2 (double (ptStart.y - ptEnd.y), double(ptStart.x - ptEnd.x));
	//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
	pDC->MoveTo(ptEnd);
	pDC->LineTo((int)(ptEnd.x + len * cos(theta + theta1)), (int)(ptEnd.y + len * sin(theta + theta1)));//point3
	pDC->MoveTo(ptEnd);
	pDC->LineTo((int)(ptEnd.x + len * cos(theta1 - theta)), (int)(ptEnd.y + len * sin(theta1 - theta)));//point4

	//起點
	ptStart.x = center.x ;
	ptStart.y = center.y - linelength/2;
	//終點
	ptEnd.x = center.x;
	ptEnd.y = center.y + linelength/2;
	pDC->MoveTo(ptStart);
	pDC->LineTo(ptEnd);
	theta1 = atan2 (double (ptEnd.y - ptStart.y), double(ptEnd.x - ptStart.x));
	//theta2 = -atan2 (double(end.y - start.y), double(end.x - start.x));
	pDC->MoveTo(ptStart);
	pDC->LineTo((int)(ptStart.x + len * cos(theta + theta1)), (int)(ptStart.y + len * sin(theta + theta1)));//point3
	pDC->MoveTo(ptStart);
	pDC->LineTo((int)(ptStart.x + len * cos(theta1 - theta)), (int)(ptStart.y + len * sin(theta1 - theta)));//point4

	pDC->SelectObject(oldpen);
}
void CTMVedioShow::DrawRedCircle(CDC *pDC, CRect &rt, DPOINT &center, UINT nRadius, COLORREF clColor, BOOL bFill)
{
	CPen pen, *oldpen;
	CBrush brush, *oldbrush;
	pen.CreatePen(PS_SOLID, 1, clColor);
	oldpen = pDC->SelectObject(&pen);
	if (bFill)
		brush.CreateSolidBrush(clColor);
	else
	{
		HBRUSH hbrush  = (HBRUSH)::GetStockObject(NULL_BRUSH);
		brush.Attach(hbrush);
	}
	oldbrush = pDC->SelectObject(&brush);
	//GoLOCK();
	rt.left = center.x - nRadius;
	rt.top = center.y - nRadius;
	rt.right = center.x + nRadius;
	rt.bottom = center.y + nRadius;
	//GoUNLOCK();
	pDC->Ellipse(&rt);	/*CPoint cpStart, cpEnd;*/



	pDC->SelectObject(oldpen);
	pDC->SelectObject(oldbrush);
}
void CTMVedioShow::DrawIris(CDC *pDC)
{
	if (m_nRadius>0&&m_irisCenter.x>0.0&&m_irisCenter.y>0.0)
	{
		DrawRedCircle(pDC, m_IrisCenterRect, m_irisCenter, m_nRadius, RGB(255, 0, 0), FALSE);
		//DrawGreenCircle(pDC, m_IrisCenterRect, m_irisCenter1, m_nRadius, RGB(0, 255, 0), FALSE);
		//m_nRadius=-1;
		//CLog::GetInstance()->WriteLog(_T("DrawGreenCircle:瞳孔半徑m_nRadius,%u"),m_nRadius);
	}

}
void CTMVedioShow::SetIrisCenterAndRadius(POINT* center,int radius)
{
	//CLog::GetInstance()->WriteLog(_T("瞳孔中心,x:%d,y:%d;"),center->x,center->y);
	//GoLOCK();
	if (radius==-1)
	{
		m_nRadius=0;
	}else
	{
		m_nRadius=radius*1.175;
	}
// 	m_irisCenter.x=320-(double)center->x;
// 	m_irisCenter.y=(double)center->y;
	m_irisCenter.x=(320-(double)center->x)*1.175;
	m_irisCenter.y=(double)center->y*1.175;
	
	//CLog::GetInstance()->WriteLog(_T("瞳孔中心,x:%lf,y:%lf;瞳孔半徑:%d;%u"),m_irisCenter.x,m_irisCenter.y,radius,m_nRadius);
}           

333