diff --git a/R/inside_polygon.R b/R/inside_polygon.R index 5cd3f58..b5f6366 100644 --- a/R/inside_polygon.R +++ b/R/inside_polygon.R @@ -16,7 +16,17 @@ #' @importFrom concaveman concaveman #' @importFrom tidyr pivot_longer #' @export - +#' @examples +#' x3p <- x3p_subsamples[[1]] +#' bounds <- x3p_boundary_points(x3p, 2) +#' polygon <- inside_polygon(bounds$x, bounds$y, 1) +#' +#' library(ggplot2) +#' library(dplyr) +#' bounds %>% +#' ggplot(aes(x = x, y = y)) + geom_point() + +#' geom_polygon(data = polygon) +#' inside_polygon <- function(x, y, concavity, center = NULL) { stopifnot(concavity > 0) diff --git a/R/x3p_boundary_points.R b/R/x3p_boundary_points.R index 29f769b..8cfe167 100644 --- a/R/x3p_boundary_points.R +++ b/R/x3p_boundary_points.R @@ -9,7 +9,16 @@ #' @importFrom dplyr `%>%` group_by mutate filter summarize select #' @importFrom rlang .data #' @export - +#' @examples +#' x3p <- x3p_subsamples[[1]] +#' bounds <- x3p_boundary_points(x3p, 2) +#' +#' library(ggplot2) +#' library(dplyr) +#' bounds %>% +#' ggplot(aes(x = x, y = y)) + +#' geom_point() +#' x3p_boundary_points <- function(x3p, sample) { stopifnot("x3p" %in% class(x3p)) x3p_df <- x3p %>% diff --git a/R/x3p_surface_polygon.R b/R/x3p_surface_polygon.R index 1d00e88..59bec74 100644 --- a/R/x3p_surface_polygon.R +++ b/R/x3p_surface_polygon.R @@ -16,7 +16,12 @@ #' @importFrom grDevices as.raster dev.off #' @importFrom graphics par plot.default polygon #' @export - +#' @examples +#' if (interactive()) { +#' x3p <- x3p_subsamples[[1]] +#' x3p <- x3p %>% x3p_surface_polygon(sample=1) +#' x3p_image(x3p, size = dim(x3p$surface.matrix), zoom=.6) +#' } x3p_surface_polygon <- function(x3p, colour = "red", sample = 10, center = NULL, concavity = 1.5) { stopifnot("x3p" %in% class(x3p), is.numeric(concavity), concavity > 0) diff --git a/man/inside_polygon.Rd b/man/inside_polygon.Rd index 9729df6..42e37e7 100644 --- a/man/inside_polygon.Rd +++ b/man/inside_polygon.Rd @@ -27,3 +27,15 @@ described by the input x and y, variable id describes the order of the points Uses concentric mirroring onto a radius around the center point, applies an alpha hull to that shape, and mirrors the result back. } +\examples{ +x3p <- x3p_subsamples[[1]] +bounds <- x3p_boundary_points(x3p, 2) +polygon <- inside_polygon(bounds$x, bounds$y, 1) + +library(ggplot2) +library(dplyr) +bounds \%>\% +ggplot(aes(x = x, y = y)) + geom_point() + + geom_polygon(data = polygon) + +} diff --git a/man/x3p_boundary_points.Rd b/man/x3p_boundary_points.Rd index 39a6ef3..ebdb561 100644 --- a/man/x3p_boundary_points.Rd +++ b/man/x3p_boundary_points.Rd @@ -19,3 +19,14 @@ data frame of boundary points, variables are named \code{x} and \code{y} \description{ Identify boundary of a 3d topographic scan in x3p format } +\examples{ +x3p <- x3p_subsamples[[1]] +bounds <- x3p_boundary_points(x3p, 2) + +library(ggplot2) +library(dplyr) +bounds \%>\% +ggplot(aes(x = x, y = y)) + +geom_point() + +} diff --git a/man/x3p_surface_polygon.Rd b/man/x3p_surface_polygon.Rd index 39450ec..dc8114d 100644 --- a/man/x3p_surface_polygon.Rd +++ b/man/x3p_surface_polygon.Rd @@ -33,3 +33,10 @@ x3p object with mask \description{ Add a polygon of the scan shape as mask } +\examples{ +if (interactive()) { + x3p <- x3p_subsamples[[1]] + x3p <- x3p \%>\% x3p_surface_polygon(sample=1) + x3p_image(x3p, size = dim(x3p$surface.matrix), zoom=.6) +} +}