将bo数据提升到浮点数组。

时间:2022-01-05 21:01:15

I'm newbee in c++ boost libraries. Can not uderstrand simple thing. How transfer data between structures like geometry::point and geometry::box to simple float array. Only way that i have found is get method. For each transfer i am need to use this?

我是c++ boost库中的newbee。不能简单的东西。如何在结构之间传输数据,如几何::点和几何::盒到简单的浮动阵列。我找到的唯一方法就是获取方法。对于每一个转移,我都需要使用这个?

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

1 个解决方案

#1


0  

Your way of doing it is not wrong, but you can simplify the process by creating a struct, with a boxvariable in it's constructor:

您的方法并不是错误的,但是您可以通过创建一个struct来简化这个过程,在它的构造函数中有一个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);
    };
};

This way, you don't have to assign the values each time you want to use the values with an array.

这样,您不必每次都要使用数组的值来分配值。

EDIT: boxonly has 2 corners (2 points) -> your array size should be float array[2][2] and you can remove the other assignments.

编辑:boxonly有两个角(2个点)->你的数组大小应该是浮点数组[2][2],你可以删除其他的赋值。

#1


0  

Your way of doing it is not wrong, but you can simplify the process by creating a struct, with a boxvariable in it's constructor:

您的方法并不是错误的,但是您可以通过创建一个struct来简化这个过程,在它的构造函数中有一个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);
    };
};

This way, you don't have to assign the values each time you want to use the values with an array.

这样,您不必每次都要使用数组的值来分配值。

EDIT: boxonly has 2 corners (2 points) -> your array size should be float array[2][2] and you can remove the other assignments.

编辑:boxonly有两个角(2个点)->你的数组大小应该是浮点数组[2][2],你可以删除其他的赋值。