Nirstorm / nirstorm

Brainstorm plugin for fNIRS data analysis
GNU General Public License v3.0
34 stars 11 forks source link

Error: Compute Voronoi volume-to-cortex interpolator #128

Closed GuyRens closed 2 years ago

GuyRens commented 4 years ago

Dear developers,

(https://github.com/Nirstorm/nirstorm/wiki/Cortical-reconstruction-with-MNE-and-MEM) When following the cortical reconstruction tutorial and using its data set I have the following problem.

I am going through all the steps of the tutorial and I want to perform the step 'compute Voronoi volume-to-cortex interpolator'. The steps I undertake are: Go to anatomical view > click run in the pipeline editor/command window > nirs > compute Voronoi volume-to-cortex interpolator.

When I run these steps when only nirstorm directory is added to the path (not its subfolders), I get the following error: image

When I run these steps when nirstorm directory and its subfolders are added to the path I get a similar error:

image

Last, I can find dg_voronoi files in both the directory

'Documents\GitHub\nirstorm\bst_plugin\math' as well as in the .brainstorm folder. Because of this, I was thinking that this issue might be coming from nirstorm rather than brainstorm?

Does anyone know how to solve this?

Many thanks in advance

Guy

Edouard2laire commented 4 years ago

Hi Guy,

Can you make sure that you 1- you have the latest version and 2-ran the installation process ('nst_install') ? Then can you make sure that your brainstorm folder ('.brainstorm/process') contains the following files : dg_voronoi.c, dg_voronoi.m, dg_voronoi.mexa64, dg_voronoi.mexglx ?

You have this error because we are using a compiled version of dg_voronoi which is developed in C. So it's compiled by Matlab to produce dg_voronoi.mexa64 and dg_voronoi.mexglx. What is the OS that you are currently using to run the code ? (I will try to see if it can influence on the mex files). Also which version of Matlab are you using ?

GuyRens commented 4 years ago

Hi Edouard,

Thank for you your reply. To keep the reply transparent, I will answer as short as possible

  1. Pulled the last version of Nirstorm of Github for this troubleshoot

  2. Ran the nst_install again for this troubleshoot. Command window states: 'Installing nirstorm--stable_v0.5.1 to C:\Users\Guy.brainstorm\process...

  3. In .brainstorm/process I have the files 'dg_voronoi.c' 'd_voronoi.m', 'dg_voronoi.mexa64' 'dg_voronoi.mexglx'

  4. MATLAB Version: 9.3.0.713579 (R2017b) 5.Operating System: Microsoft Windows 10 Pro Version 10.0 (Build 18363)

Edouard2laire commented 4 years ago

So at least it's not a problem with the installation. I think it's because of compatibility problem due to the mex file but I am not sure.

@thomas-vincent, @zhengchencai can you help us with that ?

Edouard2laire commented 4 years ago

Note : if you are running out of time and you are not using a specific anatomy, I recommend you to use Colin27 template that Thomas made for nirs. You can use it by running " nst_bst_set_template_anatomy('Colin27_4NIRS_Jan19');" if it does'nt appears in the template list.

It contains everything needed for nirs computation (eg voronoi, segmentation and fluences have been precomputed)

zhengchencai commented 4 years ago

Hi Guy,

You may want to try to compile the c file to mex on your own. The voronoi function was written by c and compile to mex on Linux OS. See https://www.mathworks.com/help/matlab/matlab_external/build-an-executable-mex-file.html about how to compile c file. You may also need to install a compiler. However the code should be simple like "mex *.c"

Thanks, Zhengchen

GuyRens commented 4 years ago

Hi Edouard and Zhengchen,

When I try to compile the mex file, I get the following error. 'Error using mex C:\Users\Guy.brainstorm\process\dg_voronoi.c:3:24: fatal error: dg_chamfer.h: No such file or directory compilation terminated.'

It seems that I need both the h- and c-files for compiling the mex file.
I have googled to see if I can compile this file on my own. But it seems that the h-file is differently named, meaning that I am unlikely to compile the h-file on my own.

Is it possible to upload this file to github so I can further test whether I can compile the mex file myself?

Many thanks

Guy

Edouard2laire commented 4 years ago

hi.

Yes, you need the h file (as it is included line 3 for dg_voronoi.c). H files are header files and contains the functions definitions (eg the identity of the functions defined in .c). h ole can also contains constant definitions.

You can try to used the following lines as dg_chamber.h. But I can't guaranty it will work. As I had hard drive issue at the begenign of the lockdown I don't have compiler installed right now to test. Maybe @thomas-vincent still have the original file ?

#include "mex.h"

void geodesic_voronoi(double *img,         /* domain image mask */
                      unsigned int *size,  /* size of domain image */
                      double *voxsize,     /* size of voxels (in mm) */
                      double *seeds,       /* positions of the seeds */
                      int nbseeds,         /* number of seeds*/
                      double *aniso,       /* Anisotropic ponderation */
                      double *vor,         /* voronoi diagram */
                      double *dmap,        /* geodesic distance map */
                      char *dist); 

void mexFunction(int nlhs, mxArray *plhs[],
                 int nrhs, const mxArray *prhs[]);
GuyRens commented 4 years ago

Hi Edouard,

It seems that this does not work. I'd be happy to test more if I could get the original (?) dg_chamfer.h file.

Just for completeness, I'll post the error I get when trying the code you offered. .>> mex dg_voronoi.c Building with 'MinGW64 Compiler (C)'. Error using mex C:\Users\Guy.brainstorm\process\dg_voronoi.c: In function 'geodesic_voronoi': C:\Users\Guy.brainstorm\process\dg_voronoi.c:31:2: error: unknown type name 'mask' mask *cmask = NULL;

Edouard2laire commented 4 years ago

Hi Edouard,

It seems that this does not work. I'd be happy to test more if I could get the original (?) dg_chamfer.h file.

yes, unfortunately I was not in the lab when this was developed so we have to wait for @thomas-vincent answer. If we don't have any by the end of the week, I will try to contact directly Guillaume Flandin who is marked as author in dg_voronoi.m

zhengchencai commented 4 years ago

Hi Guy,

Could you please try to do a manual installation meaning copy paste everything in nirstorm package into your .brainstorm/process folder?

Thanks, Zhengchen

On Mon, 18 May 2020 at 09:37, Edouard Delaire notifications@github.com wrote:

Hi Edouard,

It seems that this does not work. I'd be happy to test more if I could get the original (?) dg_chamfer.h file.

yes, unfortunately I was not in the lab when this was developed so we have to wait for @thomas-vincent https://github.com/thomas-vincent answer. If we don't have any by the end of the week, I will try to contact directly Guillaume Flandin who is marked as author in dg_voronoi.m

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Nirstorm/nirstorm/issues/128#issuecomment-630188043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHEYWCHHKBNUDDBXQAP34BLRSE2XZANCNFSM4NARUVUA .

Edouard2laire commented 4 years ago

Can you please try with this file : https://github.com/Edouard2laire/nirstorm/blob/voronoi/bst_plugin/math/dg_chamfer.h

I made it using SPM12 version of the Voronoi implementation : https://github.com/canlab/spm12/blob/master/src/spm_voronoi.c

So basically, what was missing in dg_chamfer.h was the definition of the structure used in dg_voronoi.c

edit : He already did that Zhengchen. As he said before he have the following files in his .brainstorm folder : 'dg_voronoi.c', 'd_voronoi.m', ,'dg_voronoi.mexa64' and 'dg_voronoi.mexglx'

GuyRens commented 4 years ago

Hi Edouard,

It seems that using the dg_chamfer.h file through your link works to write a mex file 'dg_voronoi.mexw64'.

However, I am not sure whether I can state that everything works correct. When I try to compute the Voronoi volume through brainstorm (fNIRS), I get the following error.

image.

It seems it is caused by a limited in memory, but the requested amount seems a bit high..

Guy

Edouard2laire commented 4 years ago

Hi Guy.

Thanks for your patience. So we had a meeting yesterday in our lab about NIRSTORM. One of the hypothesis for your issue is that you are running the voronoi with a too high resolution cortex mesh. Can you please make sure that in your brainstorm db, it's the low resolution cortex that is selected (eg ~10k vertices)

If it's still doesn't work, please give us more information about what step you did, and which input you choose. Thx :)

