internal static void ConvolutionalLayer2D(Index2 currentInput, ArrayView3D <float> weights, ArrayView2D <float> error, ArrayView2D <float> activatedPreviousLayer, ArrayView2D <float> bias, ArrayView <float> variables)
        {
            int   radius   = (int)variables[new Index1(2)];
            int   diameter = radius * 2 + 1;
            var   fac      = error[currentInput] * variables[new Index1(0)];
            float xBounds  = error.Extent.X;
            float yBounds  = error.Extent.Y;

            bias[currentInput] -= fac;
            var baseIndex = new Index2(currentInput.X - radius, currentInput.Y - radius);

            for (int i = 0; i < diameter; i++)
            {
                for (int j = 0; j < diameter; j++)
                {
                    var asosInput = baseIndex.Add(new Index2(i, j));
                    if (asosInput.X < xBounds & asosInput.X >= 0 & asosInput.Y >= 0 & asosInput.Y < yBounds)
                    {
                        var adjustment = fac * activatedPreviousLayer[asosInput];
                        var d          = activatedPreviousLayer[asosInput];
                        if (float.IsNaN(adjustment) | float.IsInfinity(adjustment))
                        {
                            ;
                        }
                        weights[new Index3(currentInput, i * diameter + j)] -= adjustment;
                    }
                }
            }
        }
예제 #2
0
        private static void strategy(Index1 index, ArrayView3D <byte> destBuffer, Index2 offset,
                                     int rWidth, int rHeight, ArrayView <byte> color)
        {
            if (index <= rWidth)
            {
                Index2 indw0 = offset + new Index2(index, 0);
                Index2 indw1 = indw0 + new Index2(0, rHeight);

                for (int i = 0; i < color.Length; i++)
                {
                    destBuffer[new Index3(i, indw0)] = color[i];
                    destBuffer[new Index3(i, indw1)] = color[i];
                }
            }
            if (index <= rHeight)
            {
                Index2 indh0 = offset + new Index2(0, index);
                Index2 indh1 = indh0 + new Index2(rWidth, 0);

                for (int i = 0; i < color.Length; i++)
                {
                    destBuffer[new Index3(i, indh0)] = color[i];
                    destBuffer[new Index3(i, indh1)] = color[i];
                }
            }
        }
예제 #3
0
        internal static void ConvolutionalLayer2D(Index2 currentInput, ArrayView3D <float> weight, ArrayView2D <float> outputPreviousLayerActivated, ArrayView2D <float> sumInput, ArrayView2D <float> bias, ArrayView <float> variables)
        {
            int   radius    = (int)variables[new Index1(1)];
            int   diameter  = radius * 2 + 1;
            var   baseIndex = new Index2(currentInput.X - radius, currentInput.Y - radius);
            var   xBounds   = outputPreviousLayerActivated.Extent.X;
            var   yBounds   = outputPreviousLayerActivated.Extent.Y;
            float sum       = bias[currentInput];

            for (int i = 0; i < diameter; i++)
            {
                for (int j = 0; j < diameter; j++)
                {
                    var asosInput = baseIndex.Add(new Index2(i, j));
                    if (asosInput.X < xBounds & asosInput.X >= 0 & asosInput.Y >= 0 & asosInput.Y < yBounds)
                    {
                        sum += weight[new Index3(currentInput, i * diameter + j)] * outputPreviousLayerActivated[asosInput];
                        var w = weight[new Index3(currentInput, i * diameter + j)]; var oA = outputPreviousLayerActivated[asosInput];
                        if (float.IsNaN(w * oA) | float.IsInfinity(w * oA))
                        {
                            ;
                        }
                    }
                }
            }
            sumInput[currentInput] = sum;
            if (float.IsNaN(sum) | float.IsInfinity(sum))
            {
                ;
            }
        }
