1 |
francois |
285 |
//------------------------------------------------------------
|
2 |
|
|
//------------------------------------------------------------
|
3 |
|
|
// MAGiC
|
4 |
|
|
// Jean Christophe Cuilli�re et Vincent FRANCOIS
|
5 |
|
|
// D�partement de G�nie M�canique - UQTR
|
6 |
|
|
//------------------------------------------------------------
|
7 |
|
|
// Le projet MAGIC est un projet de recherche du d�partement
|
8 |
|
|
// de g�nie m�canique de l'Universit� du Qu�bec �
|
9 |
|
|
// Trois Rivi�res
|
10 |
|
|
// Les librairies ne peuvent �tre utilis�es sans l'accord
|
11 |
|
|
// des auteurs (contact : francois@uqtr.ca)
|
12 |
|
|
//------------------------------------------------------------
|
13 |
|
|
//------------------------------------------------------------
|
14 |
|
|
//
|
15 |
|
|
// mailleur.cpp
|
16 |
|
|
//
|
17 |
|
|
//------------------------------------------------------------
|
18 |
|
|
//------------------------------------------------------------
|
19 |
|
|
// COPYRIGHT 2000
|
20 |
|
|
// Version du 02/03/2006 � 11H23
|
21 |
|
|
//------------------------------------------------------------
|
22 |
|
|
//------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "gestionversion.h"
|
26 |
|
|
#include "mailleur_delaunay.h"
|
27 |
|
|
#include "dly_noeud.h"
|
28 |
|
|
#include "dly_tetra.h"
|
29 |
|
|
#include "dly_triangle.h"
|
30 |
|
|
#include "dly_segment.h"
|
31 |
|
|
#include "mg_maillage.h"
|
32 |
|
|
#include "robustPredicates.h"
|
33 |
|
|
#include <algorithm>
|
34 |
|
|
#include <math.h>
|
35 |
|
|
#include "mg_gestionnaire.h"
|
36 |
|
|
#include "ot_cpu.h"
|
37 |
|
|
#include "mg_maillage_algos.h"
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
MAILLEUR_DELAUNAY::MAILLEUR_DELAUNAY(MG_MAILLAGE* m,FCT_GENERATEUR_3D<4> *cartetmp,double crit_arret,class OT_CPU* comp):MAILLEUR(comp),carte(cartetmp),mai(m),critere_arret(crit_arret)
|
41 |
|
|
{
|
42 |
|
|
robustPredicates::exactinit();
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
MAILLEUR_DELAUNAY::~MAILLEUR_DELAUNAY()
|
46 |
|
|
{
|
47 |
|
|
for (int i=0;i<tabnoeud.size();i++)
|
48 |
|
|
delete tabnoeud[i];
|
49 |
|
|
for (int i=0;i<tabtri.size();i++)
|
50 |
|
|
delete tabtri[i];
|
51 |
|
|
for (int i=0;i<tabtet.size();i++)
|
52 |
|
|
delete tabtet[i];
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
void MAILLEUR_DELAUNAY::maille(class MG_GROUPE_TOPOLOGIQUE* mggt)
|
56 |
|
|
{
|
57 |
|
|
if (affichageactif) affiche((char*)"Initialisation Delaunay");
|
58 |
|
|
initialise_maillage();
|
59 |
|
|
if (compteur!=NULL) compteur->ajouter_etape("Initialisation maillage");
|
60 |
|
|
if (affichageactif) affiche((char*)"Maillage");
|
61 |
|
|
raffine_maillage();
|
62 |
|
|
if (compteur!=NULL) compteur->ajouter_etape("Insertion de points");
|
63 |
|
|
if (affichageactif) affiche((char*)"Enregistrement");
|
64 |
|
|
transfert_maillage(&tabnoeud,NULL,&tabtet);
|
65 |
|
|
if (compteur!=NULL) compteur->ajouter_etape("Création du maillage");
|
66 |
|
|
if (affichageactif) affiche((char*)"Fin Delaunay");
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
void MAILLEUR_DELAUNAY::raffine_maillage(void)
|
71 |
|
|
{
|
72 |
|
|
while ((*(front_trie.begin())).first>critere_arret)
|
73 |
|
|
//for (int jj=0;jj<10000;jj++)
|
74 |
|
|
{
|
75 |
|
|
// std::multimap<double, DLY_TETRA*, std::greater<double> >::iterator it=front.begin();
|
76 |
|
|
std::multimap<double, DLY_SEGMENT*, std::greater<double> >::iterator it=front_trie.begin();
|
77 |
|
|
//DLY_TETRA* tet=(*it).second;
|
78 |
|
|
DLY_SEGMENT* seg=(*it).second;
|
79 |
|
|
DLY_TETRA* tet=seg->get_tetra_feuille();
|
80 |
|
|
std::vector<double> lstptdecoup;
|
81 |
|
|
seg->decoupe_noeud(lstptdecoup);
|
82 |
|
|
int nbptdecoup=lstptdecoup.size()/3;
|
83 |
|
|
for (int j=0;j<nbptdecoup;j++)
|
84 |
|
|
{
|
85 |
|
|
double x=lstptdecoup[3*j];
|
86 |
|
|
double y=lstptdecoup[3*j+1];
|
87 |
|
|
double z=lstptdecoup[3*j+2];
|
88 |
|
|
DLY_TETRA* tetbase=get_tetra(tet,x,y,z);
|
89 |
|
|
std::vector<DLY_TETRA*> tetdetruit;
|
90 |
|
|
std::vector<DLY_TETRA*> tetcree;
|
91 |
|
|
std::vector<DLY_TRIANGLE*> basetri;
|
92 |
|
|
ajoute_tetra_cavite(tetbase,tetdetruit,basetri);
|
93 |
|
|
for (int i=0;i<tetdetruit.size();i++)
|
94 |
|
|
{
|
95 |
|
|
DLY_TETRA* tettmp=tetdetruit[i];
|
96 |
|
|
if (tettmp->get_voisin1()!=NULL)
|
97 |
|
|
{
|
98 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin1());
|
99 |
|
|
if (itv2==tetdetruit.end())
|
100 |
|
|
if (tettmp->get_voisin1()->point_dans_le_tetra(x,y,z)!=0)
|
101 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin1(),tetdetruit,basetri);
|
102 |
|
|
}
|
103 |
|
|
if (tettmp->get_voisin2()!=NULL)
|
104 |
|
|
{
|
105 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin2());
|
106 |
|
|
if (itv2==tetdetruit.end())
|
107 |
|
|
if (tettmp->get_voisin2()->point_dans_le_tetra(x,y,z)!=0)
|
108 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin2(),tetdetruit,basetri);
|
109 |
|
|
}
|
110 |
|
|
if (tettmp->get_voisin3()!=NULL)
|
111 |
|
|
{
|
112 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin3());
|
113 |
|
|
if (itv2==tetdetruit.end())
|
114 |
|
|
if (tettmp->get_voisin3()->point_dans_le_tetra(x,y,z)!=0)
|
115 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin3(),tetdetruit,basetri);
|
116 |
|
|
}
|
117 |
|
|
if (tettmp->get_voisin4()!=NULL)
|
118 |
|
|
{
|
119 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin4());
|
120 |
|
|
if (itv2==tetdetruit.end())
|
121 |
|
|
if (tettmp->get_voisin4()->point_dans_le_tetra(x,y,z)!=0)
|
122 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin4(),tetdetruit,basetri);
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
int nbtetrabase=tetdetruit.size();
|
126 |
|
|
for (int i=0;i<tetdetruit.size();i++)
|
127 |
|
|
{
|
128 |
|
|
DLY_TETRA* tettmp=tetdetruit[i];
|
129 |
|
|
if (tettmp->get_voisin1()!=NULL)
|
130 |
|
|
{
|
131 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin1());
|
132 |
|
|
if (itv2==tetdetruit.end())
|
133 |
|
|
if (tettmp->get_voisin1()->point_dans_la_sphere(x,y,z)!=0)
|
134 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin1(),tetdetruit,basetri);
|
135 |
|
|
}
|
136 |
|
|
if (tettmp->get_voisin2()!=NULL)
|
137 |
|
|
{
|
138 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin2());
|
139 |
|
|
if (itv2==tetdetruit.end())
|
140 |
|
|
if (tettmp->get_voisin2()->point_dans_la_sphere(x,y,z)!=0)
|
141 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin2(),tetdetruit,basetri);
|
142 |
|
|
}
|
143 |
|
|
if (tettmp->get_voisin3()!=NULL)
|
144 |
|
|
{
|
145 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin3());
|
146 |
|
|
if (itv2==tetdetruit.end())
|
147 |
|
|
if (tettmp->get_voisin3()->point_dans_la_sphere(x,y,z)!=0)
|
148 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin3(),tetdetruit,basetri);
|
149 |
|
|
}
|
150 |
|
|
if (tettmp->get_voisin4()!=NULL)
|
151 |
|
|
{
|
152 |
|
|
std::vector<DLY_TETRA*>::iterator itv2=find(tetdetruit.begin(),tetdetruit.end(),tettmp->get_voisin4());
|
153 |
|
|
if (itv2==tetdetruit.end())
|
154 |
|
|
if (tettmp->get_voisin4()->point_dans_la_sphere(x,y,z)!=0)
|
155 |
|
|
ajoute_tetra_cavite(tettmp->get_voisin4(),tetdetruit,basetri);
|
156 |
|
|
}
|
157 |
|
|
}
|
158 |
|
|
|
159 |
|
|
|
160 |
|
|
|
161 |
|
|
|
162 |
|
|
int res=0;
|
163 |
|
|
do
|
164 |
|
|
{
|
165 |
|
|
res=modifie_cavite(tetdetruit,basetri,nbtetrabase,x,y,z);
|
166 |
|
|
}
|
167 |
|
|
while (res==0);
|
168 |
|
|
|
169 |
|
|
|
170 |
|
|
|
171 |
|
|
|
172 |
|
|
for (int i=0;i<tetdetruit.size();i++)
|
173 |
|
|
{
|
174 |
|
|
/*std::multimap<double, DLY_TETRA*, std::greater<double> >::iterator it2=front.find(tetdetruit[i]->get_critere_subdivision());
|
175 |
|
|
while ((*it2).second!=tetdetruit[i])
|
176 |
|
|
it2++;
|
177 |
|
|
front.erase(it2);*/
|
178 |
|
|
retirer_front(tetdetruit[i]->get_segment1());
|
179 |
|
|
retirer_front(tetdetruit[i]->get_segment2());
|
180 |
|
|
retirer_front(tetdetruit[i]->get_segment3());
|
181 |
|
|
retirer_front(tetdetruit[i]->get_segment4());
|
182 |
|
|
retirer_front(tetdetruit[i]->get_segment5());
|
183 |
|
|
retirer_front(tetdetruit[i]->get_segment6());
|
184 |
|
|
|
185 |
|
|
}
|
186 |
|
|
DLY_NOEUD* no=new DLY_NOEUD(tabnoeud.size(),x,y,z);
|
187 |
|
|
tabnoeud.push_back(no);
|
188 |
|
|
for (int i=0;i<basetri.size();i++)
|
189 |
|
|
{
|
190 |
|
|
int frontiere=basetri[i]->est_frontiere();
|
191 |
|
|
int coplanaire=basetri[i]->est_coplanaire(no->get_x(),no->get_y(),no->get_z());
|
192 |
|
|
if ((frontiere==0) || ((frontiere==1) && (coplanaire==0)))
|
193 |
|
|
{
|
194 |
|
|
DLY_TETRA* tetnv=cree_tetra(basetri[i]->get_noeud1(),basetri[i]->get_noeud2(),basetri[i]->get_noeud3(),no);
|
195 |
|
|
tetcree.push_back(tetnv);
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
double volold=0.;
|
199 |
|
|
double volnew=0.;
|
200 |
|
|
/*for (int i=0;i<tetdetruit.size();i++)
|
201 |
|
|
volold=volold+tetdetruit[i]->calcul_volume(NULL,0);
|
202 |
|
|
for (int i=0;i<tetcree.size();i++)
|
203 |
|
|
volnew=volnew+tetcree[i]->calcul_volume(NULL,0);
|
204 |
|
|
if (fabs(volold-volnew)>0.000000000001*volold)
|
205 |
|
|
//std::cout << volold << " remplacé par " << volnew << " Étape " << jj << " " << j << std::endl;
|
206 |
|
|
*/
|
207 |
|
|
for (int i=0;i<tetdetruit.size();i++)
|
208 |
|
|
tetdetruit[i]->ajoute_fils(tetcree);
|
209 |
|
|
for (int i=0;i<tetcree.size();i++)
|
210 |
|
|
{
|
211 |
|
|
mise_a_jour_voisin(tetcree[i]);
|
212 |
|
|
if (tetcree[i]->get_voisin1()!=NULL) mise_a_jour_voisin(tetcree[i]->get_voisin1());
|
213 |
|
|
if (tetcree[i]->get_voisin2()!=NULL) mise_a_jour_voisin(tetcree[i]->get_voisin2());
|
214 |
|
|
if (tetcree[i]->get_voisin3()!=NULL) mise_a_jour_voisin(tetcree[i]->get_voisin3());
|
215 |
|
|
if (tetcree[i]->get_voisin4()!=NULL) mise_a_jour_voisin(tetcree[i]->get_voisin4());
|
216 |
|
|
}
|
217 |
|
|
/* for (int i=0;i<tabtet.size();i++)
|
218 |
|
|
{
|
219 |
|
|
DLY_TETRA* tet=tabtet[i];
|
220 |
|
|
if (tet->get_feuille()==0) continue;
|
221 |
|
|
if (tet->get_voisin1()!=NULL)
|
222 |
|
|
if (tet->get_voisin1()->get_feuille()==0)
|
223 |
|
|
{
|
224 |
|
|
std::cout << "bug1 " << jj << " "<< j<< std::endl;
|
225 |
|
|
return;
|
226 |
|
|
}
|
227 |
|
|
if (tet->get_voisin2()!=NULL)
|
228 |
|
|
if (tet->get_voisin2()->get_feuille()==0)
|
229 |
|
|
{
|
230 |
|
|
std::cout << "bug2 " << jj << " "<< j<< std::endl;
|
231 |
|
|
return;
|
232 |
|
|
}
|
233 |
|
|
if (tet->get_voisin3()!=NULL)
|
234 |
|
|
if (tet->get_voisin3()->get_feuille()==0)
|
235 |
|
|
{
|
236 |
|
|
std::cout << "bug3 "<< jj << " "<< j << std::endl;
|
237 |
|
|
return;
|
238 |
|
|
}
|
239 |
|
|
if (tet->get_voisin4()!=NULL)
|
240 |
|
|
if (tet->get_voisin4()->get_feuille()==0)
|
241 |
|
|
{
|
242 |
|
|
std::cout << "bug4 "<< jj << " "<< j << std::endl;
|
243 |
|
|
return;
|
244 |
|
|
}
|
245 |
|
|
|
246 |
|
|
}*/
|
247 |
|
|
/* mai=new MG_MAILLAGE(NULL);
|
248 |
|
|
MG_GESTIONNAIRE g;
|
249 |
|
|
g.ajouter_mg_maillage(mai);
|
250 |
|
|
transfert_maillage(&tabnoeud,NULL,&tabtet);
|
251 |
|
|
g.enregistrer("test.magic");*/
|
252 |
|
|
|
253 |
|
|
}
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
void MAILLEUR_DELAUNAY::ajouter_front(double crit,DLY_SEGMENT* seg)
|
258 |
|
|
{
|
259 |
|
|
if (crit>critere_arret)
|
260 |
|
|
{
|
261 |
|
|
std::pair<const unsigned long long,DLY_SEGMENT*> tmp((const unsigned long long)seg,seg);
|
262 |
|
|
std::pair<std::map<const unsigned long long,DLY_SEGMENT*>::iterator,bool> res=front.insert(tmp);
|
263 |
|
|
if (res.second==true)
|
264 |
|
|
{
|
265 |
|
|
seg->change_critere(crit);
|
266 |
|
|
std::pair<double,DLY_SEGMENT*> tmp2(crit,seg);
|
267 |
|
|
front_trie.insert(tmp2);
|
268 |
|
|
}
|
269 |
|
|
}
|
270 |
|
|
}
|
271 |
|
|
void MAILLEUR_DELAUNAY::retirer_front(DLY_SEGMENT* seg)
|
272 |
|
|
{
|
273 |
|
|
std::map<const unsigned long long,DLY_SEGMENT*>::iterator it=front.find((const unsigned long long)seg);
|
274 |
|
|
if (it==front.end()) return;
|
275 |
|
|
front.erase(it);
|
276 |
|
|
std::multimap<double,DLY_SEGMENT*,std::greater<double> >::iterator it2=front_trie.find(seg->get_critere());
|
277 |
|
|
while ((*it2).second!=seg)
|
278 |
|
|
it2++;
|
279 |
|
|
front_trie.erase(it2);
|
280 |
|
|
}
|
281 |
|
|
int MAILLEUR_DELAUNAY::modifie_cavite(std::vector<DLY_TETRA*> &cavite,std::vector<DLY_TRIANGLE*> &basetri,int nbbase,double x, double y,double z)
|
282 |
|
|
{
|
283 |
|
|
std::map<unsigned long long,DLY_TETRA*> tetasupprimercavite;
|
284 |
|
|
for (int i=0;i<basetri.size();i++)
|
285 |
|
|
{
|
286 |
|
|
DLY_TRIANGLE* tri=basetri[i];
|
287 |
|
|
DLY_TETRA* inte=NULL;
|
288 |
|
|
DLY_TETRA* exte=NULL;
|
289 |
|
|
for (int j=0;j<tri->get_nb_tetra();j++)
|
290 |
|
|
{
|
291 |
|
|
DLY_TETRA* tet=tri->get_tetra(j);
|
292 |
|
|
if (tet->get_feuille()==1)
|
293 |
|
|
{
|
294 |
|
|
std::vector<DLY_TETRA*>::iterator it=find(cavite.begin(),cavite.end(),tet);
|
295 |
|
|
if (it==cavite.end()) exte=tet;
|
296 |
|
|
else inte=tet;
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
|
|
double nor[3];
|
300 |
|
|
int base=0;
|
301 |
|
|
for (int j=0;j<nbbase;j++)
|
302 |
|
|
if (inte==cavite[j]) base=1;
|
303 |
|
|
if (base==1) continue;
|
304 |
|
|
if (inte->get_triangle1()==tri) inte->get_normal1(nor);
|
305 |
|
|
if (inte->get_triangle2()==tri) inte->get_normal2(nor);
|
306 |
|
|
if (inte->get_triangle3()==tri) inte->get_normal3(nor);
|
307 |
|
|
if (inte->get_triangle4()==tri) inte->get_normal4(nor);
|
308 |
|
|
nor[0]=-nor[0];
|
309 |
|
|
nor[1]=-nor[1];
|
310 |
|
|
nor[2]=-nor[2];
|
311 |
|
|
double xyzo[3];
|
312 |
|
|
tri->get_noeud1()->get_coord(xyzo);
|
313 |
|
|
OT_VECTEUR_3D vecdir(x-xyzo[0],y-xyzo[1],z-xyzo[2]);
|
314 |
|
|
OT_VECTEUR_3D normal(nor);
|
315 |
|
|
vecdir.norme();
|
316 |
|
|
double ps=vecdir*normal;
|
317 |
|
|
if (ps<0.000000001)
|
318 |
|
|
{
|
319 |
|
|
tri->est_frontiere();
|
320 |
|
|
//retire_tetra_cavite(inte,cavite,basetri);
|
321 |
|
|
unsigned long long adresse=(unsigned long long)inte;
|
322 |
|
|
tetasupprimercavite.insert(std::pair<unsigned long long,DLY_TETRA*>(adresse,inte));
|
323 |
|
|
|
324 |
|
|
}
|
325 |
|
|
}
|
326 |
|
|
int nbtetasupprimer=tetasupprimercavite.size();
|
327 |
|
|
if (nbtetasupprimer==0) return 1;
|
328 |
|
|
for (std::map<unsigned long long,DLY_TETRA*>::iterator it=tetasupprimercavite.begin();it!=tetasupprimercavite.end();it++)
|
329 |
|
|
retire_tetra_cavite((*it).second,cavite,basetri);
|
330 |
|
|
|
331 |
|
|
return 0;
|
332 |
|
|
}
|
333 |
|
|
|
334 |
|
|
|
335 |
|
|
void MAILLEUR_DELAUNAY::retire_tetra_cavite(DLY_TETRA* tet,std::vector<DLY_TETRA*> &cavite,std::vector<DLY_TRIANGLE*> &basetri)
|
336 |
|
|
{
|
337 |
|
|
std::vector<DLY_TETRA*>::iterator it=find(cavite.begin(),cavite.end(),tet);
|
338 |
|
|
cavite.erase(it);
|
339 |
|
|
std::vector<DLY_TRIANGLE*>::iterator itv=find(basetri.begin(),basetri.end(),tet->get_triangle1());
|
340 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle1());
|
341 |
|
|
else basetri.erase(itv);
|
342 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle2());
|
343 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle2());
|
344 |
|
|
else basetri.erase(itv);
|
345 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle3());
|
346 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle3());
|
347 |
|
|
else basetri.erase(itv);
|
348 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle4());
|
349 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle4());
|
350 |
|
|
else basetri.erase(itv);
|
351 |
|
|
}
|
352 |
|
|
|
353 |
|
|
void MAILLEUR_DELAUNAY::ajoute_tetra_cavite(DLY_TETRA* tet,std::vector<DLY_TETRA*> &cavite,std::vector<DLY_TRIANGLE*> &basetri)
|
354 |
|
|
{
|
355 |
|
|
cavite.push_back(tet);
|
356 |
|
|
std::vector<DLY_TRIANGLE*>::iterator itv=find(basetri.begin(),basetri.end(),tet->get_triangle1());
|
357 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle1());
|
358 |
|
|
else basetri.erase(itv);
|
359 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle2());
|
360 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle2());
|
361 |
|
|
else basetri.erase(itv);
|
362 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle3());
|
363 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle3());
|
364 |
|
|
else basetri.erase(itv);
|
365 |
|
|
itv=find(basetri.begin(),basetri.end(),tet->get_triangle4());
|
366 |
|
|
if (itv==basetri.end()) basetri.push_back(tet->get_triangle4());
|
367 |
|
|
else basetri.erase(itv);
|
368 |
|
|
}
|
369 |
|
|
|
370 |
|
|
void MAILLEUR_DELAUNAY::initialise_maillage(void)
|
371 |
|
|
{
|
372 |
|
|
double param[32];
|
373 |
|
|
int nb_cellule=carte->get_nb_cellule();
|
374 |
|
|
carte->get_information(0,0,param);
|
375 |
|
|
double xmin=param[0]+0.005*(param[1]-param[0]);
|
376 |
|
|
double ymin=param[8]+0.005*(param[10]-param[8]);
|
377 |
|
|
double zmin=param[16]+0.005*(param[20]-param[16]);
|
378 |
|
|
carte->get_information(nb_cellule-1,0,param);
|
379 |
|
|
double xmax=param[1]-0.005*(param[1]-param[0]);
|
380 |
|
|
double ymax=param[10]-0.005*(param[10]-param[8]);
|
381 |
|
|
double zmax=param[20]-0.005*(param[20]-param[16]);
|
382 |
|
|
DLY_NOEUD* no1=new DLY_NOEUD(tabnoeud.size(),xmin,ymin,zmin);
|
383 |
|
|
tabnoeud.push_back(no1);
|
384 |
|
|
DLY_NOEUD* no2=new DLY_NOEUD(tabnoeud.size(),xmin,ymax,zmin);
|
385 |
|
|
tabnoeud.push_back(no2);
|
386 |
|
|
DLY_NOEUD* no3=new DLY_NOEUD(tabnoeud.size(),xmax,ymax,zmin);
|
387 |
|
|
tabnoeud.push_back(no3);
|
388 |
|
|
DLY_NOEUD* no4=new DLY_NOEUD(tabnoeud.size(),xmax,ymin,zmin);
|
389 |
|
|
tabnoeud.push_back(no4);
|
390 |
|
|
DLY_NOEUD* no5=new DLY_NOEUD(tabnoeud.size(),xmin,ymin,zmax);
|
391 |
|
|
tabnoeud.push_back(no5);
|
392 |
|
|
DLY_NOEUD* no6=new DLY_NOEUD(tabnoeud.size(),xmin,ymax,zmax);
|
393 |
|
|
tabnoeud.push_back(no6);
|
394 |
|
|
DLY_NOEUD* no7=new DLY_NOEUD(tabnoeud.size(),xmax,ymax,zmax);
|
395 |
|
|
tabnoeud.push_back(no7);
|
396 |
|
|
DLY_NOEUD* no8=new DLY_NOEUD(tabnoeud.size(),xmax,ymin,zmax);
|
397 |
|
|
tabnoeud.push_back(no8);
|
398 |
|
|
DLY_TETRA* tet1=cree_tetra(no2,no1,no3,no6);
|
399 |
|
|
DLY_TETRA* tet2=cree_tetra(no3,no1,no4,no5);
|
400 |
|
|
DLY_TETRA* tet3=cree_tetra(no3,no1,no5,no6);
|
401 |
|
|
DLY_TETRA* tet4=cree_tetra(no8,no5,no7,no4);
|
402 |
|
|
DLY_TETRA* tet5=cree_tetra(no7,no5,no6,no3);
|
403 |
|
|
DLY_TETRA* tet6=cree_tetra(no4,no3,no5,no7);
|
404 |
|
|
mise_a_jour_voisin(tet1);
|
405 |
|
|
mise_a_jour_voisin(tet2);
|
406 |
|
|
mise_a_jour_voisin(tet3);
|
407 |
|
|
mise_a_jour_voisin(tet4);
|
408 |
|
|
mise_a_jour_voisin(tet5);
|
409 |
|
|
mise_a_jour_voisin(tet6);
|
410 |
|
|
char message[255];
|
411 |
|
|
sprintf(message," Volume espace : %lf",(xmax-xmin)*(ymax-ymin)*(zmax-zmin));
|
412 |
|
|
if (affichageactif) affiche(message);
|
413 |
|
|
}
|
414 |
|
|
void MAILLEUR_DELAUNAY::mise_a_jour_voisin(DLY_TETRA* tet)
|
415 |
|
|
{
|
416 |
|
|
int nb=tet->get_triangle1()->get_nb_tetra();
|
417 |
|
|
for (int i=0;i<nb;i++)
|
418 |
|
|
{
|
419 |
|
|
DLY_TETRA* tetmp=tet->get_triangle1()->get_tetra(i);
|
420 |
|
|
if (tetmp->get_feuille()==1)
|
421 |
|
|
if (tetmp!=tet) tet->change_voisin1(tetmp);
|
422 |
|
|
}
|
423 |
|
|
nb=tet->get_triangle2()->get_nb_tetra();
|
424 |
|
|
for (int i=0;i<nb;i++)
|
425 |
|
|
{
|
426 |
|
|
DLY_TETRA* tetmp=tet->get_triangle2()->get_tetra(i);
|
427 |
|
|
if (tetmp->get_feuille()==1)
|
428 |
|
|
if (tetmp!=tet) tet->change_voisin2(tetmp);
|
429 |
|
|
}
|
430 |
|
|
nb=tet->get_triangle3()->get_nb_tetra();
|
431 |
|
|
for (int i=0;i<nb;i++)
|
432 |
|
|
{
|
433 |
|
|
DLY_TETRA* tetmp=tet->get_triangle3()->get_tetra(i);
|
434 |
|
|
if (tetmp->get_feuille()==1)
|
435 |
|
|
if (tetmp!=tet) tet->change_voisin3(tetmp);
|
436 |
|
|
}
|
437 |
|
|
nb=tet->get_triangle4()->get_nb_tetra();
|
438 |
|
|
for (int i=0;i<nb;i++)
|
439 |
|
|
{
|
440 |
|
|
DLY_TETRA* tetmp=tet->get_triangle4()->get_tetra(i);
|
441 |
|
|
if (tetmp->get_feuille()==1)
|
442 |
|
|
if (tetmp!=tet) tet->change_voisin4(tetmp);
|
443 |
|
|
}
|
444 |
|
|
}
|
445 |
|
|
|
446 |
|
|
|
447 |
|
|
DLY_TETRA* MAILLEUR_DELAUNAY::cree_tetra(DLY_NOEUD* n1,DLY_NOEUD* n2,DLY_NOEUD* n3,DLY_NOEUD* n4)
|
448 |
|
|
{
|
449 |
|
|
double xyz1[3],xyz2[3],xyz3[3],xyz4[3];
|
450 |
|
|
n1->get_coord(xyz1);
|
451 |
|
|
n2->get_coord(xyz2);
|
452 |
|
|
n3->get_coord(xyz3);
|
453 |
|
|
n4->get_coord(xyz4);
|
454 |
|
|
double qual=OPERATEUR::qualite_tetra(xyz1,xyz2,xyz3,xyz4);
|
455 |
|
|
DLY_TETRA* tet;
|
456 |
|
|
if (!(qual>0.))
|
457 |
|
|
{
|
458 |
|
|
DLY_NOEUD* ntmp=n1;
|
459 |
|
|
n1=n2;
|
460 |
|
|
n2=ntmp;
|
461 |
|
|
}
|
462 |
|
|
tet=new DLY_TETRA(n1,n2,n3,n4,fabs(qual));
|
463 |
|
|
tabtet.push_back(tet);
|
464 |
|
|
tet->change_triangle1(get_triangle(n1,n2,n3));
|
465 |
|
|
tet->change_triangle2(get_triangle(n1,n2,n4));
|
466 |
|
|
tet->change_triangle3(get_triangle(n1,n3,n4));
|
467 |
|
|
tet->change_triangle4(get_triangle(n2,n3,n4));
|
468 |
|
|
tet->change_segment1(get_segment(n1,n2));
|
469 |
|
|
tet->change_segment2(get_segment(n1,n3));
|
470 |
|
|
tet->change_segment3(get_segment(n1,n4));
|
471 |
|
|
tet->change_segment4(get_segment(n2,n3));
|
472 |
|
|
tet->change_segment5(get_segment(n2,n4));
|
473 |
|
|
tet->change_segment6(get_segment(n3,n4));
|
474 |
|
|
// std::pair<double,DLY_TETRA*> tmp(tet->get_critere_subdivision(),tet);
|
475 |
|
|
ajouter_front(tet->get_segment1()->calcul_longueur(carte,1),tet->get_segment1());
|
476 |
|
|
ajouter_front(tet->get_segment2()->calcul_longueur(carte,1),tet->get_segment2());
|
477 |
|
|
ajouter_front(tet->get_segment3()->calcul_longueur(carte,1),tet->get_segment3());
|
478 |
|
|
ajouter_front(tet->get_segment4()->calcul_longueur(carte,1),tet->get_segment4());
|
479 |
|
|
ajouter_front(tet->get_segment5()->calcul_longueur(carte,1),tet->get_segment5());
|
480 |
|
|
ajouter_front(tet->get_segment6()->calcul_longueur(carte,1),tet->get_segment6());
|
481 |
|
|
return tet;
|
482 |
|
|
}
|
483 |
|
|
DLY_SEGMENT* MAILLEUR_DELAUNAY::get_segment(DLY_NOEUD* n1,DLY_NOEUD* n2)
|
484 |
|
|
{
|
485 |
|
|
|
486 |
|
|
DLY_NOEUD* no;
|
487 |
|
|
if (n1->get_num()<n2->get_num()) no=n1;
|
488 |
|
|
else no=n2;
|
489 |
|
|
DLY_SEGMENT* seg=no->get_lien_segment(n1,n2);
|
490 |
|
|
if (seg==NULL)
|
491 |
|
|
{
|
492 |
|
|
seg=new DLY_SEGMENT(n1,n2);
|
493 |
|
|
tabseg.push_back(seg);
|
494 |
|
|
no->insere_lien_segment(seg);
|
495 |
|
|
}
|
496 |
|
|
return seg;
|
497 |
|
|
}
|
498 |
|
|
|
499 |
|
|
DLY_TRIANGLE* MAILLEUR_DELAUNAY::get_triangle(DLY_NOEUD* n1,DLY_NOEUD* n2,DLY_NOEUD* n3)
|
500 |
|
|
{
|
501 |
|
|
DLY_NOEUD* no;
|
502 |
|
|
if (n1->get_num()<n2->get_num()) no=n1;
|
503 |
|
|
else no=n2;
|
504 |
|
|
if (n3->get_num()<no->get_num()) no=n3;
|
505 |
|
|
DLY_TRIANGLE* tri=no->get_lien_triangle(n1,n2,n3);
|
506 |
|
|
if (tri==NULL)
|
507 |
|
|
{
|
508 |
|
|
tri=new DLY_TRIANGLE(n1,n2,n3);
|
509 |
|
|
tabtri.push_back(tri);
|
510 |
|
|
no->insere_lien_triangle(tri);
|
511 |
|
|
}
|
512 |
|
|
return tri;
|
513 |
|
|
}
|
514 |
|
|
|
515 |
|
|
|
516 |
|
|
DLY_TETRA* MAILLEUR_DELAUNAY::get_tetra(double x,double y,double z)
|
517 |
|
|
{
|
518 |
|
|
DLY_TETRA* tet;
|
519 |
|
|
tet=get_tetra(tabtet[0],x,y,z);
|
520 |
|
|
if (tet!=NULL) return tet;
|
521 |
|
|
tet=get_tetra(tabtet[1],x,y,z);
|
522 |
|
|
if (tet!=NULL) return tet;
|
523 |
|
|
tet=get_tetra(tabtet[2],x,y,z);
|
524 |
|
|
if (tet!=NULL) return tet;
|
525 |
|
|
tet=get_tetra(tabtet[3],x,y,z);
|
526 |
|
|
if (tet!=NULL) return tet;
|
527 |
|
|
tet=get_tetra(tabtet[4],x,y,z);
|
528 |
|
|
if (tet!=NULL) return tet;
|
529 |
|
|
tet=get_tetra(tabtet[5],x,y,z);
|
530 |
|
|
if (tet!=NULL) return tet;
|
531 |
|
|
return NULL;
|
532 |
|
|
}
|
533 |
|
|
|
534 |
|
|
DLY_TETRA* MAILLEUR_DELAUNAY::get_tetra(DLY_TETRA* tet,double x,double y,double z)
|
535 |
|
|
{
|
536 |
|
|
if (tet->point_dans_le_tetra(x,y,z))
|
537 |
|
|
{
|
538 |
|
|
if (tet->get_feuille()==1) return tet;
|
539 |
|
|
int nb=tet->get_nb_fils();
|
540 |
|
|
for (int i=0;i<nb;i++)
|
541 |
|
|
{
|
542 |
|
|
DLY_TETRA* tetrep=get_tetra(tet->get_fils(i),x,y,z);
|
543 |
|
|
if (tetrep!=NULL) return tetrep;
|
544 |
|
|
}
|
545 |
|
|
}
|
546 |
|
|
return NULL;
|
547 |
|
|
}
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
void MAILLEUR_DELAUNAY::transfert_maillage(std::vector<DLY_NOEUD*> *tabn,std::vector<DLY_TRIANGLE*> *tabe2d,std::vector<DLY_TETRA*> *tabe3d)
|
551 |
|
|
{
|
552 |
|
|
for (int i=0;i<tabn->size();i++)
|
553 |
|
|
{
|
554 |
|
|
DLY_NOEUD *no=(*tabn)[i];
|
555 |
|
|
MG_NOEUD* noeud=new MG_NOEUD(NULL,no->get_x(),no->get_y(),no->get_z(),TRIANGULATION);
|
556 |
|
|
mai->ajouter_mg_noeud(noeud);
|
557 |
|
|
no->change_noeud(noeud);
|
558 |
|
|
}
|
559 |
|
|
if (tabe2d!=NULL)
|
560 |
|
|
{
|
561 |
|
|
for (int i=0;i<tabe2d->size();i++)
|
562 |
|
|
{
|
563 |
|
|
DLY_TRIANGLE* tri=(*tabe2d)[i];
|
564 |
|
|
if (tri->est_frontiere())
|
565 |
|
|
MG_TRIANGLE *mgtri=mai->ajouter_mg_triangle(NULL,tri->get_noeud1()->get_noeud(),tri->get_noeud2()->get_noeud(),tri->get_noeud3()->get_noeud(),TRIANGULATION);
|
566 |
|
|
}
|
567 |
|
|
}
|
568 |
|
|
else
|
569 |
|
|
{
|
570 |
|
|
double vol=0.;
|
571 |
|
|
double nbmaitheo=0;
|
572 |
|
|
for (int i=0;i<tabe3d->size();i++)
|
573 |
|
|
{
|
574 |
|
|
DLY_TETRA* tet=(*tabe3d)[i];
|
575 |
|
|
if (tet->get_feuille()==1)
|
576 |
|
|
{
|
577 |
|
|
MG_TETRA* mgtet=mai->ajouter_mg_tetra(NULL,tet->get_noeud1()->get_noeud(),tet->get_noeud2()->get_noeud(),tet->get_noeud3()->get_noeud(),tet->get_noeud4()->get_noeud(),TRIANGULATION);
|
578 |
|
|
vol=vol+tet->calcul_volume(NULL,0);
|
579 |
|
|
nbmaitheo=nbmaitheo+tet->calcul_volume(carte,0);
|
580 |
|
|
}
|
581 |
|
|
}
|
582 |
|
|
MG_MAILLAGE_ALGOS::calcule_caracteristiques(mai,"test",carte);
|
583 |
|
|
char message[255];
|
584 |
|
|
sprintf(message," Volume maille : %lf",vol);
|
585 |
|
|
if (affichageactif) affiche(message);
|
586 |
|
|
nbmaitheo=12.*nbmaitheo/sqrt(2);
|
587 |
|
|
double erreur=nbmaitheo-mai->get_nb_mg_tetra();
|
588 |
|
|
erreur=erreur/mai->get_nb_mg_tetra();
|
589 |
|
|
sprintf(message," Nombre de maille theorique : %d, Nombre de maille pratique %d, erreur %.2lf%%",(int)nbmaitheo,mai->get_nb_mg_tetra(),erreur);
|
590 |
|
|
if (affichageactif) affiche(message);
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
}
|
594 |
|
|
|
595 |
|
|
|
596 |
|
|
int MAILLEUR_DELAUNAY::est_de_delaunay(void)
|
597 |
|
|
{
|
598 |
|
|
for (int i=0;i<tabtet.size();i++)
|
599 |
|
|
{
|
600 |
|
|
DLY_TETRA* tet=tabtet[i];
|
601 |
|
|
for (int j=0;j<tabnoeud.size();j++)
|
602 |
|
|
{
|
603 |
|
|
DLY_NOEUD* no=tabnoeud[j];
|
604 |
|
|
if (no!=tet->get_noeud1())
|
605 |
|
|
if (no!=tet->get_noeud2())
|
606 |
|
|
if (no!=tet->get_noeud3())
|
607 |
|
|
if (no!=tet->get_noeud4())
|
608 |
|
|
{
|
609 |
|
|
int num=tet->point_dans_la_sphere(no->get_x(),no->get_y(),no->get_z()>1);
|
610 |
|
|
if (num>1)
|
611 |
|
|
return 0;
|
612 |
|
|
|
613 |
|
|
}
|
614 |
|
|
}
|
615 |
|
|
}
|
616 |
|
|
return 1;
|
617 |
|
|
}
|