示例url:https://lorensen.github.io/VTKExamples/site/Cxx/Rendering/FlatVersusGouraud/
方法:
if (flat)
{
actor->GetProperty()->SetInterpolationToFlat();//上
}
else
{
actor->GetProperty()->SetInterpolationToGouraud();//下
}
平滑处理:
vtkSmartPointer<vtkSmoothPolyDataFilter> smooth =
vtkSmartPointer<vtkSmoothPolyDataFilter>::New();
smooth->SetInputConnection(marchcube->GetOutputPort());
smooth->SetNumberOfIterations(10);
smooth->SetRelaxationFactor(1.0);
smooth->FeatureEdgeSmoothingOn();
smooth->BoundarySmoothingOn();
smooth->Update();
// Update normals on newly smoothed polydata
vtkSmartPointer<vtkPolyDataNormals> normal = vtkSmartPointer<vtkPolyDataNormals>::New();
normal->SetInputConnection(smoothFilter->GetOutputPort());
normalr->ComputePointNormalsOn();
normal->ComputeCellNormalsOn();
normal->Update();
通过顶点索引构造polydata
vtkSmartPointer<vtkPolyData> polydata =
vtkSmartPointer<vtkPolyData>::New();
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(0.0,0.0,0.0);
points->InsertNextPoint(1.0,0.0,0.0);
points->InsertNextPoint(0.0,1.0,0.0);
points->InsertNextPoint(0.0,0.0,1.0);
vtkIdType pts[3];
vtkSmartPointer<vtkCellArray> cellArr =
vtkSmartPointer<vtkCellArray>::New();
pts[0]=0;pts[1]=1;pts[2]=2;
cellArr->InsertNextCell(3,pts);
pts[0]=0;pts[1]=1;pts[2]=3;
cellArr->InsertNextCell(3,pts);
pts[0]=0;pts[1]=2;pts[2]=3;
cellArr->InsertNextCell(3,pts);
polydata->SetPoints(points);
polydata->SetPolys(cellArr);
polydata->Modified();