/// <summary>
/// Obtains the list of Voronoi Facets
/// </summary>
/// <returns>The list of Voronoi Facets</returns>
private IEnumerable <VoronoiFacet> GetVoronoiFacetsHelper()
{
if (_isVoronoiDirty)
{
CvInvoke.cvCalcSubdivVoronoi2D(Ptr);
_isVoronoiDirty = false;
}
int size = MCvSubdiv2D.total;
PointF[] points = new PointF[size];
MCvSubdiv2DEdge[] edges = new MCvSubdiv2DEdge[size];
GCHandle pointHandle = GCHandle.Alloc(points, GCHandleType.Pinned);
GCHandle edgeHandle = GCHandle.Alloc(edges, GCHandleType.Pinned);
CvInvoke.PlanarSubdivisionGetSubdiv2DPoints(_ptr, pointHandle.AddrOfPinnedObject(), edgeHandle.AddrOfPinnedObject(), ref size);
pointHandle.Free();
edgeHandle.Free();
using (MemStorage stor = new MemStorage())
{
Seq <PointF> ptSeq = new Seq <PointF>(stor);
for (int i = 0; i < size; i++)
{
CvInvoke.PlanarSubdivisionEdgeToPoly(edges[i], ptSeq);
PointF[] polygon = ptSeq.ToArray();
if (polygon.Length > 0)
{
yield return(new VoronoiFacet(points[i], polygon));
}
}
}
}