⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 心跳检测view.cpp

📁 这个程序实现心电波形的提取
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	m_MaxX=GetSystemMetrics(SM_CXSCREEN);
	m_MaxY=GetSystemMetrics(SM_CYSCREEN);

	m_pMemDC->CreateCompatibleDC(pDC);
	m_pBitmap.CreateCompatibleBitmap(pDC,m_MaxX,m_MaxY);

	ReleaseDC(pDC);

	DrawCordinate();
	return 0;
}

void CMyView::DrawCordinate()
{
	CBitmap* pOldBitmap=m_pMemDC->SelectObject(&m_pBitmap);
	CString str;

	//建立字体
	CFont fontBT;
	m_FontView.lfHeight=20;
	m_FontView.lfEscapement=0;
	m_FontView.lfOrientation=0;
	fontBT.CreateFontIndirect(&m_FontView);

	CFont fontXiao;
	m_FontView.lfHeight=15;
	fontXiao.CreateFontIndirect(&m_FontView);

	CFont* pOldFont=m_pMemDC->SelectObject(&fontBT);
	m_pMemDC->SetTextColor(0);
	m_pMemDC->SetBkMode(TRANSPARENT);

	//填充背景
	CBrush *brush;
	brush=new CBrush(RGB(255,255,255));
	CBrush *pOldBrush=m_pMemDC->SelectObject(brush);
    m_pMemDC->FillRect (CRect(LeftRange,TopRange,m_MaxX,m_MaxY),brush);
//装饰条
	CPen pen(PS_SOLID,2, RGB(0,0,0));
	CPen *pOldPen=m_pMemDC->SelectObject(&pen);

	m_pMemDC->MoveTo(LeftRange, 0);
	m_pMemDC->LineTo(LeftRange, 768);
	m_pMemDC->MoveTo(LeftRange, TopRange);
	m_pMemDC->LineTo(1024, TopRange);

	CPen pen1(PS_DOT, 1, RGB(150,150,150));
	CPen pen2(PS_SOLID, 1, RGB(0,0,0));

//画刻度

    CRect rect(left,top,right,bottom);
    m_pMemDC->Rectangle(rect);

	int i;
	//画下坐标
	double Xinter,Yinter;
	if(m_EndT-m_StartT==1)
	{
		Xinter=(right-left)/100.0;
		m_pMemDC->SelectObject(&pen1);
		for(i=1;i<100;i++)
		{
			m_pMemDC->MoveTo(int(left+i*Xinter),top);
			m_pMemDC->LineTo(int(left+i*Xinter),bottom);
		}
		m_pMemDC->SelectObject(&pen2);
		for(i=1;i<10;i++)
		{
			m_pMemDC->MoveTo(int(left+i*Xinter*10),top);
			m_pMemDC->LineTo(int(left+i*Xinter*10),bottom);
		}
		m_pMemDC->SelectObject(&fontXiao);
		for(i=0;i<=10;i++)
		{
			str.Format("%i",i*100);
			m_pMemDC->TextOut(int(left+i*Xinter*10-8),bottom+5,str);
		}
	}
	//画左坐标
	Yinter=(bottom-top)/100.0;
	m_pMemDC->SelectObject(&pen1);
	for(i=1;i<100;i++)
	{
		if(i/10.0==int(i/10.0))
			continue;
		m_pMemDC->MoveTo(left,int(top+i*Yinter));
		m_pMemDC->LineTo(right,int(top+i*Yinter));
	}
	m_pMemDC->SelectObject(&pen2);
	for(i=1;i<10;i++)
	{
		m_pMemDC->MoveTo(left,int(top+i*Yinter*10));
		m_pMemDC->LineTo(right,int(top+i*Yinter*10));
	}
	for(i=1;i<=10;i++)
	{
		str.Format("%i",i*10);
		m_pMemDC->TextOut(left-25,int(bottom-i*Yinter*10-8),str);
	}
	m_pMemDC->SelectObject(pOldBrush);
	m_pMemDC->SelectObject(pOldFont);
	m_pMemDC->SelectObject(pOldPen);
	m_pMemDC->SelectObject(pOldBitmap); 
}

