/// <summary> /// Create planar subdivision for random points /// </summary> /// <param name="maxValue">The points contains values between [0, maxValue)</param> /// <param name="pointCount">The total number of points to create</param> public static void CreateSubdivision(float maxValue, int pointCount, out Triangle2DF[] delaunayTriangles, out VoronoiFacet[] voronoiFacets) { #region create random points in the range of [0, maxValue] PointF[] pts = new PointF[pointCount]; Random r = new Random((int)(DateTime.Now.Ticks & 0x0000ffff)); for (int i = 0; i < pts.Length; i++) pts[i] = new PointF((float)r.NextDouble() * maxValue, (float)r.NextDouble() * maxValue); #endregion using (Subdiv2D subdivision = new Subdiv2D(pts)) { //Obtain the delaunay's triangulation from the set of points; delaunayTriangles = subdivision.GetDelaunayTriangles(); //Obtain the voronoi facets from the set of points voronoiFacets = subdivision.GetVoronoiFacets(); } }
public static void testCrashPSD(int nPoints, int maxIter) { if (maxIter < 0) { // some ridiculously large number maxIter = 1000000000; } else if (maxIter == 0) { maxIter = 1; } int iter = 0; do { iter++; EmguAssert.WriteLine(String.Format("Running iteration {0} ... ", iter)); PointF[] points = getPoints(nPoints); /* // write points to file TextWriter writer = new StreamWriter("points.txt"); writer.WriteLine("// {0} generated points:", points.Length); writer.WriteLine("PointF[] points = new PointF[]"); writer.WriteLine("{"); foreach (PointF p in points) { writer.WriteLine("\tnew PointF({0}f, {1}f),", p.X, p.Y); } writer.WriteLine("};"); writer.Close(); */ Emgu.CV.Subdiv2D psd = new Emgu.CV.Subdiv2D(points); // hangs here: Emgu.CV.Structure.Triangle2DF[] triangles = psd.GetDelaunayTriangles(); //System.Console.WriteLine("done."); } while (iter < maxIter); }
public void TestPlanarSubdivision2() { PointF[] pts = new PointF[33]; pts[0] = new PointF(224, 432); pts[1] = new PointF(368, 596); pts[2] = new PointF(316, 428); pts[3] = new PointF(244, 596); pts[4] = new PointF(224, 436); pts[5] = new PointF(224, 552); pts[6] = new PointF(276, 568); pts[7] = new PointF(308, 472); pts[8] = new PointF(316, 588); pts[9] = new PointF(368, 536); pts[10] = new PointF(332, 428); pts[11] = new PointF(124, 380); pts[12] = new PointF(180, 400); pts[13] = new PointF(148, 360); pts[14] = new PointF(148, 416); pts[15] = new PointF(128, 372); pts[16] = new PointF(124, 392); pts[17] = new PointF(136, 412); pts[18] = new PointF(156, 416); pts[19] = new PointF(176, 404); pts[20] = new PointF(180, 384); pts[21] = new PointF(168, 364); pts[22] = new PointF(260, 104); pts[23] = new PointF(428, 124); pts[24] = new PointF(328, 32); pts[25] = new PointF(320, 200); pts[26] = new PointF(268, 76); pts[27] = new PointF(264, 144); pts[28] = new PointF(316, 196); pts[29] = new PointF(384, 196); pts[30] = new PointF(424, 136); pts[31] = new PointF(412, 68); pts[32] = new PointF(348, 32); Subdiv2D subdiv = new Subdiv2D(pts); for (int i = 0; i < pts.Length; i++) { int edge; int point; CvEnum.Subdiv2DPointLocationType location = subdiv.Locate(pts[i], out edge, out point); if (location == Emgu.CV.CvEnum.Subdiv2DPointLocationType.OnEdge) { //you might want to store the points which is not inserted here. //or alternatively, add some random noise to the point and re-insert it again. continue; } subdiv.Insert(pts[i]); } VoronoiFacet[] facets = subdiv.GetVoronoiFacets(); }