예제 #4
0
        //static readonly float[,] sobelXKern = new float[3, 3]
        //{
        //    { -1,0,1 },
        //    { -2,0,2 },
        //    { -1,0,1 }
        //};

        //static readonly float[,] sobelYKern = new float[3, 3]
        //{
        //    { -1,-2,-1 },
        //    { 0, 0, 0 },
        //    { 1, 2, 1 }
        //};

        #region Sobel
        public static void CalculateHorizontalSobel(Index2 index, ArrayView3D <short> result, ArrayView3D <short> image)
        {
            if (index.X == 0 || index.Y == 0 ||
                index.X == image.Width - 1 || index.Y == image.Height - 1)
            {
                for (int i = 0; i < image.Depth; i++)
                {
                    result[index.X, index.Y, i] = 32000;
                }
                return;
            }

            for (int i = 0; i < image.Depth; i++)
            {
                var   kern = image.GetSliceView(i).GetSubView(new Index2(index.X - 1, index.Y - 1), new Index2(3, 3));
                short val  = 0;

                val += (short)(kern[0, 0] * -1);
                val += (short)(kern[2, 0] * 1);
                val += (short)(kern[0, 1] * -2);
                val += (short)(kern[2, 1] * 2);
                val += (short)(kern[0, 2] * -1);
                val += (short)(kern[2, 2] * 1);

                result[index.X, index.Y, i] = val;
            }
        }
