scpsection7.cs

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

CS
765
字号
		{
			if ((mes != null)
			&&  (mes.measurment != null))
			{
				Empty();

				_AvgRRInterval = mes.AvgRR;
				_AvgPPInterval = mes.AvgPP;

				_NrRefTypeQRS = (byte) mes.measurment.Length;
				_Measurements = new SCPMeasurement[_NrRefTypeQRS];
				for (int loper=0;loper < _NrRefTypeQRS;loper++)
				{
					_Measurements[loper] = new SCPMeasurement();
					if (mes.measurment[loper] != null)
					{
						_Measurements[loper].Ponset = mes.measurment[loper].Ponset;
						_Measurements[loper].Poffset = mes.measurment[loper].Poffset;
						_Measurements[loper].QRSonset = mes.measurment[loper].QRSonset;
						_Measurements[loper].QRSoffset = mes.measurment[loper].QRSoffset;
						_Measurements[loper].Toffset = mes.measurment[loper].Toffset;
						_Measurements[loper].Paxis = mes.measurment[loper].Paxis;
						_Measurements[loper].QRSaxis = mes.measurment[loper].QRSaxis;
						_Measurements[loper].Taxis = mes.measurment[loper].Taxis;
					}
				}

				_NrSpikes = 0;

				if (mes.spike != null)
				{
					_NrSpikes = (byte) mes.spike.Length;
					_Spikes = new SCPSpike[_NrSpikes];
					_SpikesInfo = new SCPSpikeInfo[_NrSpikes];
					for (int loper=0;loper < _NrSpikes;loper++)
					{
						_Spikes[loper] = new SCPSpike();
						_SpikesInfo[loper] = new SCPSpikeInfo();
						if (mes.spike[loper] != null)
						{
							_Spikes[loper].Time = mes.spike[loper].Time;
							_Spikes[loper].Amplitude = mes.spike[loper].Amplitude;
						}
					}
				}
				
				_AfterSpikes = true;

				_AfterSpikesInfo = true;

				_NrQRS = 0;
				_QRSType = null;

				_AfterQRSType = true;

				_ExtraMeasurements = new SCPExtraMeasurements();
				_ExtraMeasurements.VentRate = mes.VentRate;
				_ExtraMeasurements.QTc = mes.QTc;

				byte temp = (byte) (mes.QTcType + 1);

				if (temp > 2)
					temp = 0;

				_ExtraMeasurements.FormulaType = temp;

				return 0;
			}
			return 1;
		}
		/// <summary>
		/// Class containing measurements for SCP.
		/// </summary>
		[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
		public class SCPMeasurement
		{
			public ushort Ponset = GlobalMeasurement.NoValue;
			public ushort Poffset = GlobalMeasurement.NoValue;
			public ushort QRSonset = GlobalMeasurement.NoValue;
			public ushort QRSoffset = GlobalMeasurement.NoValue;
			public ushort Toffset = GlobalMeasurement.NoValue;
			public short Paxis = GlobalMeasurement.NoAxisValue;
			public short QRSaxis = GlobalMeasurement.NoAxisValue;
			public short Taxis = GlobalMeasurement.NoAxisValue;
			/// <summary>
			/// Function to read measurements.
			/// </summary>
			/// <param name="buffer">byte array to read from</param>
			/// <param name="offset">position to start reading</param>
			/// <returns>0 on success</returns>
			public int Read(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				Ponset = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Ponset), true);
				offset += Marshal.SizeOf(Ponset);
				Poffset = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Poffset), true);
				offset += Marshal.SizeOf(Poffset);
				QRSonset = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSonset), true);
				offset += Marshal.SizeOf(QRSonset);
				QRSoffset = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSoffset), true);
				offset += Marshal.SizeOf(QRSoffset);
				Toffset = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Toffset), true);
				offset += Marshal.SizeOf(Toffset);
				Paxis= (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Paxis), true);
				offset += Marshal.SizeOf(Paxis);
				QRSaxis = (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QRSaxis), true);
				offset += Marshal.SizeOf(QRSaxis);
				Taxis = (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Taxis), true);
				offset += Marshal.SizeOf(Taxis);

				return 0x0;
			}
			/// <summary>
			/// Function to write measurements.
			/// </summary>
			/// <param name="buffer">byte array to write into</param>
			/// <param name="offset">position to start writing</param>
			/// <returns>0 on success</returns>
			public int Write(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				BytesTool.writeBytes(Ponset, buffer, offset, Marshal.SizeOf(Ponset), true);
				offset += Marshal.SizeOf(Ponset);
				BytesTool.writeBytes(Poffset, buffer, offset, Marshal.SizeOf(Poffset), true);
				offset += Marshal.SizeOf(Poffset);
				BytesTool.writeBytes(QRSonset, buffer, offset, Marshal.SizeOf(QRSonset), true);
				offset += Marshal.SizeOf(QRSonset);
				BytesTool.writeBytes(QRSoffset, buffer, offset, Marshal.SizeOf(QRSoffset), true);
				offset += Marshal.SizeOf(QRSoffset);
				BytesTool.writeBytes(Toffset, buffer, offset, Marshal.SizeOf(Toffset), true);
				offset += Marshal.SizeOf(Toffset);
				BytesTool.writeBytes(Paxis, buffer, offset, Marshal.SizeOf(Paxis), true);
				offset += Marshal.SizeOf(Paxis);
				BytesTool.writeBytes(QRSaxis, buffer, offset, Marshal.SizeOf(QRSaxis), true);
				offset += Marshal.SizeOf(QRSaxis);
				BytesTool.writeBytes(Taxis, buffer, offset, Marshal.SizeOf(Taxis), true);
				offset += Marshal.SizeOf(Taxis);

				return 0x0;
			}
		}
		/// <summary>
		/// Class containing SCP spikes.
		/// </summary>
		[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
		public class SCPSpike
		{
			public ushort Time = GlobalMeasurement.NoValue;
			public short Amplitude = GlobalMeasurement.NoAxisValue;
			/// <summary>
			/// Function to read a SCP spike.
			/// </summary>
			/// <param name="buffer">byte array to read from</param>
			/// <param name="offset">position to start reading</param>
			/// <returns>0 on success</returns>
			public int Read(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				Time = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Time), true);
				offset += Marshal.SizeOf(Time);
				Amplitude = (short) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Amplitude), true);
				offset += Marshal.SizeOf(Amplitude);

				return 0x0;
			}
			/// <summary>
			/// Function to write SCP spike.
			/// </summary>
			/// <param name="buffer">byte array to write into</param>
			/// <param name="offset">position to start writing</param>
			/// <returns>0 on success</returns>
			public int Write(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				BytesTool.writeBytes(Time, buffer, offset, Marshal.SizeOf(Time), true);
				offset += Marshal.SizeOf(Time);
				BytesTool.writeBytes(Amplitude, buffer, offset, Marshal.SizeOf(Amplitude), true);
				offset += Marshal.SizeOf(Amplitude);

				return 0x0;
			}
		}
		/// <summary>
		/// Class containing SCP Spike info.
		/// </summary>
		[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
		public class SCPSpikeInfo
		{
			public byte Type = 255;
			public byte Source = 0;
			public ushort TriggerIndex = GlobalMeasurement.NoValue;
			public ushort PulseWidth = GlobalMeasurement.NoValue;
			/// <summary>
			/// Function to read SCP spike info.
			/// </summary>
			/// <param name="buffer">byte array to read from</param>
			/// <param name="offset">position to start reading</param>
			/// <returns>0 on success</returns>
			public int Read(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				Type = (byte) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Type), true);
				offset += Marshal.SizeOf(Type);
				Source = (byte) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(Source), true);
				offset += Marshal.SizeOf(Source);
				TriggerIndex = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TriggerIndex), true);
				offset += Marshal.SizeOf(TriggerIndex);
				PulseWidth = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(PulseWidth), true);
				offset += Marshal.SizeOf(PulseWidth);

				return 0x0;
			}
			/// <summary>
			/// Function to write SCP Spike info.
			/// </summary>
			/// <param name="buffer">byte array to write into</param>
			/// <param name="offset">position to start writing</param>
			/// <returns>0 on success</returns>
			public int Write(byte[] buffer, int offset)
			{
				if ((offset + Marshal.SizeOf(this)) > buffer.Length)
				{
					return 0x1;
				}

				BytesTool.writeBytes(Type, buffer, offset, Marshal.SizeOf(Type), true);
				offset += Marshal.SizeOf(Type);
				BytesTool.writeBytes(Source, buffer, offset, Marshal.SizeOf(Source), true);
				offset += Marshal.SizeOf(Source);
				BytesTool.writeBytes(TriggerIndex, buffer, offset, Marshal.SizeOf(TriggerIndex), true);
				offset += Marshal.SizeOf(TriggerIndex);
				BytesTool.writeBytes(PulseWidth, buffer, offset, Marshal.SizeOf(PulseWidth), true);
				offset += Marshal.SizeOf(PulseWidth);

				return 0x0;
			}
		}
		/// <summary>
		/// Class containing SCP extra measurements. (no compatability with UNIPRO at all)
		/// </summary>
		public class SCPExtraMeasurements
		{
			public ushort VentRate = GlobalMeasurement.NoValue;
			public ushort AtrialRate = GlobalMeasurement.NoValue;
			public ushort QTc = GlobalMeasurement.NoValue;
			public byte FormulaType = 0;
			public ushort TaggedFieldSize = 0;
			// Tagged Field are not implemented.
			public byte[] TaggedFields = null;
			/// <summary>
			/// Function to read SCP extra measurements.
			/// </summary>
			/// <param name="buffer">byte array to read from</param>
			/// <param name="offset">position to start reading</param>
			/// <returns>0 on success</returns>
			public int Read(byte[] buffer, int offset)
			{
				Empty();
				int frontsize = Marshal.SizeOf(VentRate) + Marshal.SizeOf(AtrialRate) + Marshal.SizeOf(QTc) + Marshal.SizeOf(FormulaType) + Marshal.SizeOf(TaggedFieldSize);
				if ((offset + frontsize) > buffer.Length)
				{
					return 0x1;
				}

				VentRate = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(VentRate), true);
				offset += Marshal.SizeOf(VentRate);
				AtrialRate = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(AtrialRate), true);
				offset += Marshal.SizeOf(AtrialRate);
				QTc = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(QTc), true);
				offset += Marshal.SizeOf(QTc);
				FormulaType = (byte) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(FormulaType), true);
				offset += Marshal.SizeOf(FormulaType);
				TaggedFieldSize = (ushort) BytesTool.readBytes(buffer, offset, Marshal.SizeOf(TaggedFieldSize), true);
				offset += Marshal.SizeOf(TaggedFieldSize);

				if (TaggedFieldSize > 0)
				{
					if ((offset + TaggedFieldSize) > buffer.Length)
					{
						return 0x2;
					}

					TaggedFields = new byte[TaggedFieldSize];
					offset += BytesTool.copy(TaggedFields, 0, buffer, offset, TaggedFieldSize);
				}

				return 0x0;
			}
			/// <summary>
			/// Function to write SCP extra measurements.
			/// </summary>
			/// <param name="buffer">byte array to write into</param>
			/// <param name="offset">position to start writing</param>
			/// <returns>0 on success</returns>
			public int Write(byte[] buffer, int offset)
			{
				BytesTool.writeBytes(VentRate, buffer, offset, Marshal.SizeOf(VentRate), true);
				offset += Marshal.SizeOf(VentRate);
				BytesTool.writeBytes(AtrialRate, buffer, offset, Marshal.SizeOf(AtrialRate), true);
				offset += Marshal.SizeOf(AtrialRate);
				BytesTool.writeBytes(QTc, buffer, offset, Marshal.SizeOf(QTc), true);
				offset += Marshal.SizeOf(QTc);
				BytesTool.writeBytes(FormulaType, buffer, offset, Marshal.SizeOf(FormulaType), true);
				offset += Marshal.SizeOf(FormulaType);
				BytesTool.writeBytes(TaggedFieldSize, buffer, offset, Marshal.SizeOf(TaggedFieldSize), true);
				offset += Marshal.SizeOf(TaggedFieldSize);

				if (TaggedFields != null)
				{
					offset += BytesTool.copy(buffer, offset, TaggedFields, 0, TaggedFieldSize);
				}

				return 0x0;
			}
			/// <summary>
			/// Function to empty this extra measurements.
			/// </summary>
			public void Empty()
			{
				VentRate = 0;
				AtrialRate = 0;
				QTc = 0;
				FormulaType = 0;
				TaggedFieldSize = 0;
				TaggedFields = null;
			}
			/// <summary>
			/// Function to get length of extra measurements.
			/// </summary>
			/// <returns>length of extra measurements</returns>
			public int getLength()
			{
				if (Works())
				{
					int sum = Marshal.SizeOf(VentRate) + Marshal.SizeOf(AtrialRate);
					sum += Marshal.SizeOf(QTc) + Marshal.SizeOf(FormulaType) + Marshal.SizeOf(TaggedFieldSize);
					sum += TaggedFieldSize;
					return ((sum % 2) == 0 ? sum : sum + 1);
				}
				return 0;
			}
			/// <summary>
			/// Function to check if extra measurements works
			/// </summary>
			/// <returns>if writeable is true</returns>
			public bool Works()
			{
				if (TaggedFieldSize == 0)
				{
					return true;
				}
				else if ((TaggedFields != null)
					&&   (TaggedFields.Length >= TaggedFieldSize))
				{
					return true;
				}
				return false;
			}
		}
	}
}

⌨️ 快捷键说明

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