Skip to content

Commit

Permalink
new function setmask to include mask definition, e.g. generated by fs…
Browse files Browse the repository at this point in the history
…l_bet, in dtiData object
  • Loading branch information
Joerg Polzehl committed Oct 17, 2022
1 parent bb42234 commit 1a4b78f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dti
Version: 1.5.2
Date: 2020-05-19
Version: 1.5.3
Date: 2022-10-17
Title: Analysis of Diffusion Weighted Imaging (DWI) Data
Authors@R: c(person("Karsten", "Tabelow", role = c("aut", "cre"),
email = "[email protected]"),
Expand Down
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ exportMethods("show", "plot", "print", "summary", "dti.smooth", "dtiTensor",
"dtiIndices", "dwiQball", "dwiMixtensor", "dwiMtCombine",
"dwiRiceBias", "dkiTensor", "dkiIndices", "dwiMD")
exportMethods("extract", "show3d", "tracking", "selectFibers", "reduceFibers",
"touchingFibers", "combineFibers", "getmask", "sdpar",
"touchingFibers", "combineFibers", "getmask", "setmask", "sdpar",
"getsdofsb", "dwi.smooth", "dwi.smooth.ms")
export(dtiData, readDWIdata, subsetg, combineDWIdata, awssigmc, awslsigmc, afsigmc,
aflsigmc, dkiIndices, showFAColorScale, tensor2medinria, medinria2tensor)
5 changes: 4 additions & 1 deletion R/io.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
# #
################################################################

dtiData <- function(gradient,imagefile,ddim,bvalue=NULL,xind=NULL,yind=NULL,zind=NULL,level=0,mins0value=1,maxvalue=32000,voxelext=c(1,1,1),orientation=c(0L,2L,5L),rotation=diag(3)) {
dtiData <- function(gradient,imagefile,ddim,bvalue=NULL,xind=NULL,
yind=NULL,zind=NULL,level=0,mins0value=1,
maxvalue=32000,voxelext=c(1,1,1),
orientation=c(0L,2L,5L),rotation=diag(3)) {
args <- list(sys.call())
if (any(sort((orientation)%/%2) != 0:2)) stop("invalid orientation \n")
if (dim(gradient)[2]==3) gradient <- t(gradient)
Expand Down
25 changes: 24 additions & 1 deletion R/utilities.r
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,28 @@ setMethod("extract","dwiQball",function(x,
invisible(z)
})

setmask <- function(object, ...) cat("No method defined for class:",class(object),"\n")

setGeneric("setmask", function(object, ...) standardGeneric("getmask"))

setMethod("setmask","dtiData",function(object, maskfile){
ddim <- object@ddim0
xind <- object@xind
yind <- object@yind
zind <- object@zind
mask <- oro.nifti::readNIfTI(maskfile, reorient = FALSE)
dmask <- mask@dim_
if(all(ddim == dmask)){
object@mask <- mask[xind,yind,zind] > 0
} else if(all(dmask == object@ddim)){
object@mask <- mask > 0
} else {
stop("Incorrect dimensions of mask file")
}
object
}
)

getmask <- function(object, ...) cat("No method defined for class:",class(object),"\n")

setGeneric("getmask", function(object, ...) standardGeneric("getmask"))
Expand All @@ -1110,6 +1132,7 @@ setMethod("getmask","dtiData",function(object, level=NULL, prop=.4, size=3){
z
}
)

setMethod("getmask","array",function(object, level=NULL, prop=.4, size=3){
if(length(dim(object))!=3){
level <- NULL
Expand Down Expand Up @@ -1144,7 +1167,7 @@ selectCube <- function(xind,yind,zind,ddim,maxobj){
n1 <- length(xind)
n2 <- length(yind)
n3 <- length(zind)
if(any(c(xind[1],yind[1],zind[1]) < 1 || any(c(xind[n1]-ddim[1],yind[n2]-ddim[2],zind[n3]-ddim[3])>0))){
if(any(c(xind[1],yind[1],zind[1]) < 1) || any(c(xind[n1]-ddim[1],yind[n2]-ddim[2],zind[n3]-ddim[3])>0)){
stop("Error in index specification, specified cube exceeds dimensions of object")
}
l1 <- (xind[n1]-xind[1]+1-n1) == 0
Expand Down
41 changes: 41 additions & 0 deletions man/setmask-methods.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
%- Also NEED an '\alias' for EACH other topic documented here.
\name{setmask-methods}
\docType{methods}
\alias{setmask}
\alias{setmask-methods}
\alias{setmask,ANY-method}
\alias{setmask,dtiData-method}
\title{ Methods for Function `setmask' in Package `dti' }
\description{
Read mask definition from NIfTI file and include it in dtiData object
}
\usage{
\S4method{setmask}{dtiData}(object, maskfile)
}
%- maybe also 'usage' for other objects documented here.
\arguments{
\item{object}{an object of class \code{"dtiData"}}
\item{maskfile}{NIfTI file containing mask definition. Dimension need to be
compatible, i.e. either equal \code{object@ddim0} or \code{object@ddim}}
}
\section{Methods}{
\describe{
\item{obj = "ANY"}{ Returns a warning }
\item{obj = "dtiData"}{Set mask definition in dtiObject using information provided as NIfTI file as e.g. provided by \code{fsl_bet}. }
}
}
\value{
The function returns an object of class \code{dtiData}.
}
\author{
Karsten Tabelow \email{[email protected]}\cr
J\"org Polzehl \email{[email protected]}
}
\seealso{
\code{\link{dtiData}},
\code{\link{readDWIdata}},
}
\keyword{ methods }

0 comments on commit 1a4b78f

Please sign in to comment.