예제 #5
0
        public static void CalculateVerticalSobel(Index2 index, ArrayView3D <short> result, ArrayView3D <short> image)
        {
            if (index.X == 0 || index.Y == 0 ||
                index.X == image.Width - 1 || index.Y == image.Height - 1)
            {
                for (int i = 0; i < image.Depth; i++)
                {
                    result[index.X, index.Y, i] = 30000;
                }
                return;
            }

            //var sobelYKern = new short[3, 3]
            //{
            //    { -1,-2,-1 },
            //    { 0, 0, 0 },
            //    { 1, 2, 1 }
            //};

            for (int i = 0; i < image.Depth; i++)
            {
                var   kern = image.GetSubView(new Index3(index.X - 1, index.Y - 1, i), new Index3(3, 3, 1)).GetSliceView(0);
                short val  = 0;

                val += (short)(kern[0, 0] * -1);
                val += (short)(kern[1, 0] * -2);
                val += (short)(kern[2, 0] * -1);
                val += (short)(kern[0, 2] * 1);
                val += (short)(kern[1, 2] * 2);
                val += (short)(kern[2, 2] * 1);
                result[index.X, index.Y, i] = val;
            }
        }
        public static uint[] AccumulateEdges(ArrayView3D <short> imageShortView, ArrayView3D <byte> imageByteView, byte[] cannyData, byte pearsonThreshold, short maxValue)
        {
            uint[] result;

            var pearsonData     = CalculationWrappers.CalculatePearsonCorrelation(imageByteView, 0, pearsonThreshold).rawPicture;
            var signLengthByte  = CalculateSignatureLengthDerivative(imageByteView, true).rawPicture;
            var signLengthShort = CalculateSignatureLengthDerivative(imageShortView, true, maxValue).rawPicture;

            var picIndex = imageByteView.GetSliceView(0).Extent;

            using (var pearsBuffer = GpuContext.Instance.Accelerator.Allocate <byte>(picIndex))
                using (var signLengthByteBuffer = GpuContext.Instance.Accelerator.Allocate <byte>(picIndex))
                    using (var signLengthShortBuffer = GpuContext.Instance.Accelerator.Allocate <byte>(picIndex))
                        using (var cannyBuffer = GpuContext.Instance.Accelerator.Allocate <byte>(picIndex))
                            using (var imgBuffer = GpuContext.Instance.Accelerator.Allocate <uint>(picIndex))
                            {
                                pearsBuffer.CopyFrom(pearsonData, 0, Index2.Zero, picIndex.Size);
                                signLengthByteBuffer.CopyFrom(signLengthByte, 0, Index2.Zero, picIndex.Size);
                                signLengthShortBuffer.CopyFrom(signLengthShort, 0, Index2.Zero, picIndex.Size);
                                cannyBuffer.CopyFrom(cannyData, 0, Index2.Zero, picIndex.Size);

                                _accumulateEdgesKernel(picIndex, imgBuffer.View, pearsBuffer.View, cannyBuffer.View, signLengthByteBuffer.View, signLengthShortBuffer.View);
                                GpuContext.Instance.Accelerator.Synchronize();

                                result = imgBuffer.GetAsArray();
                            }

            return(result);
        }
        public static uint[] GetSobelMap(Index2 index, ArrayView3D <short> imageView)
        {
            var horizontalSobelKernel = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index2, ArrayView3D <short>, ArrayView3D <short> >(Kernels.CalculateHorizontalSobel);
            var verticalSobelKernel   = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index2, ArrayView3D <short>, ArrayView3D <short> >(Kernels.CalculateVerticalSobel);
            var accumulateSobelKernel = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index3, ArrayView3D <short>, ArrayView3D <short>, ArrayView3D <short> >(Kernels.AccumulateSobelMap);
            var calculateSobelKernel  = GpuContext.Instance.Accelerator.LoadAutoGroupedStreamKernel <Index2, ArrayView2D <short>, ArrayView3D <short> >(Kernels.CalculateSobel);

            uint[] result;

            using (var bufHor = GpuContext.Instance.Accelerator.Allocate <short>(imageView.Extent))
                using (var bufVer = GpuContext.Instance.Accelerator.Allocate <short>(imageView.Extent))
                    using (var bufAccum = GpuContext.Instance.Accelerator.Allocate <short>(imageView.Extent))
                        using (var bufMap = GpuContext.Instance.Accelerator.Allocate <short>(index))
                            using (var bufOut2 = GpuContext.Instance.Accelerator.Allocate <uint>(index))
                            {
                                horizontalSobelKernel(index, bufHor.View, imageView);
                                GpuContext.Instance.Accelerator.Synchronize();
                                verticalSobelKernel(index, bufVer.View, imageView);
                                GpuContext.Instance.Accelerator.Synchronize();
                                accumulateSobelKernel(bufAccum.Extent, bufAccum.View, bufHor.View, bufVer.View);
                                GpuContext.Instance.Accelerator.Synchronize();
                                calculateSobelKernel(index, bufMap.View, bufAccum.View);
                                GpuContext.Instance.Accelerator.Synchronize();

                                PiсConvertKernel(index.Size, bufOut2.AsLinearView(), bufMap.AsLinearView(), 1, 0);
                                GpuContext.Instance.Accelerator.Synchronize();

                                result = bufOut2.GetAsArray();
                            }

            return(result);
        }
        private static void strategyBestEach(Index1 index, ArrayView3D <int> palres)
        {
            int min     = palres.Extent.Z;
            int ind     = 0;
            int changed = 0;

            for (int i = 0; i < palres.Extent.Y; i++)
            {
                if (index != i && palres[index, i, 0] < min && palres[index, i, 0] >= 0)
                {
                    min     = palres[index, i, 0];
                    ind     = i;
                    changed = 1;
                }
            }

            if (changed == 1)
            {
                palres[index, index, 0] = ind;
                palres[index, index, 1] = min;
            }
            else
            {
                palres[index, index, 0] = -1;
            }
        }
        public static BrightnessCalculationData CalculateBrightnessStats(ArrayView3D <short> imageView, BrightnessCalculationData output)
        {
            using (var meanBrightnessBuf = GpuContext.Instance.Accelerator.Allocate <double>(imageView.Depth))
                using (var maxBrightnessBuf = GpuContext.Instance.Accelerator.Allocate <short>(imageView.Depth))
                    using (var deviationBuf = GpuContext.Instance.Accelerator.Allocate <double>(imageView.Depth))
                    {
                        _calcStatsKernel(imageView.Depth, imageView, meanBrightnessBuf.View, maxBrightnessBuf.View, deviationBuf.View);
                        GpuContext.Instance.Accelerator.Synchronize();

                        var max    = maxBrightnessBuf.GetAsArray().Max();
                        var dMax   = (int)deviationBuf.GetAsArray().Max();
                        var height = Math.Max(max, dMax) + 1;
                        output.imageSize = new Index2(1000, 1000);
                        double scale = 1000 / (double)height;

                        using (var imageBuf = GpuContext.Instance.Accelerator.Allocate <int>(output.imageSize))
                        {
                            _memSetKernel(output.imageSize.Size, imageBuf.AsLinearView(), ColorConsts.Black);
                            GpuContext.Instance.Accelerator.Synchronize();

                            _calcMapKernel(imageView.Depth, meanBrightnessBuf.View, maxBrightnessBuf.View, deviationBuf.View, imageBuf.View, ColorConsts.Red, ColorConsts.Blue, ColorConsts.Green, scale);
                            GpuContext.Instance.Accelerator.Synchronize();

                            output.arrImage             = imageBuf.GetAsArray();
                            output.arrMeanBrightness    = meanBrightnessBuf.GetAsArray();
                            output.arrMaxBrightness     = maxBrightnessBuf.GetAsArray();
                            output.arrStandardDeviation = deviationBuf.GetAsArray();
                        }
                    }

            return(output);
        }
