Пример #1
0
        static Bitmap BitmapFromVtkVoxels(VtkVoxels vtkVoxels, int plane)
        {
            int xsize = vtkVoxels.XSize;
            int ysize = vtkVoxels.YSize;
            int zsize = vtkVoxels.ZSize;

            byte[] pixels = new byte[xsize * 4 * ysize];

            int i = 0;

            for (int y = 0; y < ysize; y++)
            {
                for (int x = 0; x < xsize; x++)
                {
                    int   hu  = vtkVoxels.Voxels[plane][x, y];
                    Color col = colormap_[hu + colormapOffset_];
                    pixels[i++] = col.B;
                    pixels[i++] = col.G;
                    pixels[i++] = col.R;
                    pixels[i++] = col.A;
                }
            }
            Bitmap bmp = new Bitmap(xsize, ysize, xsize * 4, System.Drawing.Imaging.PixelFormat.Format32bppArgb,
                                    GCHandle.Alloc(pixels, GCHandleType.Pinned).AddrOfPinnedObject());

            return(bmp);
        }
Пример #2
0
        public static VtkVoxels ReadVtkGrid(string inputFile)
        {
            VtkVoxels vtkVoxels = new VtkVoxels();

            vtkVoxels.Voxels = new List <int[, ]>();

            using (TextReader reader = new StreamReader(inputFile))
            {
                string line;
                Match  match;

                // # vtk DataFile Version 3.0
                line = reader.ReadLine();
                // vtk output
                line = reader.ReadLine();
                // ASCII
                line = reader.ReadLine();
                // DATASET STRUCTURED_POINTS
                line = reader.ReadLine();

                // DIMENSIONS 548 548 200
                line  = reader.ReadLine();
                match = Regex.Match(line, "DIMENSIONS (.*) (.*) (.*)");
                int xsize = Int32.Parse(match.Groups[1].Value);
                int ysize = Int32.Parse(match.Groups[2].Value);
                int zsize = Int32.Parse(match.Groups[3].Value);
                vtkVoxels.XSize = xsize;
                vtkVoxels.YSize = ysize;
                vtkVoxels.ZSize = zsize;

                // ORIGIN -267.578116 -267.578116 -268
                line = reader.ReadLine();

                // SPACING 0.976562 0.976562 2.5
                line = reader.ReadLine();

                // POINT_DATA 60060800
                line  = reader.ReadLine();
                match = Regex.Match(line, "POINT_DATA (.*)");
                int pointCount = Int32.Parse(match.Groups[1].Value);

                // SCALARS image_data short 1
                line = reader.ReadLine();

                // LOOKUP_TABLE default
                line = reader.ReadLine();

                for (int z = 0; z < zsize; z++)
                {
                    int[,] slice = new int[xsize, ysize];
                    vtkVoxels.Voxels.Add(slice);
                    for (int y = 0; y < ysize; y++)
                    {
                        line = reader.ReadLine();
                        var tokens = line.Split(' ');
                        for (int x = 0; x < xsize; x++)
                        {
                            slice[x, y] = int.Parse(tokens[x]);
                        }
                    }
                }
            }
            return(vtkVoxels);
        }