Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
hash_s.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*/
23
36#include "libmmgs_private.h"
37
45static int paktri(MMG5_pMesh mesh) {
46 MMG5_pTria pt,pt1;
47 MMG5_int k;
48
49 k = 1;
50 do {
51 pt = &mesh->tria[k];
52 if ( !MG_EOK(pt) ) {
53 pt1 = &mesh->tria[mesh->nt];
54 assert ( pt && pt1 );
55 memcpy(pt,pt1,sizeof(MMG5_Tria));
56 if ( !MMGS_delElt(mesh,mesh->nt) ) return 0;
57 }
58 }
59 while ( ++k < mesh->nt );
60
61 /* Recreate nil chain */
62 mesh->nenil = mesh->nt + 1;
63
64 for(k=mesh->nenil; k<=mesh->ntmax-1; k++){
65 mesh->tria[k].v[2] = k+1;
66 }
67 return 1;
68}
69
78 MMG5_Hash hash;
79
80 if ( mesh->adja ) return 1;
81 if ( abs(mesh->info.imprim) > 5 || mesh->info.ddebug )
82 fprintf(stdout," ** SETTING STRUCTURE\n");
83
84 /* tassage */
85 if ( !paktri(mesh) ) return 0;
86
87 MMG5_ADD_MEM(mesh,(3*mesh->ntmax+5)*sizeof(MMG5_int),"adjacency table",
88 fprintf(stderr," Exit program.\n");
89 return 0);
90 MMG5_SAFE_CALLOC(mesh->adja,3*mesh->ntmax+5,MMG5_int,return 0);
91
92 if ( !MMG5_mmgHashTria(mesh, mesh->adja, &hash, 0) ) return 0;
93
95
96 return 1;
97}
98
114 MMG5_Hash hash;
115 MMG5_pTria pt;
116 MMG5_pEdge pa;
117 MMG5_int k,ia;
118 int8_t i,i1,i2;
119
120 if ( !mesh->na ) return 1;
121
122 /* adjust hash table params */
123 hash.siz = mesh->na;
124 hash.max = 3*mesh->na+1;
125 MMG5_ADD_MEM(mesh,(hash.max+1)*sizeof(MMG5_hedge),"hash table",return 0);
126 MMG5_SAFE_CALLOC(hash.item,hash.max+1,MMG5_hedge,return 0);
127
128 hash.nxt = mesh->na;
129 for (k=mesh->na; k<hash.max; k++)
130 hash.item[k].nxt = k+1;
131
132 /* hash mesh edges */
133 for (k=1; k<=mesh->na; k++)
134 MMG5_hashEdge(mesh,&hash,mesh->edge[k].a,mesh->edge[k].b,k);
135
136 /* set references to triangles */
137 for (k=1; k<=mesh->nt; k++) {
138 pt = &mesh->tria[k];
139 if ( !MG_EOK(pt) ) continue;
140
141 for (i=0; i<3; i++) {
142 i1 = MMG5_inxt2[i];
143 ia = MMG5_hashGet(&hash,pt->v[i],pt->v[i1]);
144 if ( ia ) {
145 i2 = MMG5_inxt2[i1];
146 pa = &mesh->edge[ia];
147 pt->edg[i2] = pa->ref;
148 pt->tag[i2] |= pa->tag;
149 }
150 }
151 }
152
153 /* reset edge structure */
154 MMG5_DEL_MEM(mesh,hash.item);
156 mesh->na = 0;
157
158 return 1;
159}
160
170 MMG5_Hash hash;
171 MMG5_pTria pt;
172 MMG5_int k,nad;
173 int tag;
174 int8_t i,i1,i2;
175
176 /* adjust hash table params */
177 /* Euler formula : na ~ 3np */
178 if ( !MMG5_hashNew(mesh,&hash,3*mesh->np,9*mesh->np) ) {
179 printf(" # Error: %s: Not enough memory to allocate edge hash table",__func__);
180 }
181
182 /* hash tagged edges */
183 nad = 0;
184 for (k=1; k<=mesh->nt; k++) {
185 pt = &mesh->tria[k];
186 if ( !MG_EOK(pt) ) continue;
187
188 for ( i=0; i<3; ++i ) {
189 if ( mesh->tria[k].tag[i] ) {
190 i1 = MMG5_inxt2[i];
191 i2 = MMG5_iprv2[i];
192 if ( !MMG5_hashEdgeTag(mesh,&hash,pt->v[i1],pt->v[i2],pt->tag[i]) ) {
193 printf(" # Error: %s: Lack of memory.",__func__);
194 return 0;
195 }
196 ++nad;
197 }
198 }
199 }
200
201 /* update tags */
202 if ( nad ) {
203 for (k=1; k<=mesh->nt; k++) {
204 pt = &mesh->tria[k];
205 if ( !MG_EOK(pt) ) continue;
206
207 for (i=0; i<3; i++) {
208 i1 = MMG5_inxt2[i];
209 i2 = MMG5_iprv2[i];
210
211 tag = MMG5_hashGet(&hash,pt->v[i1],pt->v[i2]);
212 if ( tag ) {
213 pt->tag[i] |= tag;
214 }
215 }
216 }
217 }
218
219 /* free hash structure */
220 MMG5_DEL_MEM(mesh,hash.item);
221
222 return 1;
223}
MMG5_pMesh * mesh
int MMG5_hashEdgeTag(MMG5_pMesh mesh, MMG5_Hash *hash, MMG5_int a, MMG5_int b, int16_t tag)
Definition: hash.c:437
int MMG5_mmgHashTria(MMG5_pMesh mesh, MMG5_int *adjt, MMG5_Hash *hash, int chkISO)
Definition: hash.c:58
int MMG5_hashNew(MMG5_pMesh mesh, MMG5_Hash *hash, MMG5_int hsiz, MMG5_int hmax)
Definition: hash.c:526
MMG5_int MMG5_hashGet(MMG5_Hash *hash, MMG5_int a, MMG5_int b)
Definition: hash.c:495
int MMG5_hashEdge(MMG5_pMesh mesh, MMG5_Hash *hash, MMG5_int a, MMG5_int b, MMG5_int k)
Definition: hash.c:345
int MMGS_assignEdge(MMG5_pMesh mesh)
Definition: hash_s.c:113
int MMGS_bdryUpdate(MMG5_pMesh mesh)
Definition: hash_s.c:169
int MMGS_hashTria(MMG5_pMesh mesh)
Definition: hash_s.c:77
static int paktri(MMG5_pMesh mesh)
Definition: hash_s.c:45
int MMGS_delElt(MMG5_pMesh mesh, MMG5_int iel)
Definition: zaldy_s.c:93
#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_iprv2[3]
static const uint8_t MMG5_inxt2[6]
#define MMG5_DEL_MEM(mesh, ptr)
Structure to store edges of a MMG mesh.
Definition: libmmgtypes.h:305
MMG5_int b
Definition: libmmgtypes.h:306
MMG5_int ref
Definition: libmmgtypes.h:307
int16_t tag
Definition: libmmgtypes.h:310
MMG5_int a
Definition: libmmgtypes.h:306
Identic as MMG5_HGeom but use MMG5_hedge to store edges instead of MMG5_hgeom (memory economy).
Definition: libmmgtypes.h:595
MMG5_int max
Definition: libmmgtypes.h:596
MMG5_int nxt
Definition: libmmgtypes.h:596
MMG5_hedge * item
Definition: libmmgtypes.h:597
MMG5_int siz
Definition: libmmgtypes.h:596
int8_t ddebug
Definition: libmmgtypes.h:532
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_int ntmax
Definition: libmmgtypes.h:612
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_int * adja
Definition: libmmgtypes.h:624
MMG5_int nenil
Definition: libmmgtypes.h:622
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int np
Definition: libmmgtypes.h:612
MMG5_pEdge edge
Definition: libmmgtypes.h:649
MMG5_int na
Definition: libmmgtypes.h:612
MMG5_int edg[3]
Definition: libmmgtypes.h:339
int16_t tag[3]
Definition: libmmgtypes.h:342
MMG5_int v[3]
Definition: libmmgtypes.h:334
Used to hash edges (memory economy compared to MMG5_hgeom).
Definition: libmmgtypes.h:584
MMG5_int nxt
Definition: libmmgtypes.h:585