コード例 #1
0
ファイル: convert.cpp プロジェクト: cran/hypervolume
// [[Rcpp::export]]
SEXP kdtree_ball_query_multiple(SEXP tr, SEXP ptlist, SEXP nr, SEXP nc, SEXP r, SEXP verb)
{
  XPtr<KDTree> tree = as<XPtr<KDTree> >(tr);
  int nrow = as<int>(nr);
  int ncol = as<int>(nc);
  NumericVector data(ptlist);
  double radius = as<double>(r);
  bool verbose = as<int>(verb);
  
  vector<vector< double > > dataMatrix
    = convertMatrixToVector(data.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> thisDistances;
    
    vector<double> thisPoint = dataMatrix[i];
    tree->ball_query(thisPoint, radius, thisIndices, thisDistances);
    
    // 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);
    }
    
  }
  
  if (verbose==1)
  {
    Rcpp::Rcout << "\ndone.\n";
  }
  
  //pb.update(1);
  
  return(wrap(finalCounts));
}