- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在使用以下 (Rcpp) 代码执行编译时断言。此代码将 10^6 个随机点插入到一个 vector 中,从该 vector 构建 r 树,然后查询落在由 (1/3, 1/3) 和 (2/3, 2/3) 包围的框内的点.
// [[Rcpp::depends(BH)]]
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
#include <vector>
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
using key_type = std::pair<double, double>;
using box_type = std::pair<key_type, key_type>;
using range_type = std::vector<key_type>;
BOOST_GEOMETRY_REGISTER_POINT_2D(key_type, double,
bg::cs::cartesian,
first, second);
BOOST_GEOMETRY_REGISTER_BOX(box_type, key_type, first, second);
// [[Rcpp::export]]
void test_it()
{
range_type data;
for (int i = 0; i != 1e6; ++i)
data.emplace_back(R::runif(0, 1), R::runif(0, 1));
using rtree_type = bgi::rtree<key_type, bgi::linear<16>>;
rtree_type rt(data);
key_type p1 = std::make_pair(0.33, 0.33),
p2 = std::make_pair(0.66, 0.66);
box_type roi = std::make_pair(p1, p2);
range_type res;
rt.query(bgi::contains(roi), std::back_inserter(res));
}
没有最后一个查询行也能正常编译。编译器输出为:
In file included from geom_test.cpp:7:
In file included from /usr/local/include/boost/geometry.hpp:17:
In file included from /usr/local/include/boost/geometry/geometry.hpp:50:
In file included from /usr/local/include/boost/geometry/strategies/strategies.hpp:33:
In file included from /usr/local/include/boost/geometry/strategies/disjoint.hpp:24:
In file included from /usr/local/include/boost/geometry/strategies/relate.hpp:23:
/usr/local/include/boost/geometry/strategies/within.hpp:80:5: error: no matching function for call to 'assertion_failed'
BOOST_MPL_ASSERT_MSG
^~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/mpl/assert.hpp:435:48: note: expanded from macro 'BOOST_MPL_ASSERT_MSG'
#define BOOST_MPL_ASSERT_MSG( c, msg, types_ ) \
^
/usr/local/include/boost/mpl/assert.hpp:429:9: note: expanded from macro '\
BOOST_MPL_ASSERT_MSG_IMPL'
boost::mpl::assertion_failed<(c)>( BOOST_PP_CAT(mpl_assert_arg,counter)::assert_arg() ) \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/local/include/boost/mpl/assert.hpp:60:58: note: expanded from macro '\
BOOST_MPL_AUX_ASSERT_CONSTANT'
# define BOOST_MPL_AUX_ASSERT_CONSTANT(T, expr) enum { expr }
^~~~
最佳答案
你说
then queries for points falling with a box bounded by (1/3, 1/3) and (2/3, 2/3)
然而您的代码正在寻找“包含”一个框的点。
你的意思可能是:
rt.query(bgi::within(roi), std::back_inserter(res));
#include <boost/geometry.hpp>
#include <boost/geometry/geometries/register/box.hpp>
#include <boost/geometry/geometries/register/point.hpp>
#include <vector>
#include <random>
#include <iostream>
namespace bg = boost::geometry;
namespace bgi = boost::geometry::index;
using key_type = std::pair<double, double>;
using box_type = std::pair<key_type, key_type>;
using range_type = std::vector<key_type>;
BOOST_GEOMETRY_REGISTER_POINT_2D(key_type, double, bg::cs::cartesian, first, second)
BOOST_GEOMETRY_REGISTER_BOX(box_type, key_type, first, second)
int main() {
std::mt19937 engine { std::random_device{}() };
std::uniform_real_distribution<double> dist(0,1.0);
range_type data;
for (int i = 0; i != 1e6; ++i)
data.emplace_back(dist(engine), dist(engine));
using rtree_type = bgi::rtree<key_type, bgi::linear<16> >;
rtree_type rt(data);
box_type const roi {{0.33, 0.33}, {0.66,0.66}};
range_type res;
rt.query(bgi::within(roi), std::back_inserter(res));
std::cout << res.size() << " results\n";
}
打印类似的东西
109073 results
关于c++ - 具有适配 std::pair 点类型的 R-Tree 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49222879/
我正在学习使用 STL 的排序函数,方法是将它用于一些复杂的对 vector 。 我有以下 vector : vector > > > > 我需要先根据对中的第一个整数对元素进行排序,如果发现有 2
我想初始化: pair>,vector>> pvp; 所以对于所有的我: pvp.first[i].first = true; 和 pvp.second[i].first = false; 我知道您可
那为什么我们能实例化Pair却不能实例化Pair Pair p=new Pair(); 对比 Pair p=new Pair(); 我知道 意思是未知类型 --> 但不是 意思是一样的---> 有
这个问题在这里已经有了答案: How to have an unordered_map where the value type is the class it's in? (1 个回答) `std
我正在编写一个代码来处理warehouse[item[batch, qty]]的组合,然后将基于[batch, qty]的batch与qty的总和分组。我的代码是: package main impo
我想知道最好的类 java 容器是什么 > 我有一个作为键的 object1 以及一个 t1 和 t2。 我的类具有以下属性: public class Patient implements Exte
所以我有一些使用 Java 8 流的代码,而且它可以工作。它做的正是我需要它做的,而且清晰易读(这在函数式编程中很少见)。在子例程结束时,代码遍历自定义对类型的列表: // All names Hun
我正在声明一个字符串映射到一对对,如下所示: std::map, std::pair>> reference; 我将其初始化为: reference.insert
例如,镜像 pair 至 pair ,我可以像这样创建一个模板函数: template void mirror(const AB& ab,BA& ba){ ba.first=ab.secon
我正在使用 PyZMQ 创建一个简单的 PAIR/PAIR 通信原型(prototype)消息传递模式。 配对服务器 import zmq import random import sys impor
我正在尝试习惯 Kotlin 中的习语和快捷方式,我想知道是否有任何方法可以做到这一点。 val pairList = listOf(Pair(1, 2), Pair(5, 10), Pair(12,
我定义的 map 是这样的 map > hmap; 如果有一个pair(2,pair(3,4))如何得到2 3 4个值,itr->first, itr->第二个不工作 最佳答案 If there is
我希望能够对以下 vector 进行排序 -vector>> 基于 pair 的第一个元素,如果它们相等,则根据它们的第二个元素对它们进行排序,我如何使用 STL 在 C++ 中做到这一点构建? 这种
通过 PHP_PDO: fetchAssoc echo 从 MySql SELECT 查询得到一个 $.getJSON 结果使用 json_encode() 编辑,在 firebug 控制台中的输出如
假设我有以下功能: (defun f (v1 v2) ...) 我想简化以下代码: (lambda (pair) (apply #'f pair)) 此处的目标是创建一个函数,该函数接受两个值的列表并
对不起,我真的不知道怎么写这个标题。我可以想到这样做的代价高昂的方法,但我想看看是否有人可以指出一个优雅的解决方案,这里是: 我有很多成对关联的元素; 每个元素都有一个与其自身关联的数值,该数值表示它
我有一个使用以下方法用 Java 编写的 PreferencesManager: public void insert(Pair keyValue, boolean async) { 我正尝试从 k
这是 assigning-of-unordered-map-to-pair-of-objects 的后续问题.这是一个关于编译器错误解释的问题(而不是一个重复的问题,因为该问题已经得到了完整的回答)。
这是我的 map : map, pair > matchMap; 这是函数: void Schedule::studentSchedule() { string s, c; cout
#include #include #include using namespace std; int main() { map,pair> items; items.inser
我是一名优秀的程序员,十分优秀!