Exemple #1
0
        /// <summary>
        /// Get reduced fluence
        /// </summary>
        /// <remarks>
        /// IscFluence will be overwritten with reduced fluence.
        /// </remarks>
        /// <returns> Reduced fluence </returns>
        public Fluence GetReducedFluence()
        {
            double xOrigin = IscFluence.OriginX;
            double yOrigin = IscFluence.OriginY;
            double xRes    = IscFluence.SpacingX;
            double yRes    = IscFluence.SpacingY;
            int    xSize   = IscFluence.SizeX;
            int    ySize   = IscFluence.SizeY;

            double[,] minDoseReductionFactorMap
                = MinDoseReductionFactorMap(xOrigin, yOrigin, xRes, yRes, xSize, ySize);

            var newFluenceValues = new float[ySize, xSize];

            for (int i = 0; i < ySize; i++)
            {
                for (int j = 0; j < xSize; j++)
                {
                    double value = IscFluence.Values[i, j];
                    IscFluence.Values[i, j] = value * minDoseReductionFactorMap[i, j];
                    newFluenceValues[i, j]  = (float)IscFluence.Values[i, j];
                }
            }

            var fluence = new Fluence(newFluenceValues, xOrigin, yOrigin);

            return(fluence);
        }
Exemple #2
0
        public bool CanSetOptimalFluence(Fluence fluence, out string message)
        {
            var message_OUT = default(string);
            var local       = this;
            var retVal      = X.Instance.CurrentContext.GetValue(sc =>
            {
                return(local._client.CanSetOptimalFluence(fluence, out message_OUT));
            });

            message = message_OUT;
            return(retVal);
        }
Exemple #3
0
    //public void AddNormal(int type)
    //{
    //    int n = NumSet(type);
    //    if (GC.ResCount[n, 1] > Value[type - 1, 1])
    //    {
    //        Value[type - 1, 1] += 1;
    //        NumCheck(false, type);
    //    }
    //    UpdateInfo();
    //}
    //public void ReduceNormal(int type)
    //{
    //    int n = NumSet(type);
    //    if (Value[type - 1, 1] > 0)
    //    {
    //        Value[type - 1, 1] -= 1;
    //        NumCheck(true, type);
    //    }
    //    UpdateInfo();
    //}
    //public void AddGood(int type)
    //{
    //    int n = NumSet(type);
    //    if (GC.ResCount[n, 2] > Value[type - 1, 2])
    //    {
    //        Value[type - 1, 2] += 1;
    //        NumCheck(false, type);
    //    }
    //    UpdateInfo();
    //}
    //public void ReduceGood(int type)
    //{
    //    int n = NumSet(type);
    //    if (Value[type - 1, 2] > 0)
    //    {
    //        Value[type - 1, 2] -= 1;
    //        NumCheck(true, type);
    //    }
    //    UpdateInfo();
    //}
    //public void AddPerfect(int type)
    //{
    //    int n = NumSet(type);
    //    if (GC.ResCount[n, 3] > Value[type - 1, 3])
    //    {
    //        Value[type - 1, 3] += 1;
    //        NumCheck(false, type);
    //    }
    //    UpdateInfo();
    //}
    //public void ReducePerfect(int type)
    //{
    //    int n = NumSet(type);
    //    if (Value[type - 1, 3] > 0)
    //    {
    //        Value[type - 1, 3] -= 1;
    //        NumCheck(true, type);
    //    }
    //    UpdateInfo();
    //}

    void UpdateInfo()
    {
        for (int i = 0; i < Text_Counts.Length; i++)
        {
            Text_Counts[i].text = Value[i].ToString();
        }
        ValueCalc();
        Text_Value[0].text = Art.ToString();
        Text_Value[1].text = Function.ToString();
        Text_Value[2].text = Fluence.ToString();
        Text_Value[3].text = Secure.ToString();
    }
