private void Initialize()
            {
                if (_background == null)
                {
                    byte[] pixelData = new byte[4 * _size.Width * _size.Height];
                    for (int n = 0; n < pixelData.Length; n += 4)
                    {
                        byte[] pixel = BitConverter.GetBytes(Color.FromArgb(196, 85, 85, 85).ToArgb());
                        pixelData[n + 0] = pixel[0];
                        pixelData[n + 1] = pixel[1];
                        pixelData[n + 2] = pixel[2];
                        pixelData[n + 3] = pixel[3];
                    }
                    base.Graphics.Add(_background = new ColorImageGraphic(_size.Height, _size.Width, pixelData));
                }

                if (_progressBarGraphic == null)
                {
                    base.Graphics.Add(_progressBarGraphic = ProgressBarGraphic.Create(_style));
                    var offset = Center(_size, _progressBarGraphic.Size) + new Size(0, 10);
                    _progressBarGraphic.SpatialTransform.TranslationX = offset.X;
                    _progressBarGraphic.SpatialTransform.TranslationY = offset.Y;
                }

                if (_progressTextGraphic == null)
                {
                    base.Graphics.Add(_progressTextGraphic = new InvariantTextPrimitive());
                    var offset = Center(_size, new Size(1, 1)) - new Size(0, 15);
                    _progressTextGraphic.SpatialTransform.TranslationX = offset.X;
                    _progressTextGraphic.SpatialTransform.TranslationY = offset.Y;
                }
            }
示例#2
0
        /// <summary>
        /// Creates a test pattern of <paramref name="size"/> consisting of red, blue, green and black in the NW, NE, SW, SE corners respectively.
        /// </summary>
        public static ColorImageGraphic CreateRGBKCorners(Size size)
        {
            int width      = size.Width;
            int height     = size.Height;
            int halfWidth  = width / 2;
            int halfHeight = height / 2;

            ColorImageGraphic imageGraphic = new ColorImageGraphic(height, width);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    Color c;
                    if (x < halfWidth)
                    {
                        c = y < halfHeight ? Color.Red : Color.LimeGreen;
                    }
                    else
                    {
                        c = y < halfHeight ? Color.Blue : Color.Black;
                    }

                    imageGraphic.PixelData.SetPixel(x, y, c);
                }
            }
            return(imageGraphic);
        }
            private void OnCloneComplete()
            {
                _progressTextGraphic = (ITextGraphic)CollectionUtils.SelectFirst(base.Graphics, g => g is ITextGraphic);
                _progressBarGraphic  = (ProgressBarGraphic)CollectionUtils.SelectFirst(base.Graphics, g => g is ProgressBarGraphic);
                _background          = (ColorImageGraphic)CollectionUtils.SelectFirst(base.Graphics, g => g is ColorImageGraphic);

                Initialize();
            }
示例#4
0
        public void TestBasicColorImage()
        {
            const int rows = 8;
            const int cols = 8;

            var pixelData = new byte[rows * cols * 4];

            using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
                using (var presentationImage = new TestPresentationImage(imageGraphic))
                {
                    presentationImage.DrawToBitmap(100, 100);
                }
        }
示例#5
0
        public DynamicTe(
            GrayscaleImageGraphic imageGraphic,
            byte[] protonDensityMap,
            byte[] t2Map,
            ColorImageGraphic probabilityOverlay,
            byte[] probabilityMap)
        {
            _imageGraphic     = imageGraphic;
            _protonDensityMap = protonDensityMap;
            _t2Map            = t2Map;

            _probabilityOverlay = probabilityOverlay;
            _probabilityMap     = probabilityMap;
        }
示例#6
0
        /// <summary>
        /// Fires the <see cref="Graphic.Drawing"/> event.  Should be called by an <see cref="IRenderer"/>
        /// for each object just before it is drawn/rendered, hence the reason it is public.
        /// </summary>
        public override void OnDrawing()
        {
            base.OnDrawing();

            if (_imageGraphic != null || !HasShutters)
            {
                return;
            }

            _cacheItem = GeometricShutterCache.GetCacheItem(GetAllShutters(), _imageRectangle, _fillColor);
            //IMPORTANT: don't just pass the value of Raw, otherwise, memory management won't work (hard reference).
            _imageGraphic = new ColorImageGraphic(_cacheItem.PixelData.Rows, _cacheItem.PixelData.Columns, () => _cacheItem.PixelData.Raw);
            base.Graphics.Add(_imageGraphic);
        }
