Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
mmg2s.c
Go to the documentation of this file.
1/* =============================================================================
2** This file is part of the mmg software package for the tetrahedral
3** mesh modification.
4** Copyright (c) Bx INP/CNRS/Inria/UBordeaux/UPMC, 2004-
5**
6** mmg is free software: you can redistribute it and/or modify it
7** under the terms of the GNU Lesser General Public License as published
8** by the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** mmg is distributed in the hope that it will be useful, but WITHOUT
12** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13** FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14** License for more details.
15**
16** You should have received a copy of the GNU Lesser General Public
17** License and of the GNU General Public License along with mmg (in
18** files COPYING.LESSER and COPYING). If not, see
19** <http://www.gnu.org/licenses/>. Please read their terms carefully and
20** use this copy of the mmg distribution only if you accept them.
21** =============================================================================
22*/
33#include "mmgcommon_private.h"
34#include "mmgexterns_private.h"
35
46 MMG5_pTria pt;
47 MMG5_pPoint p0,p1;
48 double v0,v1,*tmp;
49 int k,ns,nc,ip0,ip1;
50 int8_t i,i0,i1;
51
52 /* Allocate memory for tmp */
53 MMG5_ADD_MEM(mesh,(mesh->npmax+1)*sizeof(double),"temporary table",
54 printf(" Exit program.\n");
55 return 0);
56 MMG5_SAFE_CALLOC(tmp,mesh->npmax+1,double,return 0);
57
58 /* Reset point flags */
59 for (k=1; k<=mesh->np; k++)
60 mesh->point[k].flag = 0;
61
62 /* Snap values of sol that are close to 0 to 0 exactly */
63 ns = nc = 0;
64 for (k=1; k<=mesh->np; k++) {
65 p0 = &mesh->point[k];
66 if ( !MG_VOK(p0) ) continue;
67 if ( fabs(sol->m[k]) < MMG5_EPS ) {
68 tmp[k] = sol->m[k];
69 p0->flag = 1;
70 sol->m[k] = 0.0;
71 ns++;
72 }
73 }
74
75 /* Unsnap values that have been put to 0, entailing a component reduced to a point */
76 for (k=1; k<=mesh->nt; k++) {
77 pt = &mesh->tria[k];
78 if ( !pt->v[0] ) continue;
79
80 for (i=0; i<3; i++) {
81 if ( !(pt->tag[i] & MG_REF) ) continue;
82 i0 = MMG5_inxt2[i];
83 i1 = MMG5_inxt2[i0];
84
85 ip0 = pt->v[i0];
86 ip1 = pt->v[i1];
87
88 v0 = sol->m[ip0];
89 v1 = sol->m[ip1];
90
91 p0 = &mesh->point[pt->v[i0]];
92 p1 = &mesh->point[pt->v[i1]];
93
94 if ( fabs(v0) < MMG5_EPS && fabs(v1) < MMG5_EPS ) {
95 if ( p0->flag ) {
96 if ( tmp[ip0] < 0.0 )
97 sol->m[ip0] = -100.0*MMG5_EPS;
98 else
99 sol->m[ip0] = 100.0*MMG5_EPS;
100 nc++;
101 p0->flag = 0;
102 }
103 else if ( p1->flag ) {
104 if ( tmp[ip1] < 0.0 )
105 sol->m[ip1] = -100.0*MMG5_EPS;
106 else
107 sol->m[ip1] = 100.0*MMG5_EPS;
108 nc++;
109 p1->flag = 0;
110 }
111 }
112 }
113 }
114
115 MMG5_DEL_MEM ( mesh, tmp );
116
117 if ( (abs(mesh->info.imprim) > 5 || mesh->info.ddebug) && ns+nc > 0 )
118 fprintf(stdout," %8d points snapped, %d corrected\n",ns,nc);
119
120 return 1;
121}
122
130 MMG5_pTria pt;
131 MMG5_pPoint p0,p1;
132 MMG5_int k,ref;
133 int8_t i,i0,i1;
134
135 for (k=1; k<=mesh->nt; k++) {
136 pt = &mesh->tria[k];
137 if ( !pt->v[0] ) continue;
138
139 for (i=0; i<3; i++) {
140 if ( !(pt->tag[i] & MG_REF) ) continue;
141
142 if( !MMG5_getStartRef(mesh,pt->edg[i],&ref) ) return 0;
143 pt->edg[i] = ref;
144
145 i0 = MMG5_inxt2[i];
146 i1 = MMG5_inxt2[i0];
147
148 p0 = &mesh->point[pt->v[i0]];
149 p1 = &mesh->point[pt->v[i1]];
150
151 if ( p0->ref == mesh->info.isoref ) p0->ref = 0;
152 if ( p1->ref == mesh->info.isoref ) p1->ref = 0;
153 }
154 }
155
156 return 1;
157}
158
159/* Set references to the new triangles */
161 MMG5_pTria pt;
162 double v,v1;
163 MMG5_int k,ip1,ref,refint,refext;
164 int8_t ier,i,i1,j,nmn,npl,nz;
165
166 /* Travel all surface edges (via triangles) */
167 for(k=1; k<=mesh->nt; k++) {
168 pt = &mesh->tria[k];
169 if ( !MG_EOK(pt) ) continue;
170
171 for (i=0; i<3; i++) {
172 if ( !(pt->tag[i] & MG_REF) ) continue;
173 ref = pt->edg[i];
174 nmn = npl = nz = 0;
175
176 i1 = i;
177 for (j=0; j<2; j++) {
178 i1 = MMG5_inxt2[i1];
179 ip1 = pt->v[i1];
180 v1 = sol->m[ip1];
181
182 if ( v1 > 0.0 )
183 npl++;
184 else if ( v1 < 0.0 )
185 nmn++;
186 else
187 nz++;
188 }
189
190 assert(nz < 2);
191 ier = MMG5_isSplit(mesh,ref,&refint,&refext);
192 if ( npl ) {
193 if (ier ) {
194 assert ( !nmn );
195 pt->edg[i] = refext;
196 }
197 }
198 else {
199 if ( ier ) {
200 assert ( !npl );
201 pt->edg[i] = refint;
202 }
203 }
204 }
205 }
206
207 /* Set MG_ISO ref at vertices on the ls */
208 for (k=1; k<=mesh->np; k++) {
209 v = sol->m[k];
210 if ( v == 0.0 ) {
211 mesh->point[k].ref = MG_ISO;
212 }
213 }
214
215 return 1;
216}
int ier
tmp[*strlen0]
MMG5_pMesh MMG5_pSol * sol
MMG5_pMesh * mesh
#define MMG5_EPS
#define MG_ISO
Definition: libmmgtypes.h:65
int MMG5_isSplit(MMG5_pMesh mesh, MMG5_int ref, MMG5_int *refint, MMG5_int *refext)
Definition: mmg2.c:411
int MMG5_getStartRef(MMG5_pMesh mesh, MMG5_int ref, MMG5_int *pref)
Definition: mmg2.c:213
int MMG5_resetRef_lssurf(MMG5_pMesh mesh)
Definition: mmg2s.c:129
int MMG5_snpval_lssurf(MMG5_pMesh mesh, MMG5_pSol sol)
Definition: mmg2s.c:45
int MMG5_setref_lssurf(MMG5_pMesh mesh, MMG5_pSol sol)
Definition: mmg2s.c:160
#define MMG5_SAFE_CALLOC(ptr, size, type, law)
#define MG_EOK(pt)
#define MMG5_ADD_MEM(mesh, size, message, law)
static const uint8_t MMG5_inxt2[6]
#define MG_VOK(ppt)
#define MG_REF
#define MMG5_DEL_MEM(mesh, ptr)
int8_t ddebug
Definition: libmmgtypes.h:532
MMG5_int isoref
Definition: libmmgtypes.h:521
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_pPoint point
Definition: libmmgtypes.h:641
MMG5_int npmax
Definition: libmmgtypes.h:612
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
Structure to store points of a MMG mesh.
Definition: libmmgtypes.h:270
MMG5_int ref
Definition: libmmgtypes.h:278
MMG5_int flag
Definition: libmmgtypes.h:282
MMG5_int edg[3]
Definition: libmmgtypes.h:339
int16_t tag[3]
Definition: libmmgtypes.h:342
MMG5_int v[3]
Definition: libmmgtypes.h:334