1 | /*
|
---|
2 | * SplitMeshForRifts.c:
|
---|
3 | */
|
---|
4 | #include "./trimesh.h"
|
---|
5 | #include "../Alloc/xNewDelete.h"
|
---|
6 | #include "../Alloc/alloc.h"
|
---|
7 |
|
---|
8 | int SplitMeshForRifts(int* pnel,double** pindex,int* pnods,double** px,double** py,int* pnsegs,double** psegments,double** psegmentmarkerlist){
|
---|
9 |
|
---|
10 | /*Some notes on dimensions:
|
---|
11 | index of size nelx3
|
---|
12 | x and y of size nodsx1
|
---|
13 | segments of size nsegsx3*/
|
---|
14 |
|
---|
15 | /*Error management: */
|
---|
16 | int noerr=1;
|
---|
17 |
|
---|
18 | int i,j,k,l;
|
---|
19 | int node;
|
---|
20 | int el;
|
---|
21 |
|
---|
22 | int nriftsegs;
|
---|
23 | int* riftsegments=NULL;
|
---|
24 | int* flags=NULL;
|
---|
25 |
|
---|
26 | int NumGridElementListOnOneSideOfRift;
|
---|
27 | int* GridElementListOnOneSideOfRift=NULL;
|
---|
28 |
|
---|
29 | /*Input: */
|
---|
30 | int nel;
|
---|
31 | double* index=NULL;
|
---|
32 | int nods;
|
---|
33 | double* x=NULL;
|
---|
34 | double* y=NULL;
|
---|
35 | double* segments=NULL;
|
---|
36 | double* segmentmarkerlist=NULL;
|
---|
37 | int nsegs;
|
---|
38 |
|
---|
39 | /*Recover input: */
|
---|
40 | nel=*pnel;
|
---|
41 | index=*pindex;
|
---|
42 | nods=*pnods;
|
---|
43 | x=*px;
|
---|
44 | y=*py;
|
---|
45 | nsegs=*pnsegs;
|
---|
46 | segments=*psegments;
|
---|
47 | segmentmarkerlist=*psegmentmarkerlist;
|
---|
48 |
|
---|
49 | /*Establish list of segments that belong to a rift: */
|
---|
50 | /*riftsegments of size nriftsegsx4 (4 for first element on segment,second element,first node and second snode)*/
|
---|
51 | RiftSegmentsFromSegments(&nriftsegs,&riftsegments,nel,index,nsegs,segments);
|
---|
52 |
|
---|
53 | /*Go through all nodes of the rift segments, and start splitting the mesh: */
|
---|
54 | flags=xNewZeroInit<int>(nods); //to make sure we don't split the same nodes twice!
|
---|
55 | for (i=0;i<nriftsegs;i++){
|
---|
56 | for (j=0;j<2;j++){
|
---|
57 |
|
---|
58 | node=riftsegments[4*i+j+2];
|
---|
59 | if(flags[node-1]){
|
---|
60 | /*This node was already split, skip:*/
|
---|
61 | continue;
|
---|
62 | }
|
---|
63 | else{
|
---|
64 | flags[node-1]=1;
|
---|
65 | }
|
---|
66 |
|
---|
67 | if(IsGridOnRift(riftsegments,nriftsegs,node)){
|
---|
68 |
|
---|
69 | DetermineGridElementListOnOneSideOfRift(&NumGridElementListOnOneSideOfRift,&GridElementListOnOneSideOfRift,i,nriftsegs,riftsegments,node,index,nel);
|
---|
70 |
|
---|
71 | /*Summary: we have for node, a list of elements
|
---|
72 | * (GridElementListOnOneSideOfRift, of size
|
---|
73 | * NumGridElementListOnOneSideOfRift) that all contain node
|
---|
74 | *and that are on the same side of the rift. For all these
|
---|
75 | elements, we clone node into another node, and we swap all
|
---|
76 | instances of node in the triangulation *for those elements, to the
|
---|
77 | new node.*/
|
---|
78 |
|
---|
79 | //create new node
|
---|
80 | x=xReNew<double>(x,nods,nods+1);
|
---|
81 | y=xReNew<double>(y,nods,nods+1);
|
---|
82 | x[nods]=x[node-1]; //matlab indexing
|
---|
83 | y[nods]=y[node-1]; //matlab indexing
|
---|
84 |
|
---|
85 | //augment number of nodes
|
---|
86 | nods++;
|
---|
87 |
|
---|
88 | //change elements owning this node
|
---|
89 | for (k=0;k<NumGridElementListOnOneSideOfRift;k++){
|
---|
90 | el=GridElementListOnOneSideOfRift[k];
|
---|
91 | for (l=0;l<3;l++){
|
---|
92 | if (*(index+3*el+l)==node)*(index+3*el+l)=nods; //again, matlab indexing.
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }// if(IsGridOnRift(riftsegments,nriftsegs,node))
|
---|
96 | } //for(j=0;j<2;j++)
|
---|
97 | } //for (i=0;i<nriftsegs;i++)
|
---|
98 |
|
---|
99 | /*update segments: they got modified completely by adding new nodes.*/
|
---|
100 | UpdateSegments(&segments,&segmentmarkerlist, &nsegs,index,x,y,riftsegments,nriftsegs,nods,nel);
|
---|
101 |
|
---|
102 | /*Assign output pointers: */
|
---|
103 | *pnel=nel;
|
---|
104 | *pindex=index;
|
---|
105 | *pnods=nods;
|
---|
106 | *px=x;
|
---|
107 | *py=y;
|
---|
108 | *pnsegs=nsegs;
|
---|
109 | *psegments=segments;
|
---|
110 | *psegmentmarkerlist=segmentmarkerlist;
|
---|
111 | return noerr;
|
---|
112 | }
|
---|