예제 #10
0
        public static double PearsonSobelCorrelation(ArrayView3D <byte> bufIn, Index2 pixel1, Index2 pixel2)
        {
            var   minLength = bufIn.Depth;
            int   sum1 = 0, sum2 = 0;
            float mean1 = 0, mean2 = 0;

            for (int i = 0; i < minLength; i++)
            {
                short x = bufIn[pixel1.X, pixel1.Y, i];
                short y = bufIn[pixel2.X, pixel2.Y, i];
                sum1 += x;
                sum2 += y;
            }
            mean1 = sum1 / minLength;
            mean2 = sum2 / minLength;

            float covariation = 0;
            float xDerSqrSum  = 0;
            float yDerSqrSum  = 0;

            for (int i = 0; i < minLength; i++)
            {
                short x = bufIn[pixel1.X, pixel1.Y, i];
                short y = bufIn[pixel2.X, pixel2.Y, i];

                float xDer = x - mean1;
                float yDer = y - mean2;

                covariation += xDer * yDer;
                xDerSqrSum  += xDer * xDer;
                yDerSqrSum  += yDer * yDer;
            }

            return(covariation / XMath.Sqrt(xDerSqrSum * yDerSqrSum));
        }
        public static void CalculateSignatureLengthDerivative(Index2 index, ArrayView3D <float> output, ArrayView3D <byte> input)
        {
            var x = index.X;
            var y = index.Y;

            if (x == 0)
            {
                x = 1;
            }
            if (x == input.Width - 1)
            {
                x = input.Width - 2;
            }
            if (y == 0)
            {
                y = 1;
            }
            if (y == input.Height - 1)
            {
                y = input.Height - 2;
            }

            var depth = input.Depth;

            float xDiffComponentSum = 0;
            float yDiffComponentSum = 0;

            for (int i = 0; i < depth; i++)
            {
                var val1 = input[x - 1, y, i]; if (val1 < 0)
                {
                    val1 = 0;
                }
                var val2 = input[x + 1, y, i]; if (val2 < 0)
                {
                    val1 = 0;
                }
                var xDiff = val2 - val1;
                xDiffComponentSum += xDiff * xDiff;

                val1 = input[x, y - 1, i]; if (val1 < 0)
                {
                    val1 = 0;
                }
                val2 = input[x, y + 1, i]; if (val2 < 0)
                {
                    val1 = 0;
                }
                var yDiff = val2 - val1;
                yDiffComponentSum += yDiff * yDiff;
            }

            var xDiffLength = XMath.Sqrt(xDiffComponentSum);
            var yDiffLength = XMath.Sqrt(yDiffComponentSum);

            output[index.X, index.Y, 0] = xDiffLength;
            output[index.X, index.Y, 1] = yDiffLength;
            output[index.X, index.Y, 2] = XMath.Max(xDiffLength, yDiffLength);
        }
