MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
poly_voro.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
2 //####//------------------------------------------------------------
3 //####// MAGiC
4 //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5 //####// Departement de Genie Mecanique - UQTR
6 //####//------------------------------------------------------------
7 //####// MAGIC est un projet de recherche de l equipe ERICCA
8 //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9 //####// http://www.uqtr.ca/ericca
10 //####// http://www.uqtr.ca/
11 //####//------------------------------------------------------------
12 //####//------------------------------------------------------------
13 //####//
14 //####// poly_voro.cpp
15 //####//
16 //####//------------------------------------------------------------
17 //####//------------------------------------------------------------
18 //####// COPYRIGHT 2000-2024
19 //####// jeu 13 jun 2024 11:54:00 EDT
20 //####//------------------------------------------------------------
21 //####//------------------------------------------------------------
22 #include "poly_voro.h"
23 #include "poly_point.h"
24 #include "poly_noeud.h"
25 #include "poly_face.h"
26 #include "poly_cellule.h"
27 
28 
29 #include "tpl_grille.h"
30 #include "ot_mathematique.h"
31 
32 
33 #include <algorithm>
34 
35 #include "../voro++-0.4.6/src/voro++.hh"
36 
37 Poly_Voro::Poly_Voro(std::vector<Poly_Point*> list_pnts,double dg): POLY_AFFICHE(),list_points(list_pnts),epsfusion(dg)
38 {
39 }
40 
42 {
43  // Géométrie du conteneur
44  double x_min= list_points[0]->get_x(), x_max= list_points[6]->get_x();
45  double y_min= list_points[0]->get_y(), y_max= list_points[6]->get_y();
46  double z_min= list_points[0]->get_z(), z_max= list_points[6]->get_z();
47  double cvol = (x_max - x_min) * (y_max - y_min) * (x_max - x_min);
48 
49  // Nombre de blocs qui divise le container (blocs calculatoires)
50  int n_x= 6, n_y= 6, n_z= 6;
51 
52  // Cré un container avec la géométrie données
53  voro::container con(x_min, x_max, y_min, y_max, z_min, z_max, n_x, n_y, n_z, false, false, false, 8);
54 
55  // Ajoute les particules au container, on n'insère pas les 8 coins du cube
56  double x,y,z;
57  for(int i=8; i < list_points.size(); i++) {
58  x = list_points[i]->get_x();
59  y = list_points[i]->get_y();
60  z = list_points[i]->get_z();
61  con.put(i, x, y, z);
62  }
63 
64  // Additionne les volumes et vérifi que ça concorde avec le volume du container
65  double vvol = con.sum_cell_volumes();
66  char message[2000];
67  sprintf(message," Volume de l'echantillon = %lf",cvol);
68  affiche(message);
69  voro::voronoicell voro_cell;
70  voro::c_loop_all loop(con);
71  int nb=0;
72  if(loop.start()) do nb++;while(loop.inc());
73  sprintf(message," Nombre de cellules de Voronoi = %d",nb);
74  affiche(message);
75  sprintf(message," Volume des cellules de Voronoi = %lf",vvol);
76  affiche(message);
77 
78 
79 
80 
81 
82  // loop a travers les cellules
83  if(loop.start()) do if(con.compute_cell(voro_cell,loop))
84  {
85  Poly_Cellule* cell = new Poly_Cellule;
86  add_cell(cell);
87  loop.pos(x,y,z); // position globale de la particule en cours
88 
89  // récupération des noeuds
90  std::vector< double > vert_xyz;
91  voro_cell.vertices(x, y, z, vert_xyz); // récupère tous les vertex de la cellule dans le système global
92 
93  for(int i=0; i < vert_xyz.size(); i+=3)
94  {
95  static int numeronoeud=0;
96  numeronoeud++;
97  Poly_Noeud* nd = new Poly_Noeud(numeronoeud, vert_xyz[i], vert_xyz[i+1], vert_xyz[i+2]);
98  cell->add_noeud(nd);
99  }
100 
101  // récupération des faces
102  std::vector< int > face_vert;
103  voro_cell.face_vertices(face_vert); // liste de vertex pour chaque face
104 
105  for(int i=0; i < face_vert.size(); i++)
106  {
107  Poly_Face* face = new Poly_Face;
108  int nbVert = face_vert[i]; // première valeur = le nombre de vertex de la face
109  for(int j=i+1; j < i+nbVert+1; j++)
110  {
111  face->add_noeud(face_vert[j]);
112  }
113  cell->add_face(face);
114  i += nbVert;
115  }
116  } while (loop.inc());
117 }
118 
120 {
121  for (int i=0; i<get_nb_cell(); i++)
122  {
123  Poly_Cellule* c = list_cellules[i];
124  delete c;
125  }
126 }
127 
129 {
132  double x_min= list_points[0]->get_x(), x_max= list_points[6]->get_x();
133  double y_min= list_points[0]->get_y(), y_max= list_points[6]->get_y();
134  double z_min= list_points[0]->get_z(), z_max= list_points[6]->get_z();
135  BOITE_3D boiteenglobante(x_min,y_min,z_min,x_max,y_max,z_max);
136  boiteenglobante.change_grosseur(1.1);
137  int nb=pow(list_points.size(),0.333333333333333333)+1;
138  grille.initialiser(boiteenglobante.get_xmin(),boiteenglobante.get_ymin(),boiteenglobante.get_zmin(),boiteenglobante.get_xmax(),boiteenglobante.get_ymax(),boiteenglobante.get_zmax(),nb,nb,nb);
139 
140  double eps = epsfusion;
141 
142 
143  for(int i=0; i < get_nb_cell(); i++)
144  {
145  Poly_Cellule* c = get_cell(i);
146  for(int j=0; j < c->get_nb_noeud(); j++)
147  {
148  grille.inserer(c->get_noeud(j));
149  lstnoeud.ajouter(c->get_noeud(j));
150  }
151  }
152 
153 
155 
156  for (Poly_Noeud* nd=lstnoeud.get_premier(it);nd!=NULL;nd=lstnoeud.get_suivant(it))
157  if (nd->est_fusionne()==false)
158  {
159  double xyz[3];
160  xyz[0]=nd->get_x();
161  xyz[1]=nd->get_y();
162  xyz[2]=nd->get_z();
163  TPL_MAP_ENTITE<Poly_Noeud*> liste_entite_trouve;
164  grille.rechercher(xyz[0],xyz[1],xyz[2],eps,liste_entite_trouve);
166  for (Poly_Noeud* nd2=liste_entite_trouve.get_premier(it2);nd2!=NULL;nd2=liste_entite_trouve.get_suivant(it2))
167  if (nd2->est_fusionne()==false)
168  {
169  double xyz2[3];
170  xyz2[0]=nd2->get_x();
171  xyz2[1]=nd2->get_y();
172  xyz2[2]=nd2->get_z();
173  OT_VECTEUR_3D vec(xyz,xyz2);
174  if (vec.get_longueur()<eps)
175  {
176  nd2->set_x(xyz[0]);
177  nd2->set_y(xyz[1]);
178  nd2->set_z(xyz[2]);
179  nd2->active_fusion();
180  nd2->change_maitre_fusion(nd);
181  nd->active_fusion();
182  }
183 
184  }
185 
186  nd->change_maitre_fusion(nd);
187  }
188 
189 
190 #ifdef TYTY
191 
192 
193  for(int i=0; i < get_nb_cell(); i++)
194  {
195  Poly_Cellule* c = get_cell(i);
196  for(int j=0; j < c->get_nb_face(); j++)
197  {
198  // std::cout << "face :" << j+1 << std::endl;
199  Poly_Face *face=c->get_face(j);
200  /*int numdep= face->get_noeud(0);
201  Poly_Noeud *dep= c->get_noeud(numdep);
202  int numfin= face->get_last_noeud();
203  Poly_Noeud *fin= c->get_noeud(numfin);
204  int fusionsuite=0;
205  Poly_Noeud *lastfus;
206  int numlastfus;
207  int numnextfus;
208  int numfus;
209  Poly_Noeud *nextfus;
210  Poly_Noeud *fus;
211  std::vector<int> lstnewface;*/
212  std::vector<int> aretes(c->get_nb_face());
213  for (int i=0;i<face->get_nb_noeud();i++)
214  {
215  int num1= face->get_noeud(i);
216  Poly_Noeud* nd1=c->get_noeud(num1);
217  Poly_Noeud* nd2;
218  if (i+1!=face->get_nb_noeud())
219  {
220  int num2= face->get_noeud(i+1);
221  nd2=c->get_noeud(num2);
222  }
223  else
224  {
225  int num2= face->get_noeud(0);
226  nd2=c->get_noeud(num2);
227  }
228  if (nd1->get_maitre_fusion()==nd2->get_maitre_fusion())
229  aretes[i]=2;
230  else
231  {
232  double xyz1[3],xyz2[3];
233  xyz1[0]=nd1->get_x();
234  xyz1[1]=nd1->get_y();
235  xyz1[2]=nd1->get_z();
236  xyz2[0]=nd2->get_x();
237  xyz2[1]=nd2->get_y();
238  xyz2[2]=nd2->get_z();
239  OT_VECTEUR_3D vec(xyz1,xyz2);
240  if (vec.get_longueur()<epsfusion)
241  aretes[i]=0;
242  else
243  if (vec.get_longueur()<1e-10)
244  aretes[i]=2;
245  else
246  aretes[i]=1;
247  }
248  }
249  int numlastfus;
250  int numfus;
251  int numnextfus;
252  int fusionsuite=0;
253  std::vector<int> lstnewface;
254  if (aretes[0]==1)
255  numlastfus=1;
256  else
257  {
258  int num=face->get_nb_noeud()-1;
259  while (aretes[num]==0)
260  num--;
261  numlastfus=num+1;
262  if (numlastfus>=face->get_nb_noeud()) numlastfus=0;
263  fusionsuite=face->get_nb_noeud()-num;
264  }
265  for (int i=0;i<face->get_nb_noeud();i++)
266  {
267  if (aretes[i]==0)
268  {
269  fusionsuite++;
270  numfus=i;
271  }
272  else
273  {
274  if (fusionsuite>1)
275  {
276  numnextfus=i;
277  lstnewface.push_back(numlastfus);
278  lstnewface.push_back(numfus);
279  lstnewface.push_back(numnextfus);
280  }
281  fusionsuite=0;
282  numlastfus=i+1;
283  }
284 
285  }
286 
287 
288 
289 
290 
291  for (int i=0;i<face->get_nb_noeud();i++)
292  if (aretes[i]==0)
293  face->supprimer_noeud(i+1);
294 
295  for (int i=0;i<lstnewface.size();i=i+3)
296  {
297  Poly_Face *face=new Poly_Face;
298  face->add_noeud(lstnewface[i]);
299  face->add_noeud(lstnewface[i+1]);
300  face->add_noeud(lstnewface[i+2]+1);
301  c->add_face(face);
302  }
303  }
304 
305  }
306 #endif
307 }
308 
309 
310 
312 {
313  list_cellules.push_back(element);
314 }
315 
317 {
318  return list_points[num];
319 }
320 
322 {
323  return list_cellules[num];
324 }
325 
327 {
328  return list_cellules.size();
329 }
330 
331 
TPL_MAP_ENTITE::get_premier
virtual X get_premier(ITERATEUR &it)
Definition: tpl_map_entite.h:112
Poly_Voro::epsfusion
double epsfusion
Definition: poly_voro.h:50
TPL_MAP_ENTITE
Definition: tpl_map_entite.h:35
Poly_Cellule
Definition: poly_cellule.h:31
BOITE_3D::get_xmin
double get_xmin(void)
Definition: ot_boite_3d.cpp:104
poly_cellule.h
Poly_Point::get_x
double get_x(void)
Definition: poly_point.cpp:36
TPL_GRILLE::inserer
virtual void inserer(A a)
Definition: tpl_grille.h:274
Poly_Cellule::get_face
Poly_Face * get_face(int num)
Definition: poly_cellule.cpp:48
Poly_Point::get_z
double get_z(void)
Definition: poly_point.cpp:38
TPL_GRILLE
Definition: tpl_grille.h:121
Poly_Voro::fusion_noeuds
virtual void fusion_noeuds(void)
Definition: poly_voro.cpp:128
Poly_Voro::construit
virtual void construit(void)
Definition: poly_voro.cpp:41
Poly_Point
Definition: poly_point.h:25
poly_noeud.h
BOITE_3D::get_zmax
double get_zmax(void)
Definition: ot_boite_3d.cpp:129
BOITE_3D::get_ymin
double get_ymin(void)
Definition: ot_boite_3d.cpp:114
Poly_Voro::get_nb_cell
virtual int get_nb_cell(void)
Definition: poly_voro.cpp:326
POLY_AFFICHE
Definition: poly_affiche.h:29
Poly_Cellule::get_nb_noeud
int get_nb_noeud(void)
Definition: poly_cellule.cpp:53
BOITE_3D::get_xmax
double get_xmax(void)
Definition: ot_boite_3d.cpp:109
TPL_GRILLE::rechercher
virtual void rechercher(BOITE_3D bt, TPL_MAP_ENTITE< A > &liste_entite_trouve)
Definition: tpl_grille.h:202
Poly_Voro::~Poly_Voro
~Poly_Voro()
Definition: poly_voro.cpp:119
tpl_grille.h
TPL_MAP_ENTITE::ITERATEUR
std::map< unsigned long, X, std::less< unsigned long > >::iterator ITERATEUR
Definition: tpl_map_entite.h:38
Poly_Cellule::get_nb_face
int get_nb_face(void)
Definition: poly_cellule.cpp:54
Poly_Voro::add_cell
virtual void add_cell(Poly_Cellule *element)
Definition: poly_voro.cpp:311
ot_mathematique.h
Poly_Face::get_noeud
int get_noeud(int num)
Definition: poly_face.cpp:40
BOITE_3D::get_ymax
double get_ymax(void)
Definition: ot_boite_3d.cpp:119
Poly_Noeud::get_maitre_fusion
Poly_Noeud * get_maitre_fusion(void)
Definition: poly_noeud.cpp:91
Poly_Face::supprimer_noeud
void supprimer_noeud(int num)
Definition: poly_face.cpp:44
POLY_AFFICHE::affiche
virtual void affiche(char *mess)
Definition: poly_affiche.cpp:42
Poly_Cellule::add_face
void add_face(Poly_Face *newface)
Definition: poly_cellule.cpp:51
OT_VECTEUR_3D
Definition: ot_mathematique.h:94
TPL_MAP_ENTITE::ajouter
virtual void ajouter(X x)
Definition: tpl_map_entite.h:55
Poly_Face::get_nb_noeud
int get_nb_noeud(void)
Definition: poly_face.cpp:43
poly_face.h
BOITE_3D
Definition: ot_boite_3d.h:27
poly_voro.h
Poly_Voro::list_cellules
std::vector< Poly_Cellule * > list_cellules
Definition: poly_voro.h:49
Poly_Face::add_noeud
void add_noeud(int numNoeud)
Definition: poly_face.cpp:42
Poly_Cellule::get_noeud
Poly_Noeud * get_noeud(int num)
Definition: poly_cellule.cpp:47
BOITE_3D::get_zmin
double get_zmin(void)
Definition: ot_boite_3d.cpp:124
OT_VECTEUR_3D::get_longueur
virtual double get_longueur(void) const
Definition: ot_mathematique.cpp:483
Poly_Voro::get_point
Poly_Point * get_point(int num)
Definition: poly_voro.cpp:316
Poly_Cellule::add_noeud
void add_noeud(Poly_Noeud *newNoeud)
Definition: poly_cellule.cpp:50
Poly_Voro::Poly_Voro
Poly_Voro(std::vector< Poly_Point * > list_pnts, double dg)
Definition: poly_voro.cpp:37
poly_point.h
BOITE_3D::change_grosseur
void change_grosseur(double f)
Definition: ot_boite_3d.cpp:176
TPL_MAP_ENTITE::get_suivant
virtual X get_suivant(ITERATEUR &it)
Definition: tpl_map_entite.h:120
Poly_Point::get_y
double get_y(void)
Definition: poly_point.cpp:37
Poly_Voro::get_cell
Poly_Cellule * get_cell(int num)
Definition: poly_voro.cpp:321
TPL_GRILLE::initialiser
virtual void initialiser(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax, int nb_pasx, int nb_pasy, int nb_pasz)
Definition: tpl_grille.h:142
Poly_Voro::list_points
std::vector< Poly_Point * > list_points
Definition: poly_voro.h:48
Poly_Noeud
Definition: poly_noeud.h:31
Poly_Face
Definition: poly_face.h:27