当前位置: 首页>>代码示例>>C#>>正文


C# List.AsParallel方法代码示例

本文整理汇总了C#中System.Windows.Documents.List.AsParallel方法的典型用法代码示例。如果您正苦于以下问题:C# List.AsParallel方法的具体用法?C# List.AsParallel怎么用?C# List.AsParallel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.List的用法示例。


在下文中一共展示了List.AsParallel方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DrawFieldSprtDoIt

        private static void DrawFieldSprtDoIt(byte[] pixels, double[] ink, bool[] blocked, int size, byte[] colorZFront, byte[] colorZBack, AxisFor pixelX, AxisFor pixelY, AxisFor pixelZ)
        {
            List<Mapping_2D_1D> flattened = new List<Mapping_2D_1D>();

            // Setup the pixel array
            //for (int y2D = pixelY.Start; pixelY.IsPos ? y2D <= pixelY.Stop : y2D >= pixelY.Stop; y2D += pixelY.Increment)
            foreach (int y2D in pixelY.Iterate())
            {
                int offsetY = pixelY.GetValueForOffset(y2D) * size;

                //for (int x2D = pixelX.Start; pixelX.IsPos ? x2D <= pixelX.Stop : x2D >= pixelX.Stop; x2D += pixelX.Increment)
                foreach (int x2D in pixelX.Iterate())
                {
                    int offset = offsetY + pixelX.GetValueForOffset(x2D);

                    flattened.Add(new Mapping_2D_1D(x2D, y2D, offset));
                }
            }

            // Each pixel of the output bitmap can be added up independently, so employ some threading
            flattened.AsParallel().ForAll(o =>
                {
                    //TODO: Color is 6.5 times slower than byte array
                    List<byte[]> colorColumn = new List<byte[]>();

                    for (int z2D = pixelZ.Start; pixelZ.IsPos ? z2D <= pixelZ.Stop : z2D >= pixelZ.Stop; z2D += pixelZ.Increment)
                    {
                        int x = -1, y = -1, z = -1;
                        pixelX.Set3DIndex(ref x, ref y, ref z, o.X);
                        pixelY.Set3DIndex(ref x, ref y, ref z, o.Y);
                        pixelZ.Set3DIndex(ref x, ref y, ref z, z2D);

                        int index = FluidField3D.Get1DIndex(x, y, z, size);
                        if (blocked[index])
                        {
                            // Blocked cells are all white, so save the overlay method a bit of work, and throw out everything behind this
                            colorColumn.Clear();
                            colorColumn.Add(new byte[] { 255, 255, 255, 255 });
                            continue;
                        }

                        double inkCell = ink[index];

                        if (Math1D.IsNearZero(inkCell))
                        {
                            continue;
                        }

                        byte[] depthColor = UtilityWPF.AlphaBlend(colorZBack, colorZFront, UtilityCore.GetScaledValue_Capped(0, 1, 0, size - 1, z));

                        int alpha = Convert.ToInt32(Math.Round(inkCell * 255));
                        if (alpha < 0)
                        {
                            alpha = 0;
                        }
                        else if (alpha > 255)
                        {
                            alpha = 255;
                        }

                        colorColumn.Add(new byte[] { Convert.ToByte(alpha), depthColor[1], depthColor[2], depthColor[3] });
                    }

                    byte[] color = colorColumn.Count > 0 ? UtilityWPF.OverlayColors(colorColumn) : new byte[] { 0, 0, 0, 0 };

                    pixels[o.Offset1D * 4 + 0] = color[3];   // Blue
                    pixels[o.Offset1D * 4 + 1] = color[2];     // Green
                    pixels[o.Offset1D * 4 + 2] = color[1];     // Red
                    pixels[o.Offset1D * 4 + 3] = color[0];   // Alpha
                });
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:71,代码来源:FluidPainter3D.xaml.cs

示例2: GetDelaunayResults_FixedSet_Power

        private static Task<Tuple<int, int, int>[]> GetDelaunayResults_FixedSet_Power(int maxPoints, int numRunsPerPointCount, double brainIORatio, Func<Point3D> getRandomPoint)
        {
            const int LINEARTO = 15;
            const int NONLINEARSAMPLES = 15;

            List<int> samplePoints = new List<int>();

            // The first set should increment by 1
            samplePoints.AddRange(Enumerable.Range(1, Math.Min(LINEARTO, maxPoints)));

            // The second set should increment faster and faster
            if (maxPoints > LINEARTO)
            {
                double step = 1d / NONLINEARSAMPLES;
                double current = step;

                while (current <= 1d)
                {
                    double percent = Math.Pow(current, 2);
                    current += step;

                    int samplePoint = LINEARTO + (percent * (maxPoints - LINEARTO)).ToInt_Round();

                    if (!samplePoints.Contains(samplePoint))
                    {
                        samplePoints.Add(samplePoint);
                    }
                }
            }

            return Task.Run(() => samplePoints.
                AsParallel().
                SelectMany(o => GetDelaunayResults_Run(o, numRunsPerPointCount, brainIORatio, getRandomPoint)).
                ToArray());
        }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:35,代码来源:MissileCommand0D.xaml.cs


注:本文中的System.Windows.Documents.List.AsParallel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。