dfsp-spirit / fsbrain

R library for structural neuroimaging. Provides high-level functions to access (read and write) and visualize surface-based brain morphometry data for individuals and groups.
Other
65 stars 13 forks source link

highlighting directly adjacent vertices fails with error #25

Closed dfsp-spirit closed 3 years ago

dfsp-spirit commented 3 years ago

Describe the bug

Trying to highlight 2 adjacent vertices using the function highlight.vertices.on.subject.spheres() leads to the following error message:

Error in rgl.material(...) : There must be at least one color
In addition: Warning messages:
1: In coloredmesh.from.color(subjects_dir, subject_id, color_data$rh,  :
  Data mismatch: surface has 163842 vertices, but 0 color values passed in argument 'color_data'.

2: In fs.coloredmesh(mesh, color_data, hemi, metadata = metadata) :
  The mesh3d instance from parameter 'mesh' has 163842 vertices, but 0 colors passed in parameter 'col'.

3: In cbind(x, 1) :

 Error in rgl.material(...) : There must be at least one color 

To Reproduce

devtools::install_github('dfsp-spirit/fsbrain', ref="geodesic");
fsbrain::download_optional_data();
    fsbrain::download_fsaverage(accept_freesurfer_license = TRUE);
    subjects_dir = fsbrain::get_optional_data_filepath("subjects_dir");
    subject_id = 'fsaverage';

    vertices = c(32258, 171); # These are directly adjacent
    highlight.vertices.on.subject.spheres(subjects_dir, subject_id, vertices = vertices);

Expected behavior The 2 vertices get highlight in a plot.

Screenshots none

Environment:

Additional context Add any other context about the problem here.

dfsp-spirit commented 3 years ago

It turned out that this issue was not related to the vertices being adjacent. The problem was that there was no vertex to highlight for one hemi, leading to all-NA per-vertex data, leading to an empty color value vector (per-vertex colors) for the coloredmesh.

This has been fixed in 93d0c57 by setting the color to white if 0 colors are passed (with a warning).