Could I pass a 'triangulation' class into mex?

1 visualizzazione (ultimi 30 giorni)
Hi,
I am trying to use mexcuda to accelerate some code with triangle mesh. I would like to use 'triangulation' class variable as input. But I don't know how to get the matrix under field "Points" or "ConnectivityList". Could any one give me a brief sample? Like below
#define DT prhs[0]
void mexFunction(int nlhs, mxArray * plhs[], int nrhs, const mxArray * prhs[])
{
mxArray *pt = DT.Points;
mxArray *con = DT.ConnectivityList;
}
I know I could use DT.Points as a matrix input. I just want to know more about other data classes input into mex. Thank you.

Risposta accettata

James Tursa
James Tursa il 17 Feb 2021
Modificato: James Tursa il 18 Feb 2021
triangulation is a classdef OOP class. You cannot use struct API functions such as mxGetField( ) to get at the properties. You need to use mxGetProperty( ). Unfortunately, mxGetProperty( ) gives you a deep data copy. So your options are:
1) Use mxGetProperty( ) to get the properties as deep data copies. If the properties are not too large then this would be OK.
2) Extract the properties at the m-file level (DT.Points etc.) which will end up being shared data copies or reference copies, and pass these into the mex routine. This avoids the deep data copies.
3) Use the C++ API interface, which I am not completely familiar with but I think supports getting shared data copies of classdef OOP object properties.
4) Use an undocumented function called mxGetPropertyShared( ) for this. It started out as a C++ only library function in R2008a, then appeared in the C library in R2018a. I don't know if this function is still in the library or not. You have to jump through some hoops to use it, such as supplying your own prototype. Details can be found in the header file here:
Even if this works for now, it could break in a future release.
5) You could try the following FEX submission to get the property pointers, but this hasn't been tested or updated in a few years (it involves mxArray hacks) so it is uncertain if it works with the latest versions of MATLAB:
Even if this works for now, it could break in a future release.

Più risposte (1)

Walter Roberson
Walter Roberson il 17 Feb 2021

Categorie

Scopri di più su MATLAB Compiler in Help Center e File Exchange

Prodotti


Release

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by