2016-07-13 12 views
-1

私はnewbeeをC++ブーストライブラリに入れました。 簡単なことはできません。 geometry::pointgeometry::boxのような構造間のデータを単純な浮動小数点配列にどのように転送するか。私が見つけた唯一の方法はgetメソッドです。転送ごとにこれを使用する必要がありますか?C++ブーストデータを浮動小数点配列に置き換える

#include <boost/geometry.hpp> 
#include <boost/geometry/geometries/point.hpp> 
#include <boost/geometry/geometries/box.hpp> 
#include <iostream> 
#include <vector> 

namespace bg = boost::geometry; 
namespace bgi = boost::geometry::index; 

typedef bg::model::point<float, 2, bg::cs::cartesian> point; 
typedef bg::model::box<point> box; 

int main() 
{ 
    box B(point(10,10), point(20,20)); 
    float VertexQuad[4][2]; 

    VertexQuad[0][0] = bg::get<bg::min_corner, 0>(B); 
    VertexQuad[0][1] = bg::get<bg::min_corner, 1>(B); 
    VertexQuad[1][0] = bg::get<bg::min_corner, 0>(B); 
    VertexQuad[1][1] = bg::get<bg::max_corner, 1>(B); 
    VertexQuad[2][0] = bg::get<bg::max_corner, 0>(B); 
    VertexQuad[2][1] = bg::get<bg::max_corner, 1>(B); 
    VertexQuad[3][0] = bg::get<bg::max_corner, 0>(B); 
    VertexQuad[3][1] = bg::get<bg::min_corner, 1>(B); 

    return 0; 
} 

答えて

0

それを行うのあなたのやり方は間違っていないですが、あなたはそれのコンストラクタでbox変数で、構造体を作成することにより、プロセスを簡素化することができます。

struct VertexQuad 
{ 
    float array[2][2]; 

    VertexQuad(box B) 
    { 
     array[0][0] = bg::get<bg::min_corner, 0>(B); 
     array[0][1] = bg::get<bg::min_corner, 1>(B); 
     array[1][0] = bg::get<bg::max_corner, 0>(B); 
     array[1][1] = bg::get<bg::max_corner, 1>(B); 
    }; 
}; 

この方法で、あなたはありません配列で値を使用するたびに値を割り当てます。

編集:boxは2コーナー(2 points) - >あなたの配列サイズはfloat array[2][2]である必要があり、他の割り当てを削除することができます。

+0

を理解してください。ありがとう。 – SomeCoder

関連する問題