openep / openep-core

Core OpenEP code - Matlab implementation
Apache License 2.0
9 stars 6 forks source link

What's the correct method for outputting a CARTO mesh to a .VTK file? #68

Open Jsalas424 opened 2 years ago

Jsalas424 commented 2 years ago

Hello Dr. Williams,

I've been putting in some questions so I figured I'd explain that I'm with the University of Pennsylvania's translational EP research group and we're trying to get some CARTO data processed using your platform. We are very impressed and excited about this tool!

I'm now trying to export the CARTO mesh to a VTK file for some post-processing in 3d Slicer but am struggling with the correct method. I've attempted to use the cartoMesh2VTK api with no luck.

>> tr = openEP2VTK('datatype', 'lat')
Dot indexing is not supported for variables of this type.

Error in openEP2VTK (line 97)
                pointdata = userdata.surface.act_bip(:,1);

This is attempted with an imported RV Paced LAT map. The userdata.surface.act_bip() array is indeed empty. Can you please advise the correct way to get a VTK file out?

I do have userdata.triRep.X and userdata.triRep.triangulation data available as well.

Jsalas424 commented 2 years ago

I have seemingly come up with a side answer, but would still be interested to know what the endorsed method is using the openep toolkit and your thoughts on this method. I still have to experiment with the data output to make sure it's consistent as I move between Matlab-OpenEP and 3D Slicer v5.0.3

The following solution will be how to generate VTK’s from OpenEP using vtkwrite in Matlab

x = userdata.surface.triRep.X(1:end,1);
y = userdata.surface.triRep.X(1:end,2);
z = userdata.surface.triRep.X(1:end,3);
vtkwrite('mesh.vtk','polydata','triangle',x,y,z,userdata.surface.triRep.Triangulation);

https://www.mathworks.com/matlabcentral/fileexchange/47814-vtkwrite-exports-various-2d-3d-data-to-paraview-in-vtk-file-format

Edit: It should be noted that this method has "precision" issues - i.e., it rounds the decimals and the option to change the precision of the output files doesn't work. I have since moved to the trimesh python library which works very well.

Jsalas424 commented 2 years ago

Sorry, didn't meant to close the issue. Still open.

p-j-smith commented 2 years ago

Hello, are you using the cartoMesh2VTK function or 'openEP2VTK'? If it's openEP2VTK, does it work if you set a different datatype (one that is present), e.g.

openEP2VTK('datatype', 'uni')

Or set no datatype:

openEP2VTK('datatype', 'none')
Jsalas424 commented 2 years ago

HI @p-j-smith thanks for responding!

None work sadly:

>> openEP2VTK('datatype', 'none')
Dot indexing is not supported for variables of this type.

Error in openEP2VTK (line 97)
                pointdata = userdata.surface.act_bip(:,1);

>> openEP2VTK('datatype', 'uni')
Dot indexing is not supported for variables of this type.

Error in openEP2VTK (line 97)
                pointdata = userdata.surface.act_bip(:,1);

>> openEP2VTK('datatype', 'bip')
Dot indexing is not supported for variables of this type.

Error in openEP2VTK (line 97)
                pointdata = userdata.surface.act_bip(:,1);

>> openEP2VTK('datatype', 'lat')
Dot indexing is not supported for variables of this type.

Error in openEP2VTK (line 97)
                pointdata = userdata.surface.act_bip(:,1);

This is a paced map and there's definitely LAT data in there as evidenced by my ability to calculate conduction velocities and make those maps:

image
p-j-smith commented 2 years ago

Hmm, that's strange, is there any chance you could share this openep dataset too?

Jsalas424 commented 2 years ago

Absolutely! We tend to to run into issues because we generally run the latest/development version of CARTO in our lab, BWI tends to change up the text file organization every couple of iterations.

p-j-smith commented 2 years ago

Hi, sorry for not getting back to you sooner. I just had a look at your dataset and in doing so realised that the way you were calling the function was not quite right. The first argument should be the userdata you would like to export:

tr = openEP2VTK(userdata, 'datatype', 'none')

Hopefully that works for you!

Jsalas424 commented 2 years ago

Hi Paul,

I tried this on 2 datasets (including the one I sent you) but still no luck:

>> tr = openEP2VTK(userdata, 'datatype', 'none')
Unrecognized function or variable 'pointdata'.

Error in openEP2VTK (line 104)
writeTriRep2VTK(getMesh(userdata), pointdata, 'outputfile', path2VTKfile);

>>