/// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="field"></param>
        /// <param name="getColor"></param>
        /// <param name="parallel"></param>
        /// <returns></returns>
        public static PointCloud ToPointCloud <T>(this IDiscreteField3d <T> field, Func <T, Color> getColor, bool parallel = false)
            where T : struct
        {
            var cloud = new PointCloud(field.Coordinates.Select(p => new Point3d(p.X, p.Y, 0.0)));

            if (parallel)
            {
                Parallel.ForEach(Partitioner.Create(0, field.Count), range => Body(range.Item1, range.Item2));
            }
            else
            {
                Body(0, field.Count);
            }

            void Body(int from, int to)
            {
                var vals = field.Values;

                for (int i = from; i < to; i++)
                {
                    cloud[i].Color = getColor(vals[i]);
                }
            }

            return(cloud);
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="field"></param>
        /// <param name="other"></param>
        /// <param name="converter"></param>
        /// <param name="parallel"></param>
        public static void Sample <T, U>(this IDiscreteField3d <T> field, IField3d <U> other, Func <U, T> converter, bool parallel = false)
        {
            var vals = field.Values;

            Action <Tuple <int, int> > body = range =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    vals[i] = converter(other.ValueAt(field.CoordinateAt(i)));
                }
            };

            if (parallel)
            {
                Parallel.ForEach(Partitioner.Create(0, field.Count), body);
            }
            else
            {
                body(Tuple.Create(0, field.Count));
            }
        }
예제 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="U"></typeparam>
        /// <param name="field"></param>
        /// <param name="other"></param>
        /// <param name="converter"></param>
        /// <param name="parallel"></param>
        public static void Sample <T, U>(this IDiscreteField3d <T> field, IField3d <U> other, Func <U, T> converter, bool parallel = false)
        {
            if (parallel)
            {
                Parallel.ForEach(Partitioner.Create(0, field.Count), range => Body(range.Item1, range.Item2));
            }
            else
            {
                Body(0, field.Count);
            }

            void Body(int from, int to)
            {
                var vals = field.Values;

                for (int i = from; i < to; i++)
                {
                    vals[i] = converter(other.ValueAt(field.CoordinateAt(i)));
                }
            }
        }
예제 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="field"></param>
 /// <returns></returns>
 public static IDiscreteField3d <T> Duplicate <T>(this IDiscreteField3d <T> field)
     where T : struct
 {
     return(field.Duplicate(true));
 }