Could I pass a 'triangulation' class into mex?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
wei zhang
el 17 de Feb. de 2021
Editada: James Tursa
el 18 de Feb. de 2021
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.
0 comentarios
Respuesta aceptada
James Tursa
el 17 de Feb. de 2021
Editada: James Tursa
el 18 de Feb. de 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.
0 comentarios
Más respuestas (1)
Ver también
Categorías
Más información sobre MATLAB Compiler en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!