VTKがMarchingCube Activizを実現
3861 ワード
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();
}
}