private void ReadSTL() { // Path to vtk data must be set as an environment variable // VTK_DATA_ROOT = "C:\VTK\vtkdata-5.8.0" vtkTesting test = vtkTesting.New(); string root = test.GetDataRoot(); string filePath = System.IO.Path.Combine(root, @"Data\42400-IDGH.stl"); vtkSTLReader reader = vtkSTLReader.New(); reader.SetFileName(filePath); reader.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(reader.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); // get a reference to the renderwindow of our renderWindowControl1 vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow; // renderer vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); // set background color renderer.SetBackground(0.2, 0.3, 0.4); // add our actor to the renderer renderer.AddActor(actor); }
static public vtkProp3D genSTLActor(CompontData data, vtkProperty pro) { if (data.restriction != null) { return(genActorByRestriction(data, pro)); } vtkSTLReader reader = vtkSTLReader.New(); reader.SetFileName(data.param_str); reader.Update(); return(genUserActor(data, reader.GetOutputPort(), pro)); }
/// <summary> /// 读取STL文件 /// </summary> /// <param name="fileName"></param> /// <returns></returns> vtkActor ReadStlFile(string fileName) {// 读取stl模型 vtkSTLReader stlReader = vtkSTLReader.New(); stlReader.SetFileName(fileName); stlReader.Update(); vtkPolyDataMapper mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(stlReader.GetOutputPort()); vtkActor actor = vtkActor.New(); actor.SetMapper(mapper); return(actor); }