2017-02-07 1 views
-1

私はCGALとC++の初心者です(実際には私はCの開発者であり、CGALを使うためにC++に移動しました)。CGALの要素にペアのデータを分割する

私は、CGALのドキュメントで提供されている2-3の例を混ぜ合わせることで、私はCGALで欲しいことをすることができます。もし私が別々に各コードを実行し、出力を取り、それを第2コードに導入すれば、すべてが問題ありません。 (それらのうちの1つでは、その位置で生成された法線ベクトルを手動で削除する必要があります)。

私は、 1-Normal_estimation 2-edge_aware_upsampling 3-advancing_front_surface_reconstructionを使用します。私は多くのサンプルで実行する必要があるので、それらを単一のコードにしたいと思います。

問題は、最初の2つのコードがpairデータ型を扱っていることです。

typedef CGAL::Simple_cartesian<double> K; 
typedef K::Point_3 Point; 
typedef K::Vector_3 Vector;  
typedef std::pair<Point, Vector> PointVectorPair; 
std::list<PointVectorPair> points; 

最後のコードは

std::vector<Point> points_n; 

で動作しますしかし、私は私のPointsあるstd::list<std::pair<Point , Vector>>の最初の部分を与える機能が欲しい:magic_functionが何であるかを

points_n = magic_function(points); 

を?

答えて

2

std::listを反復処理し、各ペアからPointをコピーしてベクトルにプッシュする必要があります。

std::vector<Point> magic_function(const std::list<PointVectorPair>& list) 
{ 
    std::vector<Point> out;//a temporary object to store the output 
    for(auto&& p: list)// for each pair in the list 
    { 
     out.push_back(std::get<0>(p)); //copy the point and push it on to the vector 
    } 
    return out; //return the vector of points 
} 

それとも、ポイントをコピーしたくないのではなく、それはあなたが行うことができます移動したい場合:

std::vector<Point> magic_function(const std::list<PointVectorPair>& list) 
{ 
    std::vector<Point> out;//a temporary object to store the output 
    for(auto&& p: list)// for each pair in the list 
    { 
     out.push_back(std::move(std::get<0>(p))); //move the point to the vector 
    } 
    return out; //return the vector of points 
} 
+0

を、あなたはこのような何かを行うことができ、少なくともC++ 11のサポートを持っている場合コンパイルエラー: 'begin(const std :: pair >、CGAL :: Vector_3 >&')の呼び出しで一致する関数がありません ' for(auto && p :list)//リストの各ペアの// – Alibemz

+0

私は間違いを犯しました。私は引数として間違ったデータ型を持っていました。やってみよう –

関連する問題