void CMyView::InitData()
{
	m_FontView.lfHeight=15;
	m_FontView.lfWidth=0;
	m_FontView.lfEscapement=0;
	m_FontView.lfOrientation=0;
	m_FontView.lfWeight=FW_NORMAL;
	m_FontView.lfItalic=FALSE;
	m_FontView.lfUnderline=FALSE;
	m_FontView.lfStrikeOut=FALSE;
	m_FontView.lfCharSet=GB2312_CHARSET;
	m_FontView.lfOutPrecision=OUT_STROKE_PRECIS;
	m_FontView.lfClipPrecision=CLIP_STROKE_PRECIS;
	m_FontView.lfQuality=DRAFT_QUALITY;
	m_FontView.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
	strcpy(m_FontView.lfFaceName,"System");

	TopRange=0;
	LeftRange=0;

	left=LeftRange+40;
	right=820;
	top=TopRange+20;
	bottom=630;
}

void CMyView::DrawLine()
{
	CBitmap* pOldBitmap=m_pMemDC->SelectObject(&m_pBitmap);
	CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
	CPen pen1(PS_SOLID, 1, RGB(255,0,0));
	CPen *pOldPen = m_pMemDC->SelectObject(&pen1);
	
	double Xinter,Yinter;
	Xinter=(right-left)/float(m_pFrm->TP.WholeNumber);
	Yinter=(bottom-top)/100.0;

/*
	for(int i=1;i<=m_pFrm->TP.PointNumber;i++)
	{
		int e1=int(bottom-m_pFrm->TP.data[i-1]*Yinter);
		int e2=int(bottom-m_pFrm->TP.data[i]*Yinter);
		if(e1<top)	e1=top;
		if(e1>bottom)	e1=bottom;
		if(e2<top)	e2=top;
		if(e2>bottom)	e2=bottom;
		m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e1);
		m_pMemDC->LineTo(int(left+i*Xinter),e2);
	}
*/
	for(int i=1;i<m_pFrm->TP.PointNumber;i++)
	{
		int e1=int(bottom-m_pFrm->TP.data[i-1]*Yinter);
		int e2=int(bottom-m_pFrm->TP.data[i]*Yinter);
		int e3=int(bottom-m_pFrm->TP.data1[i-1]*Yinter);
		int e4=int(bottom-m_pFrm->TP.data1[i]*Yinter);

		m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e1);
		m_pMemDC->LineTo(int(left+i*Xinter),e2);

		m_pMemDC->MoveTo(int(left+(i-1)*Xinter),e3);
		m_pMemDC->LineTo(int(left+i*Xinter),e4);

	}


	m_pMemDC->SelectObject(pOldPen);
	m_pMemDC->SelectObject(pOldBitmap); 
	Invalidate(FALSE);
}
void CMyView::SaveFile(CStdioFile *file)
{
	CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
	CString mStr;
	for(int i=0;i<m_pFrm->TP.PointNumber;i++)
	{
		if(m_pFrm->TP.data[i]<0)
			break;
	}
	mStr.Format("采集点共:%d\n",i);
	file->WriteString(mStr);
	for(int j=0;j<i;j++)
	{
		mStr.Format("采集点%d:%3.4f\n",j,m_pFrm->TP.data[j]);
		file->WriteString(mStr);
	}
}
void CMyView::Openfile(CStdioFile *file)
{
	CMainFrame *m_pFrm=(CMainFrame *)AfxGetMainWnd();
	CString mStr;
	int j;
	CEdit* pEdit;
	CString str;

	file->ReadString(mStr);
	j=mStr.Find(":",0)+1;
	mStr=mStr.Right(mStr.GetLength()-j);
	pEdit=(CEdit *)GetDlgItem(IDC_F);
	pEdit->SetSel(0,-1);
	pEdit->ReplaceSel(mStr);

	m_pFrm->TP.PointNumber=atoi(mStr)-1;
	str=mStr;

	int i;
	for(i=0;i<atoi(str);i++)
	{
		file->ReadString(mStr);
		j=mStr.Find(":",0)+1;
		mStr=mStr.Right(mStr.GetLength()-j);
		m_pFrm->TP.data[i]=atof(mStr);
	}

	DrawCordinate();
	DrawLine();	

/*	file->Seek(-15,CFile::end);
	file->ReadString(mStr);
	j=mStr.Find(":",0)+1;
	mStr=mStr.Right(mStr.GetLength()-j);
	pEdit=(CEdit *)GetDlgItem(IDC_E);
	pEdit->SetSel(0,-1);
	pEdit->ReplaceSel(mStr);
*/
}


