Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="idx"></param>
        /// <param name="facetList"></param>
        /// <param name="facetCenters"></param>
        public void GetVoronoiFacetList(IEnumerable <int> idx, out Point2f[][] facetList, out Point2f[] facetCenters)
        {
            ThrowIfDisposed();

            IntPtr facetListPtr, facetCentersPtr;

            if (idx == null)
            {
                NativeMethods.imgproc_Subdiv2D_getVoronoiFacetList(ptr, IntPtr.Zero, 0, out facetListPtr, out facetCentersPtr);
            }
            else
            {
                int[] idxArray = EnumerableEx.ToArray(idx);
                NativeMethods.imgproc_Subdiv2D_getVoronoiFacetList(ptr, idxArray, idxArray.Length, out facetListPtr, out facetCentersPtr);
            }

            using (VectorOfVectorPoint2f facetListVec = new VectorOfVectorPoint2f(facetListPtr))
            {
                facetList = facetListVec.ToArray();
            }
            using (VectorOfPoint2f facetCentersVec = new VectorOfPoint2f(facetCentersPtr))
            {
                facetCenters = facetCentersVec.ToArray();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a list of all Voronoi facets.
        /// </summary>
        /// <param name="idx">Vector of vertices IDs to consider. For all vertices you can pass empty vector.</param>
        /// <param name="facetList">Output vector of the Voronoi facets.</param>
        /// <param name="facetCenters">Output vector of the Voronoi facets center points.</param>
        public void GetVoronoiFacetList(IEnumerable <int>?idx, out Point2f[][] facetList, out Point2f[] facetCenters)
        {
            ThrowIfDisposed();

            int[]? idxArray           = idx as int[] ?? idx?.ToArray();
            using var facetListVec    = new VectorOfVectorPoint2f();
            using var facetCentersVec = new VectorOfPoint2f();
            NativeMethods.HandleException(
                NativeMethods.imgproc_Subdiv2D_getVoronoiFacetList(
                    ptr, idxArray, idxArray?.Length ?? 0, facetListVec.CvPtr, facetCentersVec.CvPtr));
            GC.KeepAlive(this);
            facetList    = facetListVec.ToArray();
            facetCenters = facetCentersVec.ToArray();
        }