Beispiel #1
0
 public override void OnEnter()
 {
     if (!Application.isEditor)
     {
         SteamFriends.ActivateGameOverlay(overlayType.ToString());
     }
     else
     {
         Debug.LogWarning("Steam Overlay does not work in editor mode");
     }
     Finish();
 }
Beispiel #2
0
 public override void OnEnter()
 {
     if (!Application.isEditor)
     {
         ulong    ID = ulong.Parse(this.steamID.Value);
         CSteamID IDsteam;
         IDsteam.m_SteamID = ID;
         SteamFriends.ActivateGameOverlayToUser(overlayType.ToString(), IDsteam);
     }
     else
     {
         Debug.LogWarning("Steam Overlay does not work in editor mode");
         Finish();
     }
     Finish();
 }
Beispiel #3
0
        public static void ProcessOverlay(string baseLayerPath, string overlayLayerPath, string resultLayerPath, OverlayType type)
        {
            try
            {
                _cancellationSource = new CancellationTokenSource();
                _progressMonitor    = WorkbenchSingleton.StatusBar.CreateProgressMonitor(_cancellationSource.Token);

                Thread thread = new Thread(() => RunThread(baseLayerPath, overlayLayerPath, resultLayerPath, type));
                thread.Name         = type.ToString();
                thread.Priority     = ThreadPriority.BelowNormal;
                thread.IsBackground = true;
                thread.Start();
            }
            catch
            {
            }
        }
		/// <summary>
		/// Sets an overlay plane module on the given dataset by embedding the overlay in an unused bit of the Pixel Data.
		/// </summary>
		/// <remarks>
		/// Call <see cref="SetImagePixels"/> before calling this method as it updates the current PixelData in the dataset.
		/// </remarks>
		/// <param name="dataset">The dataset.</param>
		/// <param name="overlayIndex">The index of the overlay plane.</param>
		/// <param name="overlayData">The overlay data.</param>
		/// <param name="type">The overlay type.</param>
		/// <param name="origin">The overlay origin per frame.</param>
		/// <param name="bitPosition">The position of the unused bit in the PixelData where the overlay should be stored.</param>
		/// <param name="bigEndian">Whether or not the dataset is big endian.</param>
		/// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
		public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int bitPosition, bool bigEndian)
		{
			Platform.CheckForNullReference(dataset, "dataset");

			var rows = dataset[DicomTags.Rows].GetInt32(0, 0);
			var columns = dataset[DicomTags.Columns].GetInt32(0, 0);
			var frames = dataset[DicomTags.NumberOfFrames].GetInt32(0, 1);
			var bitsAllocated = dataset[DicomTags.BitsAllocated].GetInt32(0, 16);
			var bitsStored = dataset[DicomTags.BitsStored].GetInt32(0, 16);
			var highBit = dataset[DicomTags.HighBit].GetInt32(0, bitsStored - 1);
			var pixelData = (byte[]) dataset[DicomTags.PixelData].Values;

			// sanity check
			Platform.CheckForNullReference(overlayData, "overlayData");
			Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
			Platform.CheckTrue(bitPosition >= 0 && bitPosition <= 15 && (bitPosition > highBit || bitPosition <= highBit - bitsStored), "bitPosition must specify an unused bit");
			Platform.CheckTrue(rows*columns*frames == overlayData.Length, "overlayData must have length equal to rows*columns*frames");
			Platform.CheckArgumentRange(bitsStored, 1, 16, "bitsStored");
			Platform.CheckTrue(highBit >= bitsStored - 1 && highBit <= 15, "highBit must be between bitsStored-1 and 15, inclusive");
			Platform.CheckTrue(bitsAllocated == 8 || bitsAllocated == 16, "bitsAllocated must be 8 or 16");
			Platform.CheckTrue(rows*columns*frames*(bitsAllocated/8) == pixelData.Length, "pixelData must have length equal to rows*columns*frames*bitsAllocated/8");

			uint tagOffset = ((uint) overlayIndex)*2*0x10000;

			// set basic attributes
			dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
			dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
			dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
			dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
			dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, bitsAllocated);
			dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, bitPosition);

			// set multiframe attributes
			if (frames > 1)
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames);
			else
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
			dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();

			// set overlay in unused bits of pixel data
			if (bitsAllocated == 16)
			{
				var highByte = bigEndian ? 0 : 1; // in a big endian word, the high byte is first
				var overlayBitMaskLow = (byte) (bitPosition <= 7 ? (1 << bitPosition) : 0);
				var overlayBitMaskHigh = (byte) (bitPosition > 7 ? (1 << (bitPosition - 8)) : 0);
				for (int i = 0; i < overlayData.Length; i++)
				{
					var cursor = i*2;
					pixelData[cursor + highByte] = (byte) ((pixelData[cursor + highByte] & ~overlayBitMaskHigh) | (overlayData[i] ? overlayBitMaskHigh : (byte) 0));
					pixelData[cursor + 1 - highByte] = (byte) ((pixelData[cursor + 1 - highByte] & ~overlayBitMaskLow) | (overlayData[i] ? overlayBitMaskLow : (byte) 0));
				}
			}
			else if (bitsAllocated == 8)
			{
				var overlayBitMask = (byte) (1 << bitPosition);
				for (int i = 0; i < overlayData.Length; i++)
				{
					pixelData[i] = (byte) ((pixelData[i] & ~overlayBitMask) | (overlayData[i] ? overlayBitMask : (byte) 0));
				}
			}
			dataset[DicomTags.PixelData].Values = pixelData;
		}
		/// <summary>
		/// Sets an overlay plane module on the given dataset using the OverlayData attribute.
		/// </summary>
		/// <param name="dataset">The dataset.</param>
		/// <param name="overlayIndex">The index of the overlay plane.</param>
		/// <param name="overlayData">The overlay data.</param>
		/// <param name="type">The overlay type.</param>
		/// <param name="origin">The overlay origin per frame.</param>
		/// <param name="rows">The number of rows per frame.</param>
		/// <param name="columns">The number of columns per frame.</param>
		/// <param name="frames">The number of frames. If NULL, will not set multiframe attributes.</param>
		/// <param name="frameOrigin">The number of the image frame that matches the first overlay frame. If NULL, the attribute is not included and the reader is supposed to assume 1.</param>
		/// <param name="bigEndian">Whether or not the dataset is big endian.</param>
		/// <param name="useOW">Whether or not OverlayData should have a VR of OW.</param>
		/// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
		public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int rows, int columns, int? frames, int? frameOrigin, bool bigEndian, bool useOW)
		{
			// sanity check
			Platform.CheckForNullReference(dataset, "dataset");
			Platform.CheckForNullReference(overlayData, "overlayData");
			Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
			Platform.CheckTrue(rows*columns*frames.GetValueOrDefault(1) == overlayData.Length, "overlayData must have length equal to rows*columns*frames");

			uint tagOffset = ((uint) overlayIndex)*2*0x10000;

			// set basic attributes
			dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
			dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
			dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
			dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
			dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, 1);
			dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, 0);

			// set multiframe attributes
			if (frames.HasValue)
			{
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames.Value);
				if (frameOrigin.HasValue)
					dataset[tagOffset + DicomTags.ImageFrameOrigin].SetInt32(0, frameOrigin.Value);
				else
					dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
			}
			else
			{
				dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
				dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
			}

			// set overlay data by bit packing
			var packedBitsLength = (int) Math.Ceiling(overlayData.Length/8f);
			var packedBits = new byte[packedBitsLength + (packedBitsLength%2)];
			if (useOW)
			{
				var highByte = bigEndian ? 0 : 1; // in a big endian word, the high byte is first
				var cursor = 0;
				ushort window = 0;
				for (int n = 0; n < overlayData.Length; n++)
				{
					window = (ushort) (((window >> 1) & 0x007FFF) | (overlayData[n] ? 0x008000 : 0x000000));
					if ((n + 1)%16 == 0)
					{
						packedBits[cursor + highByte] = (byte) ((window >> 8) & 0x00FF);
						packedBits[cursor + 1 - highByte] = (byte) (window & 0x00FF);
						cursor += 2;
						window = 0;
					}
				}

				// flush the last window
				if (cursor == packedBits.Length - 1)
				{
					packedBits[cursor + highByte] = (byte) ((window >> 8) & 0x00FF);
					packedBits[cursor + 1 - highByte] = (byte) (window & 0x00FF);
				}
			}
			else
			{
				var cursor = 0;
				byte window = 0;
				for (int n = 0; n < overlayData.Length; n++)
				{
					window = (byte) (((window >> 1) & 0x007F) | (overlayData[n] ? 0x0080 : 0x0000));
					if ((n + 1)%8 == 0)
					{
						packedBits[cursor++] = window;
						window = 0;
					}
				}

				// flush the last window
				if (cursor == packedBits.Length - 1)
					packedBits[cursor] = window;
			}
			dataset[FixVR(tagOffset + DicomTags.OverlayData, useOW ? DicomVr.OWvr : DicomVr.OBvr)].Values = packedBits;
		}
