Beispiel #1
0
 public void Dispose()
 {
     if (actor != null)
     {
         actor.Dispose();
         _polyDataMapper.Dispose();
         reader.Dispose();
     }
 }
        public void RemoveMe()
        {
            if (actor != null)
            {
                _renderer.RemoveActor(actor);

                if (reader != null)
                {
                    reader.Dispose();
                }
                PolyData.Dispose();
                _polyDataMapper.Dispose();
                actor.Dispose();
            }
            actor = null;
        }
Beispiel #3
0
        public static void ShowPolydata(string airwayPath)
        {
            if (!File.Exists(airwayPath))
            {
                MessageBox.Show("文件不存在!");
                return;
            }
            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);
            vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();

            reader.SetFileName(airwayPath);
            reader.Update();

            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(reader.GetOutput());
            reader.Dispose();
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renWin.Render();
        }
        internal static vtkPolyData ReadPolyData(this string vtpFileName)
        {
            if (string.IsNullOrEmpty(vtpFileName))
            {
                throw new Exception("Empty filename is given.");
            }
            if (!File.Exists(vtpFileName))
            {
                throw new FileNotFoundException(string.Format("{0} not found", vtpFileName), vtpFileName);
            }

            //File.ReadAllBytes(vtpFileName);

            if (vtpFileName.EndsWith(".vtp"))
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(vtpFileName);
                reader.Update();
                vtkPolyData polyData = reader.GetOutput();
                reader.Dispose();
                return(polyData);
            }
            else if (vtpFileName.EndsWith(".stl"))
            {
                return(VTKUtil.ReadSTLPolyData(vtpFileName));
            }
            else
            {
                vtkXMLPolyDataReader reader = vtkXMLPolyDataReader.New();
                reader.SetFileName(vtpFileName);
                reader.Update();
                vtkPolyData polyData = reader.GetOutput();
                reader.Dispose();
                return(polyData);
                //throw new Exception(string.Format("Unknown file type = " + vtpFileName));
            }
        }
Beispiel #5
0
        public static void ShowPolydata(string airwayPath, string lesionPath)
        {
            vtkAppendPolyData appendPolydata = new vtkAppendPolyData();

            if (File.Exists(airwayPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(airwayPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("airwayPath : " + airwayPath + "文件不存在!");
            }

            if (File.Exists(lesionPath))
            {
                vtkXMLPolyDataReader reader = new vtkXMLPolyDataReader();
                reader.SetFileName(lesionPath);
                reader.Update();
                appendPolydata.AddInput(reader.GetOutput());
                reader.Dispose();
            }
            else
            {
                MessageBox.Show("lesionPath : " + lesionPath + "文件不存在!");
            }

            vtkRenderWindow renWin = vtkRenderWindow.New();

            renWin.SetSize(600, 600);

            vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

            renWin.SetInteractor(iren);

            vtkInteractorStyleTrackballCamera interactorStyle = new vtkInteractorStyleTrackballCamera();

            iren.SetInteractorStyle(interactorStyle);

            vtkRenderer renderer = vtkRenderer.New();

            renderer.GradientBackgroundOn();
            renderer.SetBackground(0, 0, 0);
            renderer.SetBackground2(0, 0, 1);
            renWin.AddRenderer(renderer);


            vtkPolyDataMapper mapper = vtkPolyDataMapper.New();

            mapper.ScalarVisibilityOff();
            mapper.SetInput(appendPolydata.GetOutput());
            vtkActor actor = new vtkActor();

            actor.SetMapper(mapper);

            renderer.AddActor(actor);

            renderer.Render();
            renderer.ResetCamera();
            renWin.Render();

            //Thread thread = new Thread(new ThreadStart(
            //                                       delegate
            //                                       {
            //                                           iren.Start();
            //                                       }));
            //thread.Start();
        }