MyNixOS website logo
Description

'Rcpp' Integration for 'CGAL'.

Creates a header only package to link to the 'CGAL' (Computational Geometry Algorithms Library) header files in 'Rcpp'. There are a variety of potential uses for the software such as Hilbert sorting, K-D Tree nearest neighbors, and convex hull algorithms. For more information about how to use the header files, see the 'CGAL' documentation at <https://www.cgal.org>. Currently downloads version 5.6.1 of the 'CGAL' header files.

R-CMD-check

RcppCGAL: CGAL Headers for R

Description

This package provides access to the Computational Geometry Algorithms Library (CGAL) in R.
CGAL provides access to methods like KDtree, Hilbert sorting, convex hull calculation, and many more.

This package allows for the easy linking of the CGAL header files into R packages without having to download and manually add the appropriate CGAL header file into an R package.

Much like the BH package, the RcppCGAL package can be used via the LinkingTo: field in the DESCRIPTION file in R packages. This will allow access to the header files in C/C++ source code.

Version

This package currently bundles the 5.6 stable release.

Installation

To install this package, you can install the version from CRAN:

install.packages("RcppCGAL")

Alternatively, you can download or clone the git repository. Then you can install using devtools

devtools::install("RcppCGAL")

You may also install from github directly using the devtools::install_github() function.

By default, the package will use the header files bundled with the package. However, if you already have a version of the CGAL headers that you prefer to use, you can specify the environmental variable CGAL_DIR and R will use that instead:

Sys.setenv("CGAL_DIR" = "path/to/CGAL")

or, if the function is already installed, you can use the set_cgal() function in the package

set_cgal("path/to/CGAL")

and then re-install.

Typically, the folder with all the header files is called CGAL. For example, on my Mac with a Homebrew install of CGAL, I would do

Sys.setenv("CGAL_DIR" = "/usr/local/Cellar/cgal/5.6/include/CGAL")

Note: this must be done before the package is installed by R.

Example

We provide an example of how to perform Hilbert sorting using an R matrix:

// [[Rcpp::depends(RcppCGAL)]]
// [[Rcpp::depends(BH)]]
// [[Rcpp::depends(RcppEigen)]]
// [[Rcpp::plugins(cpp14)]]  

#include <RcppEigen.h>
#include <CGAL/basic.h>
#include <CGAL/Cartesian_d.h>
#include <CGAL/spatial_sort.h>
#include <CGAL/Spatial_sort_traits_adapter_d.h>
#include <CGAL/boost/iterator/counting_iterator.hpp>
#include <CGAL/hilbert_sort.h>
#include <CGAL/Spatial_sort_traits_adapter_d.h>

typedef CGAL::Cartesian_d<double>           Kernel;
typedef Kernel::Point_d                     Point_d;

typedef CGAL::Spatial_sort_traits_adapter_d<Kernel, Point_d*>   Search_traits_d;

void hilbert_sort_cgal_fun(const double * A, int D, int N,  int * idx)
{
  
  std::vector<Point_d> v;
  double * temp = new double[D];
  
  for (int n = 0; n < N; n++ ) {
    for (int d = 0; d < D; d ++) {
      temp[d] = A[D * n + d];
    }
    v.push_back(Point_d(D, temp, temp+D));
  }
  
  std::vector<std::ptrdiff_t> temp_index;
  temp_index.reserve(v.size());
  
  std::copy(
    boost::counting_iterator<std::ptrdiff_t>(0),
    boost::counting_iterator<std::ptrdiff_t>(v.size()),
    std::back_inserter(temp_index) );
  
  CGAL::hilbert_sort (temp_index.begin(), temp_index.end(), Search_traits_d( &(v[0]) ) ) ;
  
  for (int n = 0; n < N; n++) {
    idx[n] = temp_index[n];
  }
  
  delete [] temp;
  temp=NULL;
}

// [[Rcpp::export]]
Rcpp::IntegerVector hilbertSort(const Eigen::MatrixXd & A)
{
  int K = A.rows();
  int N = A.cols();
  std::vector<int> idx(N);
  
  hilbert_sort_cgal_fun(A.data(), K, N, &idx[0] );
  return(Rcpp::wrap(idx));
}

Saving this code as hilbertSort.cpp and sourcing with Rcpp Rcpp::sourceCpp("hilbertSort.cpp") makes the function hilbertSort(). Be aware that this example function example assumes that the observations are stored by column rather than by row, that is as the transpose of the usual Rmatrix or data.frame.

Author

Eric Dunipace

License

This package is provided under the GPL-3. For the use of the header files outside this package, please see the information at the CGAL site: https://www.cgal.org/license.html.

Metadata

Version

5.6.4

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows