📄 form1.cs
字号:
this.Text = "ECG_Program";
this.Load += new System.EventHandler(this.Form1_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.groupBox3.ResumeLayout(false);
this.groupBox4.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.trackBar1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
protected ECG_DATA ECG =new ECG_DATA();
protected double MaxVolt = 1; //心电图的最大电压值
protected double MinVolt = -0.5;//心电图的最小电压值
private int position=0; //记录当前绘图过程中,面板最左侧的第一个点在整个心电数据列中的位置
private int DrawMethod=3; //绘图方式。绘12个导联值为1,绘单极加压导联为2,绘胸导联为3.绘标准肢体导联为4
private Graphics g;
private int VoltToY(double voltage,int Scale) //电压转换为Y的坐标
{
switch(DrawMethod)
{
case 1:return (int)(panel1.Size.Height/12 - panel1.Size.Height/12 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/12 *(Scale-StartingScale));
case 2:return (int)(panel1.Size.Height/3 - panel1.Size.Height/3 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/3 *(Scale-StartingScale));
case 3:return (int)(panel1.Size.Height/5 - panel1.Size.Height/5 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/5 *(Scale-StartingScale));
case 4:return (int)(panel1.Size.Height/3 - panel1.Size.Height/3 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/3 *(Scale-StartingScale));
default :return (int)(panel1.Size.Height/12 - panel1.Size.Height/12 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/12 *(Scale-StartingScale));
}
}
/*private int VoltToY(double voltage,int Scale,int method) //重载电压转换方法
{
switch(method)
{
case 1:return (int)(panel1.Size.Height/12 - panel1.Size.Height/12 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/12 );
case 2:return (int)(panel1.Size.Height/3 - panel1.Size.Height/3 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/3 );
case 3:return (int)(panel1.Size.Height/6 - panel1.Size.Height/6 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/6 );
case 4:return (int)(panel1.Size.Height/3 - panel1.Size.Height/3 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/3 );
default :return (int)(panel1.Size.Height/12 - panel1.Size.Height/12 /(MaxVolt - MinVolt) * (voltage - MinVolt) + panel1.Size.Height/12 );
}
}*/
private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
}
private void draw_grid()
{
Pen pen=new Pen(Color.Khaki,1);
for(int Scale=StartingScale;Scale<=EndingScale;Scale++)
{
for (double v =MinVolt; v <=MaxVolt; v += 0.5) //画横线
{
int y ;
y=VoltToY(v,Scale);
g.DrawLine(pen, 0, y, panel1.Size.Width, y);
if(v==MaxVolt)g.DrawLine(new Pen(Color.Black,1), 0, y, panel1.Size.Width, y);
}
if(Scale==1) g.DrawString("原始信号",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
if(Scale==2) g.DrawString(" 2尺度",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
if(Scale==3) g.DrawString(" 4尺度",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
if(Scale==4) g.DrawString(" 8尺度",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
if(Scale==5) g.DrawString("16尺度",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
// if(Scale==6) g.DrawString("5尺度",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,Scale));
//if(lead==7) g.DrawString("V1",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
//if(lead==8) g.DrawString("V2",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
//if(lead==9) g.DrawString("V3",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
//if(lead==10) g.DrawString("V4",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
//if(lead==11) g.DrawString("V5",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
//if(lead==12) g.DrawString("V6",new Font("Times New Roman",9),new SolidBrush(Color.Black),0,VoltToY(MaxVolt,lead));
}
for(int i=0;i<=panel1.Size.Width;i+=20) //每隔20个点画竖线
g.DrawLine(pen, i, 0, i, panel1.Size.Height);
}
private void DrawEcg(int Method)
{
if(ECG.DataInputed && ECG.WTProcessed)
{
Pen pen=new Pen(Color.Black,1);
Pen pen1=new Pen(Color.Violet,1);
if(position==0) BtnPreviousPage.Enabled=false;
else BtnPreviousPage.Enabled=true;
if(position+panel1.Size.Width>=2*ECG.Length)BtnNextPage.Enabled=false;
else BtnNextPage.Enabled=true;
for(int Scale=StartingScale;Scale<=EndingScale;Scale++)
{
int j=0,k=0;
for(int i=position/2;j<panel1.Size.Width&& i<ECG.Length-1;i++,j+=2)
{
//g.DrawLine(pen,j,VoltToY(ECG.WTcoefficients[Scale-1,i],Scale),j+2,VoltToY(ECG.WTcoefficients[Scale-1,i+1],Scale));
g.DrawLine(pen,j,VoltToY(ECG.WTcoefficients[Scale-1,i],Scale),j+2,VoltToY(ECG.WTcoefficients[Scale-1,i+1],Scale));
if(ECG.Flag[i]==1)g.DrawLine(new Pen(Color.Red,1),j,VoltToY(-0.5,Scale),j,VoltToY(0.75,Scale));
if(ECG.Flag[i]==2)g.DrawLine(new Pen(Color.Blue,1),j,VoltToY(-0.5,Scale),j,VoltToY(0.75,Scale));
//if(ECG.QRSProcessed && ECG.Flag[i]==3)g.DrawLine(new Pen(Color.Red,1),j,VoltToY(-1.5,Scale),j,VoltToY(1.75,Scale));
//if(i==flag[k]-55){g.DrawLine(new Pen(Color.Red,1),j,VoltToY(-1.5,Scale),j,VoltToY(1.75,Scale));k++;}
//if(ECG.QRSProcessed && ECG.Flag[i]==4)g.DrawLine(new Pen(Color.Red,1),j,VoltToY(-0.5,Scale),j,VoltToY(0.75,Scale));
//if(ECG.QRSProcessed && ECG.Flag[i]==5)g.DrawLine(new Pen(Color.Red,1),j,VoltToY(-0.5,Scale),j,VoltToY(0.75,Scale));
}
}
// statusBar1.Text ="起始数据点位置:"+ position.ToString()+" 终止位置:"+(position+panel1.Size.Width-1).ToString()+" 总数据点数:"+ECG.Length+" QRS波群总数:"+ECG.TotalHeartBeatNumber.ToString();
}
}
private void PlayWave()
{
/*Pen pen=new Pen(Color.Black,1);
statusBar1.Text="";
int j=0;
int i=0;
for(i=ECG.Length-panel1.Size.Width-1;i>=0;i-=5)
{
g.Clear(Color.Ivory);
for(j=panel1.Size.Width-1;j>=0;j--)
g.DrawLine(pen,j,VoltToY(ECG.ECGdata[0,i+j],2,2),j+1,VoltToY(ECG.ECGdata[0,i+j+1],2,2));
System.Threading.Thread.Sleep(10);
statusBar1.Text ="起始数据点位置:"+ i.ToString()+" 终止位置:"+(i+panel1.Size.Width-1).ToString()+" 总数据点数:"+ECG.Length+" QRS波群总数:"+ECG.TotalHeartBeatNumber.ToString();
}*/
}
private void BtnOpenFile_Click(object sender, System.EventArgs e) //打开文件并存储文件数据到ecgData数组
{
string FileName=ECG.OpenFile();
if(FileName!=null)
{
this.Text=FileName;
g= panel1.CreateGraphics();
position=0;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
BtnQRSProcessed.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)), ((System.Byte)(64)));
BtnTWaveProcessed.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)), ((System.Byte)(64)));
BtnWT.ForeColor= System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)), ((System.Byte)(64)));
}
}
private void BtnNextPage_Click(object sender, System.EventArgs e) //下一页
{
if(ECG.DataInputed)
{
if(position+panel1.Size.Width-1<=2*ECG.Length)
position +=panel1.Size.Width-1;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void BtnPreviousPage_Click(object sender, System.EventArgs e) //上一页
{
if(ECG.DataInputed)
{
position -=panel1.Size.Width-1;
if(position<=0)
position=0;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void BtnPlayWave_Click(object sender, System.EventArgs e) //播放
{
if(ECG.DataInputed)
PlayWave();
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void statusBar1_PanelClick(object sender, System.Windows.Forms.StatusBarPanelClickEventArgs e)
{
}
private int StartingScale=1; //对应于每种绘心电图方法中起始导联
private int EndingScale=6; //对应于每种绘心电图方法中结束导联
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
/*DrawMethod=1;
if(ECG.DataInputed)
{
StartingScale=1;
EndingScale=12;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
*/
}
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
/*DrawMethod=2;
if(ECG.DataInputed)
{
StartingScale=4;
EndingScale=6;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
*/
}
private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
{
DrawMethod=3;
if(ECG.DataInputed)
{
StartingScale=1;
EndingScale=6;
g.Clear(Color.Ivory);
g.Clear(Color.White);
draw_grid();
DrawEcg(DrawMethod);
}
}
private void radioButton4_CheckedChanged(object sender, System.EventArgs e)
{
/*DrawMethod=4;
if(ECG.DataInputed)
{
StartingScale=1;
EndingScale=3;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
*/
}
private void BtnQRSProcessed_Click(object sender, System.EventArgs e)
{
if(ECG.DataInputed)
{
if(ECG.WalshTtansformProcessed)
{
for(int index=0;index<ECG.Length;index++)
ECG.Flag[index]=0;
ECG.Delaminate();
BtnQRSProcessed.ForeColor=Color.DarkGreen;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
}
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void BtnTWaveProcessed_Click(object sender, System.EventArgs e)
{
if(ECG.DataInputed)
{
if(!ECG.PTProcessed)
{
if(ECG.QRSProcessed)
{
ECG.PTDetect();
BtnTWaveProcessed.ForeColor=Color.DarkGreen;
}
else
{
MessageBox.Show("请先完成QRS波群特征点检测!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
}
}
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void BtnWT_Click(object sender, System.EventArgs e)
{
if(ECG.DataInputed)
{
ECG.Normalzie();
if(ECG.MarrWT() & ECG.WalshTransform())
{
BtnWT.ForeColor=Color.DarkGreen;
g.Clear(Color.Ivory);
draw_grid();
DrawEcg(DrawMethod);
}
}
else
MessageBox.Show("数据没有输入!","错误",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
private void groupBox4_Enter(object sender, System.EventArgs e)
{
}
private void trackBar1_Scroll(object sender, System.EventArgs e)
{
ECG.Threshold=0.15+trackBar1.Value/100.0;
BtnQRSProcessed.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(64)), ((System.Byte)(0)), ((System.Byte)(64)));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -