From 2602f2eed081c1f6c5692fbe93954cdd9ceaf79a Mon Sep 17 00:00:00 2001 From: "Yuhang (Tom) Lin" Date: Tue, 30 Apr 2024 19:19:57 -0500 Subject: [PATCH] Option for extracting the original shape --- R/x3p_insidepoly_df.R | 12 +++++++++--- README.md | 2 +- man/x3p_insidepoly_df.Rd | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/R/x3p_insidepoly_df.R b/R/x3p_insidepoly_df.R index d65fa0f..60a3417 100644 --- a/R/x3p_insidepoly_df.R +++ b/R/x3p_insidepoly_df.R @@ -4,7 +4,7 @@ #' #' @param x3p An `x3p` object representing a topographic scan. #' @param mask_col A string representing the color to be used for the polygon. -#' @param concavity A strictly positive number used in `concaveman::concaveman` to influence the shape of the polygon. +#' @param concavity A strictly positive number used in `concaveman::concaveman` to influence the shape of the polygon. If `NULL`, the shape is taken to be the whole scan. #' @param b A positive integer representing the block size for `x3ptools::x3p_average`. #' @param ifplot A Boolean flag indicating whether to save ggplot lists in the output attributes. #' @return A data frame summarizing the inner polygon. The data frame includes the following columns: @@ -56,8 +56,14 @@ x3p_insidepoly_df <- function(x3p, mask_col = "#FF0000", concavity = 1.5, b = 10 n_discrete <- NULL - x3p <- x3p %>% - x3p_surface_polygon(colour = mask_col, concavity = concavity) + if (!is.null(concavity)) { + x3p <- x3p %>% + x3p_surface_polygon(colour = mask_col, concavity = concavity) + } else { + x3p <- x3p %>% + x3p_add_mask() + x3p$mask <- mask_col + } ### Extract inner part as x3p based on mask x3p_inner <- x3p_extract(x3p, mask_vals = mask_col) diff --git a/README.md b/README.md index a556bb7..0846c27 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) -[![Last-changedate](https://img.shields.io/badge/last%20change-2024--04--28-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main) +[![Last-changedate](https://img.shields.io/badge/last%20change-2024--04--30-yellowgreen.svg)](https://github.com/YuhangTom/wire/commits/main) [![CRAN status](https://www.r-pkg.org/badges/version/wire.png)](https://CRAN.R-project.org/package=wire) [![Codecov test diff --git a/man/x3p_insidepoly_df.Rd b/man/x3p_insidepoly_df.Rd index 95c84c1..b024653 100644 --- a/man/x3p_insidepoly_df.Rd +++ b/man/x3p_insidepoly_df.Rd @@ -17,7 +17,7 @@ x3p_insidepoly_df( \item{mask_col}{A string representing the color to be used for the polygon.} -\item{concavity}{A strictly positive number used in \code{concaveman::concaveman} to influence the shape of the polygon.} +\item{concavity}{A strictly positive number used in \code{concaveman::concaveman} to influence the shape of the polygon. If \code{NULL}, the shape is taken to be the whole scan.} \item{b}{A positive integer representing the block size for \code{x3ptools::x3p_average}.}