Mouse-Imaging-Centre / RMINC

Statistics for MINC volumes: A library to integrate voxel-based statistics for MINC volumes into the R environment. Supports getting and writing of MINC volumes, running voxel-wise linear models, correlations, etc.; correcting for multiple comparisons using the False Discovery Rate, and more. With contributions from Jason Lerch, Chris Hammill, Jim Nikelski and Matthijs van Eede. Some additional information can be found here:
https://mouse-imaging-centre.github.io/RMINC
Other
22 stars 17 forks source link

read_obj error #253

Closed egarza closed 5 years ago

egarza commented 5 years ago

I'm trying to read an OBJ file to use in obj_to_graph and vertexFindPeaks. However it gives me a strange error:

> read_obj("CIVET_2.0_icbm_avg_mid_sym_mc_left.obj", use_civet_triangles = FALSE)
Error in names(object) <- nm : 
  'names' attribute [5] must be the same length as the vector [4]
In addition: Warning message:
In readLines(bic_obj) :
  incomplete final line found on 'CIVET_2.0_icbm_avg_mid_sym_mc_left.obj'

The obj file works in Display and opens with nano.

Thanks

egarza commented 5 years ago

As a follow-up, I made an object as the mean of all my subject (rh_average.obj), and that one worked. So it's a problem with the file. Got it from here: [http://www.bic.mni.mcgill.ca/ServicesSoftware/CIVET-2-1-0-Statistical-Analyses-Surfstat]

cfhammill commented 5 years ago

Hmm, I think I've seen something like this before, just had to do with a missing newline. Although if you're using CIVET 2.1 you should not use the CIVET 2.0 surfaces, they are not the same, this bit me a while back.

EDIT: The parser is a pretty weak hack. It doesn't actually respect the full BIC-OBJ spec. It's something that would be worth fixing, but not a high priority at the moment especially if this problem can be fixed by adding/removing a newline at the end of the obj file.

gdevenyi commented 5 years ago

Its really sad that there's essentially no third-party OBJ reader.....

cfhammill commented 5 years ago

Does VTK not handle everything properly?

gdevenyi commented 5 years ago

Okay, yes, VTK does read it, I just can't grok the VTK datastructures at all

egarza commented 5 years ago

Thanks for the help. 1) Where can I find the 2.1 surface ICBM templates? 2) Which line should be corrected with what info?

Thanks

cfhammill commented 5 years ago

I got the 2.1 surfaces from Claude LePage, I think if you send him an email he'll send you them.

If it's the problem I'm thinking of it's the last line of the file, there's either an extra, or a missing newline.

egarza commented 5 years ago

Will do, thanks.

egarza commented 5 years ago

Hi Chris,

Got an answer from Claude, here are some of the comments:

-This sounds like a bug in the read_obj parser. -The model surfaces for CIVET-2.0.0 and CIVET-2.1.0 are the same. They are based on the marching-cubes surfaces. Note that the CIVET-1.1.12 model surface (and all prior versions) is different from CIVET-2.X.Y. The vertex projections and distribution is different in CIVET-1.X (ASP deformable ellipsoid model) and CIVET-2.X (marching-cubes). -Is your parser expecting to read a space in the first column?

CIVET-1.1.12 model surface:

P 0.3 0.3 0.4 10 1 40962 -2.86076 25.1982 16.6128 -13.9641 -58.3774 20.3814 -40.2469 9.32828 8.83384 -44.9451 -47.1145 17.8576

CIVET-2.0.0 model surface:

P 0.3 0.3 0.4 10 1 40962 -4.03771 40.0262 15.9554 -18.836 -56.0411 16.8517 -47.0494 2.62527 8.28734 -45.8479 -44.4945 17.6259

The reader should be free format.

cfhammill commented 5 years ago

Ahh my mistake, I misremembered, it's not the surfaces but the AAL atlas that's changed.

I just checked the 2.0 vs 2.1 object files that I have. It is exactly as I claimed, the 2.0 has an extra newline at the end of the file. Just delete it and you will be fine.

egarza commented 5 years ago

Ok, I deleted the last line and now I don't get the error. I only get the "names" error:


icbm_obj_left <- read_obj("CIVET_2.0_icbm_avg_mid_sym_mc_left2.obj", use_civet_triangles = FALSE)
Error in names(object) <- nm : 
  'names' attribute [5] must be the same length as the vector [4]```
egarza commented 5 years ago

Interestingly, this last error is only on the LEFT, not the right object. The other one was uploaded succesfully.

cfhammill commented 5 years ago

Hi Eduardo, I'm very sorry I gave you some bad advice, the problem was the left object was missing a newline after the vertex block, not the right having an extra. I've fixed the parser so this won't be a problem any longer. Sorry for the inconvenience.

egarza commented 5 years ago

Hi,

Not to worry, I appreciate the help and glad it got figured out. So, should I update the read_obj or what do I do next?

Thanks

Eduardo

gdevenyi commented 5 years ago

Already fixed: https://github.com/Mouse-Imaging-Centre/RMINC/commit/44d07d941fa6f68ef8b3d0152b09bdcce1662ddf