C ++将bo数据提升为浮点数组

C++ boost bo data to float array

如何将 geometry::pointgeometry::box 等结构之间的数据传输到简单的 float 数组?

我找到的唯一方法是 get 方法。我每次转账都需要用这个吗?

#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;
}

你的做法并没有错,但是你可以通过创建一个结构来简化这个过程,在它的构造函数中有一个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],你可以删除其他分配。