0

CGALのKdツリー実装とファジー球をクエリオブジェクトとして使用して、ポイントr_maxを中心とする半径の球で囲まれたポイントを取得しています。この最小限の作業例を次に示します。

    #include <CGAL/Simple_cartesian.h>
    #include <CGAL/Kd_tree.h>
    #include <CGAL/Search_traits_2.h>
    #include <CGAL/Fuzzy_sphere.h>
    #include <iostream>
    #include <fstream>

    typedef CGAL::Simple_cartesian<double>  K;
    typedef K::Point_2                      Point;
    typedef CGAL::Search_traits_2<K>        TreeTraits;
    typedef CGAL::Kd_tree<TreeTraits>       Kd_tree;
    typedef Kd_tree::Tree                   Tree;
    typedef CGAL::Fuzzy_sphere<TreeTraits>  Sphere;

    int main(int argc, char* argv[])
    {
        double r_max;
        Tree tree;

        /* ... fill the tree with points, set the value of r_max ...*/

        // Report indices for the neighbors within a sphere
        unsigned int   idc_query = tree.size()/2;           // test index
        Tree::iterator kti       = idc_query + tree.begin();                                                                                
        Sphere s_query(*kti, r_max);                            

        // Print points
        tree.search(std::ostream_iterator<Point>(std::cout, "\n"), s_query);

        return 0;
    }

CGALの例のSpatial_searchingフォルダーの下にあるinterior_neighbor_searching.cppファイルからコメント「Printpoints」の下の行を取得して適合させました(私のバージョンは3.9です)。

質問は次のとおりです。ポイントの座標を標準に出力する代わりに、ある種のコンテナで検索の結果として得られたポイントへのポインタ/イテレータ/ハンドルを格納する別のOutputIterator(ではなく)を設定する方法はありますか?出力?ありがとうございました。std::ostream_iterator

4

2 に答える 2

4

C++ 標準ライブラリには、次の 5 種類の反復子があります。

  • 入力反復子
  • 出力反復子
  • 前方反復子
  • 双方向反復子
  • ランダムアクセス反復子

詳細については、cplusplus.comを参照してください。

あなたの場合、Output iterator、つまり、書き込み可能な非 const 参照を取得するためにインクリメント ( ) および逆参照 ( )itできるオブジェクトが必要です。++it*it

以下を使用して、書き込まれたすべてのアイテムをコンテナの最後に挿入する出力イテレータを作成できますstd::back_inserter

#include <iterator>
#include <vector>

...

std::vector<Point> points;
tree.search(std::back_inserter(points), s_query);
于 2011-11-13T09:24:45.493 に答える
0

CGALでは物事が進化しました。つまり、ポイント以外のものを保存できます。 ユーザーマニュアルのポイントプロパティマップで任意のポイントタイプを使用する例をご覧ください。

于 2013-02-08T09:50:12.597 に答える