A concave vtkPolygon
has rendering issues. I have tested this with multiple different shapes; the example I provide below is minimalistic. The bug propagates into other filters as well; for example a vtkGeometryFilter
on the concave polygon will result in the same triangle shape as indicated by the rendering example.
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkDataSetMapper.h>
#include <vtkIdList.h>
#include <vtkNew.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
int main(int, char*[])
{
vtkNew<vtkPoints> points;
vtkNew<vtkPolyData> polyData;
polyData->SetPoints(points);
polyData->Allocate(1);
vtkNew<vtkIdList> list;
list->InsertNextId(points->InsertNextPoint(0.0, 0.0, 0.0));
list->InsertNextId(points->InsertNextPoint(3.0, 0.0, 0.0));
list->InsertNextId(points->InsertNextPoint(3.0, 2.0, 0.0));
list->InsertNextId(points->InsertNextPoint(2.0, 2.0, 0.0));
list->InsertNextId(points->InsertNextPoint(2.0, 1.0, 0.0));
list->InsertNextId(points->InsertNextPoint(1.0, 1.0, 0.0));
list->InsertNextId(points->InsertNextPoint(1.0, 2.0, 0.0));
list->InsertNextId(points->InsertNextPoint(0.0, 2.0, 0.0));
polyData->InsertNextCell(VTK_POLYGON, list);
vtkNew<vtkDataSetMapper> mapper;
mapper->SetInputData(polyData);
vtkNew<vtkActor> wireActor;
wireActor->SetMapper(mapper);
wireActor->GetProperty()->SetRepresentationToWireframe();
wireActor->GetProperty()->SetColor(1.0, 0, 0);
wireActor->GetProperty()->SetLineWidth(5);
vtkNew<vtkActor> surfaceActor;
surfaceActor->SetMapper(mapper);
surfaceActor->GetProperty()->SetRepresentationToSurface();
surfaceActor->GetProperty()->SetColor(1.0, 1.0, 1.0);
vtkNew<vtkRenderer> renderer;
vtkNew<vtkRenderWindow> renderWindow;
renderWindow->AddRenderer(renderer);
vtkNew<vtkRenderWindowInteractor> iren;
iren->SetRenderWindow(renderWindow);
renderer->AddActor(surfaceActor);
renderer->AddActor(wireActor);
renderWindow->SetSize(1500, 1500);
renderWindow->SetWindowName("testPolygon");
renderWindow->Render();
iren->Start();
return EXIT_SUCCESS;
}
Results in:
Note the shape should be āUā shaped. The bug fills in the part in the upper middle. The red wire outline is the correct shape.
Not supported by VTK afaik.
Graphics hardware uses a primitive method to tessellate polygons, and it assumes the polygons are convex. Use vtkTriangleFilter to fix the rendering issues.
1 Like
Thanks! Looking further at it appears you may be right, and I got fooled by it, i.e. vtkGeometryFilter
appears to be working as intended as well.