Sorry to not include this code in the first post (This is my 10th or so attempt to post this, I kept getting the error "Bad Request
Your browser sent a request that this server could not understand.")
void projection::matlab(ptcloud model){
R = model.R;
nl = model.num_el/3;
mxArray *x_p, *x_n;
//array of floats?
mwSignedIndex dims[2];
dims[0] = nl*3;
dims[1] = 1;
// array of points, where point i has x coordinate x_p(3*i), y coordinate x_p(3*i + 1) and z coordinate x_p(3*i + 2)
x_p = mxCreateNumericArray(2,dims,mxSINGLE_CLASS,mxREAL);
// array of the corresponding normal vectors, where point i has normal vector with
// x component x_p(3*i), y coordinate x_p(3*i + 1) and z coordinate x_p(3*i + 2)
x_n = mxCreateNumericArray(2,dims,mxSINGLE_CLASS, mxREAL);
mwSignedIndex dims2[2];
dims2[0] = 2;
dims2[1] = 1;
mxArray *xy_size_of_image;
xy_size_of_image = mxCreateNumericArray(2,dims2,mxINT32_CLASS, mxREAL);
int xy_cpp_size[2];
xy_cpp_size[0] = X_Size;
xy_cpp_size[1] = Y_Size;
// xy_size_of_image is is used to send the x and y dimensions of the image to the matlab function
// xy_size_of_image[0] is the number of columns
// xy_size_of_image[1] is the number of rows
memcpy( mxGetPr(xy_size_of_image) , &xy_cpp_size[0] , sizeof(int)*2);
mxArray *pts_and_normals[3];
pts_and_normals[0] = mxCreateDoubleMatrix(1,1,mxREAL);
pts_and_normals[1] = mxCreateDoubleMatrix(1,1,mxREAL);
pts_and_normals[2] = mxCreateDoubleMatrix(1,1,mxREAL);
// copy in the actual points
memcpy( mxGetPr(x_p) , &model.pts[0].x , sizeof(float)*nl*3);
// copy in the actual normal vectors
memcpy( mxGetPr(x_n) , &model.normals[0].x , sizeof(float)*nl*3);
pts_and_normals[0] = x_p;
pts_and_normals[1] = x_n;
pts_and_normals[2] = xy_size_of_image;
mxArray *ppLhs[2];
// Call the matlab function check_occ_curve( xyz, xyz_n, dimensions)
mexCallMATLAB(2, ppLhs ,3,pts_and_normals,"check_occ_curve");
n_oc = (int) *mxGetPr(ppLhs[0]);
for(int i=0; i<n_oc ; i++){
oc_ind[i]= (int) *(mxGetPr(ppLhs[1]) + i * sizeof(double));}
// see comment 1
// mxSetData(pts_and_normals[0], NULL);
// mxSetData(pts_and_normals[1], NULL);
// mxSetData(pts_and_normals[2], NULL);
// see comment 2
// mxDestroyArray(ppLhs[0]);
// mxDestroyArray(ppLhs[1]);
mxDestroyArray(pts_and_normals[0]);
mxDestroyArray(pts_and_normals[1]);
mxDestroyArray(pts_and_normals[2]);
mxDestroyArray(x_p);
mxDestroyArray(x_n);
mxDestroyArray(xy_size_of_image);