コード例 #1
0
ファイル: Form1.cs プロジェクト: dustinnorwood/RadarServer
        private void RunAnimation()
        {
            GraphParams gp = new GraphParams(XDIM, YDIM, BITCOLS, BITROWS, filtering, gamma, dBBox.Checked, MultiplyBox.Checked, ColorBox.Checked);

            if (GuiUtil.DrawGraph(ref fullBit, Radars, GaussianKernel, gp))
            {
                Graphics g     = this.tabPage1.CreateGraphics();
                double   ratio = (double)BITCOLS / (double)BITROWS;
                g.DrawImage(fullBit, 5, 30, (ratio > 1.0 ? 300 : (int)(300 * ratio)), (ratio > 1.0 ? (int)(300 / ratio) : 300));
                g.Dispose();
            }
        }
コード例 #2
0
        /* ==========================================================================
        *  ==																		   ==
        *  ==		FUNCTION		KevinFilter				                           ==
        *  ==																		   ==
        *  ==		DESCRIPTION		A moving weighted average filter                 ==
        *  ==																		   ==
        *  ==		ENTRY			int[] filtin - the unfiltered input array          ==
        *  ==                      double[] gauss - the filter window                 ==
        *  ==                      double[] filtout - the filtered output array       ==
        *  ==                      out double average - the average value in the output array ==
        *  ==                      bool db - a flag for conversion to dB scale        ==
        *  ==																		   ==
        *  ==		RETURN			the maximum value in the input array               ==
        *  ========================================================================== */
        public static double FindStrength(double[] filtin, MRM_SCAN_INFO t, Point loc, Point radar, double offset, double maxstren, double inmax, GraphParams gp)
        {
            double coeff   = (double)gp.CmWidth / (double)gp.PixWidth;
            int    radX    = (gp.PixWidth * radar.X) / gp.CmWidth;
            int    radY    = (gp.PixHeight * radar.Y) / gp.CmHeight;
            double bitDist = PSPERCM * (coeff * Math.Sqrt((loc.X - radX) * (loc.X - radX) + (loc.Y - radY) * (loc.Y - radY)) - offset); //Pixel's distance from radar 1 in picoseconds

            if (filtin != null)
            {
                int dist = (int)((bitDist - (double)t.ScanStartPS + 12000.0) / (((double)t.ScanStepBins) * PSPERBIN)); //converts picoseconds to range bin index
                if (dist >= filtin.Length)
                {
                    dist = filtin.Length - 1;
                }
                if (dist < 0)
                {
                    dist = 0;
                }
                return((maxstren / inmax) * filtin[dist]); // *(filtin[dist] / inmax);
            }
            else
            {
                return(1);
            }
        }
