// [[Rcpp::export]] SEXP kdtree_range_query_multiple(SEXP tr, SEXP pminlist, SEXP pmaxlist, SEXP nr, SEXP nc, SEXP verb) { XPtr<KDTree> tree = as<XPtr<KDTree> >(tr); int nrow = as<int>(nr); int ncol = as<int>(nc); NumericVector datamin(pminlist); NumericVector datamax(pmaxlist); bool verbose = as<int>(verb); if (ncol != tree->ndims()) { throw(length_error("pmin or pmax not same dimensionality as data in kdtree")); } vector<vector< double > > dataminMatrix = convertMatrixToVector(datamin.begin(), nrow, ncol); vector<vector< double > > datamaxMatrix = convertMatrixToVector(datamax.begin(), nrow, ncol); vector<int> finalCounts; if (ncol != tree->ndims()) { throw(length_error("Points not same dimensionality as data in kdtree")); } //RProgress::RProgress pb("[:bar]", nrow); if (verbose==1) { Rcpp::Rcout << "Ball query... \n"; //pb.tick(0); } for (int i=0; i<nrow; i++) { vector<int> thisIndices; vector<double> thisPointMin = dataminMatrix[i]; vector<double> thisPointMax = datamaxMatrix[i]; tree->range_query(thisPointMin, thisPointMax, thisIndices); // store the number of points within the ball for each point finalCounts.push_back(thisIndices.size()); if (i%10==0 && verbose==1) { //pb.update(1.0*(i+1)/nrow); } } //pb.update(1); if (verbose==1) { Rcpp::Rcout << "\ndone.\n"; } return(wrap(finalCounts)); }