繁体   English   中英

框的提升rtree与段错误相交

[英]boost rtree of box gives wrong intersection with segment

Boost rtree对于与段查询的某些交集给出错误的交集结果。 在这种情况下,边界框是在y = 0处的y平面10x10正方形。 我正在查询从(2,1,0)到(2,1,10)的z对齐线。 有趣的是,如果我使用查询框而不是句段,那么它将按预期工作。 当盒子不是平面时,也存在这种现象,只需将最小角移到(0,-5,0)上,它仍然会发生。

我是用错了还是升压中的错误?

编辑:已经在Boost 1.56和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

看起来似乎不太可能,这似乎是一个错误。

甚至可以编译的第一个版本是Boost 1.56。 所有以前的版本均以失败

BOOST_MPL_ASSERT_MSG
    (
        false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
        , (types<Geometry>)
    );

但是,即使代码已编译,也似乎不正确...:查询谓词本身的intersects调用似乎返回“假阳性”。

大大简化: Live on 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));
}

UPDATE

有趣的是, 有时 2d似乎可以正常工作。 我不确定结果不是只是不确定的...

生活在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?
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM