箱升压RTREE给出了段相交错误 [英] boost rtree of box gives wrong intersection with segment
问题描述
升压RTREE给出了一些交叉口段查询交集错误的结果。
在这种情况下,边框在y = 0的y平面10×10平方。我与一个Z-对齐线从查询(2,1,0)到(2,1,10)。有趣的是,如果我用一个框查询,而不是一个段,那么它将按预期工作。这种行为也是present当箱子不是平面,只要将分一角(0,-5,0),它仍然发生。
Boost rtree gives wrong intersection result for some intersection with segment queries. In this case the bounding box is a y-planar 10x10 square at y=0. I'm querying with a z-aligned line from (2, 1, 0) to (2, 1, 10). What's interesting is that if I use a box for query instead of a segment then it works as expected. This behavior is also present when the box is not planar, just move the min corner to (0, -5, 0) and it still happens.
我使用这个错误或者是在提升一个bug?
Am I using this wrong or is it a bug in boost?
编辑:曾尝试对升压1.56和1.59
have tried this on Boost 1.56 and 1.59.
#include <vector>
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
#include <boost/geometry/index/rtree.hpp>
#include <vector>
#include <iterator>
#include <memory>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
typedef bg::model::point<double, 3, bg::cs::cartesian> point_def;
typedef bg::model::box<point_def> box;
typedef bg::model::segment<point_def> segment;
typedef std::pair<box, size_t> tri_box;
typedef bgi::rtree< tri_box, bgi::linear<8>> tree_type;
using namespace std;
TEST(boost_rtree, cant_intersect_box_with_segment) {
vector<tri_box> buff(1);
buff[0].first = box{point_def{0, 0, 0}, point_def{10, 0, 10}};
buff[0].second = 1;
tree_type tree(buff);
segment query{point_def{2, 1, 0}, point_def{2, 1, 10}};
// box query{point_def{2, 1, 0}, point_def{2, 1, 10}};
vector<tri_box> out;
size_t count = tree.query(bgi::intersects(query), back_inserter(out));
ASSERT_EQ(0, count); // fails here
ASSERT_EQ(0, out.size());
}
编辑:问题正在采取行动,扩大邮件列表:lists.boost.org/geometry/2015/09/3472.php
issue is being moved to boost mailing list: lists.boost.org/geometry/2015/09/3472.php
推荐答案
由于不太可能,因为它看来,这在我看来是一个错误。
As unlikely as it seems, this appears to me to be a bug.
这甚至编译这样做的第一个版本是1.56提升。所有previous版本失败,
The first version that even compiles this is Boost 1.56. All previous versions fail with
BOOST_MPL_ASSERT_MSG
(
false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
, (types<Geometry>)
);
不过,即使code编译,它似乎并不正确......:在相交
电话构成了这一查询predicate本身返回假阳性看来。
But, even though the code is compiled, it does not seem to be correct...: the intersects
call that underlies the query predicate itself returns "false positive" it seems.
大大简化: <大骨节病> 住在Coliru 骨节病>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<int, 3, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef bg::model::segment<point> segment;
int main() {
box y0rect = box{point{0, 0, 0}, point{10, 0, 10}};
segment seg{point{2, 1, 0}, point{2, 1, 10}};
bg::correct(y0rect);
bg::correct(seg);
assert(!bg::intersects(seg, y0rect));
}
更新
有趣的是,它似乎正常工作的有时的作为2D。我不知道结果不是简单地不确定...
Interestingly, it seems to work correctly sometimes for 2d. I'm not sure the outcome isn't simply undefined...
<大骨节病> 住在Coliru 骨节病>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/box.hpp>
#include <boost/geometry/geometries/segment.hpp>
namespace bg = boost::geometry;
typedef bg::model::point<int, 4, bg::cs::cartesian> point;
typedef bg::model::box<point> box;
typedef bg::model::segment<point> segment;
int main() {
box y0rect = box{point{0, 0}, point{10, 10}};
bg::correct(y0rect);
{
segment seg{point{12, 0}, point{20, 10}};
bg::correct(seg);
assert(!bg::intersects(seg, y0rect));
}
{
segment seg{point{2, 0}, point{8, 6}};
bg::correct(seg);
assert(bg::intersects(seg, y0rect));
}
{
segment seg{point{2, 0}, point{18, 6}};
bg::correct(seg);
assert(bg::intersects(seg, y0rect)); // OOPS BREAKS?
}
}
这篇关于箱升压RTREE给出了段相交错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!