示例#7
0
        private ColorImageGraphic CreateImageGraphic()
        {
            byte[] pixelData;
            using (Bitmap buffer = new Bitmap(this.Size.Width, this.Size.Height))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(buffer))
                {
                    RenderProgressBar(_progress, g);
                }
                pixelData = GetPixelData(buffer);
            }
            ColorImageGraphic imageGraphic = new ColorImageGraphic(this.Size.Height, this.Size.Width, pixelData);

            return(imageGraphic);
        }
示例#8
0
        private void Invalidate()
        {
            if (_imageGraphic != null)
            {
                base.Graphics.Remove(_imageGraphic);
                _imageGraphic.Dispose();
                _imageGraphic = null;

                //don't de-allocate and reallocate unnecessarily.
                if (!HasShutters)
                {
                    _cacheItem = null;
                }
            }
        }
示例#9
0
        public void TestInvalidPixelDataColorImage()
        {
            const int rows = 8;
            const int cols = 8;

            try
            {
                var badPixelData = new byte[rows * cols * 4 - 10];
                using (var imageGraphic = new ColorImageGraphic(rows, cols, () => badPixelData))
                    using (var presentationImage = new TestPresentationImage(imageGraphic))
                    {
                        presentationImage.DrawToBitmap(100, 100);
                    }
                Assert.Fail("Expected RenderingException was not thrown");
            }
            catch (RenderingException ex)
            {
                Trace.WriteLine(string.Format("Rendering exception thrown: {0}", ex.UserMessage));
            }
        }
示例#10
0
        public void TestMaximumPracticalColorImage()
        {
            if (Assert64Bit())
            {
                return;
            }

            // due to the 2GB limit for a single buffer and the current ImageViewer rendering infrastructure,
            // it is not possible to render the largest possible valid-DICOM color image.
            // these values test the maximum renderable image under the current infrastructure assuming a 64-bit machine
            const int rows = (1 << 15) - 1;
            const int cols = (1 << 14);

            var pixelData = new byte[rows * cols * 4];

            using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
                using (var presentationImage = new TestPresentationImage(imageGraphic))
                {
                    presentationImage.DrawToBitmap(100, 100);
                }
        }
            private void Initialize()
            {
                if (_background == null)
                {
                    var pixelCount = _size.Width * _size.Height;
                    var pixelData  = new byte[4 * pixelCount];
                    var fillColor  = Color.FromArgb(196, 85, 85, 85).ToArgb();
                    unsafe
                    {
                        fixed(byte *pPixelBytes = pixelData)
                        {
                            var pPixels = (int *)pPixelBytes;

                            for (var n = 0; n < pixelCount; ++n)
                            {
                                pPixels[n] = fillColor;
                            }
                        }
                    }
                    base.Graphics.Add(_background = new ColorImageGraphic(_size.Height, _size.Width, pixelData));
                }

                if (_progressBarGraphic == null)
                {
                    base.Graphics.Add(_progressBarGraphic = ProgressBarGraphic.Create(_style));
                    var offset = Center(_size, _progressBarGraphic.Size) + new Size(0, 10);
                    _progressBarGraphic.SpatialTransform.TranslationX = offset.X;
                    _progressBarGraphic.SpatialTransform.TranslationY = offset.Y;
                }

                if (_progressTextGraphic == null)
                {
                    base.Graphics.Add(_progressTextGraphic = new InvariantTextPrimitive());
                    var offset = Center(_size, new Size(1, 1)) - new Size(0, 15);
                    _progressTextGraphic.SpatialTransform.TranslationX = offset.X;
                    _progressTextGraphic.SpatialTransform.TranslationY = offset.Y;
                }
            }
示例#12
0
        private static void RenderColor(
            ColorImageGraphic image,
            RectangleF srcViewableRectangle,
            Rectangle dstViewableRectangle,
            IntPtr pDstPixelData,
            int dstWidth,
            int dstBytesPerPixel)
        {
            fixed(byte *pSrcPixelData = image.PixelData.Raw)
            {
                if (image.InterpolationMode == InterpolationMode.Bilinear)
                {
                    int srcBytesPerPixel = 4;

                    if (image.VoiLutsEnabled)
                    {
                        int[] finalLutBuffer = ConstructFinalLut(image.OutputLut, image.Invert);
                        fixed(int *pFinalLutData = finalLutBuffer)
                        {
                            ImageInterpolatorBilinear.LutData lutData;
                            lutData.Data = pFinalLutData;
                            lutData.FirstMappedPixelData = image.OutputLut.MinInputValue;
                            lutData.Length = finalLutBuffer.Length;

                            ImageInterpolatorBilinear.Interpolate(
                                srcViewableRectangle,
                                pSrcPixelData,
                                image.Columns,
                                image.Rows,
                                srcBytesPerPixel,
                                32,
                                dstViewableRectangle,
                                (byte *)pDstPixelData,
                                dstWidth,
                                dstBytesPerPixel,
                                IsRotated(image),
                                &lutData,                                 //ok because it's a local variable in an unsafe method, therefore it's already fixed.
                                true,
                                false,
                                false);
                        }
                    }
                    else
                    {
                        ImageInterpolatorBilinear.Interpolate(
                            srcViewableRectangle,
                            pSrcPixelData,
                            image.Columns,
                            image.Rows,
                            srcBytesPerPixel,
                            32,
                            dstViewableRectangle,
                            (byte *)pDstPixelData,
                            dstWidth,
                            dstBytesPerPixel,
                            IsRotated(image),
                            null,
                            true,
                            false,
                            false);
                    }
                }
            }
        }
示例#13
0
		public void TestMaximumPracticalColorImage()
		{
			if (Assert64Bit()) return;

			// due to the 2GB limit for a single buffer and the current ImageViewer rendering infrastructure,
			// it is not possible to render the largest possible valid-DICOM color image.
			// these values test the maximum renderable image under the current infrastructure assuming a 64-bit machine
			const int rows = (1 << 15) - 1;
			const int cols = (1 << 14);

			var pixelData = new byte[rows*cols*4];
			using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
			using (var presentationImage = new TestPresentationImage(imageGraphic))
			{
				presentationImage.DrawToBitmap(100, 100);
			}
		}
示例#14
0
		public void TestInvalidPixelDataColorImage()
		{
			const int rows = 8;
			const int cols = 8;

			try
			{
				var badPixelData = new byte[rows*cols*4 - 10];
				using (var imageGraphic = new ColorImageGraphic(rows, cols, () => badPixelData))
				using (var presentationImage = new TestPresentationImage(imageGraphic))
				{
					presentationImage.DrawToBitmap(100, 100);
				}
				Assert.Fail("Expected RenderingException was not thrown");
			}
			catch (RenderingException ex)
			{
				Trace.WriteLine(string.Format("Rendering exception thrown: {0}", ex.UserMessage));
			}
		}
 private void AddProbabilityOverlay()
 {
     _probabilityOverlay = new ColorImageGraphic(_frame.Rows, _frame.Columns);
     this.OverlayGraphics.Add(_probabilityOverlay);
 }
