public partial class Form1 : Form { #region 私有成员 private string _fileName = null; private vtkRenderer render = null; private vtkRenderWindow renwin = null; private vtkRenderWindowInteractor iren = null; private vtkDICOMImageReader reader = null; private vtkContourFilter skinExtractor = null; #endregion #region public string FileName { get { return _fileName; } set { _fileName=value;} } #endregion public Form1() { InitializeComponent(); } private void renderWindowControl1_Load(object sender, EventArgs e) { render = renderWindowControl1.RenderWindow.GetRenderers().GetFirstRenderer(); renwin = renderWindowControl1.RenderWindow; iren = renderWindowControl1.RenderWindow.GetInteractor(); } private void button1_Click(object sender, EventArgs e) { btn_render.Enabled = false; _fileName = null; FolderBrowserDialog dlg = new FolderBrowserDialog(); if (dlg.ShowDialog() == DialogResult.OK) { _fileName= dlg.SelectedPath; } dlg.Dispose(); btn_render.Enabled = true; } private void btn_render_Click(object sender, EventArgs e) { if(String.IsNullOrEmpty(_fileName)) { MessageBox.Show("请先指定文件夹路径!"); return; } //还需要修改,可以将这一部分抽取出来做一个单独的方法。 if (reader != null) { reader.Dispose(); skinExtractor.Dispose();//需要修正 render.RemoveAllViewProps(); render.ResetCamera(); } reader = new vtkDICOMImageReader(); reader.SetDataByteOrderToLittleEndian(); //reader.SetDirectoryName(@"E:\decompress"); reader.SetDirectoryName(_fileName); reader.Update(); skinExtractor = vtkContourFilter.New(); skinExtractor.SetInputConnection(reader.GetOutputPort()); skinExtractor.SetValue(0, 200);//200 //skinExtractor.Modified(); //skinExtractor.SetValue(1, 500); vtkPolyDataNormals skinNormals = vtkPolyDataNormals.New(); skinNormals.SetInputConnection(skinExtractor.GetOutputPort()); skinNormals.SetFeatureAngle(60.0);//? vtkPolyDataMapper skinmapper = vtkPolyDataMapper.New(); skinmapper.SetInputConnection(skinNormals.GetOutputPort()); skinmapper.ScalarVisibilityOff(); vtkActor skin = new vtkActor(); skin.SetMapper(skinmapper); vtkOutlineFilter outLineData = vtkOutlineFilter.New(); outLineData.SetInputConnection(reader.GetOutputPort()); vtkPolyDataMapper outlinemapper = vtkPolyDataMapper.New(); outlinemapper.SetInputConnection(outLineData.GetOutputPort()); vtkActor outline = vtkActor.New(); outline.SetMapper(outlinemapper); outline.GetProperty().SetColor(0, 0, 0); vtkCamera acamera = render.GetActiveCamera(); acamera.SetViewUp(0, 0, -1); acamera.SetPosition(0, 1, 0); acamera.SetFocalPoint(0, 0, 0); acamera.ComputeViewPlaneNormal(); render.AddActor(outline); render.AddActor(skin); render.ResetCamera(); acamera.Dolly(1.5); render.SetBackground(1, 1, 1); render.ResetCameraClippingRange(); renwin.Render(); iren.Initialize(); iren.Start(); } }