Exemple #4
0
        private void createMlcField(float[,] flncMtx, float rotAng)
        {
            int    height = flncMtx.GetLength(0);
            int    width  = flncMtx.GetLength(1);
            double xOrg   = -0.5 * ((double)width * flncRes - flncRes);
            double yOrg   = 0.5 * ((double)height * flncRes - flncRes);
            // Create fluence
            Fluence mlcFlnc = new Fluence(flncMtx, xOrg, yOrg);
            // Add beam
            Beam currBm = currPln.AddMLCBeam(currMachParam, new float[2, 60], new VRect <double>(-50.0, -50.0, 50.0, 50.0), rotAng, 0.0, 0.0, currIsoCtr);

            currBm.SetOptimalFluence(mlcFlnc);
            currPln.CalculateLeafMotions(vlmcOpt);
        }
        private void OnPrint()
        {
            PrintDialog pd = new PrintDialog();

            if (pd.ShowDialog() == true)
            {
                FlowDocument document = new FlowDocument();
                document.Blocks.Add(new Paragraph(new Run($"Optimal Fluence for {beams.First().Plan.Id}"))
                {
                    FontWeight    = FontWeights.Bold,
                    TextAlignment = TextAlignment.Center
                });
                foreach (Beam b in beams.Where(x => !x.IsSetupField))
                {
                    Fluence f = b.GetOptimalFluence();
                    if (f != null)
                    {
                        StackPanel sp = new StackPanel();
                        sp.Children.Add(new TextBlock()
                        {
                            Text = b.Id, TextAlignment = TextAlignment.Center
                        });
                        sp.Children.Add(new System.Windows.Controls.Image()
                        {
                            Height = 100,
                            Width  = 100,
                            Source = DrawImage(f)
                        });
                        document.Blocks.Add(new BlockUIContainer()
                        {
                            Child = sp
                        });
                    }
                }
                document.PageHeight  = pd.PrintableAreaHeight;
                document.PageWidth   = pd.PrintableAreaWidth;
                document.PagePadding = new Thickness(50);
                document.ColumnGap   = 0;
                document.ColumnWidth = pd.PrintableAreaWidth;
                IDocumentPaginatorSource dps = document;
                pd.PrintDocument(dps.DocumentPaginator, "FluencePrint");
            }
        }
        private void FillOptimalFluences()
        {
            foreach (Beam b in beams.Where(x => !x.IsSetupField))
            {
                Fluence fluence = b.GetOptimalFluence();
                if (fluence != null)
                {
                    float[,] pixels = fluence.GetPixels();

                    var          SizeX  = fluence.XSizePixel;
                    var          SizeY  = fluence.YSizePixel;
                    int          stride = SizeY * 3 + (SizeY % 4);
                    BitmapSource bms    = DrawImage(fluence);
                    OptimalFluences.Add(new OptimalFluenceModel
                    {
                        FieldId           = b.Id,
                        OptimalFluenceMap = bms
                    });
                }
            }
        }
        private BitmapSource DrawImage(Fluence f)
        {
            float[,] pixels = f.GetPixels();
            float image_min = 1000;
            float image_max = -1;

            float[] image_pixels = new float[f.XSizePixel * f.YSizePixel];
            for (int j = 0; j < f.YSizePixel; j++)
            {
                for (int k = 0; k < f.XSizePixel; k++)
                {
                    image_pixels[k + j * f.XSizePixel] = pixels[j, k];
                    if (pixels[j, k] < image_min)
                    {
                        image_min = pixels[j, k];
                    }
                    if (pixels[j, k] > image_max)
                    {
                        image_max = pixels[j, k];
                    }
                }
            }
            //byte[] image_bytes = new byte[image_pixels.Length * sizeof(UInt16)];
            //Buffer.BlockCopy(image_pixels, 0, image_bytes, 0, image_bytes.Length);
            PixelFormat format = PixelFormats.Rgb24;
            //get min and max of the data.
            //iamge min now comes from the method input parameter image_min
            //image_min = image_pixels.Min();//this is the red value. I.e. 255,0,0
            //image_max = image_pixels.Max();//this is the blue value. i.e. 0,0,255.
            double image_med = (image_max + image_min) / 2;
            int    stride    = (f.XSizePixel * format.BitsPerPixel + 7) / 8;

            byte[] image_bytes = new byte[stride * f.XSizePixel];
            //copy data to image bytes
            for (int j = 0; j < image_pixels.Length; j++)
            {
                float value = image_pixels[j];
                System.Windows.Media.Color c = new System.Windows.Media.Color();
                if (value < image_min)
                {
                    c.B = 0;
                    c.R = 0;
                    c.G = 0;
                }
                else if (value < image_med)
                {
                    c.R = 0;
                    c.B = Convert.ToByte(255 - (255 * (value - image_min) / (image_med - image_min)));
                    c.G = Convert.ToByte(255 - (255 * (image_med - value) / (image_med - image_min)));
                }
                else if (value <= image_max)
                {
                    c.B = 0;
                    c.R = Convert.ToByte(255 - (255 * (image_max - value) / (image_max - image_med)));
                    c.G = Convert.ToByte(255 - (255 * (value - image_med) / (image_max - image_med)));
                }
                else if (value > image_max)
                {
                    c.R = 0;
                    c.B = 0;
                    c.G = 0;
                }
                image_bytes[j * 3]     = c.R;
                image_bytes[j * 3 + 1] = c.G;
                image_bytes[j * 3 + 2] = c.B;
            }
            BitmapSource bmp = BitmapSource.Create(f.XSizePixel,
                                                   f.YSizePixel,
                                                   (f.XSizePixel / f.XSizeMM) / mm_to_inch,
                                                   (f.YSizePixel / f.YSizeMM) / mm_to_inch,
                                                   format,
                                                   null,
                                                   image_bytes,
                                                   stride
                                                   );

            return(bmp);
        }
Exemple #8
0
        public void SetOptimalFluence(Fluence fluence)
        {
            var local = this;

            X.Instance.CurrentContext.Thread.Invoke(() => { local._client.SetOptimalFluence(fluence); });
        }