public unsafe SeqTest() { using (CvMemStorage storage = new CvMemStorage(0)) { Random rand = new Random(); CvSeq <int> seq = new CvSeq <int>(SeqType.EltypeS32C1, storage); // push for (int i = 0; i < 10; i++) { int push = seq.Push(rand.Next(100));//seq.Push(i); Console.WriteLine("{0} is pushed", push); } Console.WriteLine("----------"); // enumerate Console.WriteLine("contents of seq"); foreach (int item in seq) { Console.Write("{0} ", item); } Console.WriteLine(); // sort CvCmpFunc <int> func = delegate(int a, int b) { return(a.CompareTo(b)); }; seq.Sort(func); // convert to array int[] array = seq.ToArray(); Console.WriteLine("contents of sorted seq"); foreach (int item in array) { Console.Write("{0} ", item); } Console.WriteLine(); Console.WriteLine("----------"); // pop for (int i = 0; i < 10; i++) { int pop = seq.Pop(); Console.WriteLine("{0} is popped", pop); } Console.ReadKey(); } }
public static extern void cvSeqSort(IntPtr seq, CvCmpFunc func, IntPtr userdata);
public static extern IntPtr cvSeqSearch(IntPtr seq, IntPtr elem, CvCmpFunc func, [MarshalAs(UnmanagedType.Bool)] bool is_sorted, out int elem_idx);
public static extern int cvSeqPartition(IntPtr seq, IntPtr storage, ref IntPtr labels, CvCmpFunc is_equal, IntPtr userdata);
/// <summary> /// シーケンスの要素を,指定した比較関数を用いてソートする (cvSeqSort). /// </summary> /// <param name="func">要素の関係に応じて,負・0・正の値を返す比較関数</param> #else /// <summary> /// Sorts sequence element using the specified comparison function (cvSeqSort). /// </summary> /// <param name="func">The comparison function that returns negative, zero or positive value depending on the elements relation (see the above declaration and the example below) - similar function is used by qsort from C runtime except that in the latter userdata is not used </param> #endif public virtual void Sort(CvCmpFunc <T> func) { Cv.SeqSort(this, func); }
/// <summary> /// シーケンスの中から要素を検索する (cvSeqSearch). /// </summary> /// <param name="elem">検索する要素</param> /// <param name="func">要素の関係に応じて,負・0・正の値を返す比較関数</param> /// <param name="isSorted">シーケンスがソート済みか否かを示すフラグ</param> /// <param name="elemIdx">出力パラメータ.見つかった要素のインデックス.</param> #else /// <summary> /// Searches element in sequence (cvSeqSearch). /// </summary> /// <param name="elem">The element to look for </param> /// <param name="func">The comparison function that returns negative, zero or positive value depending on the elements relation</param> /// <param name="isSorted">Whether the sequence is sorted or not. </param> /// <param name="elemIdx">Output parameter; index of the found element. </param> /// <returns></returns> #endif public virtual T Search(T elem, CvCmpFunc <T> func, bool isSorted, out int elemIdx) { return(Cv.SeqSearch(this, elem, func, isSorted, out elemIdx)); }
/// <summary> /// データシーケンスを同値類(同じクラスに属すると定義されたデータ群)に分割する /// </summary> /// <param name="storage">同値類として分割されたシーケンスの保存領域.nullの場合は,seq->storage を使用する.</param> /// <param name="labels">出力パラメータ.入力シーケンスの各要素に割り振られた(分割結果を表す)0から始まるラベルシーケンスへのポインタのポインタ.</param> /// <param name="isEqual">2つのシーケンス要素が同じクラスである場合,関係関数は 0以外を返す. そうでなければ0を返す.分割アルゴリズムは,同値基準として関係関数の推移閉包を用いる.</param> /// <returns></returns> #else /// <summary> /// Splits sequence into equivalence classes /// </summary> /// <param name="storage">The storage to store the sequence of equivalence classes. If it is null, the function uses seq->storage for output labels. </param> /// <param name="labels">Output parameter. Double pointer to the sequence of 0-based labels of input sequence elements. </param> /// <param name="isEqual">The relation function that should return non-zero if the two particular sequence elements are from the same class, and zero otherwise. The partitioning algorithm uses transitive closure of the relation function as equivalence criteria. </param> /// <returns></returns> #endif public int Partition(CvMemStorage storage, out CvSeq labels, CvCmpFunc <T> isEqual) { return(Cv.SeqPartition(this, storage, out labels, isEqual)); }
/// <summary> /// シーケンスの中から要素を検索する (cvSeqSearch). /// </summary> /// <param name="elem">検索する要素</param> /// <param name="func">要素の関係に応じて,負・0・正の値を返す比較関数</param> /// <param name="isSorted">シーケンスがソート済みか否かを示すフラグ</param> /// <param name="elemIdx">出力パラメータ.見つかった要素のインデックス.</param> #else /// <summary> /// Searches element in sequence (cvSeqSearch). /// </summary> /// <param name="elem">The element to look for </param> /// <param name="func">The comparison function that returns negative, zero or positive value depending on the elements relation</param> /// <param name="isSorted">Whether the sequence is sorted or not. </param> /// <param name="elemIdx">Output parameter; index of the found element. </param> /// <returns></returns> #endif public virtual IntPtr Search(IntPtr elem, CvCmpFunc func, bool isSorted, out int elemIdx) { return(Cv.SeqSearch(this, elem, func, isSorted, out elemIdx)); }
internal static extern int cvSeqPartition(Seq seq, MemStorage storage, out Seq labels, CvCmpFunc is_equal, IntPtr userdata);
internal static extern IntPtr cvSeqSearch(Seq seq, IntPtr elem, CvCmpFunc func, int is_sorted, out int elem_idx, IntPtr userdata);
internal static extern void cvSeqSort(Seq seq, CvCmpFunc func, IntPtr userdata);