Mmg
Simplicial remeshers (mesh adaptation, isovalue discretization, lagrangian movement)
apptools.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
35#include "mmgcommon_private.h"
36
45static inline
47
48 MMG5_ADD_MEM(mesh,sizeof(MMG5_iNode),"boundary reference node",
49 return 0;);
50
51 MMG5_SAFE_MALLOC(*node,1,MMG5_iNode,return 0);
52
53 return 1;
54}
55
68int MMG5_Add_inode( MMG5_pMesh mesh, MMG5_iNode **liLi, int val ) {
69 MMG5_iNode *newNode, *cur;
70
71 cur = *liLi;
72
73 /* Travel through the linked list and search if the value val exist or, if
74 * not, where to insert it */
75 if ( cur ) {
76 if ( val < (*liLi)->val ) {
77 /* Add a value at the list head */
78 if ( !MMG5_Alloc_inode(mesh,&newNode) ) return -1;
79
80 newNode->val = val;
81 newNode->nxt = (*liLi);
82
83 (*liLi) = newNode;
84
85 return 1;
86
87 }
88 else if (val == (*liLi)->val ) return 0;
89
90 while ( cur->nxt && ( val >= (cur->nxt)->val) )
91 cur = cur->nxt;
92
93 if ( val == cur->val ) return 0;
94
95 if ( !MMG5_Alloc_inode(mesh,&newNode) ) return -1;
96
97 newNode->val = val;
98 newNode->nxt = cur->nxt;
99 cur->nxt = newNode;
100 }
101 else {
102 if ( !MMG5_Alloc_inode(mesh,&newNode) ) return -1;
103
104 newNode->val = val;
105 newNode->nxt = NULL;
106
107 *liLi = newNode;
108 }
109
110 return 1;
111}
112
121 MMG5_iNode *cur,*nxt;
122
123 cur = liLi;
124 while (cur) {
125 nxt = cur;
126 cur = cur->nxt;
127
128 MMG5_DEL_MEM(mesh,nxt);
129 }
130}
131
143 MMG5_int k;
144 int npar,ier;
145
147 (*bdryRefs) = NULL;
148
149 k = mesh->nt? mesh->tria[1].ref : 0;
150
151 /* Try to alloc the first node */
152 ier = MMG5_Add_inode( mesh, bdryRefs, k );
153 if ( ier < 0 ) {
154 fprintf(stderr,"\n ## Error: %s: unable to allocate the first boundary"
155 " reference node.\n",__func__);
156 return 0;
157 }
158 else {
159 assert(ier);
160 npar = 1;
161 }
162
163 for ( k=1; k<=mesh->nt; ++k ) {
164 ier = MMG5_Add_inode( mesh, bdryRefs, mesh->tria[k].ref );
165
166 if ( ier < 0 ) {
167 printf(" ## Warning: %s: unable to list the tria references."
168 " Uncomplete parameters file.\n",__func__ );
169 break;
170 }
171 else if ( ier ) ++npar;
172 }
173
174 return npar;
175}
176
187 FILE *out ) {
188 MMG5_iNode *cur;
189
190 cur = bdryRefs;
191 while( cur ) {
192 fprintf(out,"%"MMG5_PRId" Triangle %e %e %e \n",cur->val,
194 cur = cur->nxt;
195 }
196
197 MMG5_Free_ilinkedList(mesh,bdryRefs);
198
199 return 1;
200}
int ier
MMG5_pMesh * mesh
int MMG5_Add_inode(MMG5_pMesh mesh, MMG5_iNode **liLi, int val)
Definition: apptools.c:68
int MMG5_countLocalParamAtTri(MMG5_pMesh mesh, MMG5_iNode **bdryRefs)
Definition: apptools.c:142
static int MMG5_Alloc_inode(MMG5_pMesh mesh, MMG5_iNode **node)
Functions used in mmg applications.
Definition: apptools.c:46
void MMG5_Free_ilinkedList(MMG5_pMesh mesh, MMG5_iNode *liLi)
Definition: apptools.c:120
int MMG5_writeLocalParamAtTri(MMG5_pMesh mesh, MMG5_iNode *bdryRefs, FILE *out)
Definition: apptools.c:186
#define MMG5_ADD_MEM(mesh, size, message, law)
#define MMG5_SAFE_MALLOC(ptr, size, type, law)
#define MMG5_DEL_MEM(mesh, ptr)
double hmin
Definition: libmmgtypes.h:518
double hmax
Definition: libmmgtypes.h:518
double hausd
Definition: libmmgtypes.h:518
MMG mesh structure.
Definition: libmmgtypes.h:605
MMG5_Info info
Definition: libmmgtypes.h:651
MMG5_int nt
Definition: libmmgtypes.h:612
MMG5_pTria tria
Definition: libmmgtypes.h:647
MMG5_int ref
Definition: libmmgtypes.h:335
Cell for linked list of integer value.