コード例 #1
0
        /// <summary>
        /// 将一个actor保存为stl格式
        /// </summary>
        /// <param name="actor"></param>
        void SaveActorToStl(vtkActor actor, string stlFileName)
        {
            //通过actor模型生成stl文件
            vtkPolyDataMapper mapper   = (vtkPolyDataMapper)actor.GetMapper();//获取mapper
            vtkPolyData       polyData = vtkPolyData.New();

            polyData = mapper.GetInput();//从mapper中提取数据
            vtkTriangleFilter filter = vtkTriangleFilter.New();

            filter.SetInput(polyData);//三角化后才能保存为正常的stl格式

            vtkSTLWriter stlWriter = vtkSTLWriter.New();

            stlWriter.SetFileName(stlFileName);
            stlWriter.SetInputConnection(filter.GetOutputPort());//提取数据
            stlWriter.Write();
        }