예제 #12
0
        public static PicturesData CalculateSignatureLengthDerivative(ArrayView3D <byte> imageView, bool normalize)
        {
            PicturesData result   = new PicturesData();
            var          slice    = imageView.GetSliceView(0);
            var          picIndex = new Index3(slice.Extent.X, slice.Extent.Y, 3);

            using (var calcBuffer = GpuContext.Instance.Accelerator.Allocate <float>(picIndex))
                using (var byteBuf = GpuContext.Instance.Accelerator.Allocate <byte>(picIndex))
                    using (var imageBuffer = GpuContext.Instance.Accelerator.Allocate <uint>(picIndex))
                    {
                        if (normalize)
                        {
                            BCalculateSignatureLengthDerivativeWithNormalizationKernel(slice.Extent, calcBuffer.View, imageView);
                        }
                        else
                        {
                            BCalculateSignatureLengthDerivativeKernel(slice.Extent, calcBuffer.View, imageView);
                        }
                        GpuContext.Instance.Accelerator.Synchronize();

                        var array    = calcBuffer.GetAsArray();
                        var maxBand1 = array.Take(slice.Extent.Size).Max();
                        var maxBand2 = array.Skip(slice.Extent.Size).Take(slice.Extent.Size).Max();
                        //var maxBand3 = array.Skip(slice.Extent.Size * 2).Max();
                        var maxBand3 = XMath.Max(maxBand1, maxBand2);

                        NormalizeLengthMapKernel(slice.Extent, calcBuffer, 0, maxBand1); GpuContext.Instance.Accelerator.Synchronize();
                        NormalizeLengthMapKernel(slice.Extent, calcBuffer, 1, maxBand2); GpuContext.Instance.Accelerator.Synchronize();
                        NormalizeLengthMapKernel(slice.Extent, calcBuffer, 2, maxBand3); GpuContext.Instance.Accelerator.Synchronize();

                        FloatToByteKernel(calcBuffer.Extent.Size, calcBuffer.AsLinearView(), byteBuf.AsLinearView());
                        GpuContext.Instance.Accelerator.Synchronize();

                        result.rawPicture = byteBuf.GetAsArray().Skip(slice.Extent.Size * 2).ToArray();


                        PinConvertFromByteKernel(slice.Extent.Size, imageBuffer.GetSliceView(0).AsLinearView(), byteBuf.GetSliceView(0).AsLinearView(), 1.0, 0);
                        PinConvertFromByteKernel(slice.Extent.Size, imageBuffer.GetSliceView(1).AsLinearView(), byteBuf.GetSliceView(1).AsLinearView(), 1.0, 0);
                        PinConvertFromByteKernel(slice.Extent.Size, imageBuffer.GetSliceView(2).AsLinearView(), byteBuf.GetSliceView(2).AsLinearView(), 1.0, 0);
                        GpuContext.Instance.Accelerator.Synchronize();

                        var img  = imageBuffer.GetAsArray();
                        var size = slice.Extent.Size;

                        var buf = new uint[size];
                        Array.Copy(img, 0, buf, 0, size);
                        result.xPicture = buf;

                        buf = new uint[size];
                        Array.Copy(img, size, buf, 0, size);
                        result.yPicture = buf;

                        buf = new uint[size];
                        Array.Copy(img, size * 2, buf, 0, size);
                        result.xyPicture = buf;
                    }

            return(result);
        }
예제 #13
0
파일: DebugViews.cs 프로젝트: m4rs-mt/ILGPU
        public DebugArrayView3D(ArrayView3D <T, TStride> source)
        {
            Extent = source.Extent;
            Stride = source.Stride;

            SyncDebuggerState(source.BaseView);
            Data = source.AsGeneral().GetAsArray3D();
        }
예제 #14
0
        private static void strategy(Index2 index, ArrayView3D <byte> destBuffer, Index2 offset, ArrayView <byte> color)
        {
            Index2 ind = index + offset;

            for (int i = 0; i < color.Length; i++)
            {
                destBuffer[new Index3(i, ind)] = color[i];
            }
        }
