/* * TriMesh: out of a domain outline file ( Argus format ), * use the Triangle package to create a triangular mesh * */ #include "./TriMesh.h" void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] ) { /*Matlab arrays: */ mxArray* pmxa_array=NULL; int i,j; int counter,counter2,backcounter; int prhs_counter; /* returned quantities: */ double* index=NULL; double* x=NULL; double* y=NULL; double* segments=NULL; double* segmentmarkerlist=NULL; /* input: */ char* domainname=NULL; char* riftname=NULL; double area; char* order=NULL; /*Domain outline variables: */ int nprof; int* profngrids=NULL; double** pprofx=NULL; double** pprofy=NULL; double* xprof=NULL; double* yprof=NULL; int numberofpoints; /*Rift outline variables: */ int numrifts; int* riftsnumgrids=NULL; double** riftsgridsx=NULL; double** riftsgridsy=NULL; /* error handling: */ int noerr=1; /* Triangle structures: */ struct triangulateio in,out; char options[256]; /* verify correct usage: */ if (nlhs==0 && nrhs==0) { /* special case: */ TriMeshUsage(); return; } if (!( (nlhs==5) ||(nrhs==2) || (nrhs==3) || (nrhs==4) )){ mexPrintf(" %s format error.\n", __FUNCT__); TriMeshUsage(); printf(" "); mexErrMsgTxt(" "); } /*Fetch data needed by Triangle: */ prhs_counter=0; /*First recover the domain outline file name: */ if (!mxIsChar(prhs[prhs_counter])){ mexPrintf("%s%s\n",__FUNCT__," error message; first argument should be the domain outline file name!"); mexErrMsgTxt(" "); } domainname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); mxGetString(prhs[prhs_counter],domainname,mxGetN(prhs[prhs_counter])+1); /*Look for optional rifts file name: */ prhs_counter++; if (mxIsChar(prhs[prhs_counter])){ riftname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); mxGetString(prhs[prhs_counter],riftname,mxGetN(prhs[prhs_counter])+1); prhs_counter++; } /*Recover the mesh density desired:*/ area=mxGetScalar(prhs[prhs_counter]); /*Optionaly, recover desired order: */ prhs_counter++; if (mxIsChar(prhs[prhs_counter])){ order = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); mxGetString(prhs[prhs_counter],order,mxGetN(prhs[prhs_counter])+1); } #ifdef _ISSM_DEBUG_ printf("Domain name: %s\n",domainname); printf("Rift name: %s\n",riftname); printf("Maximum area: %16.16lf\n",area); printf("Order: %s\n",order); #endif /*Start reading the domain outline file: */ noerr=DomainOutlineRead(&nprof,&profngrids,&pprofx,&pprofy,domainname); if(!noerr){ printf("%s%s%s\n",__FUNCT__," error message reading domain outline ",domainname); mexErrMsgTxt(" "); } /*Read rifts file if present: */ if(riftname){ noerr=DomainOutlineRead(&numrifts,&riftsnumgrids,&riftsgridsx,&riftsgridsy,riftname); if(!noerr){ printf("%s%s%s\n",__FUNCT__," error message reading rifts outline ",riftname); mexErrMsgTxt(" "); } } #ifdef _ISSM_DEBUG_ printf("# points in domain outline: %i\n",nprof); #endif #ifdef _DEBUG2_ for (i=0;i=2 flag them ), outlinefilename an Argus domain outline file.\n"); printf(" riftsoutlinename is an Argus domain file, defining rifts (ie: open profiles), \n"); printf(" area is the maximum area desired for any element of the resulting mesh. \n"); printf(" and ordered is a string ('yes' or 'no') that determines whether segments are output in the \n"); printf(" order they are made by Triangle (ie none), or ordered counter clockwise around the domain outline.\n"); printf(" riftsoutlinename and ordered are optional arguments.\n"); printf("\n"); }