Changeset 12071
- Timestamp:
- 04/20/12 08:39:29 (13 years ago)
- Location:
- issm/trunk-jpl/src/modules
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified issm/trunk-jpl/src/modules/TriMeshProcessRifts/TriMeshProcessRifts.cpp ¶
r12060 r12071 189 189 190 190 /*Order rifts so that they start from one tip, go to the other tip, and back: */ 191 OrderRifts(&out_riftstips, out_riftssegments,out_riftspairs,numrifts,out_riftsnumsegments,x_in,y_in );191 OrderRifts(&out_riftstips, out_riftssegments,out_riftspairs,numrifts,out_riftsnumsegments,x_in,y_in,nods,nel); 192 192 193 193 /*Create penalty pairs, used by Imp: */ -
TabularUnified issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.cpp ¶
r11933 r12071 1 1 /* 2 * TriMeshRifts: out of a domain outline file ( Argus format ), 3 * use the Triangle package to create a triangular mesh 4 * 2 * TriMeshRifts: mesh a domain using an .exp file 5 3 */ 6 4 7 5 #include "./TriMeshRifts.h" 8 6 9 void mexFunction( int nlhs, mxArray* plhs[], 10 int nrhs, const mxArray* prhs[] ) 11 { 7 WRAPPER(TriMeshRifts){ 8 9 /* input: */ 10 char *domainname = NULL; 11 char *riftsname = NULL; 12 double area; 13 bool order; 12 14 15 /*intermediary: */ 16 DataSet *domain = NULL; 17 DataSet *rifts = NULL; 13 18 14 /*Matlab arrays: */ 15 mxArray* pmxa_array=NULL; 16 int i,j; 17 int counter,counter2,backcounter; 18 int prhs_counter; 19 /* output: */ 20 Matrix *index = NULL; 21 Vector *x = NULL; 22 Vector *y = NULL; 23 Matrix *segments = NULL; 24 Vector *segmentmarkerlist = NULL; 25 26 /*Boot module: */ 27 MODULEBOOT(); 28 29 /*checks on arguments on the matlab side: */ 30 CHECKARGUMENTS(NLHS,NRHS,&TriMeshRiftsUsage); 19 31 20 /* returned quantities: */ 32 /*Fetch data needed for meshing: */ 33 FetchData(&domainname,DOMAINOUTLINE); 34 FetchData(&riftsname,RIFTSOUTLINE); 35 FetchData(&area,AREA); 36 FetchData(&order,ORDER); 21 37 22 double* index=NULL; 23 double* x=NULL; 24 double* y=NULL; 25 double* segments=NULL; 26 double* segmentmarkerlist=NULL; 38 /*Read domain outline: */ 39 domain = DomainOutlineRead(domainname,false); 40 rifts = DomainOutlineRead(riftsname,false); 27 41 28 /* input: */ 29 char* domainname=NULL; 30 char* riftname=NULL; 31 double area; 32 char* order=NULL; 42 /*call x core: */ 43 TriMeshRiftsx(&index,&x,&y,&segments,&segmentmarkerlist,domain,rifts,area,order); 33 44 34 /*Domain outline variables: */ 35 int nprof; 36 int* profnvertices=NULL; 37 double** pprofx=NULL; 38 double** pprofy=NULL; 39 double* xprof=NULL; 40 double* yprof=NULL; 41 int numberofpoints; 45 /*write outputs: */ 46 WriteData(INDEX,index); 47 WriteData(X,x); 48 WriteData(Y,y); 49 WriteData(SEGMENTS,segments); 50 WriteData(SEGMENTMARKERLIST,segmentmarkerlist); 42 51 43 /*Rift outline variables: */ 44 int numrifts; 45 int* riftsnumvertices=NULL; 46 double** riftsverticesx=NULL; 47 double** riftsverticesy=NULL; 52 /*free ressources: */ 53 delete domain; 54 delete rifts; 55 xdelete_module(&index); 56 xdelete_module(&x); 57 xdelete_module(&y); 58 xdelete_module(&segments); 59 xdelete_module(&segmentmarkerlist); 48 60 49 /* Triangle structures: */ 50 struct triangulateio in,out; 51 char options[256]; 52 53 /* verify correct usage: */ 54 if (nlhs==0 && nrhs==0) { 55 /* special case: */ 56 TriMeshRiftsUsage(); 57 return; 58 } 59 60 if (!( (nlhs==5) ||(nrhs==2) || (nrhs==3) || (nrhs==4) )){ 61 mexPrintf(" %s format error.\n", __FUNCT__); 62 TriMeshRiftsUsage(); 63 printf(" "); 64 mexErrMsgTxt(" "); 65 } 66 67 /*Fetch data needed by Triangle: */ 68 69 prhs_counter=0; 70 /*First recover the domain outline file name: */ 71 if (!mxIsChar(prhs[prhs_counter])){ 72 mexPrintf("%s%s\n",__FUNCT__," error message; first argument should be the domain outline file name!"); 73 mexErrMsgTxt(" "); 74 } 75 domainname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); 76 mxGetString(prhs[prhs_counter],domainname,mxGetN(prhs[prhs_counter])+1); 77 78 /*Look for optional rifts file name: */ 79 prhs_counter++; 80 if (mxIsChar(prhs[prhs_counter])){ 81 riftname = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); 82 mxGetString(prhs[prhs_counter],riftname,mxGetN(prhs[prhs_counter])+1); 83 prhs_counter++; 84 } 85 86 /*Recover the mesh density desired:*/ 87 area=mxGetScalar(prhs[prhs_counter]); 88 89 /*Optionaly, recover desired order: */ 90 prhs_counter++; 91 if (mxIsChar(prhs[prhs_counter])){ 92 order = (char *) mxMalloc((mxGetN(prhs[prhs_counter])+1)*sizeof(char)); 93 mxGetString(prhs[prhs_counter],order,mxGetN(prhs[prhs_counter])+1); 94 } 95 96 /*Start reading the domain outline file: */ 97 if(!DomainOutlineRead(&nprof,&profnvertices,&pprofx,&pprofy,NULL,domainname,false)){ 98 printf("%s%s%s\n",__FUNCT__," error message reading domain outline ",domainname); 99 mexErrMsgTxt(" "); 100 } 101 102 /*Read rifts file if present: */ 103 if(riftname){ 104 if(!DomainOutlineRead(&numrifts,&riftsnumvertices,&riftsverticesx,&riftsverticesy,NULL,riftname,false)){ 105 printf("%s%s%s\n",__FUNCT__," error message reading rifts outline ",riftname); 106 mexErrMsgTxt(" "); 107 } 108 } 109 110 /*Create initial triangulation to call triangulate():*/ 111 numberofpoints=0; 112 for (i=0;i<nprof;i++){ 113 numberofpoints+=profnvertices[i]; 114 } 115 if (riftname){ 116 for (i=0;i<numrifts;i++){ 117 numberofpoints+=riftsnumvertices[i]; 118 } 119 } 120 in.numberofpoints=numberofpoints; 121 122 in.numberofpointattributes=1; 123 in.pointlist = (REAL *) mxMalloc(in.numberofpoints * 2 * sizeof(REAL)); 124 125 counter=0; 126 for (i=0;i<nprof;i++){ 127 xprof=pprofx[i]; 128 yprof=pprofy[i]; 129 for (j=0;j<profnvertices[i];j++){ 130 in.pointlist[2*counter+0]=xprof[j]; 131 in.pointlist[2*counter+1]=yprof[j]; 132 counter++; 133 } 134 } 135 if(riftname){ 136 for (i=0;i<numrifts;i++){ 137 xprof=riftsverticesx[i]; 138 yprof=riftsverticesy[i]; 139 for (j=0;j<riftsnumvertices[i];j++){ 140 in.pointlist[2*counter+0]=xprof[j]; 141 in.pointlist[2*counter+1]=yprof[j]; 142 counter++; 143 } 144 } 145 } 146 147 in.pointattributelist = (REAL *) mxMalloc(in.numberofpoints * 148 in.numberofpointattributes * 149 sizeof(REAL)); 150 for (i=0;i<in.numberofpoints;i++){ 151 in.pointattributelist[i] = 0.0; 152 } 153 in.pointmarkerlist = (int *) mxMalloc(in.numberofpoints * sizeof(int)); 154 for(i=0;i<in.numberofpoints;i++){ 155 in.pointmarkerlist[i] = 0; 156 } 157 158 /*Build segments: */ 159 /*Figure out number of segments: holes and closed outlines have as many segments as vertices, 160 *for rifts, we have one less segment as we have vertices*/ 161 in.numberofsegments=0; 162 for (i=0;i<nprof;i++){ 163 in.numberofsegments+=profnvertices[i]; 164 } 165 if (riftname){ 166 for (i=0;i<numrifts;i++){ 167 in.numberofsegments+=riftsnumvertices[i]-1; 168 } 169 } 170 171 in.segmentlist = (int *) mxMalloc(in.numberofsegments * 2 * sizeof(int)); 172 in.segmentmarkerlist = (int *) mxCalloc(in.numberofsegments,sizeof(int)); 173 counter=0; 174 backcounter=0; 175 for (i=0;i<nprof;i++){ 176 for (j=0;j<(profnvertices[i]-1);j++){ 177 in.segmentlist[2*counter+0]=counter; 178 in.segmentlist[2*counter+1]=counter+1; 179 in.segmentmarkerlist[counter]=0; 180 counter++; 181 } 182 /*Close this profile: */ 183 in.segmentlist[2*counter+0]=counter; 184 in.segmentlist[2*counter+1]=backcounter; 185 in.segmentmarkerlist[counter]=0; 186 counter++; 187 backcounter=counter; 188 } 189 counter2=counter; 190 if(riftname){ 191 for (i=0;i<numrifts;i++){ 192 for (j=0;j<(riftsnumvertices[i]-1);j++){ 193 in.segmentlist[2*counter2+0]=counter; 194 in.segmentlist[2*counter2+1]=counter+1; 195 in.segmentmarkerlist[counter2]=2+i; 196 counter2++; 197 counter++; 198 } 199 counter++; 200 } 201 } 202 203 204 /*Build regions: */ 205 in.numberofregions = 0; 206 207 /*Build holes: */ 208 in.numberofholes = nprof-1; /*everything is a hole, but for the first profile.*/ 209 in.holelist = (REAL *) mxMalloc(in.numberofholes * 2 * sizeof(REAL)); 210 for (i=0;i<nprof-1;i++){ 211 /*We are looking for a vertex that lies inside the hole: */ 212 GridInsideHole(&in.holelist[2*i+0],&in.holelist[2*i+1],profnvertices[i+1],pprofx[i+1],pprofy[i+1]); 213 } 214 215 /* Make necessary initializations so that Triangle can return a */ 216 /* triangulation in `out': */ 217 218 out.pointlist = (REAL *) NULL; 219 out.pointattributelist = (REAL *) NULL; 220 out.pointmarkerlist = (int *) NULL; 221 out.trianglelist = (int *) NULL; 222 out.triangleattributelist = (REAL *) NULL; 223 out.neighborlist = (int *) NULL; 224 out.segmentlist = (int *) NULL; 225 out.segmentmarkerlist = (int *) NULL; 226 out.edgelist = (int *) NULL; 227 out.edgemarkerlist = (int *) NULL; 228 229 /* Triangulate the points:. Switches are chosen to read and write a */ 230 /* PSLG (p), preserve the convex hull (c), number everything from */ 231 /* zero (z), assign a regional attribute to each element (A), and */ 232 /* produce an edge list (e), a Voronoi diagram (v), and a triangle */ 233 /* neighbor list (n). */ 234 235 sprintf(options,"%s%lf","pQzDq30ia",area); /*replace V by Q to quiet down the logging*/ 236 237 triangulate(options, &in, &out, NULL); 238 /*report(&out, 0, 1, 1, 1, 1, 0);*/ 239 240 /*Allocate index, x and y: */ 241 index=(double*)mxMalloc(3*out.numberoftriangles*sizeof(double)); 242 x=(double*)mxMalloc(out.numberofpoints*sizeof(double)); 243 y=(double*)mxMalloc(out.numberofpoints*sizeof(double)); 244 segments=(double*)mxMalloc(3*out.numberofsegments*sizeof(double)); 245 segmentmarkerlist=(double*)mxMalloc(out.numberofsegments*sizeof(double)); 246 247 for (i = 0; i < out.numberoftriangles; i++) { 248 for (j = 0; j < out.numberofcorners; j++) { 249 *(index+3*i+j)=(double)out.trianglelist[i * out.numberofcorners + j]+1; 250 } 251 } 252 for (i = 0; i < out.numberofpoints; i++) { 253 x[i]=out.pointlist[i * 2 + 0]; 254 y[i]=out.pointlist[i * 2 + 1]; 255 } 256 257 for (i = 0; i < out.numberofsegments; i++) { 258 segments[3*i+0]=(double)out.segmentlist[i*2+0]+1; 259 segments[3*i+1]=(double)out.segmentlist[i*2+1]+1; 260 segmentmarkerlist[i]=(double)out.segmentmarkerlist[i]; 261 } 262 263 /*Associate elements with segments: */ 264 AssociateSegmentToElement(&segments,out.numberofsegments,index,out.numberoftriangles); 265 266 /*Order segments so that their normals point outside the domain: */ 267 if(!strcmp(order,"yes")){ 268 OrderSegments(&segments,out.numberofsegments, index,out.numberoftriangles); 269 } 270 271 /*Output : */ 272 pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL); 273 mxSetM(pmxa_array,3); 274 mxSetN(pmxa_array,out.numberoftriangles); 275 mxSetPr(pmxa_array,index); 276 mexCallMATLAB( 1, &plhs[0], 1, &pmxa_array, "transpose"); 277 278 pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL); 279 mxSetM(pmxa_array,1); 280 mxSetN(pmxa_array,out.numberofpoints); 281 mxSetPr(pmxa_array,x); 282 mexCallMATLAB( 1, &plhs[1], 1, &pmxa_array, "transpose"); 283 284 pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL); 285 mxSetM(pmxa_array,1); 286 mxSetN(pmxa_array,out.numberofpoints); 287 mxSetPr(pmxa_array,y); 288 mexCallMATLAB( 1, &plhs[2], 1, &pmxa_array, "transpose"); 289 290 pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL); 291 mxSetM(pmxa_array,3); 292 mxSetN(pmxa_array,out.numberofsegments); 293 mxSetPr(pmxa_array,segments); 294 mexCallMATLAB( 1, &plhs[3], 1, &pmxa_array, "transpose"); 295 296 pmxa_array= mxCreateDoubleMatrix(0,0,mxREAL); 297 mxSetM(pmxa_array,1); 298 mxSetN(pmxa_array,out.numberofsegments); 299 mxSetPr(pmxa_array,segmentmarkerlist); 300 mexCallMATLAB( 1, &plhs[4], 1, &pmxa_array, "transpose"); 301 302 return; 61 /*end module: */ 62 MODULEEND(); 303 63 } 304 64 305 void TriMeshRiftsUsage(void) 65 void TriMeshRiftsUsage(void) //{{{1 306 66 { 307 67 printf("\n"); 308 printf(" usage: [index,x,y,segments,segmentmarkers]=TriMeshRifts(domainoutlinefilename, riftsoutlinename,area,ordered) \n");68 printf(" usage: [index,x,y,segments,segmentmarkers]=TriMeshRifts(domainoutlinefilename,area,ordered) \n"); 309 69 printf(" where: index,x,y defines a triangulation, segments is an array made \n"); 310 printf(" of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment \n"); 311 printf(" (if rifts are present, markers >=2 flag them ), outlinefilename an Argus domain outline file.\n"); 312 printf(" riftsoutlinename is an Argus domain file, defining rifts (ie: open profiles), \n"); 313 printf(" area is the maximum area desired for any element of the resulting mesh. \n"); 314 printf(" and ordered is a string ('yes' or 'no') that determines whether segments are output in the \n"); 70 printf(" of exterior segments to the mesh domain outline, segmentmarkers is an array flagging each segment, \n"); 71 printf(" outlinefilename an Argus domain outline file, \n"); 72 printf(" area is the maximum area desired for any element of the resulting mesh, \n"); 73 printf(" and ordered is a bool that determines whether segments are output in the \n"); 315 74 printf(" order they are made by Triangle (ie none), or ordered counter clockwise around the domain outline.\n"); 316 printf(" riftsoutlinename and ordered are optional arguments.\n");317 75 printf("\n"); 318 76 } 319 320 321 322 77 //}}} -
TabularUnified issm/trunk-jpl/src/modules/TriMeshRifts/TriMeshRifts.h ¶
r12013 r12071 6 6 #define _TRIMESHRIFTS_H_ 7 7 8 #include "mex.h" 9 #include "triangle.h" 10 #include "string.h" 8 #ifdef HAVE_CONFIG_H 9 #include <config.h> 10 #else 11 #error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!" 12 #endif 11 13 14 /*Very important definition in case we are compiling a python module!: needs to come before header files inclusion*/ 15 #ifdef _HAVE_PYTHON_ 16 #define PY_ARRAY_UNIQUE_SYMBOL PythonIOSymbol 17 #endif 18 19 /*Header files: */ 12 20 #include "../../c/include/globals.h" 21 #include "../../c/toolkits/toolkits.h" 22 #include "../../c/include/include.h" 13 23 #include "../../c/modules/modules.h" 14 24 #include "../../c/Container/Container.h" 15 25 #include "../../c/shared/shared.h" 16 26 #include "../../c/issm-binding.h" 27 #include "../../c/io/io.h" 28 #include "../../c/EnumDefinitions/EnumDefinitions.h" 17 29 18 void TriMeshRiftsUsage(void); 30 #ifdef _HAVE_MATLAB_MODULES_ 31 /* serial input macros: */ 32 #define DOMAINOUTLINE (mxArray *)prhs[0] 33 #define RIFTSOUTLINE (mxArray *)prhs[1] 34 #define AREA (mxArray *)prhs[2] 35 #define ORDER (mxArray *)prhs[3] 36 /* serial output macros: */ 37 #define INDEX (mxArray**)&plhs[0] 38 #define X (mxArray**)&plhs[1] 39 #define Y (mxArray**)&plhs[2] 40 #define SEGMENTS (mxArray**)&plhs[3] 41 #define SEGMENTMARKERLIST (mxArray**)&plhs[4] 42 #endif 43 44 #ifdef _HAVE_PYTHON_MODULES_ 45 /* serial input macros: */ 46 #define DOMAINOUTLINE PyTuple_GetItem(args,0) 47 #define RIFTSOUTLINE PyTuple_GetItem(args,1) 48 #define AREA PyTuple_GetItem(args,2) 49 #define ORDER PyTuple_GetItem(args,3) 50 /* serial output macros: */ 51 #define INDEX output,0 52 #define X output,1 53 #define Y output,2 54 #define SEGMENTS output,3 55 #define SEGMENTMARKERLIST output,4 56 #endif 19 57 20 58 #undef __FUNCT__ 21 59 #define __FUNCT__ "TriMeshRifts" 22 60 23 #endif 61 /* serial arg counts: */ 62 #undef NLHS 63 #define NLHS 5 64 #undef NRHS 65 #define NRHS 4 66 67 /* local prototypes: */ 68 void TriMeshRiftsUsage(void); 69 70 #endif /* _TRIMESHRIFTS_H_*/
Note:
See TracChangeset
for help on using the changeset viewer.