Beispiel #6
0
 public OverlayContainer(OverlayType type) : this(type.ToString())
 {
 }
Beispiel #7
0
 public void RemoveOverlay(OverlayType type) => RemoveOverlay(type.ToString());
        /// <summary>
        /// Sets an overlay plane module on the given dataset by embedding the overlay in an unused bit of the Pixel Data.
        /// </summary>
        /// <remarks>
        /// Call <see cref="SetImagePixels"/> before calling this method as it updates the current PixelData in the dataset.
        /// </remarks>
        /// <param name="dataset">The dataset.</param>
        /// <param name="overlayIndex">The index of the overlay plane.</param>
        /// <param name="overlayData">The overlay data.</param>
        /// <param name="type">The overlay type.</param>
        /// <param name="origin">The overlay origin per frame.</param>
        /// <param name="bitPosition">The position of the unused bit in the PixelData where the overlay should be stored.</param>
        /// <param name="bigEndian">Whether or not the dataset is big endian.</param>
        /// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
        public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int bitPosition, bool bigEndian)
        {
            Platform.CheckForNullReference(dataset, "dataset");

            var rows          = dataset[DicomTags.Rows].GetInt32(0, 0);
            var columns       = dataset[DicomTags.Columns].GetInt32(0, 0);
            var frames        = dataset[DicomTags.NumberOfFrames].GetInt32(0, 1);
            var bitsAllocated = dataset[DicomTags.BitsAllocated].GetInt32(0, 16);
            var bitsStored    = dataset[DicomTags.BitsStored].GetInt32(0, 16);
            var highBit       = dataset[DicomTags.HighBit].GetInt32(0, bitsStored - 1);
            var pixelData     = (byte[])dataset[DicomTags.PixelData].Values;

            // sanity check
            Platform.CheckForNullReference(overlayData, "overlayData");
            Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
            Platform.CheckTrue(bitPosition >= 0 && bitPosition <= 15 && (bitPosition > highBit || bitPosition <= highBit - bitsStored), "bitPosition must specify an unused bit");
            Platform.CheckTrue(rows * columns * frames == overlayData.Length, "overlayData must have length equal to rows*columns*frames");
            Platform.CheckArgumentRange(bitsStored, 1, 16, "bitsStored");
            Platform.CheckTrue(highBit >= bitsStored - 1 && highBit <= 15, "highBit must be between bitsStored-1 and 15, inclusive");
            Platform.CheckTrue(bitsAllocated == 8 || bitsAllocated == 16, "bitsAllocated must be 8 or 16");
            Platform.CheckTrue(rows * columns * frames * (bitsAllocated / 8) == pixelData.Length, "pixelData must have length equal to rows*columns*frames*bitsAllocated/8");

            uint tagOffset = ((uint)overlayIndex) * 2 * 0x10000;

            // set basic attributes
            dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
            dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
            dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
            dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
            dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, bitsAllocated);
            dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, bitPosition);

            // set multiframe attributes
            if (frames > 1)
            {
                dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames);
            }
            else
            {
                dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
            }
            dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();

            // set overlay in unused bits of pixel data
            if (bitsAllocated == 16)
            {
                var highByte           = bigEndian ? 0 : 1;       // in a big endian word, the high byte is first
                var overlayBitMaskLow  = (byte)(bitPosition <= 7 ? (1 << bitPosition) : 0);
                var overlayBitMaskHigh = (byte)(bitPosition > 7 ? (1 << (bitPosition - 8)) : 0);
                for (int i = 0; i < overlayData.Length; i++)
                {
                    var cursor = i * 2;
                    pixelData[cursor + highByte]     = (byte)((pixelData[cursor + highByte] & ~overlayBitMaskHigh) | (overlayData[i] ? overlayBitMaskHigh : (byte)0));
                    pixelData[cursor + 1 - highByte] = (byte)((pixelData[cursor + 1 - highByte] & ~overlayBitMaskLow) | (overlayData[i] ? overlayBitMaskLow : (byte)0));
                }
            }
            else if (bitsAllocated == 8)
            {
                var overlayBitMask = (byte)(1 << bitPosition);
                for (int i = 0; i < overlayData.Length; i++)
                {
                    pixelData[i] = (byte)((pixelData[i] & ~overlayBitMask) | (overlayData[i] ? overlayBitMask : (byte)0));
                }
            }
            dataset[DicomTags.PixelData].Values = pixelData;
        }
        /// <summary>
        /// Sets an overlay plane module on the given dataset using the OverlayData attribute.
        /// </summary>
        /// <param name="dataset">The dataset.</param>
        /// <param name="overlayIndex">The index of the overlay plane.</param>
        /// <param name="overlayData">The overlay data.</param>
        /// <param name="type">The overlay type.</param>
        /// <param name="origin">The overlay origin per frame.</param>
        /// <param name="rows">The number of rows per frame.</param>
        /// <param name="columns">The number of columns per frame.</param>
        /// <param name="frames">The number of frames. If NULL, will not set multiframe attributes.</param>
        /// <param name="frameOrigin">The number of the image frame that matches the first overlay frame. If NULL, the attribute is not included and the reader is supposed to assume 1.</param>
        /// <param name="bigEndian">Whether or not the dataset is big endian.</param>
        /// <param name="useOW">Whether or not OverlayData should have a VR of OW.</param>
        /// <exception cref="ArgumentException">Thrown if input values are inconsistent.</exception>
        public static void AddOverlayPlane(IDicomAttributeProvider dataset, int overlayIndex, bool[] overlayData, OverlayType type, Point origin, int rows, int columns, int?frames, int?frameOrigin, bool bigEndian, bool useOW)
        {
            // sanity check
            Platform.CheckForNullReference(dataset, "dataset");
            Platform.CheckForNullReference(overlayData, "overlayData");
            Platform.CheckArgumentRange(overlayIndex, 0, 15, "overlayIndex");
            Platform.CheckTrue(rows * columns * frames.GetValueOrDefault(1) == overlayData.Length, "overlayData must have length equal to rows*columns*frames");

            uint tagOffset = ((uint)overlayIndex) * 2 * 0x10000;

            // set basic attributes
            dataset[tagOffset + DicomTags.OverlayRows].SetInt32(0, rows);
            dataset[tagOffset + DicomTags.OverlayColumns].SetInt32(0, columns);
            dataset[tagOffset + DicomTags.OverlayType].SetString(0, type.ToString());
            dataset[tagOffset + DicomTags.OverlayOrigin].SetStringValue(string.Format(@"{0}\{1}", origin.X, origin.Y));
            dataset[tagOffset + DicomTags.OverlayBitsAllocated].SetInt32(0, 1);
            dataset[tagOffset + DicomTags.OverlayBitPosition].SetInt32(0, 0);

            // set multiframe attributes
            if (frames.HasValue)
            {
                dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetInt32(0, frames.Value);
                if (frameOrigin.HasValue)
                {
                    dataset[tagOffset + DicomTags.ImageFrameOrigin].SetInt32(0, frameOrigin.Value);
                }
                else
                {
                    dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
                }
            }
            else
            {
                dataset[tagOffset + DicomTags.NumberOfFramesInOverlay].SetEmptyValue();
                dataset[tagOffset + DicomTags.ImageFrameOrigin].SetEmptyValue();
            }

            // set overlay data by bit packing
            var packedBitsLength = (int)Math.Ceiling(overlayData.Length / 8f);
            var packedBits       = new byte[packedBitsLength + (packedBitsLength % 2)];

            if (useOW)
            {
                var    highByte = bigEndian ? 0 : 1;              // in a big endian word, the high byte is first
                var    cursor   = 0;
                ushort window   = 0;
                for (int n = 0; n < overlayData.Length; n++)
                {
                    window = (ushort)(((window >> 1) & 0x007FFF) | (overlayData[n] ? 0x008000 : 0x000000));
                    if ((n + 1) % 16 == 0)
                    {
                        packedBits[cursor + highByte]     = (byte)((window >> 8) & 0x00FF);
                        packedBits[cursor + 1 - highByte] = (byte)(window & 0x00FF);
                        cursor += 2;
                        window  = 0;
                    }
                }

                // flush the last window
                if (cursor == packedBits.Length - 1)
                {
                    packedBits[cursor + highByte]     = (byte)((window >> 8) & 0x00FF);
                    packedBits[cursor + 1 - highByte] = (byte)(window & 0x00FF);
                }
            }
            else
            {
                var  cursor = 0;
                byte window = 0;
                for (int n = 0; n < overlayData.Length; n++)
                {
                    window = (byte)(((window >> 1) & 0x007F) | (overlayData[n] ? 0x0080 : 0x0000));
                    if ((n + 1) % 8 == 0)
                    {
                        packedBits[cursor++] = window;
                        window = 0;
                    }
                }

                // flush the last window
                if (cursor == packedBits.Length - 1)
                {
                    packedBits[cursor] = window;
                }
            }
            dataset[FixVR(tagOffset + DicomTags.OverlayData, useOW ? DicomVr.OWvr : DicomVr.OBvr)].Values = packedBits;
        }
Beispiel #10
0
 GMapOverlay getOverlay(OverlayType overlayType)
 {
     return((from ov in MapControl.Overlays
             where ov.Id == overlayType.ToString()
             select ov).FirstOrDefault());
 }