Could I pass a 'triangulation' class into mex?

조회 수: 1 (최근 30일)
wei zhang
wei zhang 2021년 2월 17일
편집: James Tursa 2021년 2월 18일
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.

채택된 답변

James Tursa
James Tursa 2021년 2월 17일
편집: James Tursa 2021년 2월 18일
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.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 17일

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by