예제 #15
0
        public static void ConvertToByte(Index3 index, ArrayView3D <byte> output, ArrayView3D <short> input, short maxValue)
        {
            var val = input[index];

            val = XMath.Clamp(val, (short)0, maxValue);
            byte result = (byte)((val / (float)maxValue) * 255);

            output[index] = result;
        }
예제 #16
0
파일: ArrayViews.cs 프로젝트: rpfeuti/ILGPU
        internal static void ArrayViewMultidimensionalAccessKernel(
            Index1D index,
            ArrayView3D <int, Stride3D.DenseXY> data,
            ArrayView3D <int, Stride3D.DenseXY> source)
        {
            var reconstructedIndex = data.Extent.ReconstructIndex(index);

            data[reconstructedIndex] = source[reconstructedIndex];
        }
예제 #17
0
        public static CorrelationData CalculatePearsonCorrelation(ArrayView3D <byte> imageView, byte lowThreshold = 0, byte highThreshold = 0)
        {
            var result = new CorrelationData();

            var slice      = imageView.GetSliceView(0);
            var comboSlice = new Index3(slice.Width, slice.Height, 3);

            using (var calcBuf = GpuContext.Instance.Accelerator.Allocate <float>(comboSlice))
                using (var byteBuf = GpuContext.Instance.Accelerator.Allocate <byte>(comboSlice))
                    using (var imageBuf = GpuContext.Instance.Accelerator.Allocate <uint>(comboSlice))
                    {
                        PearsonKernel(slice.Extent, calcBuf.View, imageView);
                        GpuContext.Instance.Accelerator.Synchronize();

                        var maxCorrelation = calcBuf.GetAsArray().Max();
                        NormalizeKernel(calcBuf.Extent.Size, calcBuf.AsLinearView(), maxCorrelation);
                        GpuContext.Instance.Accelerator.Synchronize();

                        var maxGradientValue = calcBuf.GetAsArray().Skip(slice.Extent.Size).Take(slice.Extent.Size).Max();
                        NormalizeKernel(slice.Extent.Size, calcBuf.GetSliceView(1).AsLinearView(), maxGradientValue);
                        GpuContext.Instance.Accelerator.Synchronize();

                        FloatToByteKernel(calcBuf.Extent.Size, calcBuf.AsLinearView(), byteBuf.AsLinearView());
                        GpuContext.Instance.Accelerator.Synchronize();

                        if (highThreshold != 0 || lowThreshold != 0)
                        {
                            ThresholdingKernel(byteBuf.Extent.Size, byteBuf.AsLinearView(), lowThreshold, highThreshold);
                            GpuContext.Instance.Accelerator.Synchronize();
                        }

                        result.rawPicture = byteBuf.GetAsArray().Skip(slice.Extent.Size * 2).ToArray();

                        PiсConvertFromByteKernel(slice.Extent.Size, imageBuf.GetSliceView(0).AsLinearView(), byteBuf.GetSliceView(0).AsLinearView(), 1.0, 0);
                        PiсConvertFromByteKernel(slice.Extent.Size, imageBuf.GetSliceView(1).AsLinearView(), byteBuf.GetSliceView(1).AsLinearView(), 1.0, 0);
                        PiсConvertFromByteKernel(slice.Extent.Size, imageBuf.GetSliceView(2).AsLinearView(), byteBuf.GetSliceView(2).AsLinearView(), 1.0, 0);
                        GpuContext.Instance.Accelerator.Synchronize();

                        var img  = imageBuf.GetAsArray();
                        var size = slice.Extent.Size;

                        var buf = new uint[size];
                        Array.Copy(img, 0, buf, 0, size);
                        result.xCorrelation = buf;

                        buf = new uint[size];
                        Array.Copy(img, size, buf, 0, size);
                        result.yCorrelation = buf;

                        buf = new uint[size];
                        Array.Copy(img, size * 2, buf, 0, size);
                        result.xyCorrelation = buf;
                    }

            return(result);
        }