示例#16
0
        private void Probe(Point sourcePointRounded, bool showPixelValue, bool showVoiValue)
        {
            string probeString;
            string coordinateString  = String.Format(SR.FormatProbeInfo, SR.LabelLocation, string.Format(SR.FormatCoordinates, SR.LabelNotApplicable, SR.LabelNotApplicable));
            string pixelValueString  = String.Format(SR.FormatProbeInfo, SR.LabelRawPixel, SR.LabelNotApplicable);
            string modalityLutString = String.Format(SR.FormatProbeInfo, SR.LabelModalityLut, SR.LabelNotApplicable);
            string voiLutString      = String.Format(SR.FormatProbeInfo, SR.LabelVOILut, SR.LabelNotApplicable);

            try
            {
                var displayString = new StringBuilder();
                if (_selectedImageGraphic.BoundingBox.Contains(sourcePointRounded))
                {
                    coordinateString = String.Format(SR.FormatProbeInfo, SR.LabelLocation, string.Format(SR.FormatCoordinates, sourcePointRounded.X, sourcePointRounded.Y));

                    if (_selectedImageGraphic is GrayscaleImageGraphic)
                    {
                        GrayscaleImageGraphic image = _selectedImageGraphic as GrayscaleImageGraphic;

                        int pixelValue = 0;

                        GetPixelValue(image, sourcePointRounded, ref pixelValue, ref pixelValueString);
                        GetModalityLutValue(image, pixelValue, ref modalityLutString);
                        GetVoiLutValue(image, pixelValue, ref voiLutString);

                        // the modality LUT value is always shown
                        displayString.AppendLine(modalityLutString);

                        if (showPixelValue)
                        {
                            displayString.AppendLine(pixelValueString);
                        }
                        if (showVoiValue)
                        {
                            displayString.AppendLine(voiLutString);
                        }
                    }
                    else if (_selectedImageGraphic is ColorImageGraphic)
                    {
                        ColorImageGraphic image        = _selectedImageGraphic as ColorImageGraphic;
                        Color             color        = image.PixelData.GetPixelAsColor(sourcePointRounded.X, sourcePointRounded.Y);
                        string            rgbFormatted = String.Format(SR.FormatRGB, color.R, color.G, color.B);
                        pixelValueString = String.Format(SR.FormatProbeInfo, SR.LabelRGBPixel, rgbFormatted);
                        displayString.AppendLine(pixelValueString);
                    }
                }

                // show the coordinate last, cause it's probably the least interesting information
                displayString.AppendLine(coordinateString);

                probeString = displayString.ToString().Trim();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
                probeString = SR.MessageProbeToolError;
            }

            var destinationPoint = Point.Round(_selectedImageGraphic.SpatialTransform.ConvertToDestination(sourcePointRounded));

            _selectedTile.InformationBox.Update(probeString, destinationPoint);
        }
示例#17
0
        private void Probe(Point sourcePointRounded, bool showPixelValue, bool showVoiValue)
        {
            string probeString;
            string pixelValueString  = String.Format(SR.FormatProbeInfo, SR.LabelRawPixel, SR.LabelNotApplicable);
            string modalityLutString = String.Format(SR.FormatProbeInfo, SR.LabelModalityLut, SR.LabelNotApplicable);
            string voiLutString      = String.Format(SR.FormatProbeInfo, SR.LabelVOILut, SR.LabelNotApplicable);

            try
            {
                var displayString = new StringBuilder();

                if (_selectedImageGraphic != null && _selectedImageGraphic.BoundingBox.Contains(sourcePointRounded))
                {
                    if (_selectedImageGraphic is ILutPipelineProvider)
                    {
                        var luts       = _selectedImageGraphic as ILutPipelineProvider;
                        var pixelValue = _selectedImageGraphic.PixelData.GetPixel(sourcePointRounded.X, sourcePointRounded.Y);

                        GetPixelValue(luts, pixelValue, ref pixelValueString);
                        GetModalityLutValue(luts, pixelValue, ref modalityLutString);
                        GetVoiLutValue(luts, pixelValue, ref voiLutString);

                        // the modality LUT value is always shown
                        displayString.AppendLine(modalityLutString);

                        if (showPixelValue)
                        {
                            displayString.AppendLine(pixelValueString);
                        }
                        if (showVoiValue)
                        {
                            displayString.AppendLine(voiLutString);
                        }
                    }
                    else if (_selectedImageGraphic is ColorImageGraphic)
                    {
                        ColorImageGraphic image        = _selectedImageGraphic as ColorImageGraphic;
                        Color             color        = image.PixelData.GetPixelAsColor(sourcePointRounded.X, sourcePointRounded.Y);
                        string            rgbFormatted = String.Format(SR.FormatRGB, color.R, color.G, color.B);
                        pixelValueString = String.Format(SR.FormatProbeInfo, SR.LabelRGBPixel, rgbFormatted);
                        displayString.AppendLine(pixelValueString);
                    }
                }

                // show the coordinates last, cause it's probably the least interesting information
                var coordinateString = String.Format(SR.FormatProbeInfo, SR.LabelLocation, string.Format(SR.FormatCoordinates, sourcePointRounded.X, sourcePointRounded.Y));
                displayString.AppendLine(coordinateString);

                var patientPoint = _selectedCoordinateMapping != null && _selectedCoordinateMapping.IsValid
                                                        ? _selectedCoordinateMapping.ConvertToPatient(sourcePointRounded)
                                                        : _selectedFrame.ImagePlaneHelper.ConvertToPatient(sourcePointRounded);
                if (patientPoint != null)
                {
                    var patientString = String.Format(SR.FormatProbeInfo, SR.LabelPatientLocation, string.Format(SR.FormatCoordinates3D, patientPoint.X.ToString("f3"), patientPoint.Y.ToString("f3"), patientPoint.Z.ToString("f3")));
                    displayString.AppendLine(patientString);
                }

                probeString = displayString.ToString().Trim();
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
                probeString = SR.MessageProbeToolError;
            }

            var destinationPoint = Point.Round(_selectedSpatialTransform.ConvertToDestination(sourcePointRounded));

            _selectedTile.InformationBox.Update(probeString, destinationPoint);
        }
