Thanks again for the fast reply. Good to know about the backtick characters. So the test code may got rendered somehow misleading:
I only have one polygon as the input.
x=[0,6,6,3,3,5,5,3,3,4,4,2,2,3,3,1,1,3,3,0]
y=[0,0,6,6,5,5,4,4,3,3,1,1,3,3,4,4,5,5,6,6]
The triangulation is just (needed?) because of the extrusion done in the 2nd step. If I look at the result of vtkDelaunay2D I find some missing triangles at the outside boundary (hull is not convex).
I also tried to SetSourceData() to create a constrained delaunay. This results in:
Warning: In /build/vtk7-w4DzBd/vtk7-7.1.1+dfsg1/Filters/Core/vtkDelaunay2D.cxx, line 1340
vtkDelaunay2D (0x263da50): Edge not recovered, polygon fill suspect
This is the (now readable ) test code:
#!/usr/bin/env python
from vtk import *
# define test polygon ---------------------------------------------------------
# 20 ______4______ 3 concave polygon CCW
# |17____|____6 | Self-touching two edges
# | |_________| | 4,19 at same coords
# |16 __|__ 7 | 5,18 at same coords
# | 13| 9 |10 | 9,14 at same coords
# | 12|_____|11 |
# |_____________|
# 1 2
x=[0,6,6,3,3,5,5,3,3,4,4,2,2,3,3,1,1,3,3,0]
y=[0,0,6,6,5,5,4,4,3,3,1,1,3,3,4,4,5,5,6,6]
npts = len(x)
# creation of the source ------------------------------------------------------
points = vtkPoints()
polygon = vtkPolygon()
polygon.GetPointIds().SetNumberOfIds( npts )
for i in range( npts ):
points.InsertNextPoint( x[i], y[i], 0 ) # xy plane aligned
polygon.GetPointIds().SetId(i, i)
polys = vtkCellArray()
polys.InsertNextCell(polygon)
polyData = vtkPolyData()
polyData.SetPoints(points)
polyData.SetPolys(polys)
result = polyData # set inital result
# filter the polydata ---------------------------------------------------------
pdflt = vtkDelaunay2D()
pdflt.SetSourceData( polyData )
pdflt.SetInputData( polyData )
pdflt.Update()
result = pdflt.GetOutput()
# info ------------------------------------------------------------------------
numpoints = result.GetNumberOfPoints()
print( '#points = ', numpoints )
numpolys = result.GetNumberOfPolys()
print( '#polys = ', numpolys )
# map it ----------------------------------------------------------------------
mapper = vtkPolyDataMapper()
mapper.SetInputData( result )
# render it -------------------------------------------------------------------
actor = vtkActor()
actor.SetMapper(mapper)
actor.GetProperty().SetRepresentationToWireframe()
render = vtkRenderer()
render.AddActor(actor)
renwin = vtkRenderWindow()
renwin.AddRenderer(render)
rwiact = vtkRenderWindowInteractor()
rwiact.SetRenderWindow(renwin)
rwiact.SetInteractorStyle(vtkInteractorStyleTrackballCamera())
rwiact.Initialize()
rwiact.Start()
Here is a Octave version (for comparison):
vx=[0,6,6,3,3,5,5,3,3,4,4,2,2,3,3,1,1,3,3,0];
vy=[0,0,6,6,5,5,4,4,3,3,1,1,3,3,4,4,5,5,6,6];
tri = delaunay (vx, vy);
cx = [ vx(tri(:,1)) + vx(tri(:,2)) + vx(tri(:,3)) ] ./ 3;
cy = [ vy(tri(:,1)) + vy(tri(:,2)) + vy(tri(:,3)) ] ./ 3;
[in,on] = inpolygon (cx, cy, vx, vy);
fin = tri(find(in),:);
clf;
triplot (tri, vx, vy);
hold on;
triplot( fin, vx, vy, "c" );
plot (vx, vy, "r*");
plot (cx, cy, "g*");
axis( 'equal' );
The octave version is internaly based on http://www.qhull.org/ library. As a second step I simply check if all center points of the generated triangles are within the original polygon. Any others are dropped. I was assuming the vtkDelaunay2D works somehow similar.
Gerald