示例#1
0
        /// <summary>
        /// Load image files into vtkImageData.
        /// </summary>
        /// <param name="path">Path to images.</param>
        /// <param name="extension">Image extension.</param>
        /// <returns></returns>
        public static vtkImageData VTKLoader(string path, string extension)
        {
            /*DEPRECATED!!*/
            //Output
            vtkImageData data = vtkImageData.New();
            //Get files from path
            DirectoryInfo d = new DirectoryInfo(@path);

            FileInfo[] files = d.GetFiles();

            vtkStringArray allfiles = vtkStringArray.New();

            //Iterate over files and read image data
            foreach (FileInfo file in files)
            {
                //Fullfile
                string fullfile = Path.Combine(path, file.Name);
                allfiles.InsertNextValue(fullfile);
            }
            if (extension == ".png")
            {
                vtkPNGReader reader = vtkPNGReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            if (extension == ".jpg")
            {
                vtkJPEGReader reader = vtkJPEGReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            if (extension == ".bmp")
            {
                vtkBMPReader reader = vtkBMPReader.New();
                reader.SetFileNames(allfiles);
                reader.Update();
                data = reader.GetOutput();
                reader.Dispose();
            }
            data.SetScalarTypeToUnsignedChar();
            data.Update();
            return(data);
        }
        static void ReadSupport(string Spath)
        {
            vtkJPEGReader reader = vtkJPEGReader.New();

            reader.SetFileName(Spath);
            reader.Update();

            // Visualize
            _ImageViewer = vtkImageViewer2.New();
            _ImageViewer.SetInputConnection(reader.GetOutputPort());

            _SliceStatusMapper = vtkTextMapper.New();
            _SliceStatusMapper.SetInputConnection(reader.GetOutputPort());

            vtkActor2D sliceStatusActor = vtkActor2D.New();

            sliceStatusActor.SetMapper(_SliceStatusMapper);

            vtkRenderWindow renderWindow = vtkRenderWindow.New();

            //Display in full screen
            renderWindow.SetFullScreen(1);

            vtkInteractorStyleImage interactorStyle = vtkInteractorStyleImage.New();

            renderWindow.GetRenderers().InitTraversal();
            vtkRenderer ren;

            while ((ren = renderWindow.GetRenderers().GetNextItem()) != null)
            {
                renderWindow.AddRenderer(ren);
            }

            _ImageViewer.SetRenderWindow(renderWindow);
            _ImageViewer.GetRenderer().AddActor2D(sliceStatusActor);
            _ImageViewer.SetSlice(_SupportSlice);

            iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renderWindow);
            renderWindow.Render();
            _ColorLevel = 60;
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Down(_period, 170);
            Backward(_period, 1);

            for (int i = 0; i < _SupportLayers; i++)
            {
                System.Threading.Thread.Sleep(_layertime); // delay
                Backward(_period, 1);
            }
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Forward(_period, _MovedLayers);
            Console.WriteLine(_MovedLayers);

            if (reader != null)
            {
                reader.Dispose();
            }
            if (_ImageViewer != null)
            {
                _ImageViewer.Dispose();
            }
            if (_SliceStatusMapper != null)
            {
                _SliceStatusMapper.Dispose();
            }
            if (sliceStatusActor != null)
            {
                sliceStatusActor.Dispose();
            }
            if (renderWindow != null)
            {
                renderWindow.Dispose();
            }
            if (interactorStyle != null)
            {
                interactorStyle.Dispose();
            }
            if (ren != null)
            {
                ren.Dispose();
            }
            if (iren != null)
            {
                iren.Dispose();
            }
        }