nat icon indicating copy to clipboard operation
nat copied to clipboard

im3d [ operator (as alternative to imslice)

Open jefferis opened this issue 10 years ago • 1 comments

Should review why this was tricky

x=im3d(...)
y=x[,10,]
z=x[,,10]

is rather more intuitive than

y=imslice(x,10,slicedim='z')
z=imslice(x,10)

jefferis avatar Mar 20 '14 01:03 jefferis

some work already on feature/im3d-sub branch but does not handle bounding boxes for singleton dimensions properly

`[.im3d`<-function(x, i, j, ... , drop = TRUE){
  subswehave=rep(FALSE,3)
  sublist=as.list(rep(TRUE,3))
  if(!missing(i)) {
    subswehave[1]=TRUE
    sublist[[1]]=i
  }
  if(!missing(j)){
    subswehave[2]=TRUE
    sublist[[2]]=j
  }
  if(!missing(...) && length(...)){
    subswehave[3]=TRUE
    sublist[[3]]=as.list(...)[[1]]
  }
  # if this is a regular array (rather than an empty im3d object) this will do
  # the basic subset operation
  rval=NextMethod()
  newdims=dim(rval)
  voxpos=mapply('[',attributes(x)[c("x",'y','z')],sublist)
  attributes(rval)[names(voxpos)]=voxpos
  class(rval)=class(x)
  boundingbox(rval)=boundingbox(rval)
  rval
}

jefferis avatar Mar 21 '14 10:03 jefferis