コード例 #3
0
ファイル: GuiUtil.cs プロジェクト: dustinnorwood/RadarServer
        /* ==========================================================================
        *  ==																		   ==
        *  ==		FUNCTION		DrawGraph							       ==
        *  ==																		   ==
        *  ==		DESCRIPTION		Draw the 2-D backprojection plot          ==
        *  ==																		   ==
        *  ==		ENTRY			Bitmap bit - the Bitmap object to draw on       ==
        *  ==						List<Radar> - a List of the Radars to process   ==
        *  ==						int cmWidth - the width of the enclosure in cm   ==
        *  ==						GraphParams gp - all GUI parameters needed   ==
        *  ==																		   ==
        *  ==		RETURN			A bool representing whether the operation completed successfully  ==
        *  ========================================================================== */
        public static bool DrawGraph(ref System.Drawing.Bitmap bit, List <Radar> Radars, double[] gauss, GraphParams gp)
        {
            if (Radars.Count == 0)
            {
                return(false);
            }
            double[][] filters       = new double[Radars.Count][];
            int[][]    peaks         = new int[Radars.Count][];
            double[]   maxVals       = new double[Radars.Count];
            double     totalStrength = 1.0;
            double     strengthDivisor;
            double     maxStrength = 1.0;
            byte       intensity;
            byte       count;

            try
            {
                for (int z = 0; z < Radars.Count; z++) //Filter all radars' current ScanData field
                {
                    if (Radars[z].CurrentScan.ScanData != null)
                    {
                        int[] temp;
                        lock (Program.lockObj)
                        {
                            temp = new int[Radars[z].CurrentScan.ScanData.Length];
                            Radars[z].CurrentScan.ScanData.CopyTo(temp, 0); //temp now references a different array, not an alias to CurrentScan.ScanData
                            MRM_SCAN_INFO ts = Radars[z].CurrentScan;
                        }
                        filters[z] = Filter.FilterData(temp, gauss, out peaks[z], gp.DB);
                        maxVals[z] = filters[z].Max();
                    }
                }
                maxStrength = maxVals.Max();
                for (int j = 0; j < gp.PixHeight; j++) //Fill the Bitmap pixel by pixel
                                                       //Could perhaps be offloaded to GPU in future for potentially faster drawing time
                                                       //300x300 Bitmap means 90000 independent calculations... okay to be done on CPU
                                                       //1000x1000 Bitmap (perhaps more desirable) means 1000000 independent calculations... unfeasible task for CPU
                {
                    for (int i = 0; i < gp.PixWidth; i++)
                    {
                        count           = 0;
                        strengthDivisor = 1.0;
                        totalStrength   = 1.0;
                        bool IsZero = false;
                        for (int z = 0; z < Radars.Count; z++) //Find the strength of each radar signal at the range bin corresponding to this pixel
                                                               //This automatically provides the radial plot we need by just knowing the distance between the pixel and the radar in terms of range bins
                        {
                            if (filters[z] != null)
                            {
                                count++;
                                double stren = Filter.FindStrength(filters[z], Radars[z].CurrentScan, new Point(i, j), Radars[z].Location, Radars[z].Offset, maxStrength, maxVals[z], gp);
                                if (stren <= 0)
                                {
                                    IsZero = true;
                                }
                                if ((gp.Filtering % 2) == 1)
                                {
                                    stren = (stren * stren) / maxStrength;
                                }
                                if (gp.Multiply)
                                {
                                    totalStrength *= stren;
                                }
                                else
                                {
                                    totalStrength += stren;
                                }
                            }
                        }
                        if (IsZero)
                        {
                            totalStrength = 0;
                        }
                        else
                        {
                            totalStrength = Math.Pow(totalStrength, gp.Gamma);  //Boosting function: (sum or product of all radar strengths)^Gamma. Provides greater flexibility than a simple add or multiply function
                        }
                        for (int k = 0; k < count; k++)
                        {
                            if (gp.Multiply)
                            {
                                strengthDivisor *= maxStrength;
                            }
                            else
                            {
                                strengthDivisor += maxStrength;
                            }
                        }
                        strengthDivisor = Math.Pow(strengthDivisor, gp.Gamma);
                        if (gp.Filtering >= 2)
                        {
                            totalStrength = (totalStrength * totalStrength) / strengthDivisor;
                        }
                        if (gp.Color) //Scale for color mode
                        {
                            double quotient = totalStrength / strengthDivisor;
                            if (quotient > 1.0)
                            {
                                quotient = 1.0;
                            }
                            byte red   = (quotient > 0.5 ? (byte)(255 * ((quotient - 0.5) / 0.5)) : (byte)0);
                            byte green = (quotient > 0.5 ? (byte)(255 - 255 * ((quotient - 0.5) / 0.5)) : (byte)(255 * (quotient / 0.5)));
                            byte blue  = (quotient < 0.5 ? (byte)(255 - 255 * (quotient / 0.5)) : (byte)0);
                            bit.SetPixel(i, j, System.Drawing.Color.FromArgb(red, green, blue));
                        }
                        else
                        {
                            if (totalStrength > strengthDivisor)
                            {
                                count++;
                            }
                            intensity = (byte)((255 * totalStrength) / strengthDivisor);
                            bit.SetPixel(i, j, System.Drawing.Color.FromArgb(intensity, intensity, intensity));
                        }
                    }
                }

#if TIMER
                // if (!radarGraph.IsDisposed && radarGraph.Visible)
                //    radarGraph.Draw(filters, maxVals, peaks);
#endif
                return(true);
            }
            catch
            {
                return(false);
            }
        }