示例#18
0
		public void TestBasicColorImage()
		{
			const int rows = 8;
			const int cols = 8;

			var pixelData = new byte[rows*cols*4];
			using (var imageGraphic = new ColorImageGraphic(rows, cols, () => pixelData))
			using (var presentationImage = new TestPresentationImage(imageGraphic))
			{
				presentationImage.DrawToBitmap(100, 100);
			}
		}
示例#19
0
        private void Probe(Point destinationPoint)
        {
            Point sourcePointRounded = Point.Truncate(_selectedImageGraphic.SpatialTransform.ConvertToSource(destinationPoint));

            bool showPixelValue    = true;
            bool showModalityValue = true;
            bool showVoiValue      = true;

            string probeString       = String.Format(SR.FormatLocation, SR.LabelNotApplicable, SR.LabelNotApplicable, SR.LabelNotApplicable);
            string pixelValueString  = String.Format(SR.FormatPixelValue, SR.LabelNotApplicable);
            string modalityLutString = String.Format(SR.FormatModalityLutValue, SR.LabelNotApplicable);
            string voiLutString      = String.Format(SR.FormatVoiLutValue, SR.LabelNotApplicable);

            try
            {
                DicomImagePlane dip = DicomImagePlane.FromImage(this.SelectedPresentationImage);
                if (_selectedImageGraphic.HitTest(destinationPoint))
                {
                    Vector3D voxelCoordinate = dip.ConvertToPatient(new PointF(sourcePointRounded.X, sourcePointRounded.Y));
                    probeString = String.Format(SR.FormatLocation, voxelCoordinate.X, voxelCoordinate.Y, voxelCoordinate.Z);

                    if (_selectedImageGraphic is GrayscaleImageGraphic)
                    {
                        GrayscaleImageGraphic image = _selectedImageGraphic as GrayscaleImageGraphic;

                        int    pixelValue       = 0;
                        double modalityLutValue = 0;
                        double voiLutValue      = 0;

                        GetPixelValue(image, sourcePointRounded, ref pixelValue, ref pixelValueString);
                        GetModalityLutValue(image, pixelValue, ref modalityLutValue, ref modalityLutString);
                        GetVoiLutValue(image, modalityLutValue, ref voiLutValue, ref voiLutString);
                    }
                    else if (_selectedImageGraphic is ColorImageGraphic)
                    {
                        showModalityValue = false;
                        showVoiValue      = false;

                        ColorImageGraphic image        = _selectedImageGraphic as ColorImageGraphic;
                        Color             color        = image.PixelData.GetPixelAsColor(sourcePointRounded.X, sourcePointRounded.Y);
                        string            rgbFormatted = String.Format(SR.FormatRgb, color.R, color.G, color.B);
                        pixelValueString = String.Format(SR.FormatPixelValue, rgbFormatted);
                    }
                    else
                    {
                        showPixelValue    = false;
                        showModalityValue = false;
                        showVoiValue      = false;
                    }
                }

                if (showPixelValue)
                {
                    probeString += "\n" + pixelValueString;
                }
                if (showModalityValue)
                {
                    probeString += "\n" + modalityLutString;
                }
                if (showVoiValue)
                {
                    probeString += "\n" + voiLutString;
                }
            }
            catch (Exception e)
            {
                Platform.Log(LogLevel.Error, e);
                probeString = SR.MessageProbeToolError;
            }

            _selectedTile.InformationBox.Update(probeString, destinationPoint);
        }