Do you know if it exist libraries or functions in R to plot voxel objects (3D array)? I found the package rgl that can perform 3d scatter plot, but I am really looking for an equivalent of the function "image" that works with 3D array. Thanks
-
It might be worth looking at the [Medical Imaging task view](http://cran.r-project.org/web/views/MedicalImaging.html). There are packages that allow you to slice three dimensional images, I'm not sure what else would be useful within a visualisation. – mnel Dec 21 '12 at 00:26
-
Can you provide some details on what you want to display? For example, a trivial voxel display might be a 3-D scatter plot of points, each point using color to indicate the variable of interest. If you want to plot, say, a cube (frame or shaded) at each coordinate location, then it's a matter of creating a cube plotting routine and mapping its product to a 3D scatterplot. – Carl Witthoft Dec 21 '12 at 12:51
-
1@CarlWitthoft, Indeed, the RGL package has a nice plotting function for 3D scatterplot, but this does not correspond to my need. Like the image function is plotting 2-dimension matrix, I would like to find a function that can plot a 3d array. Each little box of the array would be represented by a cube in the plot where the cube's color would be coded in respect to its value (whatever the variable is). Before trying coding something clunky and slow myself, I want to check if someone already work on such programming. Thanks though. – Simon Dec 21 '12 at 21:59
1 Answers
Here is a basic example of something using the rgl package. You can easily make it into a function that operates on a 3D array to alter the colour, alpha or other features of interest.
library(rgl)
cubit=cube3d(color="blue", alpha=0.3)
cubit$vb[cubit$vb == -1]= 0
gridx=0:5;gridy=0:5;gridz=0:5
temp=cubit
plot3d(temp,box=FALSE,axes=FALSE,xlab="",ylab="",zlab="")
wire3d(temp,add=TRUE,color="blue",alpha=1)
for(ix in gridx){
for(iy in gridy){
for(iz in gridz){
temp$vb[1,]=cubit$vb[1,]+ix
temp$vb[2,]=cubit$vb[2,]+iy
temp$vb[3,]=cubit$vb[3,]+iz
shade3d(temp,add=TRUE,,alpha=runif(1))
wire3d(temp,add=TRUE,color="blue")
}
}
}
I have used something like this, but I have noted that the memory size grows very quickly (I cannot do more than 60000 voxels, using 3-4Gb RAM). I have tried something similar using cube3D from the plot3D package thinking that a non-interactive plot would (should!) be more memory efficient, but for some reason this package had worse performance (only 1000 voxels). If you have a solid cube, then you can be much smarter about only plotting the outer edges using a ploygon3D plot ... but that is not my case. I am still searching for better performance using R functionality, but thought I should add to this conversation in case of any other wandering souls who cross paths here too.

- 51
- 1
- 3