Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="image"></param>
        /// <param name="mapper"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public GridField2d <T> CreateFromImage(Bitmap image, Func <Color, T> mapper)
        {
            var result = Create(image.Width, image.Height);

            FieldIO.ReadFromImage(image, result, mapper);
            return(result);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="field"></param>
 /// <param name="path"></param>
 /// <param name="mapper"></param>
 public static void SaveAsImage(GridField2d <T> field, string path, Func <T, Color> mapper)
 {
     using (Bitmap bmp = new Bitmap(field.CountX, field.CountY, PixelFormat.Format32bppArgb))
     {
         FieldIO.WriteToImage(field, bmp, mapper);
         bmp.Save(path);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="images"></param>
        /// <param name="mapper"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public GridField3d <T> CreateFromImageStack(IList <Bitmap> images, Func <Color, T> mapper)
        {
            var bmp0   = images[0];
            var result = Create(bmp0.Width, bmp0.Height, images.Count);

            FieldIO.ReadFromImageStack(images, result, mapper);
            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="mapper"></param>
        /// <param name="origin"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        public static GridScalarField2d CreateFromImage(Bitmap bitmap, Func <Color, double> mapper, Vec2d origin, Vec2d scale)
        {
            int nx = bitmap.Width;
            int ny = bitmap.Height;

            var result = new GridScalarField2d(origin, scale, nx, ny);

            FieldIO.ReadFromImage(bitmap, result, mapper);

            return(result);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmap"></param>
        /// <param name="mapper"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static GridScalarField2d CreateFromImage(Bitmap bitmap, Func <Color, double> mapper, Interval2d interval)
        {
            int nx = bitmap.Width;
            int ny = bitmap.Height;

            var result = new GridScalarField2d(interval, nx, ny);

            FieldIO.ReadFromImage(bitmap, result, mapper);

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="bitmaps"></param>
        /// <param name="mapper"></param>
        /// <param name="interval"></param>
        /// <returns></returns>
        public static GridVectorField3d CreateFromImageStack(IList <Bitmap> bitmaps, Func <Color, Vec3d> mapper, Interval3d interval)
        {
            var bmp0 = bitmaps[0];
            int nx   = bmp0.Width;
            int ny   = bmp0.Height;
            int nz   = bitmaps.Count;

            var result = new GridVectorField3d(interval, nx, ny, nz);

            FieldIO.ReadFromImageStack(bitmaps, result, mapper);

            return(result);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="field"></param>
        /// <param name="path"></param>
        /// <param name="mapper"></param>
        public static void SaveAsImageStack(GridField3d <T> field, string path, Func <T, Color> mapper)
        {
            string dir  = Path.GetDirectoryName(path);
            string name = Path.GetFileNameWithoutExtension(path);
            string ext  = Path.GetExtension(path);

            Parallel.For(0, field.CountZ, z =>
            {
                using (Bitmap bmp = new Bitmap(field.CountX, field.CountY, PixelFormat.Format32bppArgb))
                {
                    FieldIO.WriteToImage(field, z, bmp, mapper);
                    bmp.Save(String.Format(@"{0}\{1}_{2}{3}", dir, name, z, ext));
                }
            });
        }