C ++将bo数据提升为float数组

问题描述 投票:-1回答:1

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

我发现的唯一方法是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;
}
c++ arrays boost boost-geometry
1个回答
0
投票

你这样做的方式并没有错,但是你可以通过创建一个结构来简化这个过程,在它的构造函数中使用boxvariable:

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

这样,每次要将值与数组一起使用时,就不必分配值。

编辑:boxonly有2个角(2 points) - >你的数组大小应该是float array[2][2],你可以删除其他任务。

© www.soinside.com 2019 - 2024. All rights reserved.