Пример #1
0
 // Release resource
 private void MainPaltform_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (imgProp != null)
     {
         imgProp.Dispose();
     }
     if (this.renderWindowControl1 != null)
     {
         this.renderWindowControl1.Dispose();
     }
     if (this.renderWindowControl2 != null)
     {
         this.renderWindowControl2.Dispose();
     }
     if (this.Interactor != null)
     {
         this.Interactor.Dispose();
     }
     System.GC.Collect();
 }
Пример #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_modelRootProp != null)
         {
             _modelRootProp.Dispose();
             _modelRootProp = null;
         }
     }
     base.Dispose(disposing);
 }
Пример #3
0
        public void ImportVTK()
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Get the name of the file you want to open from the dialog
                string      fileName = openFileDialog1.FileName;
                vtkRenderer ren      = (vtkRenderer)this.myRenderWindowControl.RenderWindow.GetRenderers().GetItemAsObject(0);

                //Get rid of any props already there
                if (imgProp != null)
                {
                    ren.RemoveActor(imgProp);
                    imgProp.Dispose();
                    imgProp = null;
                }

                //Look at known file types to see if they are readable
                if (fileName.Contains(".png") ||
                    fileName.Contains(".jpg") ||
                    fileName.Contains(".jpeg") ||
                    fileName.Contains(".tif") ||
                    fileName.Contains(".slc") ||
                    fileName.Contains(".dicom") ||
                    fileName.Contains(".minc") ||
                    fileName.Contains(".bmp") ||
                    fileName.Contains(".pmn"))
                {
                    vtkImageReader2 rdr = vtkImageReader2Factory.CreateImageReader2(fileName);
                    rdr.SetFileName(fileName);
                    rdr.Update();
                    imgProp = vtkImageActor.New();

                    ((vtkImageActor)imgProp).SetInput(rdr.GetOutput());
                    rdr.Dispose();
                }

                //.vtk files need a DataSetReader instead of a ImageReader2
                //some .vtk files need a different kind of reader, but this
                //will read most and serve our purposes
                else if (fileName.Contains(".vtk") || fileName.Contains(".VTK"))
                {
                    vtkDataSetReader dataReader = vtkDataSetReader.New();
                    dataReader.SetFileName(fileName);
                    dataReader.Update();

                    vtkDataSetMapper dataMapper = vtkDataSetMapper.New();
                    dataMapper.SetInput(dataReader.GetOutput());

                    imgProp = vtkActor.New();
                    ((vtkActor)imgProp).SetMapper(dataMapper);

                    dataMapper.Dispose();
                    dataMapper = null;

                    dataReader.Dispose();
                    dataReader = null;
                }
                else
                {
                    return;
                }

                ren.RemoveAllViewProps();
                ren.AddActor(imgProp);
                ren.ResetCamera();
                ren.SetBackground(0.0, 0.46, 0.5);

                //Rerender the screen
                //NOTE: sometimes you have to drag the mouse
                //a little before the image shows up
                ren.Render();
                myRenderWindowControl.RenderWindow.Render();
                myRenderWindowControl.Refresh();
            }
        }
Пример #4
0
        /// <summary>
        /// Load an image with an open dialog
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Get the name of the file you want to open from the dialog
                string fileName = openFileDialog1.FileName;

                vtkRenderer ren = (vtkRenderer)this.renderWindowControl1.RenderWindow.GetRenderers().GetItemAsObject(0);

                //Get rid of any props already there
                if (imgProp != null)
                {
                    ren.RemoveActor(imgProp);
                    imgProp.Dispose();
                    imgProp = null;
                }

                //Look at known file types to see if they are readable
                if (fileName.Contains(".png") ||
                    fileName.Contains(".jpg") ||
                    fileName.Contains(".jpeg") ||
                    fileName.Contains(".tif") ||
                    fileName.Contains(".slc") ||
                    fileName.Contains(".dicom") ||
                    fileName.Contains(".minc") ||
                    fileName.Contains(".bmp") ||
                    fileName.Contains(".pmn"))
                {
                    Kitware.VTK.vtkImageReader2 rdr =
                        Kitware.VTK.vtkImageReader2Factory.CreateImageReader2(fileName);
                    rdr.SetFileName(fileName);
                    rdr.Update();
                    imgProp = vtkImageActor.New();
                    ((vtkImageActor)imgProp).SetInputConnection(rdr.GetOutputPort());
                    rdr.Dispose();
                }

                //.vtk files need a DataSetReader instead of a ImageReader2
                //some .vtk files need a different kind of reader, but this
                //will read most and serve our purposes
                else if (fileName.Contains(".vtk"))
                {
                    vtkDataSetReader dataReader = vtkDataSetReader.New();
                    vtkDataSetMapper dataMapper = vtkDataSetMapper.New();
                    imgProp = vtkActor.New();
                    dataReader.SetFileName(fileName);
                    dataReader.Update();
                    dataMapper.SetInputConnection(dataReader.GetOutputPort());
                    ((vtkActor)imgProp).SetMapper(dataMapper);
                    dataMapper.Dispose();
                    dataMapper = null;
                    dataReader.Dispose();
                    dataReader = null;
                }
                else
                {
                    return;
                }
                ren.AddActor(imgProp);
                //Reset the camera to show the image
                //Equivilant of pressing 'r'
                ren.ResetCamera();
                //Rerender the screen
                //NOTE: sometimes you have to drag the mouse
                //a little before the image shows up
                renderWindowControl1.RenderWindow.Render();
                ren.Render();
            }
        }