示例#1
0
        public ISopDataSource[] CreateSops(int width, int height, int sliceCount, bool signed)
        {
            string studyInstanceUid    = DicomUid.GenerateUid().UID;
            string seriesInstanceUid   = DicomUid.GenerateUid().UID;
            string frameOfReferenceUid = DicomUid.GenerateUid().UID;

            List <SimpleSopDataSource> sops = new List <SimpleSopDataSource>();

            for (int z = 0; z < sliceCount; z++)
            {
                byte[] data = new byte[width * height * 2];
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        ushort value = (ushort)Math.Max(Math.Min(this.Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue);
                        byte[] bytes;
                        if (signed)
                        {
                            bytes = BitConverter.GetBytes((short)(value - 32768));
                        }
                        else
                        {
                            bytes = BitConverter.GetBytes(value);
                        }
                        Array.Copy(bytes, 0, data, (y * width + x) * 2, 2);
                    }
                }

                SimpleSopDataSource sop = new SimpleSopDataSource(CreateMockDataset(_name, width, height, signed));
                sop[DicomTags.PixelData].Values = data;
                sop[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);
                sop[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid);
                sop[DicomTags.FrameOfReferenceUid].SetStringValue(frameOfReferenceUid);
                sop[DicomTags.ImageOrientationPatient].SetStringValue(@"1\0\0\0\1\0");
                sop[DicomTags.ImagePositionPatient].SetStringValue(string.Format(@"0\0\{0}", z));
                sops.Add(sop);
            }
            return(sops.ToArray());
        }
示例#2
0
		public unsafe ISopDataSource[] CreateSops(int width, int height, int sliceCount, bool signed = false, bool bpp8 = false)
		{
			string studyInstanceUid = DicomUid.GenerateUid().UID;
			string seriesInstanceUid = DicomUid.GenerateUid().UID;
			string frameOfReferenceUid = DicomUid.GenerateUid().UID;

			var sops = new List<ISopDataSource>();
			for (int z = 0; z < sliceCount; z++)
			{
				var data = new byte[width*height*(bpp8 ? 1 : 2)];
				fixed (byte* pData = data)
				{
					if (bpp8)
					{
						var pDataS8 = (sbyte*) pData;
						for (int y = 0; y < height; y++)
						{
							for (int x = 0; x < width; x++)
							{
								byte value = (byte) (((ushort) Math.Max(Math.Min(Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue)) >> 8);
								if (signed)
									pDataS8[y*width + x] = (sbyte) (value - 128);
								else
									pData[y*width + x] = value;
							}
						}
					}
					else
					{
						var pDataU16 = (ushort*) pData;
						var pDataS16 = (short*) pData;
						for (int y = 0; y < height; y++)
						{
							for (int x = 0; x < width; x++)
							{
								ushort value = (ushort) Math.Max(Math.Min(Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue);
								if (signed)
									pDataS16[y*width + x] = (short) (value - 32768);
								else
									pDataU16[y*width + x] = value;
							}
						}
					}
				}

				var sop = new SimpleSopDataSource(CreateMockDataset(_name, width, height, signed, bpp8));
				sop[DicomTags.PixelData].Values = data;
				sop[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);
				sop[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid);
				sop[DicomTags.FrameOfReferenceUid].SetStringValue(frameOfReferenceUid);
				sop[DicomTags.ImageOrientationPatient].SetStringValue(@"1\0\0\0\1\0");
				sop[DicomTags.ImagePositionPatient].SetStringValue(string.Format(@"0\0\{0}", z));
				sops.Add(sop);
			}
			return sops.ToArray();
		}
示例#3
0
        public unsafe ISopDataSource[] CreateSops(int width, int height, int sliceCount, bool signed = false, bool bpp8 = false)
        {
            string studyInstanceUid    = DicomUid.GenerateUid().UID;
            string seriesInstanceUid   = DicomUid.GenerateUid().UID;
            string frameOfReferenceUid = DicomUid.GenerateUid().UID;

            var sops = new List <ISopDataSource>();

            for (int z = 0; z < sliceCount; z++)
            {
                var data = new byte[width * height * (bpp8 ? 1 : 2)];
                fixed(byte *pData = data)
                {
                    if (bpp8)
                    {
                        var pDataS8 = (sbyte *)pData;
                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                byte value = (byte)(((ushort)Math.Max(Math.Min(Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue)) >> 8);
                                if (signed)
                                {
                                    pDataS8[y * width + x] = (sbyte)(value - 128);
                                }
                                else
                                {
                                    pData[y * width + x] = value;
                                }
                            }
                        }
                    }
                    else
                    {
                        var pDataU16 = (ushort *)pData;
                        var pDataS16 = (short *)pData;
                        for (int y = 0; y < height; y++)
                        {
                            for (int x = 0; x < width; x++)
                            {
                                ushort value = (ushort)Math.Max(Math.Min(Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue);
                                if (signed)
                                {
                                    pDataS16[y * width + x] = (short)(value - 32768);
                                }
                                else
                                {
                                    pDataU16[y * width + x] = value;
                                }
                            }
                        }
                    }
                }

                var sop = new SimpleSopDataSource(CreateMockDataset(_name, width, height, signed, bpp8));
                sop[DicomTags.PixelData].Values = data;
                sop[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);
                sop[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid);
                sop[DicomTags.FrameOfReferenceUid].SetStringValue(frameOfReferenceUid);
                sop[DicomTags.ImageOrientationPatient].SetStringValue(@"1\0\0\0\1\0");
                sop[DicomTags.ImagePositionPatient].SetStringValue(string.Format(@"0\0\{0}", z));
                sops.Add(sop);
            }
            return(sops.ToArray());
        }
示例#4
0
		public ISopDataSource[] CreateSops(int width, int height, int sliceCount, bool signed)
		{
			string studyInstanceUid = DicomUid.GenerateUid().UID;
			string seriesInstanceUid = DicomUid.GenerateUid().UID;
			string frameOfReferenceUid = DicomUid.GenerateUid().UID;

			List<SimpleSopDataSource> sops = new List<SimpleSopDataSource>();
			for (int z = 0; z < sliceCount; z++)
			{
				byte[] data = new byte[width*height*2];
				for (int y = 0; y < height; y++)
				{
					for (int x = 0; x < width; x++)
					{
						ushort value = (ushort) Math.Max(Math.Min(this.Evaluate(x, y, z), ushort.MaxValue), ushort.MinValue);
						byte[] bytes;
						if (signed)
							bytes = BitConverter.GetBytes((short) (value - 32768));
						else
							bytes = BitConverter.GetBytes(value);
						Array.Copy(bytes, 0, data, (y*width + x)*2, 2);
					}
				}

				SimpleSopDataSource sop = new SimpleSopDataSource(CreateMockDataset(_name, width, height, signed));
				sop[DicomTags.PixelData].Values = data;
				sop[DicomTags.StudyInstanceUid].SetStringValue(studyInstanceUid);
				sop[DicomTags.SeriesInstanceUid].SetStringValue(seriesInstanceUid);
				sop[DicomTags.FrameOfReferenceUid].SetStringValue(frameOfReferenceUid);
				sop[DicomTags.ImageOrientationPatient].SetStringValue(@"1\0\0\0\1\0");
				sop[DicomTags.ImagePositionPatient].SetStringValue(string.Format(@"0\0\{0}", z));
				sops.Add(sop);
			}
			return sops.ToArray();
		}