예제 #18
0
        public static void CalculateHistogram(Index3 index, ArrayView <int> result, ArrayView3D <short> input)
        {
            var val = input[index];

            if (val < 0)
            {
                val = 0;
            }
            Atomic.Add(ref result[(int)val], 1);
        }
예제 #19
0
        public static short Magnitude(ArrayView3D <short> a, Index2 index)
        {
            var extent = a.Depth;
            int sum    = 0;

            for (int i = 0; i < extent; i++)
            {
                sum = (int)XMath.Pow(a[index.X, index.Y, i], 2);
            }
            return((short)XMath.Sqrt(sum));
        }
 internal static void AlternateWeights(Index2 currentInput, ArrayView3D <float> weight, ArrayView3D <float> newWeights)
 {
     for (int z = 0; z < weight.Extent.Z; z++)
     {
         var index = new Index3(currentInput, z);
         if (newWeights[index] != 0f)
         {
             weight[index] = newWeights[index];
         }
     }
 }
 internal static void AlternateConnections(Index2 currentInput, ArrayView3D <int> connectionInfo, ArrayView3D <int> newConnenctionInfo)
 {
     for (int z = 0; z < connectionInfo.Extent.Z; z++)
     {
         var index = new Index3(currentInput, z);
         if (newConnenctionInfo[index] != 0f)
         {
             connectionInfo[index] = newConnenctionInfo[index];
         }
     }
 }
예제 #22
0
 public dVoxelChunk(AABB aabb, Vec3 position, int width, int depth, int height, int maxViewDist, ArrayView3D <int> tiles, ArrayView <int> tileMaterialIDs)
 {
     this.aabb            = aabb;
     this.position        = position;
     this.width           = width;
     this.depth           = depth;
     this.height          = height;
     this.maxViewDist     = maxViewDist;
     this.tiles           = tiles;
     this.tileMaterialIDs = tileMaterialIDs;
 }
예제 #23
0
        public static uint[] PictureConvertion(ArrayView3D <byte> imageView, int band, double mult, short min)
        {
            uint[] result;
            using (var bufOut = GpuContext.Instance.Accelerator.Allocate <uint>(imageView.Width * imageView.Height))
            {
                PiсConvertFromByteKernel(bufOut.Length, bufOut.View, imageView.GetSliceView(band - 1).AsLinearView(), mult, min);
                GpuContext.Instance.Accelerator.Synchronize();
                result = bufOut.GetAsArray();
            }

            return(result);
        }
        internal static void Calculate(Index2 currentInput, ArrayView3D <float> weight, ArrayView3D <int> connectionInfo, ArrayView2D <float> outputPreviousLayerActivated, ArrayView2D <float> sumInput, ArrayView2D <float> bias, ArrayView <float> variables)
        {
            float sum = bias[currentInput];

            for (int i = 0; i < connectionInfo.Extent.Z; i += 2)
            {
                int x = connectionInfo[new Index3(currentInput, i)];
                int y = connectionInfo[new Index3(currentInput, i + 1)];
                sum += outputPreviousLayerActivated[new Index2(x, y)] * weight[new Index3(currentInput, i / 2)];
            }
            sumInput[currentInput] = sum;
        }
        private static void strategy(Index2 index, ArrayView3D <byte> destBuffer, ArrayView3D <byte> srcBuffer,
                                     Index2 dstOffset, Index2 srcOffset, int ColorSize, ArrayView <byte> BitChecker,
                                     int Zoom, ArrayView <byte> BackgroundColor)
        {
            bool change = true;
            byte b      = 0;

            for (int i = 0; i < ColorSize; i++)
            {
                b = BitChecker[i];
                if (change && BitChecker[i] != 0 &&
                    (srcBuffer[new Index3(i, index + srcOffset)] & b) != 0)
                {
                    change = false;
                }
            }

            if (!change && BackgroundColor.Length != ColorSize)
            {
                return;
            }

            Index2 off = dstOffset + (index * Zoom);

            if (change)
            {
                Index2 srcOff = index + srcOffset;
                for (int x = 0; x < Zoom; x++)
                {
                    for (int y = 0; y < Zoom; y++)
                    {
                        for (int i = 0; i < ColorSize; i++)
                        {
                            destBuffer[new Index3(i, off + new Index2(x, y))] = srcBuffer[new Index3(i, srcOff)];
                        }
                    }
                }
            }
            else
            {
                for (int x = 0; x < Zoom; x++)
                {
                    for (int y = 0; y < Zoom; y++)
                    {
                        for (int i = 0; i < ColorSize; i++)
                        {
                            destBuffer[new Index3(i, off + new Index2(x, y))] = BackgroundColor[i];
                        }
                    }
                }
            }
        }
