I’m new to VTK and trying to triangulate a polygon using vtkAdaptiveSubdivisionFilter having failed using vtkPolygon->Triangulate and BoundedTriangulate. There doesn’t seem to be anything produced. Any idea what I’m missing?
Thanks,
Scott
#include <iostream>
#include <vtkAdaptiveSubdivisionFilter.h>
#include <vtkAlgorithmOutput.h>
#include <vtkCellArray.h>
#include <vtkFiltersModelingModule.h>
#include <vtkInformation.h>
#include <vtkNew.h>
#include <vtkPoints.h>
#include <vtkPolyData.h>
#include <vtkPolygon.h>
#include <vtkTriangleFilter.h>
int main()
{
vtkNew<vtkPolygon> polygon;
polygon->GetPoints()->InsertNextPoint(0.0, 0.0, 0.0);
polygon->GetPoints()->InsertNextPoint(0.0, 20.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-20.0, 20.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-20.0, 0.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-40.0, 0.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-40.0, 20.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-60.0, 20.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-60.0, -60.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-20.0, -60.0, 0.0);
polygon->GetPoints()->InsertNextPoint(-20.0, -20.0, 0.0);
vtkIdType numPoints = polygon->GetPoints()->GetNumberOfPoints();
polygon->GetPointIds()->SetNumberOfIds(numPoints);
for (int i = 0; i < numPoints; i++) {
polygon->GetPointIds()->SetId(i, i);
}
vtkNew<vtkCellArray> cells;
cells->InsertNextCell(numPoints);
for (int i = 0; i < numPoints; i++) {
cells->InsertCellPoint(i);
}
vtkNew<vtkPolyData> polys;
polys->SetPoints(polygon->GetPoints());
polys->SetPolys(cells);
vtkNew<vtkAdaptiveSubdivisionFilter> asf;
asf->SetInputData(polys);
asf->SetMaximumEdgeLength(0.1);
asf->Update();
vtkInformation* asfOutputInfo = asf->GetOutputInformation(0);
asfOutputInfo->Print(std::cout);
vtkPolyData* asfOutput = asf->GetOutput();
asfOutput->Print(std::cout);
}