/// <summary> /// 读取stl文件,并在窗口进行显示,并设置全局变量originalMesh /// </summary> private void ReadSTL() { //Path to vtk data must be set as an environment variable //VTK_DATA_ROOT="" vtkSTLReader reader = vtkSTLReader.New(); reader.SetFileName(FileFullName); reader.Update(); mapper = vtkPolyDataMapper.New(); mapper.SetInputConnection(reader.GetOutputPort()); actor = vtkActor.New(); actor.SetMapper(mapper); //get a reference to the renderwindow of our renderWindowControll renderWindow = renderWindowControl1.RenderWindow; //renderer renderer = renderWindow.GetRenderers().GetFirstRenderer(); //移除之前所有prop renderer.RemoveAllViewProps(); //set background color renderer.SetBackground(0.2, 0.3, 0.4); //add our actor to the renderer renderer.AddActor(actor); originalMesh = vtkPolyData.New(); originalMesh.DeepCopy(reader.GetOutput()); tb_numOfPoint.Text = originalMesh.GetNumberOfPoints().ToString(); //creat a cell picker picker = vtkCellPicker.New(); vtkRenderWindowInteractor iren = renderWindow.GetInteractor(); iren.SetPicker(picker); renderer.ResetCamera(); renderWindow.Render(); }
/// <summary> /// Subdivides a vtkPolyData into pieces containing max. MaxVertices. /// </summary> /// <param name="pd">The pd.</param> /// <returns>A list of vtkPolyData</returns> private static List<vtkPolyData> Subdivide(vtkPolyData pd) { var pds = new List<vtkPolyData>(); if (pd.GetNumberOfPoints() <= MaxVertices) { // Debug.Log("No subdivide neccessary. " + pd.GetNumberOfPoints()); pds.Add(pd); return pds; } var dicer = vtkOBBDicer.New(); dicer.SetInput(pd); dicer.SetNumberOfPointsPerPiece(MaxVertices); dicer.SetDiceModeToNumberOfPointsPerPiece(); dicer.Update(); // Debug.Log("Subdivided into " + dicer.GetNumberOfActualPieces() + " pieces."); var threshold = vtkThreshold.New(); pd = vtkPolyData.SafeDownCast(dicer.GetOutput()); threshold.SetInput(pd); threshold.SetInputArrayToProcess(0, 0, 0, (int)vtkDataObject.FieldAssociations.FIELD_ASSOCIATION_POINTS, "vtkOBBDicer_GroupIds"); var geometry = vtkGeometryFilter.New(); geometry.SetInputConnection(threshold.GetOutputPort()); for(var i = 0; i < dicer.GetNumberOfActualPieces(); i++) { threshold.ThresholdBetween(i, i); geometry.Update(); // Last submesh needs not to be copied if (i == dicer.GetNumberOfActualPieces() - 1) pds.Add(geometry.GetOutput()); else { var copiedOutput = new vtkPolyData(); copiedOutput.DeepCopy(geometry.GetOutput()); pds.Add(copiedOutput); } } return pds; }