예제 #26
0
 public static void CalculateSlices(Index index, ArrayView2D <uint> result, ArrayView3D <short> input, int row, int column)
 {
     for (int i = 0; i < input.Width; i++)
     {
         uint val = (uint)(input[i, row, index.X] / 9000f * 255);
         result[i + 1 /*+ index.X*/, input.Depth /*- index.X*/] = (uint)((val) + (val << 8) + (val << 16) + (255 << 24));
     }
     for (int i = 0; i < input.Height; i++)
     {
         uint val = (uint)(input[column, i, index.X] / 9000f * 255);
         result[input.Width /*+ index.X*/, input.Depth - 1 /*- index.X*/ + i] = (uint)((val) + (val << 8) + (val << 16) + (255 << 24));
     }
 }
예제 #27
0
        internal static void FullyConnectedLayer2D(Index2 currentInput, ArrayView3D <float> weights, ArrayView2D <float> outputsPreviousLayerActivated, ArrayView2D <float> sumInput, ArrayView2D <float> bias, ArrayView <float> variables)
        {
            float sum = bias[currentInput];

            for (int x = 0; x < outputsPreviousLayerActivated.Width; x++)
            {
                for (int y = 0; y < outputsPreviousLayerActivated.Height; y++)
                {
                    sum += weights[new Index3(currentInput, x * y + x)] * outputsPreviousLayerActivated[new Index2(x, y)];
                }
            }
            sumInput[currentInput] = sum;
        }
        private static void strategyReduceColors(Index1 index, ArrayView3D <int> palres, ArrayView3D <int> palres2, ArrayView2D <int> palsBuff, ArrayView2D <int> indsbuff, ArrayView2D <int> tilesPerPalBuff)
        {
            int i1 = indsbuff[index, 0];
            int i2 = indsbuff[index, 1];

            for (int i = 0; i < palsBuff.Extent.Y; i++)
            {
                palsBuff[i1, i] = palres[i1, i2, i + 1];
            }
            for (int i = 0; i < tilesPerPalBuff.Extent.Y; i++)
            {
                tilesPerPalBuff[i1, i] = palres2[i1, i2, i];
            }
        }
예제 #29
0
        public static void Execute(Index3 index, ArrayView3D <byte> destBuffer, byte[] color)
        {
            if (color == null)
            {
                throw new ArgumentNullException(nameof(color));
            }

            using (MemoryBuffer <byte> c = HardwareAcceleratorManager.GPUAccelerator.Allocate <byte>(color.Length))
            {
                c.CopyFrom(color, 0, 0, color.Length);
                kernel(index, destBuffer, c);
                HardwareAcceleratorManager.GPUAccelerator.Synchronize();
            }
        }
        internal static void FullyConnectedLayer2D(Index2 currentInput, ArrayView3D <float> weights, ArrayView2D <float> error, ArrayView2D <float> activatedPreviousLayer, ArrayView2D <float> bias, ArrayView <float> variables)
        {
            var fac = error[currentInput] * variables[new Index1(0)];

            bias[currentInput] -= fac;
            for (int x = 0; x < activatedPreviousLayer.Width; x++)
            {
                for (int y = 0; y < activatedPreviousLayer.Height; y++)
                {
                    Index2 asosIndex  = new Index2(x, y);
                    var    adjustment = fac * activatedPreviousLayer[asosIndex];
                    weights[new Index3(currentInput, x * y + x)] -= adjustment;
                }
            }
        }