Exemple #1
0
      /// <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();
         }
      }
Exemple #2
0
        /// <summary>
        /// Obtains the list of Voronoi Facets
        /// </summary>
        /// <returns>The list of Voronoi Facets</returns>
        public VoronoiFacet[] GetVoronoiFacets(int[] idx = null)
        {
            using (VectorOfInt vi = new VectorOfInt())
                using (VectorOfVectorOfPointF facetVec = new VectorOfVectorOfPointF())
                    using (VectorOfPointF centerVec = new VectorOfPointF())
                    {
                        if (idx != null)
                        {
                            vi.Push(idx);
                        }

                        CvInvoke.cveSubdiv2DGetVoronoiFacetList(_ptr, vi, facetVec, centerVec);
                        PointF[][] vertices = facetVec.ToArrayOfArray();
                        PointF[]   centers  = centerVec.ToArray();

                        VoronoiFacet[] facets = new VoronoiFacet[centers.Length];
                        for (int i = 0; i < facets.Length; i++)
                        {
                            facets[i] = new VoronoiFacet(centers[i], vertices[i]);
                        }
                        return(facets);
                    }
        }
Exemple #3
0
      /// <summary>
      /// Obtains the list of Voronoi Facets 
      /// </summary>
      /// <returns>The list of Voronoi Facets</returns>
      public VoronoiFacet[] GetVoronoiFacets(int[] idx = null)
      {
         using (VectorOfInt vi = new VectorOfInt())
         using (VectorOfVectorOfPointF facetVec = new VectorOfVectorOfPointF())
         using (VectorOfPointF centerVec = new VectorOfPointF())
         {
            if (idx != null)
               vi.Push(idx);
         
            CvInvoke.cveSubdiv2DGetVoronoiFacetList(_ptr, vi, facetVec, centerVec);
            PointF[][] vertices = facetVec.ToArrayOfArray();
            PointF[] centers = centerVec.ToArray();

            VoronoiFacet[] facets = new VoronoiFacet[centers.Length];
            for (int i = 0; i < facets.Length; i++)
            {
               facets[i] = new VoronoiFacet(centers[i], vertices[i]);
            }
            return facets;
         }
         
      }