Exemple #1
0
 ///<summary>Deletes all static objects created</summary>
 public static void deleteAllVTKObjects()
 {
     //clean up vtk objects
     if (ren1 != null)
     {
         ren1.Dispose();
     }
     if (renWin != null)
     {
         renWin.Dispose();
     }
     if (iren != null)
     {
         iren.Dispose();
     }
     if (v16 != null)
     {
         v16.Dispose();
     }
     if (iso != null)
     {
         iso.Dispose();
     }
     if (isoMapper != null)
     {
         isoMapper.Dispose();
     }
     if (isoActor != null)
     {
         isoActor.Dispose();
     }
     if (mask != null)
     {
         mask.Dispose();
     }
     if (visPts != null)
     {
         visPts.Dispose();
     }
     if (ldm != null)
     {
         ldm.Dispose();
     }
     if (tprop != null)
     {
         tprop.Dispose();
     }
     if (contourLabels != null)
     {
         contourLabels.Dispose();
     }
 }
        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();
            }
        }
        static void PrintImage(string Ipath)
        {
            vtkDICOMImageReader reader = vtkDICOMImageReader.New();

            reader.SetDirectoryName(Ipath);
            reader.Update();
            X = reader.GetWidth();
            Y = reader.GetHeight();
            Z = reader.GetPixelSpacing();
            Console.WriteLine(X * Z[0]);
            Console.WriteLine(Y * Z[1]);
            Console.WriteLine(Z[2]);

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

            // Get range of slices (min is the first index, max is the last index)
            _ImageViewer.GetSliceRange(ref _MinSlice, ref _MaxSlice);
            Console.WriteLine(_MinSlice);
            Console.WriteLine(_MaxSlice);

            _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(_Slice);
            _ColorLevel = 500;
            _ImageViewer.SetColorLevel(_BlackLevel);
            _ImageViewer.Render();
            Down(_period, 62);
            Backward(_period, 1);

            _ImageViewer.SetColorLevel(_ColorLevel);
            _ImageViewer.Render();
            System.Threading.Thread.Sleep(_layertime);  // delay

            iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renderWindow);
            renderWindow.Render();

            //Start Timer
            InitTimer();
            iren.Start();

            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();
            }
        }