Exemple #1
0
        private double GetReading(
            float aperture, uint[,] data,
            int nWidth, int nHeight,
            float x0, float y0,
            GetPixelMeasurementCallback pixelMeasurementCallback,
            ref float totalPixels,
            int xCent = 0, int yCent = 0)
        {
            double total = 0;

            totalPixels = 0;

            for (int x = 0; x < nWidth; x++)
            {
                for (int y = 0; y < nHeight; y++)
                {
                    DebugContext.SubPixelData subPixelInfo = null;
                    if (DebugContext.DebugSubPixelMeasurements)
                    {
                        subPixelInfo = new DebugContext.SubPixelData();
                        DebugContext.CurrentSubPixels[DebugContext.TargetNo][x + xCent, y + yCent] = subPixelInfo;
                        subPixelInfo.X0 = x0 + xCent;
                        subPixelInfo.Y0 = y0 + yCent;
                    }

                    double dist = Math.Sqrt((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y));
                    if (dist + 1.5 <= aperture)
                    {
                        // If the point plus 1 pixel diagonal is still in the aperture
                        // then add the readin directly

                        if (pixelMeasurementCallback != null)
                        {
                            total += pixelMeasurementCallback(x, y);
                        }
                        else
                        {
                            total += (int)data[x, y];
                        }

                        totalPixels++;

                        if (DebugContext.DebugSubPixelMeasurements)
                        {
                            subPixelInfo.FullyIncluded = true;
                        }
                    }
                    else if (dist - 1.5 <= aperture)
                    {
                        float subpixels    = 0;
                        bool  hasSubpixels = false;
                        bool  isEvenSide   = m_SubPixelSquare % 2 == 0;
                        if (m_SubPixelSquare > 0)
                        {
                            if (DebugContext.DebugSubPixelMeasurements)
                            {
                                subPixelInfo.Included = new bool[m_SubPixelSquare, m_SubPixelSquare];
                            }

                            for (int dx = 0; dx < m_SubPixelSquare; dx++)
                            {
                                for (int dy = 0; dy < m_SubPixelSquare; dy++)
                                {
                                    double xx = isEvenSide
                                                                                ? x - 1.0 + (2.0 * dx + 1.0) / (2.0 * m_SubPixelSquare)
                                                                                : x - 0.5 + (dx - (m_SubPixelSquare / 2)) * 1.0 / m_SubPixelSquare;

                                    double yy = isEvenSide
                                                                                ? y - 1.0 + (2.0 * dy + 1.0) / (2.0 * m_SubPixelSquare)
                                                                                : y - 0.5 + (dy - (m_SubPixelSquare / 2)) * 1.0 / m_SubPixelSquare;

                                    dist = Math.Sqrt((x0 - xx) * (x0 - xx) + (y0 - yy) * (y0 - yy));
                                    if (dist <= aperture)
                                    {
                                        subpixels   += 1.0f / (m_SubPixelSquare * m_SubPixelSquare);
                                        hasSubpixels = true;
                                        if (DebugContext.DebugSubPixelMeasurements)
                                        {
                                            subPixelInfo.Included[dx, dy] = true;
                                        }
                                    }
                                }
                            }
                        }
                        else if (dist <= aperture)
                        {
                            subpixels    = 1.0f;
                            hasSubpixels = true;
                            if (DebugContext.DebugSubPixelMeasurements)
                            {
                                subPixelInfo.FullyIncluded = true;
                            }
                        }

                        if (hasSubpixels)
                        {
                            if (pixelMeasurementCallback != null)
                            {
                                total += pixelMeasurementCallback(x, y) * subpixels;
                            }
                            else
                            {
                                total += (int)data[x, y] * subpixels;
                            }

                            totalPixels += subpixels;
                        }

                        if (DebugContext.DebugSubPixelMeasurements)
                        {
                            subPixelInfo.TotalSubpixels = subpixels;
                            subPixelInfo.TotalReading   = total;
                        }
                    }

                    if (data[x, y] >= m_SaturationValue)
                    {
                        m_HasSaturatedPixels = true;
                    }
                }
            }

            return(Math.Round(total));
        }
        private double GetReading(
            float aperture, uint[,] data,
            int nWidth, int nHeight,
            float x0, float y0,
            GetPixelMeasurementCallback pixelMeasurementCallback,
            ref float totalPixels,
			int xCent = 0, int yCent = 0)
        {
            double total = 0;
            totalPixels = 0;

            for (int x = 0; x < nWidth; x++)
                for (int y = 0; y < nHeight; y++)
                {
                    DebugContext.SubPixelData subPixelInfo = null;
                    if (DebugContext.DebugSubPixelMeasurements)
                    {
                        subPixelInfo = new DebugContext.SubPixelData();
                        DebugContext.CurrentSubPixels[DebugContext.TargetNo][x + xCent, y + yCent] = subPixelInfo;
                        subPixelInfo.X0 = x0 + xCent;
                        subPixelInfo.Y0 = y0 + yCent;
                    }

                    double dist = Math.Sqrt((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y));
                    if (dist + 1.5 <= aperture)
                    {
                        // If the point plus 1 pixel diagonal is still in the aperture
                        // then add the readin directly

                        if (pixelMeasurementCallback != null)
                            total += pixelMeasurementCallback(x, y);
                        else
                            total += (int) data[x, y];

                        totalPixels++;

                        if (DebugContext.DebugSubPixelMeasurements)
                            subPixelInfo.FullyIncluded = true;

                    }
                    else if (dist - 1.5 <= aperture)
                    {
                        float subpixels = 0;
                        bool hasSubpixels = false;
                        bool isEvenSide = m_SubPixelSquare % 2 == 0;
                        if (m_SubPixelSquare > 0)
                        {
                            if (DebugContext.DebugSubPixelMeasurements)
                                subPixelInfo.Included = new bool[m_SubPixelSquare, m_SubPixelSquare];

                            for (int dx = 0; dx < m_SubPixelSquare; dx++)
                                for (int dy = 0; dy < m_SubPixelSquare; dy++)
                                {
                                    double xx = isEvenSide
                                        ? x - 1.0 + (2.0 * dx + 1.0) / (2.0 * m_SubPixelSquare)
                                        : x - 0.5 + (dx - (m_SubPixelSquare / 2)) * 1.0 / m_SubPixelSquare;

                                    double yy = isEvenSide
                                        ? y - 1.0 + (2.0 * dy + 1.0) / (2.0 * m_SubPixelSquare)
                                        : y - 0.5 + (dy - (m_SubPixelSquare / 2)) * 1.0 / m_SubPixelSquare;

                                    dist = Math.Sqrt((x0 - xx) * (x0 - xx) + (y0 - yy) * (y0 - yy));
                                    if (dist <= aperture)
                                    {
                                        subpixels += 1.0f/(m_SubPixelSquare*m_SubPixelSquare);
                                        hasSubpixels = true;
                                        if (DebugContext.DebugSubPixelMeasurements)
                                            subPixelInfo.Included[dx, dy] = true;
                                    }
                                }
                        }
                        else if (dist <= aperture)
                        {
                            subpixels = 1.0f;
                            hasSubpixels = true;
                            if (DebugContext.DebugSubPixelMeasurements)
                                subPixelInfo.FullyIncluded = true;
                        }

                        if (hasSubpixels)
                        {
                            if (pixelMeasurementCallback != null)
                                total += pixelMeasurementCallback(x, y)*subpixels;
                            else
                                total += (int) data[x, y]*subpixels;

                            totalPixels += subpixels;
                        }

                        if (DebugContext.DebugSubPixelMeasurements)
                        {
                            subPixelInfo.TotalSubpixels = subpixels;
                            subPixelInfo.TotalReading = total;
                        }
                    }

                    if (data[x, y] >= m_SaturationValue) m_HasSaturatedPixels = true;

                }

            return Math.Round(total);
        }