mandymejia / ciftiTools

ciftiTools R package
45 stars 8 forks source link

Does ciftitools support individual space surface rendering? #33

Closed YaoMeng94 closed 2 years ago

YaoMeng94 commented 2 years ago

Hi, I try to using ciftitools to visualize individual surfaces which two hemispheres have not equal vertices, I keep getting wrong messages, so I just want confirmation does ciftitools support this kind of situation?

Best wishes, Yao Meng

damondpham commented 2 years ago

Hey Yao Meng!

ciftiTools does support visualizing surfaces for which the left and right hemispheres have different numbers of vertices. In fact, for most surfaces I've seen the left and right hemispheres have slightly different numbers of vertices.

Could you attach the file you are trying to read here, or refer me to where I can find it?

YaoMeng94 commented 2 years ago

Hi Damon, Thanks for your reply! The file has been attached, which include a subject's inflated surfaces and curvature for overlay. Surf_dHCP.zip I try to visualize these with code like:

surf_L <- "sub-CC00087AN14_ses-TP1_hemi-left_Space-TP2_vinflated.surf.gii"
surf_R <- "sub-CC00087AN14_ses-TP1_hemi-right_Space-TP2_vinflated.surf.gii"
Metric_L <- "sub-CC00087AN14_ses-TP1_hemi-left_Space-TP2_curv-mean.shape.gii"
Metric_R <- "sub-CC00087AN14_ses-TP1_hemi-right_Space-TP2_curv-mean.shape.gii"

xii <- read_xifti2(cortexL = Metric_L, cortexR = Metric_R, surfL = surf_L, surfR = surf_R )
view_xifti_surface(xii, colors = "Spectral" )

But it throwing error message: Error in view_xifti_surface.mesh_val(xifti, surfL, surfR, hemisphere, : Cannot infer medial wall locations on right cortex. Please provide $meta$cortex$medial_wall_mask$cortex_right

Which a little bit confusing, the medial wall default is NULL and my overlay metric files cover the whole surface.

Best wishes, Yao

damondpham commented 2 years ago

Hello Yao Meng,

Sorry, I made a mistake in my previous post: the surfaces I have seen have the same number of total vertices on the left and right hemispheres, but different numbers of medial wall vertices on the left and right hemispheres. Therefore, we made ciftiTools assume that the left and right surfaces have the same number of total vertices. This is a problem for your data, since Metric_L and Metric_R have different numbers of total vertices.

I will look into removing this assumption in the next update, so that you can use a single "xifti" object as you intended in your code. Meanwhile, a workaround is to plot only one hemisphere at a time:

view_xifti_surface(xii, hemisphere="left", colors="Spectral") view_xifti_surface(xii, hemisphere="right", colors="Spectral")

Or to use separate "xifti" objects for the left and right hemispheres:

xiiL <- read_xifti2(cortexL=Metric_L, surfL=surf_L) plot(xiiL, colors="Spectral")

Thank you so much for bringing this issue to my attention! It's good to know that in some use cases, the numbers of total vertices don't match. I will update you about resolving this issue soon. Let me know if you have any further questions!

Lastly, here is the code I used to explore this issue, if it helps further clarify:

## -------------------------------------------------------------------------------------------------------------------------------------
library(ciftiTools)
ciftiTools.setOption("wb_path", "../fMRI/workbench")

library(rgl)
rgl::setupKnitr()

# Sometimes the first OpenGL window does not render properly.
rgl::rgl.open(); rgl::rgl.close()

## -------------------------------------------------------------------------------------------------------------------------------------
surf_L <- "sub-CC00087AN14_ses-TP1_hemi-left_Space-TP2_vinflated.surf.gii"
surf_L2 <- "sub-CC00087AN14_ses-TP1_hemi-left_Space-TP2_inflated.surf.gii"
# surf_R <- "sub-CC00087AN14_ses-TP1_hemi-right_Space-TP2_vinflated.surf.gii" # was not provided in zip file
Metric_L <- "sub-CC00087AN14_ses-TP1_hemi-left_Space-TP2_curv-mean.shape.gii"
Metric_R <- "sub-CC00087AN14_ses-TP1_hemi-right_Space-TP2_curv-mean.shape.gii"

## ---- fig.cap="xiiL", rgl=TRUE, format="png", fig.height=4.2, fig.width=2.5-----------------------------------------------------------
xiiL <- read_xifti2(cortexL=Metric_L, surfL=surf_L)
plot(xiiL) # Works!

## -------------------------------------------------------------------------------------------------------------------------------------
xii <- read_xifti2(cortexL=Metric_L, cortexR=Metric_R, surfL=surf_L, surfR=NULL)
try(plot(xii)) # Doesn't work
xii$meta$cortex$medial_wall_mask$left <- rep(TRUE, nrow(xii$data$cortex_left))
xii$meta$cortex$medial_wall_mask$right <- rep(TRUE, nrow(xii$data$cortex_right))
try(plot(xii)) # Still doesn't work

## ---- fig.cap="xii, left hemisphere", rgl=TRUE, format="png", fig.height=4.2, fig.width=2.5-------------------------------------------
xii <- read_xifti2(cortexL=Metric_L, cortexR=Metric_R, surfL=surf_L, surfR=NULL)
plot(xii, hemisphere="left") # Works!

## -------------------------------------------------------------------------------------------------------------------------------------
try(plot(xii, hemisphere="right")) # Doesn't work: needs surf_R
YaoMeng94 commented 2 years ago

Thanks Damon,

Separate "xifti" is a good idea, really appreciate your help, and hopefully can see the future release can solve the problem.

Yao