Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

43 allow user to quickly review digitized images across multiple individuals #64

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Working reviewDigitizedImages() ... nead to cleanup still
  • Loading branch information
droglenc committed Dec 21, 2023
commit 638d850ca5f24bc08362390206117ae8c69d2a54
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# RFishBC 0.2.7.9000
* `reviewDigitizedImages()`: Added (this address [#43](https://github.com/fishR-Core-Team/RFishBC/issues/43).

# RFishBC 0.2.7
* Updated my (DHO) e-mail address in description and all `@author` tags in the documentation files.
Expand Down
121 changes: 121 additions & 0 deletions R/reviewDigitizedImages.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#' @title Allows user to efficiently view images with selected points saved in multiple R data files.
#'
#' @description Allows user to efficiently view images with points to represent annuli that were saved to multiple R data files using \code{\link{digitizeRadii}}. The user can press keyboard buttons to move between (forward and backward) images.
#'
#' @param nms A string (or vector of strings) that indicates the R data file(s) created with \code{\link{digitizeRadii}}. If missing the user will be provided a dialog box from which to choose the file(s). The file(s) must be in the current working directory (see \code{\link{getwd}} result). May also be a single \code{RFishBC} object created with \code{\link{digitizeRadii}}.
#' @param pch.show See details in \code{\link{RFBCoptions}}.
#' @param col.show See details in \code{\link{RFBCoptions}}.
#' @param cex.show See details in \code{\link{RFBCoptions}}.
#' @param connect See details in \code{\link{RFBCoptions}}.
#' @param col.connect See details in \code{\link{RFBCoptions}}.
#' @param lwd.connect See details in \code{\link{RFBCoptions}}.
#' @param col.scaleBar See details in \code{\link{RFBCoptions}}.
#' @param lwd.scaleBar See details in \code{\link{RFBCoptions}}.
#' @param showScaleBarLength See details in \code{\link{RFBCoptions}}.
#' @param cex.scaleBar See details in \code{\link{RFBCoptions}}.
#' @param showAnnuliLabels See details in \code{\link{RFBCoptions}}.
#' @param annuliLabels See details in \code{\link{RFBCoptions}}.
#' @param col.ann See details in \code{\link{RFBCoptions}}.
#' @param cex.ann See details in \code{\link{RFBCoptions}}.
#' @param offset.ann See details in \code{\link{RFBCoptions}}.
#'
#' @return None, but a file is created in the working directory.
#'
#' @details None.
#'
#' @seealso \code{\link{showDigitizedImage}}, \code{\link{saveDigitizedImage}}, \code{\link{digitizeRadii}}, \code{\link{RFBCoptions}}, and \code{\link{jpeg}}, \code{\link{png}}, and \code{\link{pdf}}.
#'
#' @author Derek H. Ogle, \email{[email protected]}
#'
#' @export
#'
#' @examples
#' ## None because this requires interaction from the user.
#' ## See the link to the extensive documentation in the Details.
#'
reviewDigitizedImages <- function(nms,
pch.show,col.show,cex.show,
connect,col.connect,lwd.connect,
col.scaleBar,lwd.scaleBar,
showScaleBarLength,cex.scaleBar,
showAnnuliLabels,annuliLabels,
col.ann,cex.ann,offset.ann) {

## Internal function for handling key press event
keyPress <- function(key) ifelse(key=="f","DONE",ifelse(key=="n","Next","Prev"))

## Internal function for showing image
iReviewDigitizedImage <- function(nm,msg1,
pch.show,col.show,cex.show,
connect,col.connect,lwd.connect,
col.scaleBar,lwd.scaleBar,
showScaleBarLength,cex.scaleBar,
showAnnuliLabels,annuliLabels,
col.ann,cex.ann,offset.ann) {
cat("Showing ",msg1,".",sep="")
showDigitizedImage(nm,"default",
pch.show,col.show,cex.show,
connect,col.connect,lwd.connect,
col.scaleBar,lwd.scaleBar,
showScaleBarLength,cex.scaleBar,
showAnnuliLabels,annuliLabels,
col.ann,cex.ann,offset.ann)
}

# MAIN FUNCTION
## Get image file names ######################################################
## If nms is missing then allow the user to choose a file or files
if (missing(nms)) nms <- iHndlFilenames(nms,filter="RData",multi=TRUE) # nocov start
## If nms is an RFishBC object (and not a filename) then extract the
## filename otherwise process the filename(s)
if (inherits(nms,"RFishBC")) nms <- nms$datanm
else nms <- iHndlFilenames(nms,filter="RData",multi=TRUE)

## Setup for the loop ########################################################
num_imgs <- length(nms)
i <- 0
act <- "Next"
msg2 <- ": 'f'=DONE, 'n'=Next, 'p'=Previous"

## Access images until users says "Done" #####################################
### The use if iReviewDigitizedImage() looks redundant below, but doing this
### means that the image will not be redisplayed when trying to go to next
### or previous when next or previous does not exist.
while (act!="DONE") {
if (act=="Next") {
if (i<num_imgs) {
i <- i+1
msg1 <- tools::file_path_sans_ext(nms[i])
iReviewDigitizedImage(nms[i],msg1,
pch.show,col.show,cex.show,
connect,col.connect,lwd.connect,
col.scaleBar,lwd.scaleBar,
showScaleBarLength,cex.scaleBar,
showAnnuliLabels,annuliLabels,
col.ann,cex.ann,offset.ann)
} else {
cat("There is no 'Next' image. ")
i <- i
}
} else {
if (i>1) {
i <- i-1
msg1 <- tools::file_path_sans_ext(nms[i])
iReviewDigitizedImage(nms[i],msg1,
pch.show,col.show,cex.show,
connect,col.connect,lwd.connect,
col.scaleBar,lwd.scaleBar,
showScaleBarLength,cex.scaleBar,
showAnnuliLabels,annuliLabels,
col.ann,cex.ann,offset.ann)
} else {
cat("There is no 'Prev'ious image. ")
i <- i
}
}
act <- grDevices::getGraphicsEvent(paste0(msg1,msg2),onKeybd=keyPress,
consolePrompt="",onMouseDown="")
}
grDevices::dev.off()
cat("Done.") # nocov end
}