thomas-vincent commented 4 years ago

Hello,

the error with the too large number seems like a compilation issue. The interfacing between matlab and C variables may be bugged. To find a fix, it is indeed worth trying to compile the mex on the side without using the one shipped in nirstorm, but on the long term, it can get messy when things update.

I would advise first to try with a previous stable version of nirstorm. First clean you brainstorm user folder to remove any nirstorm-related files. Then install this older nirstorm release https://github.com/Nirstorm/nirstorm/releases/tag/v0.5 and try running the Voronoi-related process.

Thomas.

On Fri, May 22, 2020 at 8:37 AM Edouard Delaire notifications@github.com wrote:

Hi Guy.

Thanks for your patience. So we had a meeting yesterday in our lab about NIRSTORM. One of the hypothesis for your issue is that you are running the voronoi with a too high resolution cortex mesh. Can you please make sure that in your brainstorm db, it's the low resolution cortex that is selected (eg ~10k vertices)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Nirstorm/nirstorm/issues/128#issuecomment-632669744, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAE2GDREDZZMR56JFJ4IECDRSZWZPANCNFSM4NARUVUA .

GuyRens commented 4 years ago

Hi Thomas, Sorry for the delay in answering. I have a lot of other things on my plate lately. I will try your solution in the near future.

Guy

