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

📄 torog.~cpp

📁 脑电信号分析软件
💻 ~CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Main.h"
#include "Torog.h"
#include <math.h>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TTopograp *Topograp;
//---------------------------------------------------------------------------
__fastcall TTopograp::TTopograp(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TTopograp::Button1Click(TObject *Sender)
{
 Topograp->Close() ;
}
//---------------------------------------------------------------------------
//------------------------------------------------------------------------------
//double dd2[16];  ///用以放置待测点距16导位置的距离 的数组
//int d2_order[3];////用以放置与待测点距离最近的导联号
//float scale_2d[14]={1.9,2.1,2.2,2.3,2.4,2.5,2.6,2.7,2.8,2.9,3.0,3.1,3.2,3.3};//,3.4,4.2,4.7,5.4,6.1,6.9,7.0,9};//{37,36,31,28,24,22,20,18,16,14,12,10,8,6,4,1};
int Posi_Lead[16][2]={   {36,12},{54,12},
                         {33,28},{57,28},
                         {31,45},{59,45},
                         {33,62},{57,62},
                         {36,78},{54,78},
                         {18,26},{72,26},
                         {15,45},{75,45},
                         {18,64},{72,64}};
//double d2_power[16]={4,4.2,6.3,9,19.5,6,12,23.4,45.6,10,46,32,28,24,11,14}; //{ 2.0,4.1,10.1,12.5,5.8,13.1,13.5,10.6,13.3,12.6,8.5,5.15,13.08,3.54,23.19,82.7} ;
//long cr_color[17]={               ( 10),            (  15*256+112),
//                          ( 63*256+127),           (  191*256+239),
//                 ( 15*65536+239*256+144),            (  240*256+47),
//                   ( 48*65536+240*256+0),    ( 112*65536+240*256+0),
//                 ( 191*65536+240*256+0),    ( 239*65536+240*256+0),
//                  ( 239*65536+191*256+0),    ( 240*65536+112*256+0),
//                  ( 239*65536+80*256+15),     ( 240*65536+48*256+0),
//                   ( 245*65536+15*256+0),     ( 233*65536+3*256+37),
//                ( 255*65536+255*256+255)
//                };
TColor cr_color[17]={
                 tRGB(0,0,0),
                 tRGB(0,15,112),  tRGB(0,63,127),  tRGB(0,191,239),
                 tRGB(15,239,144),tRGB(0,240,47),  tRGB(48,240,0),
                 tRGB(112,240,0), tRGB(191,240,0), tRGB(239,240,0),
                 tRGB(239,191,0), tRGB(240,112,0), tRGB(239,80,15),
                 tRGB(240,48,0),  tRGB(245,15,0),tRGB(233,3,37),
                 tRGB(0,0,0)
                 };       //     ,clWhite
///-----------------------------------------------------------------------------
double __fastcall TTopograp:: dis2(int tx,int ty, int i) //TObject *Sender,/用来求出待测点 (tx,ty)与16导的距离
{
     double Distance;
     Distance= sqrt((Posi_Lead[i][0]-tx)*(Posi_Lead[i][0]-tx)+(Posi_Lead[i][1]-ty)*(Posi_Lead[i][1]-ty));
     return Distance;
}
////----------------------------------------------------------------------------
int  __fastcall TTopograp::  d2_sort( int getsmall[], double dd2[],int n) //TObject *Sender//将待测点与16个导联的距离进行一次从小到大的排序
{
   int LeadNo=16;
   double t,temp[16];
   int i,j,k,num;
   n=LeadNo;
   for (i=0;i<16;i++)
   {
     temp[i]=dd2[i];
   }
   ///------------------由小到大排序--------------------------------------------
 for (j=1;j<15;j++)
 {
   for (i=j;i<16;i++)
   {
    if(temp[j]>temp[i])
       {
       t=temp[i];
       temp[i]=temp[j];
       temp[j]=t;
       }
   }
 }
//--------------求出与待测点最近的三个导联的序列号-------------------------
  for(i=0;i<LeadNo;i++)
  {
   if(temp[0]==dd2[i])
     getsmall[0]=i;
  }
   for(i=0;i<LeadNo;i++)
  {
   if(temp[1]==dd2[i])
     getsmall[1]=i;
  }
  for(i=0;i<LeadNo;i++)
  {
   if(temp[2]==dd2[i])
     getsmall[2]=i;
  }
  return 1;
}
///-----------------------------------------------------------------------------

///-----------------------------------------------------------------------------
long __fastcall TTopograp:: getcolor(int tx,int ty,int Kind)//TObject *Sender,//用来求出待测点的颜色值
{
	int i, j, k;
	double tot, ddd[3];
	double fa;
	int kk;
	float p_value;
	tot = 0.0;
	fa = 0.0;
        int LeadNo=16;
       for (i = 0;i < LeadNo;i++)
           dd2[i] = dis2( tx, ty, i); //Sender,/(tx,ty)该点的坐标与第i导的坐标进行比较,算出距离
	d2_sort(d2_order,dd2,LeadNo);//Sender//找出距离第i点 最短距离的三个导联的(通过排序得到的)
	for (j = 0;j < 3;j++)
	{
		k = d2_order[j];  ///d2_order[j]中放置的是导联序号(已按照距离经过排序,由小到大),如本行中,为第 k 导
		ddd[j] = dd2[k];  /// ddd[j]中放置的是第 i 点距离选中三点的距离
	}
	fa = ddd[0] * ddd[1] + ddd[1] * ddd[2] + ddd[0] * ddd[2];
	if (fa < 1.0)
		fa = 1.0;
	tot = 0.0;
	k = d2_order[0];
	tot = ddd[1] * ddd[2] * d2_power[Kind][k];   ////d2_power中为第 k 导的功率值
	k = d2_order[1];
	tot = tot + ddd[0] * ddd[2] * d2_power[Kind][k];
	k = d2_order[2];
	tot = tot + ddd[0] * ddd[1] * d2_power[Kind][k];
	tot = tot / fa;
	p_value = (float) tot;   ////  计算Value值,即power值
	kk = 0;
	while ((p_value >(float) scale_2d[Kind][kk]) && kk < 14)
		kk++ ;
	return cr_color[kk + 1];    //////返回该点的对应的颜色值!(功率大的位置颜色深)
}
////----------------------------------------------------------------------------
void line(TCanvas *ptr,int xo,int yo,int x1,int y1,long color )
{
    ptr->Pen->Color = color;
    ptr->MoveTo(xo,yo);
    ptr->LineTo(x1,y1);
}
///-----------------------------------------------------------------------------
///----------求出地形图中每一个点的横坐标起始位置 ------------------------------
int __fastcall TTopograp:: GetYtoX(int xx[])
{  int y1=0;
 for (y1=0;y1<=45;y1=y1+1)
 {
   xx[y1]=45-sqrt(45*45-(45-y1)*(45-y1));
 }
  return 1;
}
///-----------------------------------------------------------------------------
////------------画图------------------------------------------------------------
int __fastcall TTopograp:: Dispmone( int posi_x, int posi_y,int Kindof)    //   TObject *Sender,// posi_x,posi_y 代表为在实际坐标系中的画图位置
{
        int AXIS=45;
	int x1, y1, startx;
	long color;   //  TColor
	int tx, ty;
	//POINT points[3];
	TPoint points[3];
        TCanvas *ptr;
	startx = 0;
        /////本例中 x1  y1 代表初始时计算的坐标系中需要拟和的坐标点,坐标位置: 0~90
        /////tx  ty 代表需要画图位置的坐标点(目的坐标系中的坐标点),其与计算的坐标系之间的转化关系是平移
        //////计算、画图过程是由左到右横着画,画完后,下移一个步长,再由左到右画
	for ( y1 = 0, ty = posi_y; y1 <= 2*AXIS; y1 += 2, ty += 2)
	{
		if (y1 <= 45)
			startx = xx[y1]; ///根据是圆内的点,所以由勾股定理得出起始点 y1 = 0 时的 x1 即startx的值
		else
			startx = xx[90 - y1];////判断语句表示上半圆和下半圆的位置计算不同,但想法一致
		for ( x1 = startx, tx = posi_x + startx; x1 <= 90 - startx; x1 += 2, tx += 2)
		{
		        color = getcolor(x1, y1,Kindof);// //在计算坐标系中获得需要画图点的颜色值
                        //Canvas->TextOutA(x1+150,x1+150,AnsiString(color));
			                    //---- 置画笔颜色
		     //	setcolor( color);       //
			line(Canvas, tx, ty, tx, ty + 2,color);
			line(Canvas, tx + 1, ty, tx + 1, ty + 2,color);
		}
	}
       	points[0] = Point(posi_x + 45, posi_y - 4);
	points[1] = Point(posi_x + 45 - 4, posi_y );   //  - 1
	points[2] = Point(posi_x + 45 + 4, posi_y );   // - 1
	//  points[3] = Point(240,120);
	Canvas->Brush->Color = clTeal;  //   Image1->
	Canvas->Pen->Color = clTeal;  // Image1->
	Canvas->Polygon(points, 2); // Image1->
	Canvas->Brush->Color = clWhite; // Image1->
	return 1;
}
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void __fastcall TTopograp::FormCreate(TObject *Sender)
{
  int i;
  AXIS=45;
  Image1->Width=40;
  Image1->Height =310;
  int Num_Grid=42;
  int Step=Image1->Height/42;
  Image1->Canvas->Pen->Style = psSolid	;


 /* Canvas->TextOutA(AXIS+95,AXIS+10,"二维脑电地形图");
  Canvas->TextOutA(AXIS+45,AXIS+140,"频率范围: 0~3.9"); //左上第一个
  Canvas->TextOutA(AXIS+150,AXIS+140,"频率范围: 4~7.9");  //右上第二个
  Canvas->TextOutA(AXIS+45,AXIS+260,"频率范围: 8~13.9");  //左下第三个
  Canvas->TextOutA(AXIS+150,AXIS+260,"频率范围: 14~30");//右下第四个
 */
  for ( int y=0;y<=Num_Grid;y=y+1) //画竖线
   {
     if(y%3==0)
       {
        Image1->Canvas->Pen->Color = cr_color[16-y/3];//Num_Grid-colorShow;Num_Grid-
        Image1->Canvas->Brush->Color =cr_color[16-y/3]; //Num_Grid-Num_Grid- Top
        Image1->Canvas->Rectangle(Image1->Width/40,Image1->Height/100+Step*y,Image1->Width-1,Image1->Height/100+Step*(y+2));
        Image1->Canvas->FloodFill(Image1->Width/40+1 ,Image1->Height/100+Step*y+1,clWhite,fsSurface);     //fsBorder     (int) 0xff clRed
       }
    }
}
//------------------------------------------------------------------------------
void __fastcall TTopograp::Button2Click(TObject *Sender)
{
  AXIS=45;
   GetYtoX(xx);//获得画圆的起始值,将其存入数组
    Canvas->TextOutA(300,25,"颜色标尺");
  ///////--------确定画图点的中西坐标,以此为中心,画脑电-----------------------

    Canvas->TextOutA(AXIS+95,AXIS+10,"二维脑电地形图");
    Canvas->TextOutA(AXIS+45,AXIS+140,"频率范围: 0~3.9"); //左上第一个
    Canvas->TextOutA(AXIS+160,AXIS+140,"频率范围: 4~7.9");  //右上第二个
    Canvas->TextOutA(AXIS+45,AXIS+260,"频率范围: 8~13.9");  //左下第三个
    Canvas->TextOutA(AXIS+160,AXIS+260,"频率范围: 14~30");//右下第四个
        for (int i=0;i<5;i++)
        {
         if (i==0)
          Dispmone(AXIS+45,AXIS+160,i);  //左上第一个
         if (i==1)
          Dispmone(AXIS+160,AXIS+160,i); //右上第二个
         if (i==2)
          Dispmone(AXIS+45,AXIS+280,i); //左下第三个
         if (i==3)
          Dispmone(AXIS+160,AXIS+280,i);//右下第四个
         if (i==4)
          Dispmone(AXIS+95,AXIS+40,i);//中间第一个
        }
}
//------------------------------------------------------------------------------


void __fastcall TTopograp::FormCloseQuery(TObject *Sender, bool &CanClose)
{
   MainForm->Timer3->Enabled=true;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

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