ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/microstructure/src/mstruct_generateur.cpp
Revision: 1075
Committed: Tue Aug 10 17:02:54 2021 UTC (4 years ago) by francois
File size: 47811 byte(s)
Log Message:
suppression de warning avec le dernier compilateur

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 return true;
293 }
294
295 bool MSTRUCT_GENERATEUR::distance_acceptable_bord_ves(MG_VOLUME* mgvolume)
296 {
297 BOITE_3D boite_volume=OT_GEOMETRIE::get_boite_3D(mgvolume);
298 if(boite_volume.get_xmin()<(m_boite3d_ves.get_xmin()+m_distance_min)) return false;
299 if(boite_volume.get_ymin()<(m_boite3d_ves.get_ymin()+m_distance_min)) return false;
300 if(boite_volume.get_zmin()<(m_boite3d_ves.get_zmin()+m_distance_min)) return false;
301 if(boite_volume.get_xmax()>(m_boite3d_ves.get_xmax()-m_distance_min)) return false;
302 if(boite_volume.get_ymax()>(m_boite3d_ves.get_ymax()-m_distance_min)) return false;
303 if(boite_volume.get_zmax()>(m_boite3d_ves.get_zmax()-m_distance_min)) return false;
304 return true;
305 }
306
307
308 bool MSTRUCT_GENERATEUR::configuration_acceptable(MG_CG_FORME_VOLUME* forme_volume_inclusion,MG_CG_FORME* forme_matrice)
309 {
310 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face;
311 TPL_MAP_ENTITE<MG_ARETE*> tpl_map_arete;
312 TPL_MAP_ENTITE<MG_SOMMET*> tpl_map_sommet;
313 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> tpl_map_ele_topo_matrice;
314 TPL_GRILLE<MG_ELEMENT_TOPOLOGIQUE*> tpl_grille_ele_topo;
315 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,
316 m_boite3d_ves.get_xmax()+0.1,m_boite3d_ves.get_ymax()+0.1,m_boite3d_ves.get_zmax()+0.1,
317 m_nb_pas_grille,m_nb_pas_grille,m_nb_pas_grille);
318 if(OT_GEOMETRIE::get_volume(forme_volume_inclusion->get_mg_volume())<m_volume_min) return FAIL;
319 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_inclusion->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
320 if(forme_matrice!=NULL)
321 {
322 if(forme_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::VOLUME)
323 {
324 MG_CG_FORME_VOLUME* forme_volume_matrice=(MG_CG_FORME_VOLUME*)forme_matrice;
325 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_matrice->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
326 }
327 else if(forme_matrice->get_type_forme()==MG_CG_FORME::TYPE_FORME::MULTI_VOLUME)
328 {
329 MG_CG_FORME_MULTI_VOLUME* forme_multi_volume_matrice=(MG_CG_FORME_MULTI_VOLUME*)forme_matrice;
330 std::map<long,MG_VOLUME*>::iterator it_volume;
331 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))
332 {
333 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(volume,tpl_map_sommet,tpl_map_arete,tpl_map_face);
334 }
335 }
336 }
337 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face;
338 for(MG_FACE* face=tpl_map_face.get_premier(it_face);face!=NULL;face=tpl_map_face.get_suivant(it_face))
339 {
340 if(OT_GEOMETRIE::get_aire(face)<m_aire_min) return FAIL;
341 tpl_map_ele_topo_matrice.ajouter(face);
342 tpl_grille_ele_topo.inserer(face);
343 }
344 tpl_map_face.vide();
345 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it_arete;
346 for(MG_ARETE* arete=tpl_map_arete.get_premier(it_arete);arete!=NULL;arete=tpl_map_arete.get_suivant(it_arete))
347 {
348 if(OT_GEOMETRIE::get_longueur(arete)<m_longueur_min) return FAIL;
349 if(!angle_entre_face_acceptable(arete)) return FAIL;
350 tpl_map_ele_topo_matrice.ajouter(arete);
351 tpl_grille_ele_topo.inserer(arete);
352 }
353 tpl_map_arete.vide();
354 TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it_sommet;
355 for(MG_SOMMET* sommet=tpl_map_sommet.get_premier(it_sommet);sommet!=NULL;sommet=tpl_map_sommet.get_suivant(it_sommet))
356 {
357 tpl_map_ele_topo_matrice.ajouter(sommet);
358 tpl_grille_ele_topo.inserer(sommet);
359 }
360 tpl_map_sommet.vide();
361
362 OT_GEOMETRIE::get_map_mg_ele_topo_sous_jacent(forme_volume_inclusion->get_mg_volume(),tpl_map_sommet,tpl_map_arete,tpl_map_face);
363 std::stack<MG_ELEMENT_TOPOLOGIQUE*> stack_ele_topo;
364 for(MG_FACE* face=tpl_map_face.get_premier(it_face);face!=NULL;face=tpl_map_face.get_suivant(it_face))
365 {
366 if(OT_GEOMETRIE::get_aire(face)<m_aire_min) return FAIL;
367 tpl_grille_ele_topo.inserer(face);
368 stack_ele_topo.push(face);
369 }
370 for(MG_ARETE* arete=tpl_map_arete.get_premier(it_arete);arete!=NULL;arete=tpl_map_arete.get_suivant(it_arete))
371 {
372 if(OT_GEOMETRIE::get_longueur(arete)<m_longueur_min) return FAIL;
373 if(!angle_entre_face_acceptable(arete)) return FAIL;
374
375 tpl_grille_ele_topo.inserer(arete);
376 stack_ele_topo.push(arete);
377
378 }
379 for(MG_SOMMET* sommet=tpl_map_sommet.get_premier(it_sommet);sommet!=NULL;sommet=tpl_map_sommet.get_suivant(it_sommet))
380 {
381 tpl_grille_ele_topo.inserer(sommet);
382 stack_ele_topo.push(sommet);
383 }
384 while(!stack_ele_topo.empty())
385 {
386 MG_ELEMENT_TOPOLOGIQUE* ele_topo=stack_ele_topo.top(); stack_ele_topo.pop();
387 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> tpl_map_topo_trouve;
388 BOITE_3D boite_recherche(ele_topo->get_boite_3D().get_xmin()-m_distance_min,
389 ele_topo->get_boite_3D().get_ymin()-m_distance_min,
390 ele_topo->get_boite_3D().get_zmin()-m_distance_min,
391 ele_topo->get_boite_3D().get_xmax()+m_distance_min,
392 ele_topo->get_boite_3D().get_ymax()+m_distance_min,
393 ele_topo->get_boite_3D().get_zmax()+m_distance_min);
394 tpl_grille_ele_topo.rechercher(boite_recherche,tpl_map_topo_trouve);
395 TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*>::ITERATEUR it_trouve;
396 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))
397 {
398 if(ele_topo==ele_top_trouve) continue;
399 if(OT_GEOMETRIE::get_lien_topologique(ele_topo,ele_top_trouve)==OT_GEOMETRIE::TYPE_LIEN_TOPOLOGIQUE::AUCUN)
400 {
401 double distance;
402 if(OT_GEOMETRIE::get_distance_min_mg_eletopo_mg_eletopo(ele_topo,ele_top_trouve,distance)==FAIL) return FAIL;
403 if(distance<m_distance_min) return FAIL;
404 }
405 }
406 tpl_grille_ele_topo.supprimer(ele_topo);
407 }
408 return OK;
409 }
410
411
412
413 void MSTRUCT_GENERATEUR::echec_insertion_inclusion(std::vector< MG_CG_FORME* >& vector_forme, std::vector< MG_CG_OPERATEUR* >& vector_operateur)
414 {
415 std::vector<MG_CG_FORME*>::iterator it_forme;
416 for(it_forme=vector_forme.begin();it_forme!=vector_forme.end();it_forme++) m_mgcg_modele->supprimer_mgcg_formeid((*it_forme)->get_id());
417 std::vector<MG_CG_OPERATEUR*>::iterator it_operateur;
418 for(it_operateur=vector_operateur.begin();it_operateur!=vector_operateur.end();it_operateur++) m_mgcg_modele->supprimer_mgcg_operateurid((*it_operateur)->get_id());
419 }
420
421 int MSTRUCT_GENERATEUR::faces_correspondantes(MG_VOLUME* volume1, MG_VOLUME* volume2,double decallage,int nb_pas,double precision)
422 {
423 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face_volume1;
424 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face_volume2;
425 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume1,tpl_map_face_volume1);
426 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume2,tpl_map_face_volume2);
427 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face1;
428 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face2;
429 while(tpl_map_face_volume1.get_nb()>0 && tpl_map_face_volume2.get_nb()>0)
430 {
431 bool trouve=false;
432 MG_FACE* face1=tpl_map_face_volume1.get_premier(it_face1);
433 MG_FACE* face2=tpl_map_face_volume2.get_premier(it_face2);
434 while(trouve==false && face2!=NULL)
435 {
436 double distance_moyenne;
437 double ecart_type_distance;
438 if(OT_GEOMETRIE::declage_mg_face_mg_face(face1,face2,distance_moyenne,ecart_type_distance,nb_pas,precision)!=FAIL)
439 {
440 if(OPERATEUR::egal(distance_moyenne,decallage,precision) && ecart_type_distance<precision)
441 {
442 trouve=true;
443 tpl_map_face_volume1.supprimer(face1);
444 tpl_map_face_volume2.supprimer(face2);
445 }
446 else if(OPERATEUR::egal(distance_moyenne,0.0,precision) && ecart_type_distance<precision)
447 {
448 trouve=true;
449 tpl_map_face_volume1.supprimer(face1);
450 tpl_map_face_volume2.supprimer(face2);
451 }
452 }
453 face2=tpl_map_face_volume2.get_suivant(it_face2);
454 }
455 if(trouve==false) return FAIL;
456 }
457 return OK;
458 }
459
460
461 bool MSTRUCT_GENERATEUR::insertion_inclusion(MG_CG_FORME* forme_inclusion,
462 double fraction_volumique_cible,
463 double eps_fra_vol,
464 double &fraction_volumique_actuelle,
465 std::vector<MG_CG_FORME*> &vector_inclusion_genere,
466 int &position_relative,
467 std::vector< double > *vector_epaisseur_couche,
468 bool porosite)
469 {
470
471 MG_CG_FORME_VOLUME* boite_frac_vol=MG_CG::creer_MG_CG_FORME_VOLUME_BOITE(m_mgcg_modele,
472 m_boite3d_ves.get_xmin(),m_boite3d_ves.get_ymin(),m_boite3d_ves.get_zmin(),
473 m_boite3d_ves.get_xmax(),m_boite3d_ves.get_ymax(),m_boite3d_ves.get_zmax());
474 boite_frac_vol->construire();
475 double volume_particule;
476 MG_CG_FORME* matrice=m_matrice;
477 std::vector<MG_CG_FORME*> vector_forme_genere;
478 std::vector<MG_CG_OPERATEUR*> vector_operateur_genere;
479 vector_forme_genere.push_back(forme_inclusion);
480 vector_forme_genere.push_back(boite_frac_vol);
481 if(forme_inclusion->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
482 {
483 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
484 return FAIL;
485 }
486 MG_CG_FORME_VOLUME* forme_volume_inclusion = (MG_CG_FORME_VOLUME*)forme_inclusion;
487 MG_CG_FORME_VOLUME* forme_volume_verif_grille=NULL;
488 bool multicouche=false;
489 if(vector_epaisseur_couche!=NULL) multicouche=true;
490 if(multicouche)
491 {
492 // Creation de l'enveloppe externe
493 double decallage_max=0;
494 std::vector<double>::iterator it_epaisseur;
495 for(it_epaisseur=vector_epaisseur_couche->begin();it_epaisseur!=vector_epaisseur_couche->end();it_epaisseur++) decallage_max+=*it_epaisseur;
496 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);
497 vector_operateur_genere.push_back(op_decallage_couche_externe);
498 op_decallage_couche_externe->change_decallage(decallage_max);
499 if(op_decallage_couche_externe->construire()==FAIL)
500 {
501 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
502 return FAIL;
503 }
504 vector_forme_genere.push_back(op_decallage_couche_externe->get_mgcg_forme_sortie());
505 if(op_decallage_couche_externe->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
506 {
507 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
508 return FAIL;
509 }
510 MG_CG_FORME_VOLUME* forme_volume_couche_externe=(MG_CG_FORME_VOLUME*)op_decallage_couche_externe->get_mgcg_forme_sortie();
511 forme_volume_verif_grille=forme_volume_couche_externe;
512 MG_VOLUME* volume_inclusion=forme_volume_inclusion->get_mg_volume();
513 MG_VOLUME* volume_inclusion_couche_externe=forme_volume_couche_externe->get_mg_volume();
514 // Verification du positionnement
515 if(positionnement_acceptable(forme_volume_couche_externe->get_mg_volume())==FAIL)
516 {
517 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
518 return FAIL;
519 }
520 // Verification de la fraction volumique
521 volume_particule=OT_GEOMETRIE::get_volume_intersection(volume_inclusion_couche_externe,boite_frac_vol->get_mg_volume(),m_precision);
522 m_mgcg_modele->supprimer_mgcg_formeid(boite_frac_vol->get_id());
523 // volume_particule=OT_GEOMETRIE::get_volume(volume_inclusion_couche_externe,m_precision);
524 if((volume_particule+fraction_volumique_actuelle)>fraction_volumique_cible+eps_fra_vol)
525 {
526 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
527 return FAIL;
528 }
529 // Verification des plans de coupe (coeur VS enveloppe)
530 bool plan_x0yz_inc;bool plan_x1yz_inc;bool plan_xy0z_inc;bool plan_xy1z_inc;bool plan_xyz0_inc;bool plan_xyz1_inc;
531 bool plan_x0yz_ext;bool plan_x1yz_ext;bool plan_xy0z_ext;bool plan_xy1z_ext;bool plan_xyz0_ext;bool plan_xyz1_ext;
532 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);
533 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);
534 if(position_relative_inc!=position_relative_ext || position_relative_ext==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
535 {
536 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
537 return FAIL;
538 }
539 if(!m_intersection_bords_ves && position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
540 {
541 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
542 return FAIL;
543 }
544 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
545 {
546 bool ok_plan=false;
547 if(plan_x0yz_inc==plan_x0yz_ext)
548 if(plan_x1yz_inc==plan_x1yz_ext)
549 if(plan_xy0z_inc==plan_xy0z_ext)
550 if(plan_xy1z_inc==plan_xy1z_ext)
551 if(plan_xyz0_inc==plan_xyz0_ext)
552 if(plan_xyz1_inc==plan_xyz1_ext) ok_plan=true;
553 if(!ok_plan)
554 {
555 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
556 return FAIL;
557 }
558 }
559 // Creation de l'intersection couche externe / matrice
560 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);
561 vector_operateur_genere.push_back(op_inter_ext);
562 if(op_inter_ext->construire()==FAIL)
563 {
564 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
565 return FAIL;
566 }
567 vector_forme_genere.push_back(op_inter_ext->get_mgcg_forme_sortie());
568 if(op_inter_ext->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
569 {
570 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
571 return FAIL;
572 }
573 MG_CG_FORME_VOLUME* couche_externe_inter = (MG_CG_FORME_VOLUME*)op_inter_ext->get_mgcg_forme_sortie();
574 // Fragmentation de l'inclusion / matrice
575 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);
576 vector_operateur_genere.push_back(op_inc_matrice_ext);
577 if(op_inc_matrice_ext->construire()==FAIL)
578 {
579 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
580 return FAIL;
581 }
582 vector_forme_genere.push_back(op_inc_matrice_ext->get_mgcg_forme_matrice_sortie());
583 vector_forme_genere.push_back(op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie());
584 if(op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
585 {
586 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
587 return FAIL;
588 }
589 matrice=op_inc_matrice_ext->get_mgcg_forme_matrice_sortie();
590 MG_CG_FORME_VOLUME* couche_externe_matrice=(MG_CG_FORME_VOLUME*)op_inc_matrice_ext->get_mgcg_forme_inclusion_sortie();
591 if(configuration_acceptable(couche_externe_matrice,matrice)==FAIL)
592 {
593 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
594 return FAIL;
595 }
596 // OK POUR GENERER
597 MG_CG_FORME_VOLUME* matrice_couche_partielle;
598 if(porosite)
599 {
600 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);
601 vector_operateur_genere.push_back(op_diff_porosite);
602 if(op_diff_porosite->construire()==FAIL)
603 {
604 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
605 return FAIL;
606 }
607 vector_forme_genere.push_back(op_diff_porosite->get_mgcg_forme_sortie());
608 if(op_diff_porosite->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
609 {
610 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
611 return FAIL;
612 }
613 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_diff_porosite->get_mgcg_forme_sortie();
614 }
615 else
616 {
617 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);
618 vector_operateur_genere.push_back(op_inter_couche);
619 if(op_inter_couche->construire()==FAIL)
620 {
621 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
622 return FAIL;
623 }
624 vector_forme_genere.push_back(op_inter_couche->get_mgcg_forme_sortie());
625 if(op_inter_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
626 {
627 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
628 return FAIL;
629 }
630 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);
631 vector_operateur_genere.push_back(op_inc_matrice_coeur);
632 if(op_inc_matrice_coeur->construire()==FAIL)
633 {
634 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
635 return FAIL;
636 }
637 vector_forme_genere.push_back(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie());
638 vector_forme_genere.push_back(op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie());
639 if(op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME ||
640 op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
641 {
642 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
643 return FAIL;
644 }
645
646 MG_CG_FORME_VOLUME* inclusion_coeur=(MG_CG_FORME_VOLUME*)op_inc_matrice_coeur->get_mgcg_forme_inclusion_sortie();
647 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_inc_matrice_coeur->get_mgcg_forme_matrice_sortie();
648 if(configuration_acceptable(inclusion_coeur,NULL)==FAIL)
649 {
650 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
651 return FAIL;
652 }
653 // Verification des faces correspondantes
654 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD)
655 if(faces_correspondantes(inclusion_coeur->get_mg_volume(),couche_externe_matrice->get_mg_volume(),decallage_max,m_nb_pas_echantillonnage,m_precision)==FAIL)
656 {
657 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
658 return FAIL;
659 }
660 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");
661 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");
662 vector_inclusion_genere.push_back(inclusion_coeur);
663 }
664 double decallage=0;
665 double epaisseur;
666 for(it_epaisseur=vector_epaisseur_couche->begin();it_epaisseur!=vector_epaisseur_couche->end()-1;it_epaisseur++)
667 {
668 epaisseur=*it_epaisseur;
669 decallage+=*it_epaisseur;
670 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);
671 vector_operateur_genere.push_back(op_decallage_couche);
672 op_decallage_couche->change_decallage(decallage);
673 if(op_decallage_couche->construire()==FAIL)
674 {
675 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
676 return FAIL;
677 }
678 vector_forme_genere.push_back(op_decallage_couche->get_mgcg_forme_sortie());
679 if(op_decallage_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
680 {
681 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
682 return FAIL;
683 }
684 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);
685 vector_operateur_genere.push_back(op_inter_couche);
686 if(op_inter_couche->construire()==FAIL)
687 {
688 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
689 return FAIL;
690 }
691 vector_forme_genere.push_back(op_inter_couche->get_mgcg_forme_sortie());
692 if(op_inter_couche->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
693 {
694 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
695 return FAIL;
696 }
697 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);
698 vector_operateur_genere.push_back(op_inc_matrice_couche);
699 if(op_inc_matrice_couche->construire()==FAIL)
700 {
701 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
702 return FAIL;
703 }
704 vector_forme_genere.push_back(op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie());
705 vector_forme_genere.push_back(op_inc_matrice_couche->get_mgcg_forme_matrice_sortie());
706 if(op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME ||
707 op_inc_matrice_couche->get_mgcg_forme_matrice_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
708 {
709 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
710 return FAIL;
711 }
712 MG_CG_FORME_VOLUME* inclusion_couche = (MG_CG_FORME_VOLUME*)op_inc_matrice_couche->get_mgcg_forme_inclusion_sortie();
713 vector_inclusion_genere.push_back(inclusion_couche);
714 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(inclusion_couche,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
715 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(inclusion_couche,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
716 MG_CG::creer_MG_CG_INFO_DOUBLE(inclusion_couche,(char*)"EPAISSEUR",epaisseur);
717 matrice_couche_partielle=(MG_CG_FORME_VOLUME*)op_inc_matrice_couche->get_mgcg_forme_matrice_sortie();
718 configurer_volume_mince(inclusion_couche->get_mg_volume(),epaisseur);
719 }
720 epaisseur=*it_epaisseur;
721 if(position_relative_ext==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(matrice_couche_partielle,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
722 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");
723 MG_CG::creer_MG_CG_INFO_DOUBLE(matrice_couche_partielle,(char*)"EPAISSEUR",epaisseur);
724 vector_inclusion_genere.push_back(matrice_couche_partielle);
725 configurer_volume_mince(matrice_couche_partielle->get_mg_volume(),epaisseur);
726 position_relative=position_relative_ext;
727 }
728 else
729 {
730 // Verification du positionnement
731 if(positionnement_acceptable(forme_volume_inclusion->get_mg_volume())==FAIL)
732 {
733 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
734 return FAIL;
735 }
736 // Verification de la fraction volumique
737 volume_particule=OT_GEOMETRIE::get_volume_intersection(forme_volume_inclusion->get_mg_volume(),boite_frac_vol->get_mg_volume(),m_precision);
738 m_mgcg_modele->supprimer_mgcg_formeid(boite_frac_vol->get_id());
739 if((volume_particule+fraction_volumique_actuelle)>fraction_volumique_cible+eps_fra_vol)
740 {
741 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
742 return FAIL;
743 }
744 // Verification de la position relative
745 bool plan_x0yz;bool plan_x1yz;bool plan_xy0z;bool plan_xy1z;bool plan_xyz0;bool plan_xyz1;
746 position_relative=position_relative_inclusion_ves(forme_volume_inclusion->get_mg_volume(),plan_x0yz,plan_x1yz,plan_xy0z,plan_xy1z,plan_xyz0,plan_xyz1);
747 if(position_relative==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
748 {
749 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
750 return FAIL;
751 }
752 if(!m_intersection_bords_ves && position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
753 {
754 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
755 return FAIL;
756 }
757 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
758 {
759 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);
760 vector_operateur_genere.push_back(op_inter);
761 if(op_inter->construire()==FAIL)
762 {
763 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
764 return FAIL;
765 }
766 vector_forme_genere.push_back(op_inter->get_mgcg_forme_sortie());
767 if(op_inter->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
768 {
769 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
770 return FAIL;
771 }
772 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inter->get_mgcg_forme_sortie();
773 }
774 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);
775 vector_operateur_genere.push_back(op_inc_matrice);
776 if(op_inc_matrice->construire()==FAIL)
777 {
778 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
779 return FAIL;
780 }
781 matrice=op_inc_matrice->get_mgcg_forme_matrice_sortie();
782 vector_forme_genere.push_back(matrice);
783 vector_forme_genere.push_back(op_inc_matrice->get_mgcg_forme_inclusion_sortie());
784 if(op_inc_matrice->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
785 {
786 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
787 return FAIL;
788 }
789 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inc_matrice->get_mgcg_forme_inclusion_sortie();
790 if(configuration_acceptable(forme_volume_inclusion,matrice)==FAIL)
791 {
792 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
793 return FAIL;
794 }
795 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
796 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
797 vector_inclusion_genere.push_back(forme_volume_inclusion);
798 forme_volume_verif_grille=forme_volume_inclusion;
799 }
800 fraction_volumique_actuelle+=volume_particule;
801 m_grille_volume_inclusion.inserer(forme_volume_verif_grille->get_mg_volume());
802 m_matrice=matrice;
803 return OK;
804 }
805
806 bool MSTRUCT_GENERATEUR::insertion_inclusion(MG_CG_FORME* forme_inclusion,
807 double& fraction_volumique_actuelle,
808 std::vector< MG_CG_FORME* >& vector_inclusion_genere,
809 int& position_relative)
810 {
811 double volume_particule;
812 MG_CG_FORME* matrice=m_matrice;
813 std::vector<MG_CG_FORME*> vector_forme_genere;
814 std::vector<MG_CG_OPERATEUR*> vector_operateur_genere;
815 vector_forme_genere.push_back(forme_inclusion);
816 if(forme_inclusion->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
817 {
818 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
819 return FAIL;
820 }
821 MG_CG_FORME_VOLUME* forme_volume_inclusion = (MG_CG_FORME_VOLUME*)forme_inclusion;
822 MG_CG_FORME_VOLUME* forme_volume_verif_grille=NULL;
823 // Verification du positionnement
824 if(positionnement_acceptable(forme_volume_inclusion->get_mg_volume())==FAIL)
825 {
826 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
827 return FAIL;
828 }
829 // Verification de la position relative
830 bool plan_x0yz;bool plan_x1yz;bool plan_xy0z;bool plan_xy1z;bool plan_xyz0;bool plan_xyz1;
831 position_relative=position_relative_inclusion_ves(forme_volume_inclusion->get_mg_volume(),plan_x0yz,plan_x1yz,plan_xy0z,plan_xy1z,plan_xyz0,plan_xyz1);
832 if(position_relative==MSTRUCT::POSITION_RELATIVE::EXTERIEUR)
833 {
834 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
835 return FAIL;
836 }
837 if(!m_intersection_bords_ves && position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
838 {
839 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
840 return FAIL;
841 }
842 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD)
843 {
844 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);
845 vector_operateur_genere.push_back(op_inter);
846 if(op_inter->construire()==FAIL)
847 {
848 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
849 return FAIL;
850 }
851 vector_forme_genere.push_back(op_inter->get_mgcg_forme_sortie());
852 if(op_inter->get_mgcg_forme_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
853 {
854 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
855 return FAIL;
856 }
857 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inter->get_mgcg_forme_sortie();
858 }
859 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);
860 vector_operateur_genere.push_back(op_inc_matrice);
861 if(op_inc_matrice->construire()==FAIL)
862 {
863 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
864 return FAIL;
865 }
866 matrice=op_inc_matrice->get_mgcg_forme_matrice_sortie();
867 vector_forme_genere.push_back(matrice);
868 vector_forme_genere.push_back(op_inc_matrice->get_mgcg_forme_inclusion_sortie());
869 if(op_inc_matrice->get_mgcg_forme_inclusion_sortie()->get_type_forme()!=MG_CG_FORME::TYPE_FORME::VOLUME)
870 {
871 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
872 return FAIL;
873 }
874 forme_volume_inclusion=(MG_CG_FORME_VOLUME*)op_inc_matrice->get_mgcg_forme_inclusion_sortie();
875 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR)
876 {
877 if(distance_acceptable_bord_ves(forme_volume_inclusion->get_mg_volume())==FAIL)
878 {
879 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
880 return FAIL;
881 }
882 }
883 if(m_intersection_bords_ves)
884 if(configuration_acceptable(forme_volume_inclusion,matrice)==FAIL)
885 {
886 echec_insertion_inclusion(vector_forme_genere,vector_operateur_genere);
887 return FAIL;
888 }
889 if(position_relative==MSTRUCT::POSITION_RELATIVE::INTERIEUR) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"INTERIEUR");
890 if(position_relative==MSTRUCT::POSITION_RELATIVE::AU_BORD) MG_CG::creer_MG_CG_INFO_STRING(forme_volume_inclusion,(char*)"POSITION_RELATIVE",(char*)"AU_BORD");
891 vector_inclusion_genere.push_back(forme_volume_inclusion);
892 forme_volume_verif_grille=forme_volume_inclusion;
893 volume_particule=OT_GEOMETRIE::get_volume(forme_volume_inclusion->get_mg_volume());
894 fraction_volumique_actuelle+=volume_particule;
895 m_grille_volume_inclusion.inserer(forme_volume_verif_grille->get_mg_volume());
896 m_matrice=matrice;
897 return OK;
898 }
899
900
901 bool MSTRUCT_GENERATEUR::positionnement_acceptable(MG_VOLUME* inclusion)
902 {
903 TPL_MAP_ENTITE<MG_VOLUME*> map_volume_recherche;
904 BOITE_3D boite_recherche = inclusion->get_boite_3D();
905 boite_recherche.change_grosseur(1.1);
906 m_grille_volume_inclusion.rechercher(boite_recherche,map_volume_recherche);
907 TPL_MAP_ENTITE<MG_VOLUME*>::ITERATEUR it_volume;
908 MG_VOLUME* volume_recherche=map_volume_recherche.get_premier(it_volume);
909 double distance;
910 while(volume_recherche!=NULL)
911 {
912 if(OT_GEOMETRIE::get_distance_min_mg_volume_mg_volume(inclusion,volume_recherche,distance)==FAIL) return FAIL;
913 else
914 {
915 if(distance<=m_distance_min+m_precision) return FAIL;
916 else volume_recherche=map_volume_recherche.get_suivant(it_volume);
917 }
918 }
919 return OK;
920 }
921
922 bool MSTRUCT_GENERATEUR::lien_topologique_entre(MG_ELEMENT_TOPOLOGIQUE* mg_ele_topo1, MG_ELEMENT_TOPOLOGIQUE* mg_ele_topo2)
923 {
924 TPL_MAP_ENTITE<MG_SOMMET*> map_sommet_volume1;
925 OT_GEOMETRIE::get_map_mg_sommet_sous_jacent(mg_ele_topo1,map_sommet_volume1);
926 TPL_MAP_ENTITE<MG_SOMMET*> map_sommet_volume2;
927 OT_GEOMETRIE::get_map_mg_sommet_sous_jacent(mg_ele_topo2,map_sommet_volume2);
928 TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it_sommet;
929 for(MG_SOMMET* sommet=map_sommet_volume1.get_premier(it_sommet);sommet!=NULL;sommet=map_sommet_volume1.get_suivant(it_sommet))
930 {
931 if(map_sommet_volume2.existe(sommet)) return true;
932 }
933 return false;
934 }
935
936 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)
937 {
938 if(vector_epaisseur_couches==NULL)
939 {
940 MG_CG_GROUPE_FORME* groupe_forme;
941 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom);
942 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
943 vector_groupe_forme.push_back(groupe_forme);
944 }
945 else
946 {
947 MG_CG_GROUPE_FORME* groupe_forme;
948 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom);
949 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
950 vector_groupe_forme.push_back(groupe_forme);
951 for(int i=0;i<vector_epaisseur_couches->size();i++)
952 {
953 char nom_couche[500];
954 sprintf(nom_couche,"%s_%i",nom.c_str(),i);
955 groupe_forme=MG_CG::creer_MG_CG_GROUPE_FORME(m_mgcg_modele,nom_couche);
956 m_vector_mgcg_groupe_forme_inclusion.push_back(groupe_forme);
957 vector_groupe_forme.push_back(groupe_forme);
958 }
959 }
960 }
961
962 int MSTRUCT_GENERATEUR::configurer_volume_mince(MG_CG_FORME* forme,double epaisseur)
963 {
964 if(forme->get_type_forme()==MG_CG_FORME::TYPE_FORME::VOLUME)
965 {
966 MG_VOLUME* volume = ((MG_CG_FORME_VOLUME*)forme)->get_mg_volume();
967 configurer_volume_mince(volume,epaisseur);
968 }
969 if(forme->get_type_forme()==MG_CG_FORME::TYPE_FORME::MULTI_VOLUME)
970 {
971 MG_CG_FORME_MULTI_VOLUME* forme_multi_volume = (MG_CG_FORME_MULTI_VOLUME*)forme;
972 std::map<long,MG_VOLUME*>::iterator it_volume;
973 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))
974 {
975 configurer_volume_mince(volume,epaisseur);
976 }
977 }
978 return 0;
979 }
980
981 int MSTRUCT_GENERATEUR::configurer_volume_mince(MG_VOLUME* volume, double epaisseur)
982 {
983 TPL_MAP_ENTITE<MG_FACE*> tpl_map_face;
984 OT_GEOMETRIE::get_map_mg_face_sous_jacent(volume,tpl_map_face);
985 if(tpl_map_face.get_nb()<2) return FAIL;
986 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face1;
987 TPL_MAP_ENTITE<MG_FACE*>::ITERATEUR it_face2;
988 std::cout << "NB_FACE = " << tpl_map_face.get_nb() << std::endl;
989 while(tpl_map_face.get_nb()>=2)
990 {
991 bool trouve=false;
992 MG_FACE* face1=tpl_map_face.get_premier(it_face1);
993 it_face2=it_face1;
994 MG_FACE* face2=tpl_map_face.get_suivant(it_face2);
995 while(trouve==false && face1!=NULL && face2!=NULL)
996 {
997 double distance_moyenne;
998 double ecart_type_distance;
999 OT_GEOMETRIE::declage_mg_face_mg_face(face1,face2,distance_moyenne,ecart_type_distance,32);
1000 std::cout << " Distance = " << distance_moyenne << " Std-dev = " << ecart_type_distance << " Epaisseur = " << epaisseur << std::endl;
1001 if(OPERATEUR::egal(epaisseur,distance_moyenne,m_precision) && ecart_type_distance<m_precision)
1002 {
1003 std::cout << " Correspondance : " << face1->get_id() << " , " << face2->get_id() << std::endl;
1004 trouve=true;
1005 bool face1_base=false;
1006 bool face2_base=false;
1007 if(face1_base==true)
1008 {
1009 // std::cout << "Face1 base" << std::endl;
1010 volume->ajouter_face_correspondante(face1,face2);
1011 }
1012 else if(face2_base==true)
1013 {
1014 // std::cout << "Face2 base" << std::endl;
1015 volume->ajouter_face_correspondante(face2,face1);
1016 }
1017 else
1018 {
1019 double aire_face1 = OT_GEOMETRIE::get_aire(face1,m_precision);
1020 double aire_face2 = OT_GEOMETRIE::get_aire(face2,m_precision);
1021 if(aire_face1<aire_face2)
1022 {
1023 // std::cout << "Aire Face1 base" << std::endl;
1024 volume->ajouter_face_correspondante(face1,face2);
1025 }
1026 else
1027 {
1028 // std::cout << "Aire Face2 base" << std::endl;
1029 volume->ajouter_face_correspondante(face2,face1);
1030 }
1031 }
1032 }
1033 else face2=tpl_map_face.get_suivant(it_face2);
1034 }
1035 if(trouve)
1036 {
1037 tpl_map_face.supprimer(face1);
1038 tpl_map_face.supprimer(face2);
1039 }
1040 else tpl_map_face.supprimer(face1);
1041 }
1042
1043 return 0;
1044 }
1045
1046
1047 void MSTRUCT_GENERATEUR::active_affichage(fonction_affiche* fonc)
1048 {
1049 fonc_affiche = fonc;
1050 affichageactif = 1;
1051 }
1052
1053 void MSTRUCT_GENERATEUR::affiche(char* message)
1054 {
1055 if(affichageactif==1) fonc_affiche(message);
1056 }