Exemplo n.º 1
0
 protected override void OnRenderPixel(Image3D image, DisplayImage display, int x, int y)
 {
     if (MarkerX == x || MarkerY == y)
     {
         display.SetPixel(x, y, Colors.Orange);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Process an 3D Image with this element
        /// </summary>
        /// <param name="image">Input image</param>
        /// <returns>Output image</returns>
        public Image3D Process(Image3D image)
        {
            using (var progress = Log.P(ToString()))
            {
                try
                {
                    if (PreProcessing !=null)
                    {
                        PreProcessing(this, new ProcessEventArgs(image));
                    }

                    return OnProcess(image, progress);
                }
                catch (ThreadAbortException)
                {
                    progress.Abort();
                    throw;
                }
                catch (LogException e)
                {
                    progress.Abort();
                    Log.E(e.Message);
                    throw;
                }
            }
        }
Exemplo n.º 3
0
 protected override Image3D GetOutputImage(Image3D imageIn)
 {
     var imageOut = new Image3D(imageIn.LengthY, imageIn.LengthZ, imageIn.LengthX);
     imageOut.Minimum = imageIn.Minimum;
     imageOut.Maximum = imageIn.Maximum;
     return imageOut;
 }
Exemplo n.º 4
0
        protected override Image3D OnProcess(Image3D image, Progress progress)
        {
            if (cache == null)
            {
                if (!CombineFilesToSlices)
                {
                    using (var reader = new DicomReader(Path))
                    {
                        cache = reader.ReadImage3D(progress);
                        cache.Minimum = reader.MinValue;
                        cache.Maximum = reader.MaxValue;
                    }
                }
                else
                {
                    using (var reader = new FileToSliceDicomReader(Path))
                    {
                        cache = reader.ReadImage3D(progress);
                        cache.Minimum = reader.MinValue;
                        cache.Maximum = reader.MaxValue;
                    }
                }

                Log.I("Image loaded. min: " + cache.Minimum + "; max: " + cache.Maximum);
            }

            return cache;
        }
Exemplo n.º 5
0
 protected override void OnProcess2D(Image3D imageIn, Image3D imageOut, int x, int y)
 {
     for (int z = 0; z < imageIn.LengthZ; z++)
     {
         OnProcess3D(imageIn, imageOut, x, y, z);
     }
 }
Exemplo n.º 6
0
        protected override Image3D OnProcess(Image3D image, Progress progress)
        {
            OnValidate(image);
            Size size = OnDetermineDisplaySize(image);
            int w = (int)Math.Round(size.Width);
            int h = (int)Math.Round(size.Height);

            displayImage = Display.GetDisplay(w, h);
            var result = base.OnProcess(image, progress);
            return result;
        }
Exemplo n.º 7
0
 protected override Image3D OnProcess(Image3D image, Progress progress)
 {
     if (Activated)
     {
         return base.OnProcess(image, progress);
     }
     else
     {
         progress.Done();
         return image;
     }
 }
Exemplo n.º 8
0
        protected override Image3D OnProcess(Image3D image, Progress progress)
        {
            Image3D imageOut = GetOutputImage(image);

            int delta = image.LengthY / threads.Length;

            LineRange firstRange = null;

            for (int i = 0; i < threads.Length; i++)
            {
                int min = delta * i;
                int max = (i == threads.Length - 1 ? image.LengthY : (delta * (i + 1)));
                var range = new LineRange(image, imageOut, progress, min, max);

                if (i == 0)
                {
                    // run first range in this thread
                    // so save the range for later
                    firstRange = range;
                }
                else
                {
                    threads[i] = new Thread(new ParameterizedThreadStart(ProcessLines));
                    threads[i].Start(range);
                }
            }

            // allow other threads to start
            Thread.Sleep(0);

            // run first range
            ProcessLines(firstRange);

            // join all other threads
            // Attention: start at 1, beacause 0 is null because it was processed in this Thread
            for (int i = 1; i < threads.Length; i++)
            {
                while (threads[i].ThreadState == ThreadState.Unstarted)
                {
                    Thread.Sleep(0);
                }

                threads[i].Join();
            }

            return imageOut;
        }
Exemplo n.º 9
0
        public Image3D ReadImage3D(Progress progress)
        {
            this.progress = progress;

            var directory = new DirectoryInfo(path);
            var files = directory.GetFiles();

            // TODO: remove (allow max 900 slices)
            if (files.Length > 900)
            {
                Array.Resize<FileInfo>(ref files, 900);
            }
            // ---

            Image3D slice0;
            using (var reader0 = new DicomReader(files[0].FullName))
            {
                slice0 = reader0.ReadImage3D(new Progress());
            }
            this.image = new Image3D(files.Length, slice0.LengthY, slice0.LengthX);
            this.image.CloneSlice(slice0, 0, 0);
            MinValue = Math.Min(MinValue, slice0.Minimum);
            MaxValue = Math.Max(MaxValue, slice0.Maximum);
            slice0 = null;
            slicesDone++;

            //ThreadPool.SetMaxThreads(8, 8);

            for (int z = 1; z < files.Length; z++)
            {
                ReadSlice(new SliceInfo(files[z], z));
                //ThreadPool.QueueUserWorkItem(new WaitCallback(ReadSlice), );
            }

            while (slicesDone != image.LengthZ)
            {
                Thread.Sleep(50);
            }

            progress.Done();

            path = null;
            return image;
        }
Exemplo n.º 10
0
        public void UpdateImage(Image3D image)
        {
            Histogram histogram = new Histogram(Builder.MinValue, Builder.MaxValue, displayImage.Width);
            histogram.FromImage(image);

            TransferFunction1D tf = CreateTransferFunction();
            histogram.Render(displayImage, tf);

            Dispatcher.Invoke(
                () =>
                {
                    displayImage.Update();

                    imageTfBackground.Width = canvasTf.ActualWidth;
                    imageTfBackground.Height = canvasTf.ActualHeight;
                    //UpdateAll();
                }
            );
        }
Exemplo n.º 11
0
 public static string InfoString(Image3D image)
 {
     if (image == null) { return "null"; }
     else
     {
         return image.LengthX + "x" + image.LengthY + "x" + image.LengthZ;
     }
 }
Exemplo n.º 12
0
 protected override void OnProcess2D(Image3D imageIn, Image3D imageOut, int x, int y)
 {
     OnRenderPixel(imageIn, displayImage, x, y);
 }
Exemplo n.º 13
0
 protected override void OnProcess3D(Image3D imageIn, Image3D imageOut, int x, int y, int z)
 {
     imageOut[x, z, y] = imageIn[x, y, z];
 }
Exemplo n.º 14
0
 public void Dispose()
 {
     disposed = true;
     image = null;
     progress = null;
 }
Exemplo n.º 15
0
 protected virtual Image3D GetOutputImage(Image3D imageIn)
 {
     return imageIn.EmptyCopy();
 }
Exemplo n.º 16
0
 public LineRange(Image3D imageIn, Image3D imageOut, Progress progress, int min, int max)
 {
     this.ImageIn = imageIn;
     this.ImageOut = imageOut;
     this.Progress = progress;
     this.Min = min;
     this.Max = max;
 }
Exemplo n.º 17
0
 public ProcessEventArgs(Image3D image)
 {
     this.Image = image;
 }
Exemplo n.º 18
0
 protected override Image3D GetOutputImage(Image3D imageIn)
 {
     return imageIn; // do not create new output image, use input instead, because it shouldn't be modified in a renderer
 }
Exemplo n.º 19
0
 public Image3D EmptyCopy()
 {
     var result = new Image3D(LengthZ, LengthY, LengthX);
     result.Minimum = Minimum;
     result.Maximum = Maximum;
     return result;
 }
Exemplo n.º 20
0
 protected virtual Size OnDetermineDisplaySize(Image3D image)
 {
     return new Size(image.LengthX, image.LengthY);
 }
Exemplo n.º 21
0
 /// <summary>
 /// Is called for every voxel of the input image
 /// </summary>
 /// <param name="imageIn">input image</param>
 /// <param name="imageOut">output image</param>
 /// <param name="x">x</param>
 /// <param name="y">y</param>
 /// <param name="z">z</param>
 protected abstract void OnProcess3D(Image3D imageIn, Image3D imageOut, int x, int y, int z);
Exemplo n.º 22
0
 /// <summary>
 /// Must be implemented to process the image
 /// </summary>
 /// <param name="image">Input image</param>
 /// <param name="progress">Progress of the process</param>
 /// <returns>Output image</returns>
 protected abstract Image3D OnProcess(Image3D image, Progress progress);
Exemplo n.º 23
0
 protected abstract void OnRenderPixel(Image3D image, DisplayImage display, int x, int y);
Exemplo n.º 24
0
 protected virtual void OnValidate(Image3D image)
 {
 }
Exemplo n.º 25
0
 public void CloneSlice(Image3D source, int sourceSlice, int destinationSlice)
 {
     if (source.LengthX != LengthX || source.LengthY != LengthY)
     {
         throw new ArgumentException("Slice dimensions must match!");
     }
     else
     {
         this.data[destinationSlice] = source.data[sourceSlice];
     }
 }