I would like to use Matlab's delaunayTriangulation class to construct the triangulation of a set of points in 3D, P [nx3 matrix], within a mex function.
In Matlab,
DT = delaunayTriangulation(P)
computes the triangulation with 'Points' & 'ConnectivityList' as the class properties of DT.
How do I perform the same operation within a mex file?
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
....
int n;
int elements = n*3;
double* P_ptr; /*contains 3D coordinates*/
P_ptr = mxMalloc(elements * sizeof(double));
/* fill up P_ptr with coordinates */
mxArray *DT, *P;
mxSetPr(P,P_ptr); /* Set P_ptr to mxArray P */
mxSetM(P, n);
mxSetN(P, 3);
mexCallMATLAB(1, &DT, 1, &P, "delaunayTriangulation");
....
}
Is it the right way to go? Also, if the code above is right, how do I access the class properties(Points, ConnectivityList) from output mxArray *DT?
Thanks
Edit: Changed DT
to &DT
for correctness in the code above. Also, based on Sam's solution, I was able to access the property (eg "ConnectivityList") by the following code:
mxArray* variable_name = mxGetProperty(DT,0,"ConnectivityList");
你应该能够使用mxGetProperty
访问一个对象的属性mxArray
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.