SharpNeat.Domains.BoxesVisualDiscrimination.TestCaseField.GetPixel C# (CSharp) Method

GetPixel() public method

Gets the value of the pixel at a position in the 'real/sensor' coordinate space (continuous x and y, -1 to 1).
public GetPixel ( double x, double y ) : double
x double
y double
return double
        public double GetPixel(double x, double y)
        {
            // Quantize real position to test field pixel coords.
            int pixelX = (int)(((x + 1.0) * TestFieldResolution) / 2.0);
            int pixelY = (int)(((y + 1.0) * TestFieldResolution) / 2.0);

            // Test for intersection with small box pixel.
            if(_smallBoxTopLeft._x == pixelX && _smallBoxTopLeft._y == pixelY) {
                return 1.0;
            }

            // Test for intersection with large box pixel.
            int deltaX = pixelX - _largeBoxTopLeft._x;
            int deltaY = pixelY - _largeBoxTopLeft._y;
            return (deltaX > -1 && deltaX < 3 && deltaY > -1 && deltaY < 3) ? 1.0 : 0.0;
        }

Usage Example

コード例 #1
0
        /// <summary>
        /// Apply the provided test case to the provided black box's inputs (visual input field).
        /// </summary>
        public static void ApplyVisualFieldToBlackBox(TestCaseField testCaseField, IBlackBox box, int visualFieldResolution, double visualOriginPixelXY, double visualPixelSize)
        {
            int    inputIdx = 0;
            double yReal    = visualOriginPixelXY;

            for (int y = 0; y < visualFieldResolution; y++, yReal += visualPixelSize)
            {
                double xReal = visualOriginPixelXY;
                for (int x = 0; x < visualFieldResolution; x++, xReal += visualPixelSize, inputIdx++)
                {
                    box.InputSignalArray[inputIdx] = testCaseField.GetPixel(xReal, yReal);
                }
            }
        }