ecgdraw.cs

来自「ecg tool kit for medical image retrieval」· CS 代码 · 共 1,206 行 · 第 1/4 页

CS
1,206
字号
					drawSections[ 3] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX,  5.0f * fGridY, signals[ 0].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 0].Rhythm);
					drawSections[ 4] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 16.0f * fGridY, signals[ 1].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 1].Rhythm);
					drawSections[ 5] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 27.0f * fGridY, signals[ 2].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 2].Rhythm);

					drawSections[ 6] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX,  5.0f * fGridY, signals[ 3].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 3].Rhythm);
					drawSections[ 7] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX, 16.0f * fGridY, signals[ 4].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 4].Rhythm);
					drawSections[ 8] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX, 27.0f * fGridY, signals[ 5].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 5].Rhythm);

					drawSections[ 9] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX,  5.0f * fGridY, signals[ 6].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 6].Rhythm);
					drawSections[10] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX, 16.0f * fGridY, signals[ 7].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 7].Rhythm);
					drawSections[11] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX, 27.0f * fGridY, signals[ 8].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 8].Rhythm);

					drawSections[12] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX,  5.0f * fGridY, signals[ 9].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[ 9].Rhythm);
					drawSections[13] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX, 16.0f * fGridY, signals[10].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[10].Rhythm);
					drawSections[14] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX, 27.0f * fGridY, signals[11].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[11].Rhythm);
				}
					break;
				case ECGDrawType.ThreeXFourPlusOne:
				{
					drawSections = new ECGDrawSection[17];

					int	a = nTime,
						b = (int) (2.5f * signals.RhythmSamplesPerSecond) + nTime,
						c = (5 * signals.RhythmSamplesPerSecond) + nTime,
						d = (int) (7.5f * signals.RhythmSamplesPerSecond) + nTime,
						e = (10 * signals.RhythmSamplesPerSecond) + nTime;

					drawSections[ 0] = new ECGDrawSection(true, fmm_Per_mV, 0.0f,  4.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 1] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 12.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 2] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 20.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 3] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 28.0f * fGridY, signals.RhythmSamplesPerSecond, 2);

					drawSections[ 4] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX,  4.0f * fGridY, signals[ 0].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 0].Rhythm);
					drawSections[ 5] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 12.0f * fGridY, signals[ 1].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 1].Rhythm);
					drawSections[ 6] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 20.0f * fGridY, signals[ 2].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 2].Rhythm);

					drawSections[ 7] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX,  4.0f * fGridY, signals[ 3].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 3].Rhythm);
					drawSections[ 8] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX, 12.0f * fGridY, signals[ 4].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 4].Rhythm);
					drawSections[ 9] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX, 20.0f * fGridY, signals[ 5].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 5].Rhythm);

					drawSections[10] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX,  4.0f * fGridY, signals[ 6].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 6].Rhythm);
					drawSections[11] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX, 12.0f * fGridY, signals[ 7].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 7].Rhythm);
					drawSections[12] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX, 20.0f * fGridY, signals[ 8].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 8].Rhythm);

					drawSections[13] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX,  4.0f * fGridY, signals[ 9].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[ 9].Rhythm);
					drawSections[14] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX, 12.0f * fGridY, signals[10].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[10].Rhythm);
					drawSections[15] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX, 20.0f * fGridY, signals[11].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[11].Rhythm);

					drawSections[16] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 28.0f * fGridY, signals[ 1].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, e, signals[ 1].Rhythm);
				}
					break;
				case ECGDrawType.ThreeXFourPlusThree:
				{
					drawSections = new ECGDrawSection[21];

					int	a = nTime,
						b = (int) (2.5f * signals.RhythmSamplesPerSecond) + nTime,
						c = (5 * signals.RhythmSamplesPerSecond) + nTime,
						d = (int) (7.5f * signals.RhythmSamplesPerSecond) + nTime,
						e = (10 * signals.RhythmSamplesPerSecond) + nTime;

					drawSections[ 0] = new ECGDrawSection(true, fmm_Per_mV, 0.0f,  2.5f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 1] = new ECGDrawSection(true, fmm_Per_mV, 0.0f,  8.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 2] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 13.5f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 3] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 19.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 4] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 24.0f * fGridY, signals.RhythmSamplesPerSecond, 2);
					drawSections[ 5] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 29.5f * fGridY, signals.RhythmSamplesPerSecond, 2);

					drawSections[ 6] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX,  2.5f * fGridY, signals[ 0].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 0].Rhythm);
					drawSections[ 7] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX,  8.0f * fGridY, signals[ 1].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 1].Rhythm);
					drawSections[ 8] = new ECGDrawSection(true, fmm_Per_mV,  2.0f * fGridX, 13.5f * fGridY, signals[ 2].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, b, signals[ 2].Rhythm);

					drawSections[ 9] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX,  2.5f * fGridY, signals[ 3].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 3].Rhythm);
					drawSections[10] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX,  8.0f * fGridY, signals[ 4].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 4].Rhythm);
					drawSections[11] = new ECGDrawSection(true, fmm_Per_mV, 14.5f * fGridX, 13.5f * fGridY, signals[ 5].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, b, c, signals[ 5].Rhythm);

					drawSections[12] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX,  2.5f * fGridY, signals[ 6].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 6].Rhythm);
					drawSections[13] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX,  8.0f * fGridY, signals[ 7].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 7].Rhythm);
					drawSections[14] = new ECGDrawSection(true, fmm_Per_mV, 27.0f * fGridX, 13.5f * fGridY, signals[ 8].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, c, d, signals[ 8].Rhythm);

					drawSections[15] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX,  2.5f * fGridY, signals[ 9].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[ 9].Rhythm);
					drawSections[16] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX,  8.0f * fGridY, signals[10].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[10].Rhythm);
					drawSections[17] = new ECGDrawSection(true, fmm_Per_mV, 39.5f * fGridX, 13.5f * fGridY, signals[11].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, d, e, signals[11].Rhythm);

					drawSections[18] = new ECGDrawSection(true, fmm_Per_mV, 2.0f * fGridX, 19.0f * fGridY, signals[ 1].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, e, signals[ 1].Rhythm);
					drawSections[19] = new ECGDrawSection(true, fmm_Per_mV, 2.0f * fGridX, 24.0f * fGridY, signals[ 7].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, e, signals[ 7].Rhythm);
					drawSections[20] = new ECGDrawSection(true, fmm_Per_mV, 2.0f * fGridX, 29.5f * fGridY, signals[10].Type, signals.RhythmAVM, signals.RhythmSamplesPerSecond, a, e, signals[10].Rhythm);
				}
					break;
				case ECGDrawType.Median:
				{
					drawSections = new ECGDrawSection[15];

					int	a = nTime,
						b = ((signals.MedianLength * signals.MedianSamplesPerSecond) / 1000) + nTime + 1;

					drawSections[ 0] = new ECGDrawSection(true, fmm_Per_mV, 0.0f,  5.0f * fGridY, signals.MedianSamplesPerSecond, 2);
					drawSections[ 1] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 16.0f * fGridY, signals.MedianSamplesPerSecond, 2);
					drawSections[ 2] = new ECGDrawSection(true, fmm_Per_mV, 0.0f, 27.0f * fGridY, signals.MedianSamplesPerSecond, 2);

					drawSections[ 3] = new ECGDrawSection(true, fmm_Per_mV,  4.0f * fGridX,  5.0f * fGridY, signals[ 0].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 0].Median);
					drawSections[ 4] = new ECGDrawSection(true, fmm_Per_mV,  4.0f * fGridX, 16.0f * fGridY, signals[ 1].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 1].Median);
					drawSections[ 5] = new ECGDrawSection(true, fmm_Per_mV,  4.0f * fGridX, 27.0f * fGridY, signals[ 2].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 2].Median);

					drawSections[ 6] = new ECGDrawSection(true, fmm_Per_mV, 17.0f * fGridX,  5.0f * fGridY, signals[ 3].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 3].Median);
					drawSections[ 7] = new ECGDrawSection(true, fmm_Per_mV, 17.0f * fGridX, 16.0f * fGridY, signals[ 4].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 4].Median);
					drawSections[ 8] = new ECGDrawSection(true, fmm_Per_mV, 17.0f * fGridX, 27.0f * fGridY, signals[ 5].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 5].Median);

					drawSections[ 9] = new ECGDrawSection(true, fmm_Per_mV, 30.0f * fGridX,  5.0f * fGridY, signals[ 6].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 6].Median);
					drawSections[10] = new ECGDrawSection(true, fmm_Per_mV, 30.0f * fGridX, 16.0f * fGridY, signals[ 7].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 7].Median);
					drawSections[11] = new ECGDrawSection(true, fmm_Per_mV, 30.0f * fGridX, 27.0f * fGridY, signals[ 8].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 8].Median);

					drawSections[12] = new ECGDrawSection(true, fmm_Per_mV, 43.0f * fGridX,  5.0f * fGridY, signals[ 9].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[ 9].Median);
					drawSections[13] = new ECGDrawSection(true, fmm_Per_mV, 43.0f * fGridX, 16.0f * fGridY, signals[10].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[10].Median);
					drawSections[14] = new ECGDrawSection(true, fmm_Per_mV, 43.0f * fGridX, 27.0f * fGridY, signals[11].Type, signals.MedianAVM, signals.MedianSamplesPerSecond, a, b, signals[11].Median);
				}
					break;
				default:
					ret = -4;
					break;
			}

			if (drawSections != null)
			{
				Font fontText = new Font("Verdana", _TextSize);
				SolidBrush solidBrush = new SolidBrush(TextColor);

				ret = DrawECG(myGraphics, drawSections, nMinX, nMinY, nMaxX, nMaxY);

				if (ret < 0)
					return ret;

				if (DisplayInfo)
				{
					string tempInfo = fmm_Per_s + "mm/s, " + fmm_Per_mV + "mm/mV";

					myGraphics.DrawString(
						tempInfo,
						fontText,
						solidBrush,
						(nMaxX * fGridX) - myGraphics.MeasureString(tempInfo, fontText).Width,
						(nMaxY * fGridY));
				}

				fontText.Dispose();
				solidBrush.Dispose();
			}

			if (!bAllowResample
			&&  (nOldSamplesPerSecond != 0))
			{
				ret = (int) (((long) ret * nOldSamplesPerSecond) / signals.RhythmSamplesPerSecond);
			}

			return ret;
		}
		/// <summary>
		/// Function to draw an ECG using a ECG draw section array.
		/// </summary>
		/// <param name="myGraphics">graphics object to draw with.</param>
		/// <param name="drawSections"></param>
		/// <param name="nMinX">Minimal X value for grid.</param>
		/// <param name="nMinY">Minimal Y value for grid.</param>
		/// <param name="nBoxesX">Nr of boxes allong the X-axis.</param>
		/// <param name="nBoxesY">Nr of boxes allong the Y-axis.</param>
		/// <returns>Sample number to start next draw ECG on.</returns>
		public static int DrawECG(Graphics myGraphics, ECGDrawSection[] drawSections, int nMinX, int nMinY, int nBoxesX, int nBoxesY)
		{
			if (drawSections == null)
				return -4;

			float fGridY = (DpiY * Inch_Per_mm) * _mm_Per_GridLine;
			int ret = int.MinValue;

			if ((((nBoxesY * fGridY) + (_TextSize * DpiY * Inch_Per_mm * .4f)) > myGraphics.VisibleClipBounds.Height)
			||	!DrawGrid(myGraphics, nMinX, nMinY, nBoxesX, nBoxesY))
				return -5;

			foreach (ECGDrawSection ds in drawSections)
				if (ds != null)
					ret = Math.Max(ret, ds.DrawSignal(myGraphics));

			return ret;
		}
		/// <summary>
		/// Function that will draw as much grid as is possible.
		/// </summary>
		/// <param name="myGraphics">The drawing surface.</param>
		/// <param name="fLeadYSpace">Space needed for each lead.</param>
		/// <param name="nNrLeads">Number of leads in signal.</param>
		/// <param name="nMinX">Minimal X for drawing.</param>
		/// <param name="nMinY">Minimal Y for drawing.</param>
		/// <param name="nMaxX">returns the maximum X for drawing signal</param>
		/// <param name="nMaxY">returns the maximum Y for drawing signal</param>
		private static void DrawGrid(Graphics myGraphics, float fLeadYSpace, int nNrLeads, int nMinX, int nMinY, out int nMaxX, out int nMaxY)
		{
			// begin: draw grid.
			Brush backBrush = new SolidBrush(BackColor);
			myGraphics.FillRectangle(backBrush, 0, 0, myGraphics.VisibleClipBounds.Width, myGraphics.VisibleClipBounds.Height);
			backBrush.Dispose();

			float
				fGridX = (DpiX * Inch_Per_mm) * _mm_Per_GridLine,
				fGridY = (DpiY * Inch_Per_mm) * _mm_Per_GridLine;

			int nExtraSpace = nMinY,
				nAlternate = 1;

			nMaxX = (int) (Math.Floor((myGraphics.VisibleClipBounds.Width - nMinX - 1) / fGridX) * fGridX) + nMinX;
			nMaxY = nMinY;

			float
				fTempY = (float) Math.Round((fLeadYSpace * nNrLeads) / fGridY) * fGridY + fGridY,
				fMaxY = fTempY + nMinY,
				fPenWidth = DpiX * 0.015625f;

			Pen	gridPen = new Pen(GraphColor, fPenWidth >= 1.0f ? fPenWidth : 1.0f),
				gridSecondPen = new Pen(GraphSecondColor, fPenWidth >= 1.0f ? fPenWidth : 1.0f);			

			Brush gridBrush = null;

			if ((DisplayGrid == GridType.OneMillimeters)
			&&	(fGridX >= 10f)
			&&	(fGridY >= 10f))
			{
				fGridX /= 5;
				fGridY /= 5;
				
				nAlternate = 5;
			}
			else if (DisplayGrid == GridType.OneMillimeters)
			{
				gridBrush = new HatchBrush(HatchStyle.Percent30, GraphSecondColor, BackColor);
			}

			while (fMaxY < myGraphics.VisibleClipBounds.Height)
			{
				nMaxY = (int) fMaxY;

				int j=0;

				if (gridBrush != null)
					myGraphics.FillRectangle(gridBrush, nMinX, nMinY, nMaxX, nMaxY);

				// draw vertical lines.
				for (float i=nMinX;i <= (nMaxX + fPenWidth);i+=fGridX,j++)
				{
					int nTempX = (int) Math.Round(i);

					if (DisplayGrid != GridType.None)
					{
						myGraphics.DrawLine((j % nAlternate) == 0 ? gridPen : gridSecondPen, nTempX, nMinY, nTempX, nMaxY);
					}
				}

				j=0;

				// draw horizontal lines.
				for (float i=nMinY;i <= (fMaxY + fPenWidth);i+=fGridY,j++)
				{
					int nTempY = (int) Math.Round(i);

					if (DisplayGrid != GridType.None)
					{
						myGraphics.DrawLine((j % nAlternate) == 0 ? gridPen : gridSecondPen, nMinX, nTempY, nMaxX, nTempY);
					}
				}

				nMinY = (int) (fMaxY + nExtraSpace);
				fMaxY += (fTempY + nExtraSpace);
			}

			if (gridBrush != null)
				gridBrush.Dispose();

			gridPen.Dispose();
			gridSecondPen.Dispose();
			// end: draw grid.
		}
		/// <summary>
		/// Function that will draw as much grid as is possible.
		/// </summary>
		/// <param name="myGraphics">The drawing surface.</param>
		/// <param name="fLeadYSpace">Space needed for each lead.</param>
		/// <param name="nNrLeads">Number of leads in signal.</param>
		/// <param name="nMinX">Minimal X for drawing.</param>
		/// <param name="nMinY">Minimal Y for drawing.</param>
		/// <param name="nBoxesX">Nr of boxes allong the X-axis.</param>
		/// <param name="nBoxesY">Nr of boxes allong the Y-axis.</param>
		/// <returns>true if successfull</returns>
		private static bool DrawGrid(Graphics myGraphics, int nMinX, int nMinY, int nBoxesX, int nBoxesY)
		{
			Brush backBrush = new SolidBrush(BackColor);
			myGraphics.FillRectangle(backBrush, 0, 0, myGraphics.VisibleClipBounds.Width, myGraphics.VisibleClipBounds.Height);
			backBrush.Dispose();

			float
				fGridX = (DpiX * Inch_Per_mm) * _mm_Per_GridLine,
				fGridY = (DpiY * Inch_Per_mm) * _mm_Per_GridLine,
				fPenWidth = DpiX * 0.015625f;

			int nMaxX = nMinX + (int) Math.Round(fGridX * nBoxesX),

⌨️ 快捷键说明

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