ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/microstructure/src/mstruct_generateur.cpp
Revision: 993
Committed: Sun Nov 11 17:17:59 2018 UTC (6 years, 9 months ago) by couturad
File size: 47773 byte(s)
Log Message:
MICROSTRUCTURE : 
-> Ajout d'une procedure de suivit des erreurs
-> Mise a jour des CLs
-> (Polycristaux) Correction d'un bug du calcul du tenseur d'orientation

File Contents

# Content
1 #include "mstruct_generateur.h"
2 #include "mstruct_definition.h"
3 #include "mg_cg_modele.h"
4 #include "mg_gestionnaire.h"
5 #include "mg_cg.h"
6 #include "ot_geometrie.h"
7 #include "mg_cg_forme_volume.h"
8 #include "mg_cg_forme_multi_volume.h"
9 #include "mg_cg_op_inclusion_matrice.h"
10 #include "mg_cg_op_bool_difference.h"
11 #include "mg_cg_op_bool_intersection.h"
12 #include "mg_cg_op_transf_decallage.h"
13 #include <stack>
14
15
16 MSTRUCT_GENERATEUR::MSTRUCT_GENERATEUR(MG_GESTIONNAIRE* mg_gestionnaire,char* nom_mgcg_modele)
17 {
18 m_mg_gestionnaire=mg_gestionnaire;
19 m_mgcg_modele=MG_CG::creer_MG_CG_MODELE(m_mg_gestionnaire,nom_mgcg_modele);
20 mg_gestionnaire->ajouter_mgcg_modele(m_mgcg_modele);
21 m_mgcg_modele->change_importer_triangulation(true);
22 m_mgcg_modele->change_fusionner_entite_similaire(false);
23 m_mgcg_modele->change_epsilon_triangulation(0.01);
24 m_grille_init=false;
25 }
26
27 MSTRUCT_GENERATEUR::MSTRUCT_GENERATEUR(MSTRUCT_GENERATEUR& mcpy)
28 {
29 m_mg_gestionnaire=mcpy.m_mg_gestionnaire;
30 m_mgcg_modele=mcpy.m_mgcg_modele;
31 m_boite3d_ves=mcpy.m_boite3d_ves;
32 m_boite3d_distribution=mcpy.m_boite3d_distribution;
33 m_intersection_bords_ves=mcpy.m_intersection_bords_ves;
34 m_angle_min=mcpy.m_angle_min;
35 m_longueur_min=mcpy.m_longueur_min;
36 m_aire_min=mcpy.m_aire_min;
37 m_volume_min=mcpy.m_volume_min;
38 m_distance_min=mcpy.m_distance_min;
39 m_nb_pas_grille=mcpy.m_nb_pas_grille;
40 m_nb_pas_echantillonnage=mcpy.m_nb_pas_echantillonnage;
41 m_precision=mcpy.m_precision;
42 m_grille_init=mcpy.m_grille_init;
43 if(m_grille_init)
44 m_grille_volume_inclusion.initialiser(m_boite3d_distribution.get_xmin(),m_boite3d_distribution.get_ymin(),m_boite3d_distribution.get_zmin(),
45 m_boite3d_distribution.get_xmax(),m_boite3d_distribution.get_ymax(),m_boite3d_distribution.get_zmax(),
46 m_nb_pas_echantillonnage,m_nb_pas_echantillonnage,m_nb_pas_echantillonnage);
47 m_vector_mgcg_groupe_forme_inclusion=mcpy.m_vector_mgcg_groupe_forme_inclusion;
48 std::vector<MG_CG_GROUPE_FORME*>::iterator it_gr_forme;
49 for(it_gr_forme=m_vector_mgcg_groupe_forme_inclusion.begin();it_gr_forme!=m_vector_mgcg_groupe_forme_inclusion.end();it_gr_forme++)
50 {
51 MG_CG_GROUPE_FORME* groupe_forme=*it_gr_forme;
52 TPL_MAP_ENTITE<MG_VOLUME*> tpl_map_volume=groupe_forme->get_tpl_map_volume();
53 TPL_MAP_ENTITE<MG_VOLUME*>::ITERATEUR it_volume;
54 for(MG_VOLUME* vol=tpl_map_volume.get_premier(it_volume);vol!=NULL;vol=tpl_map_volume.get_suivant(it_volume))
55 {
56 m_grille_volume_inclusion.inserer(vol);
57 }
58 }
59 m_matrice=mcpy.m_matrice;
60 m_cube_initial=mcpy.m_cube_initial;
61 m_nb_pas_x=mcpy.m_nb_pas_x;
62 m_nb_pas_y=mcpy.m_nb_pas_y;
63 m_nb_pas_z=mcpy.m_nb_pas_z;
64 affichageactif=mcpy.affichageactif;
65 fonc_affiche=mcpy.fonc_affiche;
66 }
67
68 MSTRUCT_GENERATEUR::~MSTRUCT_GENERATEUR(void)
69 {
70 }
71
72 MG_GESTIONNAIRE* MSTRUCT_GENERATEUR::get_mg_gestionnaire(void)
73 {
74 return m_mg_gestionnaire;
75 }
76
77 MG_CG_MODELE* MSTRUCT_GENERATEUR::get_mgcg_modele(void)
78 {
79 return m_mgcg_modele;
80 }
81
82 void MSTRUCT_GENERATEUR::change_mgcg_modele(MG_CG_MODELE* mgcg_modele)
83 {
84 m_mgcg_modele=mgcg_modele;
85 }
86
87 void MSTRUCT_GENERATEUR::change_boite3d_ves(BOITE_3D boite3d_ves)
88 {
89 m_boite3d_ves=boite3d_ves;
90 }
91
92 void MSTRUCT_GENERATEUR::change_boite3d_distribution(BOITE_3D boite3d_distribution)
93 {
94 m_boite3d_distribution=boite3d_distribution;
95 }
96
97 void MSTRUCT_GENERATEUR::change_intersection_bords_ves(bool intersection_bords_ves)
98 {
99 m_intersection_bords_ves=intersection_bords_ves;
100 }
101
102 void MSTRUCT_GENERATEUR::change_angle_min(double angle_min)
103 {
104 m_angle_min=angle_min;
105 }
106
107 void MSTRUCT_GENERATEUR::change_longueur_min(double longueur_min)
108 {
109 m_longueur_min=longueur_min;
110 }
111
112 void MSTRUCT_GENERATEUR::change_aire_min(double aire_min)
113 {
114 m_aire_min=aire_min;
115 }
116
117 void MSTRUCT_GENERATEUR::change_volume_min(double volume_min)
118 {
119 m_volume_min=volume_min;
120 }
121
122 void MSTRUCT_GENERATEUR::change_distance_inter_volume_min(double distance_min)
123 {
124 m_distance_min=distance_min;
125 }
126
127 void MSTRUCT_GENERATEUR::change_nb_pas_grille(int nb_pas_grille)
128 {
129 m_nb_pas_grille=nb_pas_grille;
130 }
131
132 void MSTRUCT_GENERATEUR::change_nb_pas_echantillonage(int nb_pas_echantillonnage)
133 {
134 m_nb_pas_echantillonnage=nb_pas_echantillonnage;
135 }
136
137 void MSTRUCT_GENERATEUR::change_precision(double precision)
138 {
139 m_precision=precision;
140 }
141
142 double MSTRUCT_GENERATEUR::get_fraction_volumique_groupe_forme(std::string nom)
143 {
144 std::vector<MG_CG_GROUPE_FORME*>::iterator it_gr_forme=m_vector_mgcg_groupe_forme_inclusion.begin();
145 MG_CG_GROUPE_FORME* groupe_forme=NULL;
146 while(groupe_forme==NULL && it_gr_forme!=m_vector_mgcg_groupe_forme_inclusion.end())
147 {
148 if((*it_gr_forme)->get_nom()==nom) groupe_forme=*it_gr_forme;
149 it_gr_forme++;
150 }
151 if(groupe_forme==NULL) return 0.0;
152 double fraction_volumique=0.0;
153 TPL_MAP_ENTITE<MG_VOLUME*> tpl_map_volume=groupe_forme->get_tpl_map_volume();
154 TPL_MAP_ENTITE<MG_VOLUME*>::ITERATEUR it_volume;
155 for(MG_VOLUME* vol=tpl_map_volume.get_premier(it_volume);vol!=NULL;vol=tpl_map_volume.get_suivant(it_volume))
156 {
157 fraction_volumique+=OT_GEOMETRIE::get_volume(vol,m_precision);
158 }
159 fraction_volumique=fraction_volumique/m_boite3d_ves.get_volume();
160 return fraction_volumique;
161 }
162
163
164 void MSTRUCT_GENERATEUR::initialiser_grille(void)
165 {
166 if(!m_grille_init)
167 {
168 m_grille_volume_inclusion.initialiser(m_boite3d_distribution.get_xmin(),m_boite3d_distribution.get_ymin(),m_boite3d_distribution.get_zmin(),
169 m_boite3d_distribution.get_xmax(),m_boite3d_distribution.get_ymax(),m_boite3d_distribution.get_zmax(),
170 m_nb_pas_echantillonnage,m_nb_pas_echantillonnage,m_nb_pas_echantillonnage);
171 m_grille_init=true;
172 }
173 }
174
175 int MSTRUCT_GENERATEUR::position_relative_inclusion_ves(MG_VOLUME* inclusion,bool &plan_x0yz,bool &plan_x1yz,bool &plan_xy0z,bool &plan_xy1z,bool &plan_xyz0,bool &plan_xyz1)
176 {
177 plan_x0yz=false;plan_x1yz=false;plan_xy0z=false;plan_xy1z=false;plan_xyz0=false;plan_xyz1=false;
178 BOITE_3D boite_inclusion=inclusion->get_boite_3D(m_nb_pas_echantillonnage);
179 if(m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymin(),boite_inclusion.get_zmin()))
180 if(m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymin(),boite_inclusion.get_zmax()))
181 if(m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymax(),boite_inclusion.get_zmin()))
182 if(m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymax(),boite_inclusion.get_zmax()))
183 if(m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymin(),boite_inclusion.get_zmin()))
184 if(m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymin(),boite_inclusion.get_zmax()))
185 if(m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymax(),boite_inclusion.get_zmin()))
186 if(m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymax(),boite_inclusion.get_zmax())) return MSTRUCT::POSITION_RELATIVE::INTERIEUR;
187
188 if(!m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymin(),boite_inclusion.get_zmin()))
189 if(!m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymin(),boite_inclusion.get_zmax()))
190 if(!m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymax(),boite_inclusion.get_zmin()))
191 if(!m_boite3d_ves.contient(boite_inclusion.get_xmin(),boite_inclusion.get_ymax(),boite_inclusion.get_zmax()))
192 if(!m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymin(),boite_inclusion.get_zmin()))
193 if(!m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymin(),boite_inclusion.get_zmax()))
194 if(!m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymax(),boite_inclusion.get_zmin()))
195 if(!m_boite3d_ves.contient(boite_inclusion.get_xmax(),boite_inclusion.get_ymax(),boite_inclusion.get_zmax())) return MSTRUCT::POSITION_RELATIVE::EXTERIEUR;
196
197 if(boite_inclusion.get_xmin()<m_boite3d_ves.get_xmin()) plan_x0yz=true;
198 if(boite_inclusion.get_xmax()>m_boite3d_ves.get_xmax()) plan_x1yz=true;
199 if(boite_inclusion.get_ymin()<m_boite3d_ves.get_ymin()) plan_xy0z=true;
200 if(boite_inclusion.get_ymax()>m_boite3d_ves.get_ymax()) plan_xy0z=true;
201 if(boite_inclusion.get_zmin()<m_boite3d_ves.get_zmin()) plan_xyz0=true;
202 if(boite_inclusion.get_zmax()>m_boite3d_ves.get_zmax()) plan_xyz1=true;
203 return MSTRUCT::POSITION_RELATIVE::AU_BORD;
204 }
205
206 bool MSTRUCT_GENERATEUR::angle_entre_face_acceptable(MG_ARETE* mgarete)
207 {
208 long nb_mg_coarete = mgarete->get_nb_mg_coarete();
209 for(int i=0;i<nb_mg_coarete-1;i++)
210 {
211 MG_FACE* face1 = mgarete->get_mg_coarete(i)->get_boucle()->get_mg_face();
212 for(int j=i+1;j<nb_mg_coarete;j++)
213 {
214 MG_FACE* face2 = mgarete->get_mg_coarete(j)->get_boucle()->get_mg_face();
215 double tmin = mgarete->get_tmin();
216 double tmax = mgarete->get_tmax();
217 if(mgarete->get_courbe()->est_periodique())
218 {
219 tmin=0;
220 tmax=mgarete->get_courbe()->get_periode();
221 }
222 double pas_t = (tmin-tmax)/m_nb_pas_echantillonnage;
223 bool planaire=true;
224 for(int k=0;k<m_nb_pas_echantillonnage;k++)
225 {
226 double t = tmin+k*pas_t;
227 double xyz[3];
228 mgarete->evaluer(t,xyz);
229 double uv1[2];
230 face1->inverser(uv1,xyz);
231 double uv2[2];
232 face2->inverser(uv2,xyz);
233 double normale1[3];
234 face1->calcul_normale_unitaire(uv1,normale1);
235 double normale2[3];
236 face2->calcul_normale_unitaire(uv2,normale2);
237 OT_VECTEUR_3D vect_normale1(normale1);
238 OT_VECTEUR_3D vect_normale2(normale2);
239 double angle = fabs(acos((vect_normale1*vect_normale2)/(vect_normale1.get_longueur()*vect_normale2.get_longueur())));
240 if(planaire)
241 if(angle<m_angle_min)
242 if(!OPERATEUR::egal(angle,0.0,m_precision))planaire=false;
243 if(!planaire)
244 {
245 if(angle<m_angle_min) return false;
246 }
247 }
248 }
249 }
250 return true;
251 }
252
253 bool MSTRUCT_GENERATEUR::longueur_acceptable(MG_ARETE* mgarete)
254 {
255 if(OT_GEOMETRIE::get_longueur(mgarete)<m_longueur_min) return false;
256 return true;
257 }
258
259 bool MSTRUCT_GENERATEUR::aire_acceptable(MG_FACE* mgface)
260 {
261 if(OT_GEOMETRIE::get_aire(mgface,m_precision)<m_aire_min) return false;
262 return true;
263 }
264
265 bool MSTRUCT_GENERATEUR::volume_acceptable(MG_VOLUME* mgvolume)
266 {
267 if(OT_GEOMETRIE::get_volume(mgvolume,m_precision)<m_volume_min) return false;
268 return true;
269 }
270
271 bool MSTRUCT_GENERATEUR::volume_intersection_ves_acceptable(MG_VOLUME* mgvolume)
272 {
273 if(m_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::VOLUME)
274 {
275 MG_CG_FORME_VOLUME* forme_volume_matrice = (MG_CG_FORME_VOLUME*)m_matrice;
276 double volume_inclusion = OT_GEOMETRIE::get_volume_intersection(mgvolume,forme_volume_matrice->get_mg_volume());
277 if(volume_inclusion>m_volume_min) return true;
278 return false;
279 }
280 else if(m_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::MULTI_VOLUME)
281 {
282 MG_CG_FORME_MULTI_VOLUME* forme_multi_volume_matrice = (MG_CG_FORME_MULTI_VOLUME*)m_matrice;
283 double volume_inclusion=0;
284 std::map<long,MG_VOLUME*>::iterator it_volume;
285 for(MG_VOLUME* volume_matrice=forme_multi_volume_matrice->get_premier_mg_volume(it_volume);volume_matrice!=NULL;volume_matrice=forme_multi_volume_matrice->get_suivant_mg_volume(it_volume))
286 {
287 volume_inclusion+=OT_GEOMETRIE::get_volume_intersection(mgvolume,volume_matrice);
288 }
289 if(volume_inclusion>m_volume_min) return true;
290 return false;
291 }
292 }
293
294 bool MSTRUCT_GENERATEUR::distance_acceptable_bord_ves(MG_VOLUME* mgvolume)
295 {
296 BOITE_3D boite_volume=OT_GEOMETRIE::get_boite_3D(mgvolume);
297 if(boite_volume.get_xmin()<(m_boite3d_ves.get_xmin()+m_distance_min)) return false;
298 if(boite_volume.get_ymin()<(m_boite3d_ves.get_ymin()+m_distance_min)) return false;
299 if(boite_volume.get_zmin()<(m_boite3d_ves.get_zmin()+m_distance_min)) return false;
300 if(boite_volume.get_xmax()>(m_boite3d_ves.get_xmax()-m_distance_min)) return false;
301 if(boite_volume.get_ymax()>(m_boite3d_ves.get_ymax()-m_distance_min)) return false;
302 if(boite_volume.get_zmax()>(m_boite3d_ves.get_zmax()-m_distance_min)) return false;
303 return true;
304 }
305
306
307 bool MSTRUCT_GENERATEUR::configuration_acceptable(MG_CG_FORME_VOLUME* forme_volume_inclusion,MG_CG_FORME* forme_matrice)
308 {
309 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face;
310 TPL_MAP_ENTITE<MG_ARETE*> tpl_map_arete;
311 TPL_MAP_ENTITE<MG_SOMMET*> tpl_map_sommet;
312 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> tpl_map_ele_topo_matrice;
313 TPL_GRILLE<MG_ELEMENT_TOPOLOGIQUE*> tpl_grille_ele_topo;
314 tpl_grille_ele_topo.initialiser(m_boite3d_ves.get_xmin()-0.1,m_boite3d_ves.get_ymin()-0.1,m_boite3d_ves.get_zmin()-0.1,
315 m_boite3d_ves.get_xmax()+0.1,m_boite3d_ves.get_ymax()+0.1,m_boite3d_ves.get_zmax()+0.1,
316 m_nb_pas_grille,m_nb_pas_grille,m_nb_pas_grille);
317 if(OT_GEOMETRIE::get_volume(forme_volume_inclusion->get_mg_volume())<m_volume_min) return FAIL;
318 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_inclusion->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
319 if(forme_matrice!=NULL)
320 {
321 if(forme_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::VOLUME)
322 {
323 MG_CG_FORME_VOLUME* forme_volume_matrice=(MG_CG_FORME_VOLUME*)forme_matrice;
324 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_matrice->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
325 }
326 else if(forme_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::MULTI_VOLUME)
327 {
328 MG_CG_FORME_MULTI_VOLUME* forme_multi_volume_matrice=(MG_CG_FORME_MULTI_VOLUME*)forme_matrice;
329 std::map<long,MG_VOLUME*>::iterator it_volume;
330 for(MG_VOLUME* volume=forme_multi_volume_matrice->get_premier_mg_volume(it_volume);volume!=NULL;volume=forme_multi_volume_matrice->get_suivant_mg_volume(it_volume))
331 {
332 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(volume,tpl_map_sommet,tpl_map_arete,tpl_map_face);
333 }
334 }
335 }
336 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face;
337 for(MG_FACE* face=tpl_map_face.get_premier(it_face);face!=NULL;face=tpl_map_face.get_suivant(it_face))
338 {
339 if(OT_GEOMETRIE::get_aire(face)<m_aire_min) return FAIL;
340 tpl_map_ele_topo_matrice.ajouter(face);
341 tpl_grille_ele_topo.inserer(face);
342 }
343 tpl_map_face.vide();
344 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it_arete;
345 for(MG_ARETE* arete=tpl_map_arete.get_premier(it_arete);arete!=NULL;arete=tpl_map_arete.get_suivant(it_arete))
346 {
347 if(OT_GEOMETRIE::get_longueur(arete)<m_longueur_min) return FAIL;
348 if(!angle_entre_face_acceptable(arete)) return FAIL;
349 tpl_map_ele_topo_matrice.ajouter(arete);
350 tpl_grille_ele_topo.inserer(arete);
351 }
352 tpl_map_arete.vide();
353 TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it_sommet;
354 for(MG_SOMMET* sommet=tpl_map_sommet.get_premier(it_sommet);sommet!=NULL;sommet=tpl_map_sommet.get_suivant(it_sommet))
355 {
356 tpl_map_ele_topo_matrice.ajouter(sommet);
357 tpl_grille_ele_topo.inserer(sommet);
358 }
359 tpl_map_sommet.vide();
360
361 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_inclusion->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
362 std::stack<MG_ELEMENT_TOPOLOGIQUE*> stack_ele_topo;
363 for(MG_FACE* face=tpl_map_face.get_premier(it_face);face!=NULL;face=tpl_map_face.get_suivant(it_face))
364 {
365 if(OT_GEOMETRIE::get_aire(face)<m_aire_min) return FAIL;
366 tpl_grille_ele_topo.inserer(face);
367 stack_ele_topo.push(face);
368 }
369 for(MG_ARETE* arete=tpl_map_arete.get_premier(it_arete);arete!=NULL;arete=tpl_map_arete.get_suivant(it_arete))
370 {
371 if(OT_GEOMETRIE::get_longueur(arete)<m_longueur_min) return FAIL;
372 if(!angle_entre_face_acceptable(arete)) return FAIL;
373
374 tpl_grille_ele_topo.inserer(arete);
375 stack_ele_topo.push(arete);
376
377 }
378 for(MG_SOMMET* sommet=tpl_map_sommet.get_premier(it_sommet);sommet!=NULL;sommet=tpl_map_sommet.get_suivant(it_sommet))
379 {
380 tpl_grille_ele_topo.inserer(sommet);
381 stack_ele_topo.push(sommet);
382 }
383 while(!stack_ele_topo.empty())
384 {
385 MG_ELEMENT_TOPOLOGIQUE* ele_topo=stack_ele_topo.top(); stack_ele_topo.pop();
386 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> tpl_map_topo_trouve;
387 BOITE_3D boite_recherche(ele_topo->get_boite_3D().get_xmin()-m_distance_min,
388 ele_topo->get_boite_3D().get_ymin()-m_distance_min,
389 ele_topo->get_boite_3D().get_zmin()-m_distance_min,
390 ele_topo->get_boite_3D().get_xmax()+m_distance_min,
391 ele_topo->get_boite_3D().get_ymax()+m_distance_min,
392 ele_topo->get_boite_3D().get_zmax()+m_distance_min);
393 tpl_grille_ele_topo.rechercher(boite_recherche,tpl_map_topo_trouve);
394 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*>::ITERATEUR it_trouve;
395 for(MG_ELEMENT_TOPOLOGIQUE* ele_top_trouve=tpl_map_topo_trouve.get_premier(it_trouve);ele_top_trouve!=NULL;ele_top_trouve=tpl_map_topo_trouve.get_suivant(it_trouve))
396 {
397 if(ele_topo==ele_top_trouve) continue;
398 if(OT_GEOMETRIE::get_lien_topologique(ele_topo,ele_top_trouve)==OT_GEOMETRIE::TYPE_LIEN_TOPOLOGIQUE::AUCUN)
399 {
400 double distance;
401 if(OT_GEOMETRIE::get_distance_min_mg_eletopo_mg_eletopo(ele_topo,ele_top_trouve,distance)==FAIL) return FAIL;
402 if(distance<m_distance_min) return FAIL;
403 }
404 }
405 tpl_grille_ele_topo.supprimer(ele_topo);
406 }
407 return OK;
408 }
409
410
411
412 void MSTRUCT_GENERATEUR::echec_insertion_inclusion(std::vector< MG_CG_FORME* >& vector_forme, std::vector< MG_CG_OPERATEUR* >& vector_operateur)
413 {
414 std::vector<MG_CG_FORME*>::iterator it_forme;
415 for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++) m_mgcg_modele->supprimer_mgcg_formeid((*it_forme)->get_id());
416 std::vector<MG_CG_OPERATEUR*>::iterator it_operateur;
417 for(it_operateur=vector_operateur.begin();it_operateur!=vector_operateur.end();it_operateur++) m_mgcg_modele->supprimer_mgcg_operateurid((*it_operateur)->get_id());
418 }
419
420 int MSTRUCT_GENERATEUR::faces_correspondantes(MG_VOLUME* volume1, MG_VOLUME* volume2,double decallage,int nb_pas,double precision)
421 {
422 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face_volume1;
423 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face_volume2;
424 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume1,tpl_map_face_volume1);
425 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume2,tpl_map_face_volume2);
426 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face1;
427 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face2;
428 while(tpl_map_face_volume1.get_nb()>0 && tpl_map_face_volume2.get_nb()>0)
429 {
430 bool trouve=false;
431 MG_FACE* face1=tpl_map_face_volume1.get_premier(it_face1);
432 MG_FACE* face2=tpl_map_face_volume2.get_premier(it_face2);
433 while(trouve==false && face2!=NULL)
434 {
435 double distance_moyenne;
436 double ecart_type_distance;
437 if(OT_GEOMETRIE::declage_mg_face_mg_face(face1,face2,distance_moyenne,ecart_type_distance,nb_pas,precision)!=FAIL)
438 {
439 if(OPERATEUR::egal(distance_moyenne,decallage,precision) && ecart_type_distance<precision)
440 {
441 trouve=true;
442 tpl_map_face_volume1.supprimer(face1);
443 tpl_map_face_volume2.supprimer(face2);
444 }
445 else if(OPERATEUR::egal(distance_moyenne,0.0,precision) && ecart_type_distance<precision)
446 {
447 trouve=true;
448 tpl_map_face_volume1.supprimer(face1);
449 tpl_map_face_volume2.supprimer(face2);
450 }
451 }
452 face2=tpl_map_face_volume2.get_suivant(it_face2);
453 }
454 if(trouve==false) return FAIL;
455 }
456 return OK;
457 }
458
459
460 bool MSTRUCT_GENERATEUR::insertion_inclusion(MG_CG_FORME* forme_inclusion,
461 double fraction_volumique_cible,
462 double eps_fra_vol,
463 double &fraction_volumique_actuelle,
464 std::vector<MG_CG_FORME*> &vector_inclusion_genere,
465 int &position_relative,
466 std::vector< double > *vector_epaisseur_couche,
467 bool porosite)
468 {
469
470 MG_CG_FORME_VOLUME* boite_frac_vol=MG_CG::creer_MG_CG_FORME_VOLUME_BOITE(m_mgcg_modele,
471 m_boite3d_ves.get_xmin(),m_boite3d_ves.get_ymin(),m_boite3d_ves.get_zmin(),
472 m_boite3d_ves.get_xmax(),m_boite3d_ves.get_ymax(),m_boite3d_ves.get_zmax());
473 boite_frac_vol->construire();
474 double volume_particule;
475 MG_CG_FORME* matrice=m_matrice;
476 std::vector<MG_CG_FORME*> vector_forme_genere;
477 std::vector<MG_CG_OPERATEUR*> vector_operateur_genere;
478 vector_forme_genere.push_back(forme_inclusion);
479 vector_forme_genere.push_back(boite_frac_vol);
480 if(forme_inclusion->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
481 {
482 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
483 return FAIL;
484 }
485 MG_CG_FORME_VOLUME* forme_volume_inclusion = (MG_CG_FORME_VOLUME*)forme_inclusion;
486 MG_CG_FORME_VOLUME* forme_volume_verif_grille=NULL;
487 bool multicouche=false;
488 if(vector_epaisseur_couche!=NULL) multicouche=true;
489 if(multicouche)
490 {
491 // Creation de l'enveloppe externe
492 double decallage_max=0;
493 std::vector<double>::iterator it_epaisseur;
494 for(it_epaisseur=vector_epaisseur_couche->begin();it_epaisseur!=vector_epaisseur_couche->end();it_epaisseur++) decallage_max+=*it_epaisseur;
495 MG_CG_OP_TRANSF_DECALLAGE* op_decallage_couche_externe=MG_CG::creer_MG_CG_OP_TRANSF_DECALLAGE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::DECALLAGE,forme_volume_inclusion);
496 vector_operateur_genere.push_back(op_decallage_couche_externe);
497 op_decallage_couche_externe->change_decallage(decallage_max);
498 if(op_decallage_couche_externe->construire()==FAIL)
499 {
500 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
501 return FAIL;
502 }
503 vector_forme_genere.push_back(op_decallage_couche_externe->get_mgcg_forme_sortie());
504 if(op_decallage_couche_externe->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
505 {
506 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
507 return FAIL;
508 }
509 MG_CG_FORME_VOLUME* forme_volume_couche_externe=(MG_CG_FORME_VOLUME*)op_decallage_couche_externe->get_mgcg_forme_sortie();
510 forme_volume_verif_grille=forme_volume_couche_externe;
511 MG_VOLUME* volume_inclusion=forme_volume_inclusion->get_mg_volume();
512 MG_VOLUME* volume_inclusion_couche_externe=forme_volume_couche_externe->get_mg_volume();
513 // Verification du positionnement
514 if(positionnement_acceptable(forme_volume_couche_externe->get_mg_volume())==FAIL)
515 {
516 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
517 return FAIL;
518 }
519 // Verification de la fraction volumique
520 volume_particule=OT_GEOMETRIE::get_volume_intersection(volume_inclusion_couche_externe,boite_frac_vol->get_mg_volume(),m_precision);
521 m_mgcg_modele->supprimer_mgcg_formeid(boite_frac_vol->get_id());
522 // volume_particule=OT_GEOMETRIE::get_volume(volume_inclusion_couche_externe,m_precision);
523 if((volume_particule+fraction_volumique_actuelle)>fraction_volumique_cible+eps_fra_vol)
524 {
525 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
526 return FAIL;
527 }
528 // Verification des plans de coupe (coeur VS enveloppe)
529 bool plan_x0yz_inc;bool plan_x1yz_inc;bool plan_xy0z_inc;bool plan_xy1z_inc;bool plan_xyz0_inc;bool plan_xyz1_inc;
530 bool plan_x0yz_ext;bool plan_x1yz_ext;bool plan_xy0z_ext;bool plan_xy1z_ext;bool plan_xyz0_ext;bool plan_xyz1_ext;
531 int position_relative_inc=position_relative_inclusion_ves(volume_inclusion,plan_x0yz_inc,plan_x1yz_inc,plan_xy0z_inc,plan_xy1z_inc,plan_xyz0_inc,plan_xyz1_inc);
532 int position_relative_ext=position_relative_inclusion_ves(volume_inclusion_couche_externe,plan_x0yz_ext,plan_x1yz_ext,plan_xy0z_ext,plan_xy1z_ext,plan_xyz0_ext,plan_xyz1_ext);
533 if(position_relative_inc!=position_relative_ext || position_relative_ext==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
534 {
535 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
536 return FAIL;
537 }
538 if(!m_intersection_bords_ves && position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
539 {
540 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
541 return FAIL;
542 }
543 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
544 {
545 bool ok_plan=false;
546 if(plan_x0yz_inc==plan_x0yz_ext)
547 if(plan_x1yz_inc==plan_x1yz_ext)
548 if(plan_xy0z_inc==plan_xy0z_ext)
549 if(plan_xy1z_inc==plan_xy1z_ext)
550 if(plan_xyz0_inc==plan_xyz0_ext)
551 if(plan_xyz1_inc==plan_xyz1_ext) ok_plan=true;
552 if(!ok_plan)
553 {
554 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
555 return FAIL;
556 }
557 }
558 // Creation de l'intersection couche externe / matrice
559 MG_CG_OP_BOOL_INTERSECTION* op_inter_ext=MG_CG::creer_MG_CG_OP_BOOL_INTERSECTION(m_mgcg_modele,MAGIC::SEMANTIQUECSG::INTERSECTION,forme_volume_couche_externe,matrice);
560 vector_operateur_genere.push_back(op_inter_ext);
561 if(op_inter_ext->construire()==FAIL)
562 {
563 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
564 return FAIL;
565 }
566 vector_forme_genere.push_back(op_inter_ext->get_mgcg_forme_sortie());
567 if(op_inter_ext->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
568 {
569 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
570 return FAIL;
571 }
572 MG_CG_FORME_VOLUME* couche_externe_inter = (MG_CG_FORME_VOLUME*)op_inter_ext->get_mgcg_forme_sortie();
573 // Fragmentation de l'inclusion / matrice
574 MG_CG_OP_INCLUSION_MATRICE* op_inc_matrice_ext=MG_CG::creer_MG_CG_OP_INCLUSION_MATRICE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::FRAGMENT,couche_externe_inter,matrice);
575 vector_operateur_genere.push_back(op_inc_matrice_ext);
576 if(op_inc_matrice_ext->construire()==FAIL)
577 {
578 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
579 return FAIL;
580 }
581 vector_forme_genere.push_back(op_inc_matrice_ext->get_mgcg_forme_matrice_sortie());
582 vector_forme_genere.push_back(op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie());
583 if(op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
584 {
585 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
586 return FAIL;
587 }
588 matrice=op_inc_matrice_ext->get_mgcg_forme_matrice_sortie();
589 MG_CG_FORME_VOLUME* couche_externe_matrice=(MG_CG_FORME_VOLUME*)op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie();
590 if(configuration_acceptable(couche_externe_matrice,matrice)==FAIL)
591 {
592 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
593 return FAIL;
594 }
595 // OK POUR GENERER
596 MG_CG_FORME_VOLUME* matrice_couche_partielle;
597 if(porosite)
598 {
599 MG_CG_OP_BOOL_DIFFERENCE* op_diff_porosite=MG_CG::creer_MG_CG_OP_BOOL_DIFFERENCE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::SOUSTRACTION,couche_externe_matrice,forme_volume_inclusion);
600 vector_operateur_genere.push_back(op_diff_porosite);
601 if(op_diff_porosite->construire()==FAIL)
602 {
603 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
604 return FAIL;
605 }
606 vector_forme_genere.push_back(op_diff_porosite->get_mgcg_forme_sortie());
607 if(op_diff_porosite->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
608 {
609 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
610 return FAIL;
611 }
612 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_diff_porosite->get_mgcg_forme_sortie();
613 }
614 else
615 {
616 MG_CG_OP_BOOL_INTERSECTION* op_inter_couche=MG_CG::creer_MG_CG_OP_BOOL_INTERSECTION(m_mgcg_modele,MAGIC::SEMANTIQUECSG::INTERSECTION,forme_volume_inclusion,couche_externe_matrice);
617 vector_operateur_genere.push_back(op_inter_couche);
618 if(op_inter_couche->construire()==FAIL)
619 {
620 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
621 return FAIL;
622 }
623 vector_forme_genere.push_back(op_inter_couche->get_mgcg_forme_sortie());
624 if(op_inter_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
625 {
626 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
627 return FAIL;
628 }
629 MG_CG_OP_INCLUSION_MATRICE* op_inc_matrice_coeur=MG_CG::creer_MG_CG_OP_INCLUSION_MATRICE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::FRAGMENT,op_inter_couche->get_mgcg_forme_sortie(),couche_externe_matrice);
630 vector_operateur_genere.push_back(op_inc_matrice_coeur);
631 if(op_inc_matrice_coeur->construire()==FAIL)
632 {
633 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
634 return FAIL;
635 }
636 vector_forme_genere.push_back(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie());
637 vector_forme_genere.push_back(op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie());
638 if(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME ||
639 op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
640 {
641 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
642 return FAIL;
643 }
644
645 MG_CG_FORME_VOLUME* inclusion_coeur=(MG_CG_FORME_VOLUME*)op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie();
646 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie();
647 if(configuration_acceptable(inclusion_coeur,NULL)==FAIL)
648 {
649 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
650 return FAIL;
651 }
652 // Verification des faces correspondantes
653 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
654 if(faces_correspondantes(inclusion_coeur->get_mg_volume(),couche_externe_matrice->get_mg_volume(),decallage_max,m_nb_pas_echantillonnage,m_precision)==FAIL)
655 {
656 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
657 return FAIL;
658 }
659 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie(),(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
660 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie(),(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
661 vector_inclusion_genere.push_back(inclusion_coeur);
662 }
663 double decallage=0;
664 double epaisseur;
665 for(it_epaisseur=vector_epaisseur_couche->begin();it_epaisseur!=vector_epaisseur_couche->end()-1;it_epaisseur++)
666 {
667 epaisseur=*it_epaisseur;
668 decallage+=*it_epaisseur;
669 MG_CG_OP_TRANSF_DECALLAGE* op_decallage_couche=MG_CG::creer_MG_CG_OP_TRANSF_DECALLAGE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::DECALLAGE,forme_volume_inclusion);
670 vector_operateur_genere.push_back(op_decallage_couche);
671 op_decallage_couche->change_decallage(decallage);
672 if(op_decallage_couche->construire()==FAIL)
673 {
674 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
675 return FAIL;
676 }
677 vector_forme_genere.push_back(op_decallage_couche->get_mgcg_forme_sortie());
678 if(op_decallage_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
679 {
680 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
681 return FAIL;
682 }
683 MG_CG_OP_BOOL_INTERSECTION* op_inter_couche=MG_CG::creer_MG_CG_OP_BOOL_INTERSECTION(m_mgcg_modele,MAGIC::SEMANTIQUECSG::INTERSECTION,op_decallage_couche->get_mgcg_forme_sortie(),matrice_couche_partielle);
684 vector_operateur_genere.push_back(op_inter_couche);
685 if(op_inter_couche->construire()==FAIL)
686 {
687 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
688 return FAIL;
689 }
690 vector_forme_genere.push_back(op_inter_couche->get_mgcg_forme_sortie());
691 if(op_inter_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
692 {
693 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
694 return FAIL;
695 }
696 MG_CG_OP_INCLUSION_MATRICE* op_inc_matrice_couche=MG_CG::creer_MG_CG_OP_INCLUSION_MATRICE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::FRAGMENT,op_inter_couche->get_mgcg_forme_sortie(),matrice_couche_partielle);
697 vector_operateur_genere.push_back(op_inc_matrice_couche);
698 if(op_inc_matrice_couche->construire()==FAIL)
699 {
700 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
701 return FAIL;
702 }
703 vector_forme_genere.push_back(op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie());
704 vector_forme_genere.push_back(op_inc_matrice_couche->get_mgcg_forme_matrice_sortie());
705 if(op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME ||
706 op_inc_matrice_couche->get_mgcg_forme_matrice_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
707 {
708 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
709 return FAIL;
710 }
711 MG_CG_FORME_VOLUME* inclusion_couche = (MG_CG_FORME_VOLUME*)op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie();
712 vector_inclusion_genere.push_back(inclusion_couche);
713 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(inclusion_couche,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
714 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(inclusion_couche,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
715 MG_CG::creer_MG_CG_INFO_DOUBLE(inclusion_couche,(char*)"EPAISSEUR",epaisseur);
716 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_inc_matrice_couche->get_mgcg_forme_matrice_sortie();
717 configurer_volume_mince(inclusion_couche->get_mg_volume(),epaisseur);
718 }
719 epaisseur=*it_epaisseur;
720 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(matrice_couche_partielle,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
721 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(matrice_couche_partielle,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
722 MG_CG::creer_MG_CG_INFO_DOUBLE(matrice_couche_partielle,(char*)"EPAISSEUR",epaisseur);
723 vector_inclusion_genere.push_back(matrice_couche_partielle);
724 configurer_volume_mince(matrice_couche_partielle->get_mg_volume(),epaisseur);
725 position_relative=position_relative_ext;
726 }
727 else
728 {
729 // Verification du positionnement
730 if(positionnement_acceptable(forme_volume_inclusion->get_mg_volume())==FAIL)
731 {
732 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
733 return FAIL;
734 }
735 // Verification de la fraction volumique
736 volume_particule=OT_GEOMETRIE::get_volume_intersection(forme_volume_inclusion->get_mg_volume(),boite_frac_vol->get_mg_volume(),m_precision);
737 m_mgcg_modele->supprimer_mgcg_formeid(boite_frac_vol->get_id());
738 if((volume_particule+fraction_volumique_actuelle)>fraction_volumique_cible+eps_fra_vol)
739 {
740 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
741 return FAIL;
742 }
743 // Verification de la position relative
744 bool plan_x0yz;bool plan_x1yz;bool plan_xy0z;bool plan_xy1z;bool plan_xyz0;bool plan_xyz1;
745 position_relative=position_relative_inclusion_ves(forme_volume_inclusion->get_mg_volume(),plan_x0yz,plan_x1yz,plan_xy0z,plan_xy1z,plan_xyz0,plan_xyz1);
746 if(position_relative==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
747 {
748 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
749 return FAIL;
750 }
751 if(!m_intersection_bords_ves && position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
752 {
753 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
754 return FAIL;
755 }
756 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
757 {
758 MG_CG_OP_BOOL_INTERSECTION* op_inter=MG_CG::creer_MG_CG_OP_BOOL_INTERSECTION(m_mgcg_modele,MAGIC::SEMANTIQUECSG::INTERSECTION,forme_volume_inclusion,m_matrice);
759 vector_operateur_genere.push_back(op_inter);
760 if(op_inter->construire()==FAIL)
761 {
762 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
763 return FAIL;
764 }
765 vector_forme_genere.push_back(op_inter->get_mgcg_forme_sortie());
766 if(op_inter->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
767 {
768 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
769 return FAIL;
770 }
771 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inter->get_mgcg_forme_sortie();
772 }
773 MG_CG_OP_INCLUSION_MATRICE* op_inc_matrice=MG_CG::creer_MG_CG_OP_INCLUSION_MATRICE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::FRAGMENT,forme_volume_inclusion,m_matrice);
774 vector_operateur_genere.push_back(op_inc_matrice);
775 if(op_inc_matrice->construire()==FAIL)
776 {
777 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
778 return FAIL;
779 }
780 matrice=op_inc_matrice->get_mgcg_forme_matrice_sortie();
781 vector_forme_genere.push_back(matrice);
782 vector_forme_genere.push_back(op_inc_matrice->get_mgcg_forme_inclusion_sortie());
783 if(op_inc_matrice->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
784 {
785 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
786 return FAIL;
787 }
788 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inc_matrice->get_mgcg_forme_inclusion_sortie();
789 if(configuration_acceptable(forme_volume_inclusion,matrice)==FAIL)
790 {
791 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
792 return FAIL;
793 }
794 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
795 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
796 vector_inclusion_genere.push_back(forme_volume_inclusion);
797 forme_volume_verif_grille=forme_volume_inclusion;
798 }
799 fraction_volumique_actuelle+=volume_particule;
800 m_grille_volume_inclusion.inserer(forme_volume_verif_grille->get_mg_volume());
801 m_matrice=matrice;
802 return OK;
803 }
804
805 bool MSTRUCT_GENERATEUR::insertion_inclusion(MG_CG_FORME* forme_inclusion,
806 double& fraction_volumique_actuelle,
807 std::vector< MG_CG_FORME* >& vector_inclusion_genere,
808 int& position_relative)
809 {
810 double volume_particule;
811 MG_CG_FORME* matrice=m_matrice;
812 std::vector<MG_CG_FORME*> vector_forme_genere;
813 std::vector<MG_CG_OPERATEUR*> vector_operateur_genere;
814 vector_forme_genere.push_back(forme_inclusion);
815 if(forme_inclusion->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
816 {
817 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
818 return FAIL;
819 }
820 MG_CG_FORME_VOLUME* forme_volume_inclusion = (MG_CG_FORME_VOLUME*)forme_inclusion;
821 MG_CG_FORME_VOLUME* forme_volume_verif_grille=NULL;
822 // Verification du positionnement
823 if(positionnement_acceptable(forme_volume_inclusion->get_mg_volume())==FAIL)
824 {
825 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
826 return FAIL;
827 }
828 // Verification de la position relative
829 bool plan_x0yz;bool plan_x1yz;bool plan_xy0z;bool plan_xy1z;bool plan_xyz0;bool plan_xyz1;
830 position_relative=position_relative_inclusion_ves(forme_volume_inclusion->get_mg_volume(),plan_x0yz,plan_x1yz,plan_xy0z,plan_xy1z,plan_xyz0,plan_xyz1);
831 if(position_relative==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
832 {
833 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
834 return FAIL;
835 }
836 if(!m_intersection_bords_ves && position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
837 {
838 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
839 return FAIL;
840 }
841 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
842 {
843 MG_CG_OP_BOOL_INTERSECTION* op_inter=MG_CG::creer_MG_CG_OP_BOOL_INTERSECTION(m_mgcg_modele,MAGIC::SEMANTIQUECSG::INTERSECTION,forme_volume_inclusion,m_matrice);
844 vector_operateur_genere.push_back(op_inter);
845 if(op_inter->construire()==FAIL)
846 {
847 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
848 return FAIL;
849 }
850 vector_forme_genere.push_back(op_inter->get_mgcg_forme_sortie());
851 if(op_inter->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
852 {
853 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
854 return FAIL;
855 }
856 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inter->get_mgcg_forme_sortie();
857 }
858 MG_CG_OP_INCLUSION_MATRICE* op_inc_matrice=MG_CG::creer_MG_CG_OP_INCLUSION_MATRICE(m_mgcg_modele,MAGIC::SEMANTIQUECSG::FRAGMENT,forme_volume_inclusion,m_matrice);
859 vector_operateur_genere.push_back(op_inc_matrice);
860 if(op_inc_matrice->construire()==FAIL)
861 {
862 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
863 return FAIL;
864 }
865 matrice=op_inc_matrice->get_mgcg_forme_matrice_sortie();
866 vector_forme_genere.push_back(matrice);
867 vector_forme_genere.push_back(op_inc_matrice->get_mgcg_forme_inclusion_sortie());
868 if(op_inc_matrice->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
869 {
870 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
871 return FAIL;
872 }
873 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inc_matrice->get_mgcg_forme_inclusion_sortie();
874 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR)
875 {
876 if(distance_acceptable_bord_ves(forme_volume_inclusion->get_mg_volume())==FAIL)
877 {
878 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
879 return FAIL;
880 }
881 }
882 if(m_intersection_bords_ves)
883 if(configuration_acceptable(forme_volume_inclusion,matrice)==FAIL)
884 {
885 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
886 return FAIL;
887 }
888 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
889 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
890 vector_inclusion_genere.push_back(forme_volume_inclusion);
891 forme_volume_verif_grille=forme_volume_inclusion;
892 volume_particule=OT_GEOMETRIE::get_volume(forme_volume_inclusion->get_mg_volume());
893 fraction_volumique_actuelle+=volume_particule;
894 m_grille_volume_inclusion.inserer(forme_volume_verif_grille->get_mg_volume());
895 m_matrice=matrice;
896 return OK;
897 }
898
899
900 bool MSTRUCT_GENERATEUR::positionnement_acceptable(MG_VOLUME* inclusion)
901 {
902 TPL_MAP_ENTITE<MG_VOLUME*> map_volume_recherche;
903 BOITE_3D boite_recherche = inclusion->get_boite_3D();
904 boite_recherche.change_grosseur(1.1);
905 m_grille_volume_inclusion.rechercher(boite_recherche,map_volume_recherche);
906 TPL_MAP_ENTITE<MG_VOLUME*>::ITERATEUR it_volume;
907 MG_VOLUME* volume_recherche=map_volume_recherche.get_premier(it_volume);
908 double distance;
909 while(volume_recherche!=NULL)
910 {
911 if(OT_GEOMETRIE::get_distance_min_mg_volume_mg_volume(inclusion,volume_recherche,distance)==FAIL) return FAIL;
912 else
913 {
914 if(distance<=m_distance_min+m_precision) return FAIL;
915 else volume_recherche=map_volume_recherche.get_suivant(it_volume);
916 }
917 }
918 return OK;
919 }
920
921 bool MSTRUCT_GENERATEUR::lien_topologique_entre(MG_ELEMENT_TOPOLOGIQUE* mg_ele_topo1, MG_ELEMENT_TOPOLOGIQUE* mg_ele_topo2)
922 {
923 TPL_MAP_ENTITE<MG_SOMMET*> map_sommet_volume1;
924 OT_GEOMETRIE::get_map_mg_sommet_sous_jacent(mg_ele_topo1,map_sommet_volume1);
925 TPL_MAP_ENTITE<MG_SOMMET*> map_sommet_volume2;
926 OT_GEOMETRIE::get_map_mg_sommet_sous_jacent(mg_ele_topo2,map_sommet_volume2);
927 TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it_sommet;
928 for(MG_SOMMET* sommet=map_sommet_volume1.get_premier(it_sommet);sommet!=NULL;sommet=map_sommet_volume1.get_suivant(it_sommet))
929 {
930 if(map_sommet_volume2.existe(sommet)) return true;
931 }
932 return false;
933 }
934
935 void MSTRUCT_GENERATEUR::cree_vector_groupe_forme(std::string nom, std::vector< MG_CG_GROUPE_FORME* >& vector_groupe_forme, std::vector< double >* vector_epaisseur_couches)
936 {
937 if(vector_epaisseur_couches==NULL)
938 {
939 MG_CG_GROUPE_FORME* groupe_forme;
940 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom);
941 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
942 vector_groupe_forme.push_back(groupe_forme);
943 }
944 else
945 {
946 MG_CG_GROUPE_FORME* groupe_forme;
947 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom);
948 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
949 vector_groupe_forme.push_back(groupe_forme);
950 for(int i=0;i<vector_epaisseur_couches->size();i++)
951 {
952 char nom_couche[500];
953 sprintf(nom_couche,"%s_%i",nom.c_str(),i);
954 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom_couche);
955 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
956 vector_groupe_forme.push_back(groupe_forme);
957 }
958 }
959 }
960
961 int MSTRUCT_GENERATEUR::configurer_volume_mince(MG_CG_FORME* forme,double epaisseur)
962 {
963 if(forme->get_type_forme()==MG_CG_FORME::TYPE_FORME::VOLUME)
964 {
965 MG_VOLUME* volume = ((MG_CG_FORME_VOLUME*)forme)->get_mg_volume();
966 configurer_volume_mince(volume,epaisseur);
967 }
968 if(forme->get_type_forme()==MG_CG_FORME::TYPE_FORME::MULTI_VOLUME)
969 {
970 MG_CG_FORME_MULTI_VOLUME* forme_multi_volume = (MG_CG_FORME_MULTI_VOLUME*)forme;
971 std::map<long,MG_VOLUME*>::iterator it_volume;
972 for(MG_VOLUME* volume=forme_multi_volume->get_premier_mg_volume(it_volume);volume!=NULL;volume=forme_multi_volume->get_suivant_mg_volume(it_volume))
973 {
974 configurer_volume_mince(volume,epaisseur);
975 }
976 }
977 }
978
979 int MSTRUCT_GENERATEUR::configurer_volume_mince(MG_VOLUME* volume, double epaisseur)
980 {
981 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face;
982 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume,tpl_map_face);
983 if(tpl_map_face.get_nb()<2) return FAIL;
984 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face1;
985 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face2;
986 std::cout << "NB_FACE = " << tpl_map_face.get_nb() << std::endl;
987 while(tpl_map_face.get_nb()>=2)
988 {
989 bool trouve=false;
990 MG_FACE* face1=tpl_map_face.get_premier(it_face1);
991 it_face2=it_face1;
992 MG_FACE* face2=tpl_map_face.get_suivant(it_face2);
993 while(trouve==false && face1!=NULL && face2!=NULL)
994 {
995 double distance_moyenne;
996 double ecart_type_distance;
997 OT_GEOMETRIE::declage_mg_face_mg_face(face1,face2,distance_moyenne,ecart_type_distance,32);
998 std::cout << " Distance = " << distance_moyenne << " Std-dev = " << ecart_type_distance << " Epaisseur = " << epaisseur << std::endl;
999 if(OPERATEUR::egal(epaisseur,distance_moyenne,m_precision) && ecart_type_distance<m_precision)
1000 {
1001 std::cout << " Correspondance : " << face1->get_id() << " , " << face2->get_id() << std::endl;
1002 trouve=true;
1003 bool face1_base=false;
1004 bool face2_base=false;
1005 if(face1_base==true)
1006 {
1007 // std::cout << "Face1 base" << std::endl;
1008 volume->ajouter_face_correspondante(face1,face2);
1009 }
1010 else if(face2_base==true)
1011 {
1012 // std::cout << "Face2 base" << std::endl;
1013 volume->ajouter_face_correspondante(face2,face1);
1014 }
1015 else
1016 {
1017 double aire_face1 = OT_GEOMETRIE::get_aire(face1,m_precision);
1018 double aire_face2 = OT_GEOMETRIE::get_aire(face2,m_precision);
1019 if(aire_face1<aire_face2)
1020 {
1021 // std::cout << "Aire Face1 base" << std::endl;
1022 volume->ajouter_face_correspondante(face1,face2);
1023 }
1024 else
1025 {
1026 // std::cout << "Aire Face2 base" << std::endl;
1027 volume->ajouter_face_correspondante(face2,face1);
1028 }
1029 }
1030 }
1031 else face2=tpl_map_face.get_suivant(it_face2);
1032 }
1033 if(trouve)
1034 {
1035 tpl_map_face.supprimer(face1);
1036 tpl_map_face.supprimer(face2);
1037 }
1038 else tpl_map_face.supprimer(face1);
1039 }
1040 }
1041
1042
1043 void MSTRUCT_GENERATEUR::active_affichage(fonction_affiche* fonc)
1044 {
1045 fonc_affiche = fonc;
1046 affichageactif = 1;
1047 }
1048
1049 void MSTRUCT_GENERATEUR::affiche(char* message)
1050 {
1051 if(affichageactif==1) fonc_affiche(message);
1052 }