GuyRens commented 4 years ago

Hi Developers,

I'm still working on having a full pipeline (individual anatomy - cortical reconstruction/sensitivity model) in NIRSTORM. Edouard tagging me in the brainstorm forum helped tremendously with the segmentation (as I don't have to do it in freesurfer now).

Unfortunately, I'm still stuck on this voronoi problem and was hoping whether you could please help me solve this issue.

Here is information, I'm currently working with

----specifics--- Windows 10 Enterprise, version 2004, OS build: 19041.388 Matlab R2018b Latest version of Brainstorm3 (as installed, not pulled from GitHub) Latest version of NIRSTORM (as pulled from GitHub).

----mex file--- Because I am working on Windows, I compiled the mex file as discussed above ("Can you please try with this file : https://github.com/Edouard2laire/nirstorm/blob/voronoi/bst_plugin/math/dg_chamfer.h" - Edouard May 18th)

I have the mex file, .c and .h files both in folders /.brainstorm/process and /nirstorm/bst_plugin/math.

---pipeline editor--- To run the voronoi interpolator : run > process > NIRS > Compute Voronoi volume-to-cortex interpolator. For the segmentation label I select 1 skin... 5WM. When I run this command, I have the following files active (please note this is the fNIRS colin template)

image

--- error--- When I follow the steps above, I get the following error:

image

---end---

Could you please help me with solving this issue? It is the only thing I need for having the complete pipeline.

Many thanks in advance

Guy

GuyRens commented 4 years ago

Dear developers,

Could someone please let me know whether this issue can be (easily) solved? If not, I might install a virtual Linux machine to continue using nirstorm.

Best wishes

Guy

Edouard2laire commented 4 years ago

Hello. If you have access to a virtual Linux, it would indeed be easier as I don't have access to a windows machine to do more tests. @thomas-vincent, @zhengchencai do you think you could have a more carefull look on this issue?

Another solution could be to translate the C code in Matlab to avoid such issue but I don't have time right now.

Best regards, Edouard

Edouard2laire commented 2 years ago

Hello; Thanks for your patience; I did some tests and tried to fix it with https://github.com/Nirstorm/nirstorm/pull/195.

Can you try to update Brainstrom and try again? If this doesn't work; can you try to recompile the mex you your side with the command: "mex -largeArrayDims -compatibleArrayDims dg_voronoi.c" after moving Brainstorm to the path where dg_voronoi is. typically : "/Users/edelaire1/.brainstorm/plugins/nirstorm/nirstorm-master/bst_plugin/math"

Regards, Edouard

Edouard2laire commented 2 years ago

I added the mex files for windows in #200. Update NIRSTORM and try again. Thanks @zhengchencai for the compilation of the mex file :)