Exemple #1
0
        public cFeedBackMessage Run()
        {
            if (base.Start() == false)
            {
                base.FeedBackMessage.IsSucceed = false;
                return base.FeedBackMessage;
            }

            #region parameters initilization
            object _firstValue = base.ListProperties.FindByName("Kernel size");
            int KernelSize = 0;
            if (_firstValue == null)
            {
                base.GenerateError("Kernel size not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                KernelSize = (int)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("Kernel size cast didn't work");
                return base.FeedBackMessage;
            }

            _firstValue = base.ListProperties.FindByName("Image width");
            int ImWidth = 0;
            if (_firstValue == null)
            {
                base.GenerateError("Image width not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                ImWidth = (int)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("Image width cast didn't work");
                return base.FeedBackMessage;
            }

            _firstValue = base.ListProperties.FindByName("Image height");
            int ImHeight = 0;
            if (_firstValue == null)
            {
                base.GenerateError("Image height not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                ImHeight = (int)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("Image height cast didn't work");
                return base.FeedBackMessage;
            }

            _firstValue = base.ListProperties.FindByName("Image depth");
            int ImDepth = 0;
            if (_firstValue == null)
            {
                base.GenerateError("Image depth not found !");
                return base.FeedBackMessage;
            }
            try
            {
                cProperty TmpProp = (cProperty)_firstValue;
                ImDepth = (int)TmpProp.GetValue();
            }
            catch (Exception)
            {
                base.GenerateError("Image depth cast didn't work");
                return base.FeedBackMessage;
            }
            #endregion

            if (this.Input[0].Count == 2) ImDepth = 1;
            if (this.Input[0].Count == 1)
            {
                ImDepth = 1;
                ImHeight = 1;
            }

            this.Output = new cImage(ImWidth, ImHeight, ImDepth, this.Input.Count);

            cImageDrawKernel GK = new cImageDrawKernel();
            GK.sigma_x = KernelSize;
            GK.sigma_y = KernelSize;
            GK.sigma_z = KernelSize;
            GK.Run();

            cImage K = GK.GetOutPut();

            for (int IdxChannel = 0; IdxChannel < this.Input.Count; IdxChannel++)
            {
                cExtendedTable CurrentTable = this.Input[IdxChannel];
                cExtendedList ListVolumes = new cExtendedList();

                double MaxX = CurrentTable[0].Max();
                double MinX = CurrentTable[0].Min();

                double MaxY = CurrentTable[1].Max();
                double MinY = CurrentTable[1].Min();

                double MaxZ = 0;
                double MinZ = 0;

                if (CurrentTable.Count>2)
                {
                    MaxZ = CurrentTable[2].Max();
                    MinZ = CurrentTable[2].Min();
                }

                this.Output.SingleChannelImage[IdxChannel].Resolution.X = (MaxX - MinX) / (double)ImWidth;
                this.Output.SingleChannelImage[IdxChannel].Resolution.Y = (MaxY - MinY) / (double)ImHeight;
                this.Output.SingleChannelImage[IdxChannel].Resolution.Z = (MaxZ - MinZ) / (double)ImDepth;

                if (CurrentTable.Count > 2)
                {
                    for (int j = 0; j < CurrentTable[0].Count; j++)
                    {
                        double TmpValueX = (ImWidth * (CurrentTable[0][j] - MinX)) / (MaxX - MinX) - K.Width / 2;
                        double TmpValueY = (ImHeight * (CurrentTable[1][j] - MinY)) / (MaxY - MinY) - K.Height / 2;
                        double TmpValueZ = (ImDepth * (CurrentTable[2][j] - MinZ)) / (MaxZ - MinZ) - K.Depth / 2;

                        this.Output.AddInto(K, (int)TmpValueX,  (int)TmpValueY, (int)TmpValueZ, IdxChannel);
                    }
                }
                else
                {
                    for (int j = 0; j < CurrentTable[0].Count; j++)
                    {
                        double TmpValueX = (ImWidth * (CurrentTable[0][j] - MinX)) / (MaxX - MinX) - K.Width / 2;
                        double TmpValueY = ImHeight - (ImHeight * (CurrentTable[1][j] - MinY)) / (MaxY - MinY) - K.Height / 2;

                        this.Output.AddInto(K, (int)TmpValueX, (int)TmpValueY, 0, IdxChannel);
                    }
                }
                cListExtendedTable TablesForDensity = new cListExtendedTable(this.Output);

                for (int idxChannel = 0; idxChannel < this.Output.GetNumChannels(); idxChannel++)
                {
                    this.Output.SingleChannelImage[idxChannel].Name = this.Input.Name;//cGlobalInfo.ListCellularPhenotypes[idxChannel].Name;
                    float Sum = 1;
                    if (IsNormalized)
                    {
                        Sum = (float)TablesForDensity[idxChannel].Sum();
                        if (Sum <= 0.0) continue;
                        for (int i = 0; i < this.Output.SingleChannelImage[idxChannel].Data.Length; i++)
                        {
                            this.Output.SingleChannelImage[idxChannel].Data[i] = (10000000 * this.Output.SingleChannelImage[idxChannel].Data[i]) / Sum;
                        }
                    }
                    //else
                    //{
                    //    for (int i = 0; i < this.Output.SingleChannelImage[idxChannel].Data.Length; i++)
                    //    {
                    //        // if (ClassPopulations[idxChannel] > 0)
                    //        this.Output.SingleChannelImage[idxChannel].Data[i] = this.Output.SingleChannelImage[idxChannel].Data[i];
                    //    }
                    //}
                }
            }

            this.Output.SingleChannelImage[0].UpDateMax();
            this.Output.SingleChannelImage[0].UpDateMin();
            base.End();
            return FeedBackMessage;
        }
        private void buttonProcess_Click(object sender, EventArgs e)
        {
            ImageWidth = (int)numericUpDownMapWidth.Value;
            ImageHeight = (int)numericUpDownMapHeight.Value;

            if (this.radioButton2D.Checked) ImageDepth = 1;
            else
                ImageDepth = (int)numericUpDownMapDepth.Value;

            //GlobalInfo.ListCellularPhenotypes[(int)MachineLearning.Classes[j]]
            cImageDrawKernel GK = new cImageDrawKernel();
            GK.sigma_x = (int)numericUpDownKernelSize.Value;
            GK.sigma_y = (int)numericUpDownKernelSize.Value;
            GK.sigma_z = (int)numericUpDownKernelSize.Value;
            GK.Run();

            cImage K = GK.GetOutPut();

            if (Parent.comboBoxAxeY.SelectedIndex == -1) return;
            if (Parent.comboBoxVolume.SelectedIndex == -1) return;

            cExtendedList ListVolumes = new cExtendedList();

            ListX.Clear();
            ListY.Clear();
            ListZ.Clear();

            cExtendedTable TableForDataToBeAnalyzed = Parent.GetActiveSignatures(false);

            for (int j = 0; j < TableForDataToBeAnalyzed[0].Count; j++)
            {
                ListX.Add(TableForDataToBeAnalyzed[Parent.comboBoxAxeX.SelectedIndex][j]);
                ListY.Add(TableForDataToBeAnalyzed[Parent.comboBoxAxeY.SelectedIndex][j]);
            }

            //MaxX = ListX.Max();
            //MinX = ListX.Min();

            //MaxY = ListY.Max();
            //MinY = ListY.Min();

            MaxX = Parent.chartForPoints.ChartAreas[0].AxisX.Maximum;
            MinX = Parent.chartForPoints.ChartAreas[0].AxisX.Minimum;

            MaxY = Parent.chartForPoints.ChartAreas[0].AxisY.Maximum;
            MinY = Parent.chartForPoints.ChartAreas[0].AxisY.Minimum;

            //MaxY = Parent.MaxY;
            //MinY = Parent.MinY;

            if (this.radioButton3D.Checked)
            {
                for (int j = 0; j < TableForDataToBeAnalyzed[0].Count; j++)
                {
                    ListZ.Add(TableForDataToBeAnalyzed[Parent.comboBoxVolume.SelectedIndex][j]);
                }
                MaxZ = ListZ.Max();
                MinZ = ListZ.Min();
            }

            DensityMaps = new cImage(ImageWidth, ImageHeight, ImageDepth, cGlobalInfo.ListCellularPhenotypes.Count);

            int[] ClassPopulations = new int[cGlobalInfo.ListCellularPhenotypes.Count];

            if (this.radioButton3D.Checked)
            {
                int Idx = 0;
                for (int j = 0; j < Parent.InputTable[0].Count; j++)
                {
                    if (Parent.PanelPhenotypeSelection.GetListSelectedClass()[(int)Parent.MachineLearning.Classes[j]])
                    {
                        double TmpValueX = (ImageWidth * (ListX[Idx] - MinX)) / (MaxX - MinX) - K.Width / 2;
                        double TmpValueY = ImageHeight - (ImageHeight * (ListY[Idx] - MinY)) / (MaxY - MinY) - K.Height / 2;
                        double TmpValueZ = ImageDepth - (ImageDepth * (ListZ[Idx] - MinZ)) / (MaxZ - MinZ) - K.Depth / 2;

                        DensityMaps.AddInto(K, (int)TmpValueX, (int)TmpValueY, (int)TmpValueZ, (int)Parent.MachineLearning.Classes[j]);
                        ClassPopulations[(int)Parent.MachineLearning.Classes[j]]++;
                        Idx++;
                    }
                }
            }
            else
            {
                int Idx = 0;
                for (int j = 0; j < Parent.InputTable[0].Count; j++)
                {
                    if (Parent.PanelPhenotypeSelection.GetListSelectedClass()[(int)Parent.MachineLearning.Classes[j]])
                    {
                        double TmpValueX = (ImageWidth * (ListX[Idx] - MinX)) / (MaxX - MinX) - K.Width / 2;
                        double TmpValueY = ImageHeight - (ImageHeight * (ListY[Idx] - MinY)) / (MaxY - MinY) - K.Height / 2;

                        DensityMaps.AddInto(K, (int)TmpValueX, (int)TmpValueY, 0, (int)Parent.MachineLearning.Classes[j]);
                        ClassPopulations[(int)Parent.MachineLearning.Classes[j]]++;
                        Idx++;
                    }
                }
            }
            cListExtendedTable TablesForDensity = new cListExtendedTable(DensityMaps);

            for (int idxChannel = 0; idxChannel < DensityMaps.GetNumChannels(); idxChannel++)
            {
                DensityMaps.SingleChannelImage[idxChannel].Name = cGlobalInfo.ListCellularPhenotypes[idxChannel].Name;
                float Sum = 1;
                if (checkBoxNormalized.Checked)
                {
                    Sum = (float)TablesForDensity[idxChannel].Sum();
                    if (Sum <= 0.0) continue;
                    for (int i = 0; i < DensityMaps.SingleChannelImage[idxChannel].Data.Length; i++)
                    {
                        //if (ClassPopulations[idxChannel] > 0)
                        DensityMaps.SingleChannelImage[idxChannel].Data[i] = (100 * DensityMaps.SingleChannelImage[idxChannel].Data[i]) / Sum;
                    }
                }
                else
                {
                    for (int i = 0; i < DensityMaps.SingleChannelImage[idxChannel].Data.Length; i++)
                    {
                        // if (ClassPopulations[idxChannel] > 0)
                        DensityMaps.SingleChannelImage[idxChannel].Data[i] = DensityMaps.SingleChannelImage[idxChannel].Data[i];
                    }
                }
            }

            cDisplaySingleImage IV = new cDisplaySingleImage();
            DensityMaps.Name = "Density Maps. K["+ this.numericUpDownKernelSize.Value +"]";

            if (this.checkBoxModifyColors.Checked)
                IV.ListLinearMaxColor = new List<Color>();

            int RealIdxChannel = 0;
            for (int idxChannel = 0; idxChannel < ClassPopulations.Length; idxChannel++)
            {
                if (ClassPopulations[idxChannel] == 0)
                    DensityMaps.SingleChannelImage.RemoveAt(RealIdxChannel--);
                else
                {
                    if (this.checkBoxModifyColors.Checked)
                    IV.ListLinearMaxColor.Add(cGlobalInfo.ListCellularPhenotypes[idxChannel].ColourForDisplay);
                }
                RealIdxChannel++;
            }

            IV.SetInputData(DensityMaps);
            IV.Run();

            this.buttonApply.Enabled = true;
        }