void CMyView::OnBitmap() 
{
	// TODO: Add your control notification handler code here
	CClientDC dc(this);
	BITMAP btm;
	m_pBitmap.GetBitmap(&btm);
	DWORD size=btm.bmWidthBytes*btm.bmHeight;//bmWidthBytes每条扫描线字节数
	LPSTR lpData=(LPSTR)GlobalAllocPtr(GPTR,size);
/////////////////////////////////////////////
	BITMAPINFOHEADER bih;
	bih.biBitCount=btm.bmBitsPixel;//每个象素的位数0代表JPEG格式或被指定
	bih.biClrImportant=0;//显示位图时所需要的颜色数,若为0则需要所有的颜色数
	bih.biClrUsed=0;//指定颜色表中位图所用道的颜色索引数若为0则取最大值
	bih.biCompression=0;//压缩格式0指的是未压缩
	bih.biHeight=btm.bmHeight;//位图高
	bih.biPlanes=1;//必须为一
	bih.biSize=sizeof(BITMAPINFOHEADER);//这种结构的大小
	bih.biSizeImage=size;//位图大小的字节数
	bih.biWidth=btm.bmWidth;//位图宽
	bih.biXPelsPerMeter=0;//X方向每米所规定的象素方式
	bih.biYPelsPerMeter=0;//
///////////////////////////////////
	GetDIBits(dc,m_pBitmap,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);

/////////////////////////////////////////////
	BITMAPFILEHEADER bfh;
	bfh.bfReserved1=bfh.bfReserved2=0;
	bfh.bfType=((WORD)('M'<< 8)|'B');
	bfh.bfSize=54+size;
	bfh.bfOffBits=54;
/////////////////////////////////////////////
	CFile bf;
	CFileDialog dlg(FALSE,"txt","未命名",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
			"心跳检测数据(*.bmp)|*.bmp|所有文件(*.*)|*.*||",this);
    if(dlg.DoModal()==IDCANCEL)
		 return;
	CString name;
	name=dlg.GetPathName();	
	if(bf.Open(name,CFile::modeCreate|CFile::modeWrite))
	{
		bf.WriteHuge(&bfh,sizeof(BITMAPFILEHEADER));
		bf.WriteHuge(&bih,sizeof(BITMAPINFOHEADER));
		bf.WriteHuge(lpData,size);
		bf.Close();
	
	}
	GlobalFreePtr(lpData);
}


double CMyView::fsimpf(double x)
{
	double y;
 //   y=log(1.0+x)/(1.0+x*x);

//	y=sin(x/50.0);
	y=sin(x/10);
    return(y);
}

double CMyView::fsimp(double a, double b, double eps)
{
    int n,k;
    double h,t1,t2,s1,s2,ep,p,x;
    n=1; h=b-a;
    t1=h*(fsimpf(a)+fsimpf(b))/2.0;  /*用梯形公式求出一个大概的估值*/
    s1=t1;
    ep=eps+1.0;
    while (ep>=eps)
	{
		/*用梯形法则计算*/
		p=0.0;
		for (k=0;k<=n-1;k++)
		{
			x=a+(k+0.5)*h;
			p=p+fsimpf(x);
		}
		t2=(t1+h*p)/2.0;
		/*用辛普森公式求精*/
		s2=(4.0*t2-t1)/3.0;
		ep=fabs(s2-s1);
		t1=t2; s1=s2; n=n+n; h=h/2.0;
	}
    return(s2);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -