【发布时间】:2016-02-05 00:19:00
【问题描述】:
我是 boost 和“重”模板的新手。从现在开始我就一直在玩,并试图将数组传递给惊人的 boost::geometry::convex_hull 函数。没有运气。
我准备了下面的例子:
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/polygon.hpp>
#include <boost/geometry/geometries/adapted/boost_tuple.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <iostream>
using namespace std;
namespace bg = boost::geometry;
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
int main()
{
typedef boost::tuple<float, float> point;
typedef bg::model::polygon<point> polygon;
polygon poly, hull;
// define rectangle, this will become also our convex hull
bg::append( poly, point( 0.0, 0.0 ) );
bg::append( poly, point( 1.0, 0.0 ) );
bg::append( poly, point( 1.0, 1.0 ) );
// bg::append( poly, point( 2.0, 2.0 ) );
bg::append( poly, point( 1.0, 0.0 ) );
// mid point, which should not be part of the hull
bg::append( poly, point( 0.5, 0.5 ) );
// The above poly would ideally constructed with:
// float myInputData[] = { 0.0, 0.0, 1.0, 0.0, 1.0, 1.0, 2.0, 2.0, 1.0, 0.0 };
// and then used like: bg::convex_hull( myInputData, hull );
bg::convex_hull( poly, hull );
cout << "convex hull is:\n";
vector<boost::tuples::tuple<float, float> >::iterator it;
for( it = hull.outer().begin(); it != hull.outer().end(); ++it )
cout << "(" << bg::get<0>(*it) << "/" << bg::get<1>(*it) << ")\n";
}
附加了 bg::append 的点应该在一个简单的 c 数组中,例如:
float mydataArray[ 20 ];
数据布局的格式为 [ x1, y1, x2, y2... ] 所以理想的函数是:bg::append_points(arrayOfAlternating_X_Y_coordinates)
我还想将结果(船体)作为数组指针传递给 OpenGL,而不是通过浮点数迭代并读出坐标浮动(因此,目标是:摆脱 bg::get(*it ))。
结果也应该有 [ x1, y1, x2, y2 ...]
我有一种感觉,这种提升并没有提供我想要的功能。那么,我摆脱循环的想法有问题吗?如何编写一个可以被 bg::convex_hull 函数使用的智能访问类?
【问题讨论】:
-
录制的会话是here (experiment)
标签: c++ templates boost convex-hull boost-geometry