ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/criaqoperation/src/criaqoperators.cpp
Revision: 673
Committed: Tue Jun 9 16:04:58 2015 UTC (10 years, 2 months ago) by sattarpa
File size: 111288 byte(s)
Log Message:
ajouter le calcule de aire de defaut.

File Contents

# Content
1 #include <stdio.h>
2 #include "mg_file.h"
3 #include "criaqoperators.h"
4 #include "tpl_grille.h"
5 #include "ot_mathematique.h"
6 #include <math.h>
7 #include "tpl_octree.h"
8 #include "fem_maillage_outils.h"
9 #include "mg_maillage_outils.h"
10 #include <sstream>
11 #include <string.h>
12
13 CRIAQOPERATORS::CRIAQOPERATORS():MAILLEUR(false)
14 {
15 }
16 CRIAQOPERATORS::~CRIAQOPERATORS()
17 {
18 }
19
20 void CRIAQOPERATORS::bumparea_calcul(char* magicfilename,int nummai,int mgsolid,double tolerance,char* areamagicfilename,int defnodid)
21 {
22 MG_FILE gest(magicfilename);
23 MG_MAILLAGE* mai;
24 if (nummai==0) mai=gest.get_mg_maillage(nummai); else mai=gest.get_mg_maillageid(nummai);
25 MG_SOLUTION* mgsol=gest.get_mg_solutionid(mgsolid);
26 mgsol->active_solution(0);
27 MG_NOEUD* defnd;
28 LISTE_MG_NOEUD::iterator itnd;
29 for(MG_NOEUD* nd=mai->get_premier_noeud(itnd);nd!=NULL;nd=mai->get_suivant_noeud(itnd))
30 {
31 if (nd->get_id()==defnodid)
32 defnd=nd;
33 }
34 cout<<defnd->get_solution()<<endl;
35 double max_dist=defnd->get_solution();
36 TPL_MAP_ENTITE<MG_TRIANGLE*> areatris;
37 for (int i=0;i<defnd->get_lien_triangle()->get_nb();i++)
38 {
39 MG_TRIANGLE* trii=defnd->get_lien_triangle()->get(i);
40 areatris.ajouter(trii);
41 }
42 int stoplvl=0;
43 while (areatris.get_nb()>stoplvl)
44 {
45 stoplvl=areatris.get_nb();
46 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itareatris;
47 for(MG_TRIANGLE* trii=areatris.get_premier(itareatris);trii!=NULL;trii=areatris.get_suivant(itareatris))
48 {
49 for(int i=0;i<trii->get_segment1()->get_lien_triangle()->get_nb();i++)
50 {
51 MG_TRIANGLE* trineib=trii->get_segment1()->get_lien_triangle()->get(i);
52 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
53 if (avdis>tolerance)
54 areatris.ajouter(trineib);
55 }
56 for(int i=0;i<trii->get_segment2()->get_lien_triangle()->get_nb();i++)
57 {
58 MG_TRIANGLE* trineib=trii->get_segment2()->get_lien_triangle()->get(i);
59 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
60 if (avdis>tolerance)
61 areatris.ajouter(trineib);
62 }
63 for(int i=0;i<trii->get_segment3()->get_lien_triangle()->get_nb();i++)
64 {
65 MG_TRIANGLE* trineib=trii->get_segment3()->get_lien_triangle()->get(i);
66 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
67 if (avdis>tolerance)
68 areatris.ajouter(trineib);
69 }
70 }
71 }
72 double area=0.;
73 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itareatris;
74 for(MG_TRIANGLE* tri=areatris.get_premier(itareatris);tri!=NULL;tri=areatris.get_suivant(itareatris))
75 {
76 OT_VECTEUR_3D v1(tri->get_noeud1()->get_coord(),tri->get_noeud2()->get_coord());
77 OT_VECTEUR_3D v2(tri->get_noeud1()->get_coord(),tri->get_noeud3()->get_coord());
78 OT_VECTEUR_3D area1=v1&v2;
79 double area2=0.5*area1.get_longueur();
80 area=area+area2;
81 }
82 cout<<"area= "<<area<<endl;
83
84 MG_MAILLAGE* mai1;
85 if (nummai==0) mai1=gest.get_mg_maillage(nummai); else mai1=gest.get_mg_maillageid(nummai);
86 TPL_MAP_ENTITE<MG_TRIANGLE*> deltris;
87 LISTE_MG_TRIANGLE::iterator ittri;
88 for (MG_TRIANGLE* tri=mai1->get_premier_triangle(ittri);tri!=NULL;tri=mai1->get_suivant_triangle(ittri))
89 {
90 int triexist=0;
91 for(MG_TRIANGLE* triarea=areatris.get_premier(itareatris);triarea!=NULL;triarea=areatris.get_suivant(itareatris))
92 {
93 if (triarea==tri)
94 triexist++;
95 }
96 if (triexist<1)
97 deltris.ajouter(tri);
98 }
99 for(MG_TRIANGLE* tridel=deltris.get_premier(itareatris);tridel!=NULL;tridel=deltris.get_suivant(itareatris))
100 {
101 mai1->supprimer_mg_triangleid(tridel->get_id());
102 }
103
104 gest.ajouter_mg_maillage(mai1);
105 gest.enregistrer(areamagicfilename);
106 }
107 void CRIAQOPERATORS::samplepoints_compare(char* samplepoints1,char* samplepoints2,char* sortedsmplpnts)
108 {
109 std::vector<double*> lstsamplepoints1;
110 FILE *in1=fopen(samplepoints1,"rt");
111 if (in1==NULL) affiche((char*) "file is not available");
112 while(!feof(in1))
113 {
114 char chaine[500];
115 char* res=fgets(chaine,500,in1);
116 if(res!=NULL)
117 {
118 double x,y,z;
119 double q1,q2,q3;
120 double* pcoordbc=new double[6];
121 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
122 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
123 else if(nb==6)
124 {
125 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
126 lstsamplepoints1.push_back(pcoordbc);
127 }
128 }
129 }
130 fclose(in1);
131 std::vector<double*> lstsamplepoints2;
132 FILE *in2=fopen(samplepoints2,"rt");
133 if (in2==NULL) affiche((char*) "file is not available");
134 while(!feof(in2))
135 {
136 char chaine[500];
137 char* res=fgets(chaine,500,in2);
138 if(res!=NULL)
139 {
140 double x,y,z;
141 double q1,q2,q3;
142 double* pcoordbc=new double[6];
143 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
144 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
145 else if(nb==6)
146 {
147 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
148 lstsamplepoints2.push_back(pcoordbc);
149 }
150 }
151 }
152 fclose(in2);
153 cout<<lstsamplepoints1.size()<<endl;
154 cout<<lstsamplepoints2.size()<<endl;
155
156 std::vector<double*> lstsortedsmplpnts;
157 for(std::vector<double*>::iterator itlstsamplepoints1=lstsamplepoints1.begin();itlstsamplepoints1!=lstsamplepoints1.end();itlstsamplepoints1++)
158 {
159 double* pcoordbc=new double[7];
160 int countsmpcomp=0;
161 double* xyzsmp1=(*itlstsamplepoints1);
162 for(std::vector<double*>::iterator itlstsamplepoints2=lstsamplepoints2.begin();itlstsamplepoints2!=lstsamplepoints2.end();itlstsamplepoints2++)
163 {
164 double* xyzsmp2=(*itlstsamplepoints2);
165 if(xyzsmp1[0]==xyzsmp2[0] && xyzsmp1[1]==xyzsmp2[1] && xyzsmp1[2]==xyzsmp2[2] && xyzsmp1[3]==xyzsmp2[3] && xyzsmp1[4]==xyzsmp2[4] && xyzsmp1[5]==xyzsmp2[5])
166 countsmpcomp++;
167 }
168 if(countsmpcomp==0)
169 {
170 pcoordbc[0]=0; pcoordbc[1]=xyzsmp1[0]; pcoordbc[2]=xyzsmp1[1]; pcoordbc[3]=xyzsmp1[2]; pcoordbc[4]=xyzsmp1[3]; pcoordbc[5]=xyzsmp1[4]; pcoordbc[6]=xyzsmp1[5];
171 lstsortedsmplpnts.push_back(pcoordbc);
172 }
173 else if (countsmpcomp>0)
174 {
175 pcoordbc[0]=1; pcoordbc[1]=xyzsmp1[0]; pcoordbc[2]=xyzsmp1[1]; pcoordbc[3]=xyzsmp1[2]; pcoordbc[4]=xyzsmp1[3]; pcoordbc[5]=xyzsmp1[4]; pcoordbc[6]=xyzsmp1[5];
176 lstsortedsmplpnts.push_back(pcoordbc);
177 }
178
179
180 }
181 cout<<lstsortedsmplpnts.size()<<endl;
182
183
184 FILE* insmp=fopen(sortedsmplpnts,"wt");
185 for(std::vector<double*>::iterator itlstsortedsmplpnts=lstsortedsmplpnts.begin();itlstsortedsmplpnts!=lstsortedsmplpnts.end();itlstsortedsmplpnts++)
186 {
187 double* xyzsmpsort=(*itlstsortedsmplpnts);
188 //cout<<xyzsmpsort[0]<<" "<<xyzsmpsort[1]<<endl;
189 fprintf(insmp,"%le %le %le %le %le %le %le \n",xyzsmpsort[0],xyzsmpsort[1],xyzsmpsort[2],xyzsmpsort[3],xyzsmpsort[4],xyzsmpsort[5],xyzsmpsort[6]);
190 }
191 fclose(insmp);
192
193 }
194
195 void CRIAQOPERATORS::meshdistance_compare(char* referencemagicfilename,int refmeshno,char* comparemagicfilename,int compmeshno,char* outputcomparefile)
196 {
197 MG_FILE refgest(referencemagicfilename);
198 MG_MAILLAGE* refmgmai;
199 if (refmeshno==0) refmgmai=refgest.get_mg_maillage(refmeshno); else refmgmai=refgest.get_mg_maillageid(refmeshno);
200 MG_FILE compgest(comparemagicfilename);
201 MG_MAILLAGE* compmgmai;
202 if (compmeshno==0) compmgmai=compgest.get_mg_maillage(compmeshno); else compmgmai=compgest.get_mg_maillageid(compmeshno);
203
204 //octree initialization
205 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
206 TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
207 LISTE_MG_NOEUD::iterator it;
208 for (MG_NOEUD* no=refmgmai->get_premier_noeud(it);no!=NULL;no=refmgmai->get_suivant_noeud(it))
209 {
210 if (no->get_x()<xmin) xmin=no->get_x();
211 if (no->get_y()<ymin) ymin=no->get_y();
212 if (no->get_z()<zmin) zmin=no->get_z();
213 if (no->get_x()>xmax) xmax=no->get_x();
214 if (no->get_y()>ymax) ymax=no->get_y();
215 if (no->get_z()>zmax) zmax=no->get_z();
216 }
217 for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
218 {
219 if (no->get_x()<xmin) xmin=no->get_x();
220 if (no->get_y()<ymin) ymin=no->get_y();
221 if (no->get_z()<zmin) zmin=no->get_z();
222 if (no->get_x()>xmax) xmax=no->get_x();
223 if (no->get_y()>ymax) ymax=no->get_y();
224 if (no->get_z()>zmax) zmax=no->get_z();
225 lstnoeud.ajouter(no);
226 }
227 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
228 OT_VECTEUR_3D vec(vecmmax,vecmin);
229
230 //double search_radius=0.001*(vec.get_longueur());
231 double search_radius=3.;
232 OT_VECTEUR_3D min(xmin,ymin,zmin); OT_VECTEUR_3D max(xmax,ymax,zmax); OT_VECTEUR_3D average=(min+max)/2.; OT_VECTEUR_3D lengthvec(min,max);
233 double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
234 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
235 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
236
237 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octree;
238 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
239 for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
240 octree.inserer(no);
241
242 MG_SOLUTION* mgsol=new MG_SOLUTION(refmgmai,1,(char*)"distance.sol",1,(char*)"Normaldistance",MAGIC::ENTITE_SOLUTION::ENTITE_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
243 refgest.ajouter_mg_solution(mgsol);
244 mgsol->change_legende(0,"Normaldistance");
245 int i=0;
246 for (MG_NOEUD* nop=refmgmai->get_premier_noeud(it);nop!=NULL;nop=refmgmai->get_suivant_noeud(it))
247 {
248 TPL_MAP_ENTITE<MG_NOEUD*> lstneiclose;
249 int neindnb=lstneiclose.get_nb();
250 while(neindnb==0)
251 {
252 octree.rechercher(nop->get_x(),nop->get_y(),nop->get_z(),search_radius,lstneiclose);
253 neindnb=lstneiclose.get_nb();
254 }
255 map<double,MG_NOEUD*,std::less<double> > lstdist;
256 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itnop;
257 for(MG_NOEUD* no=lstneiclose.get_premier(itnop);no!=NULL;no=lstneiclose.get_suivant(itnop))
258 {
259 double distns=sqrt(pow(nop->get_x()-no->get_x(),2)+pow(nop->get_y()-no->get_y(),2)+pow(nop->get_z()-no->get_z(),2));
260
261 OT_VECTEUR_3D w_n_tot(0.,0.,0.);
262 double norme_w_n_tot=0.;
263 OT_VECTEUR_3D w2_n_tot(0.,0.,0.);
264 double norme_w2_n_tot=0.;
265 int nbtri=nop->get_lien_triangle()->get_nb();
266 for (int i=0;i<nbtri;i++)
267 {
268 MG_TRIANGLE* tri=(MG_TRIANGLE*)nop->get_lien_triangle()->get(i);
269
270 double *xyzn1=tri->get_noeud1()->get_coord();
271 double *xyzn2=tri->get_noeud2()->get_coord();
272 double *xyzn3=tri->get_noeud3()->get_coord();
273
274 OT_VECTEUR_3D vec1(xyzn1,xyzn3);
275 OT_VECTEUR_3D vec2(xyzn1,xyzn2);
276 OT_VECTEUR_3D n_tri=vec1&vec2; // Normale au triangle
277
278 double w=n_tri.get_longueur(); // 2 fois l'aire du triangle (pour éviter une division par 2)
279 n_tri.norme();
280 OT_VECTEUR_3D w_n=w*n_tri;
281 double norme_w_n=w_n.get_longueur();
282 w_n_tot=w_n_tot+w_n;
283 norme_w_n_tot=norme_w_n_tot+norme_w_n;
284 }
285
286 OT_VECTEUR_3D n=w_n_tot/norme_w_n_tot; // Normale à la surface au noeud
287 n.norme();
288 OT_VECTEUR_3D distvec(nop->get_coord(),no->get_coord());
289 double normaldistance=distvec*n;
290 double normaldistanceabs=fabs(normaldistance);
291 //cout<<"normaldistanceabs= "<<normaldistanceabs<<endl;
292 lstdist.insert(pair<double,MG_NOEUD*>(normaldistanceabs,nop));
293 }
294 map<double,MG_NOEUD*,std::less<double> >::iterator itlstdist=lstdist.begin();
295 double distnsclos=(*itlstdist).first;
296 MG_NOEUD* nodcls=(*itlstdist).second;
297 //cout<<"distnsclos= "<<distnsclos<<endl;
298 mgsol->ecrire(distnsclos,i,0,0);
299 //mgsol->ecrire(distnsclos,1,0,0);
300 i++;
301 }
302 refgest.enregistrer(outputcomparefile);
303 }
304 void CRIAQOPERATORS::deformed_correspond_mgmaiadd(char* magicfilename,int meshno,int numsol1,int numsol2,int numsol3,int numchamp1,int numchamp2,int numchamp3,double coef)
305 {
306 MG_FILE gest(magicfilename);
307 FEM_MAILLAGE* femmai;
308 if (meshno==0) femmai=gest.get_fem_maillage(meshno); else femmai=gest.get_fem_maillageid(meshno);
309 FEM_SOLUTION* sol1=gest.get_fem_solutionid(numsol1);
310 FEM_SOLUTION* sol2=gest.get_fem_solutionid(numsol2);
311 FEM_SOLUTION* sol3=gest.get_fem_solutionid(numsol3);
312 femmai->calcul_deforme(sol1,numchamp1,sol2,numchamp2,sol3,numchamp3);
313 if (coef>1e-16)
314 {
315 cout<<" Création du maillage deforme avec correspondence text file"<<endl;
316 MG_MAILLAGE* defmgmai=new MG_MAILLAGE(gest.get_mg_geometrie(0));
317 gest.ajouter_mg_maillage(defmgmai);
318 {
319 if (femmai->get_degre()==1)
320 {
321 //gest=femmai->get_mg_maillage()->get_gestionnaire();
322 //gest->ajouter_mg_maillage(this);
323 std::vector<unsigned long*> lstcores;//sasan
324 LISTE_FEM_NOEUD::iterator it;
325 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
326 {
327 double x=no->get_x(coef);
328 double y=no->get_y(coef);
329 double z=no->get_z(coef);
330 MG_NOEUD *newno=new MG_NOEUD(no->get_lien_topologie(),x,y,z,DEFORME);
331 defmgmai->ajouter_mg_noeud(newno);
332 no->change_numero(newno->get_id());
333 unsigned long* correscad_defcad=new unsigned long[2];//sasan
334 correscad_defcad[0]=no->get_mg_element_maillage()->get_id();//sasan
335 correscad_defcad[1]=newno->get_id();//sasan
336 lstcores.push_back(correscad_defcad);//sasan
337 }
338 //sasan
339 FILE* in1=fopen("correspond_deform_mgmaill.txt","wt");
340 fprintf(in1,"MG_MAILLAGE No. : deformed_MAILLAGE No.\n");
341 fprintf(in1,"%lu %lu\n",femmai->get_mg_maillage()->get_id(),defmgmai->get_id());
342 for(std::vector<unsigned long*>::iterator itlstpinsert=lstcores.begin();itlstpinsert!=lstcores.end();itlstpinsert++)
343 {
344 unsigned long* xyzpins1;
345 xyzpins1=(*itlstpinsert);
346 //cout<<" xyzpins1[0]= "<<xyzpins1[0]<<" xyzpins1[1]= "<<xyzpins1[1]<<endl;
347 fprintf(in1,"%lu %lu\n",xyzpins1[0],xyzpins1[1]);
348 }
349 fclose(in1);
350 //sasan till
351 LISTE_FEM_ELEMENT1::iterator it1;
352 for (FEM_ELEMENT1 *ele=femmai->get_premier_element1(it1);ele!=NULL;ele=femmai->get_suivant_element1(it1))
353 {
354 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
355 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
356 MG_SEGMENT *seg=new MG_SEGMENT(ele->get_lien_topologie(),no1,no2,DEFORME);
357 defmgmai->ajouter_mg_segment(seg);
358 }
359 LISTE_FEM_ELEMENT2::iterator it2;
360 for (FEM_ELEMENT2 *ele=femmai->get_premier_element2(it2);ele!=NULL;ele=femmai->get_suivant_element2(it2))
361 {
362 if (ele->get_nb_fem_noeud()==3)
363 {
364 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
365 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
366 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
367 defmgmai->ajouter_mg_triangle(ele->get_lien_topologie(),no1,no2,no3,DEFORME);
368 }
369 if (ele->get_nb_fem_noeud()==4)
370 {
371 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
372 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
373 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
374 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
375 defmgmai->ajouter_mg_quadrangle(ele->get_lien_topologie(),no1,no2,no3,no4,DEFORME);
376 }
377 }
378 LISTE_FEM_ELEMENT3::iterator it3;
379 for (FEM_ELEMENT3 *ele=femmai->get_premier_element3(it3);ele!=NULL;ele=femmai->get_suivant_element3(it3))
380 {
381 if (ele->get_nb_fem_noeud()==4)
382 {
383 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
384 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
385 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
386 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
387 defmgmai->ajouter_mg_tetra(ele->get_lien_topologie(),no1,no2,no3,no4,DEFORME);
388 }
389 if (ele->get_nb_fem_noeud()==8)
390 {
391 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
392 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
393 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
394 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
395 MG_NOEUD* no5=defmgmai->get_mg_noeudid(ele->get_fem_noeud(4)->get_numero());
396 MG_NOEUD* no6=defmgmai->get_mg_noeudid(ele->get_fem_noeud(5)->get_numero());
397 MG_NOEUD* no7=defmgmai->get_mg_noeudid(ele->get_fem_noeud(6)->get_numero());
398 MG_NOEUD* no8=defmgmai->get_mg_noeudid(ele->get_fem_noeud(7)->get_numero());
399 defmgmai->ajouter_mg_hexa(ele->get_lien_topologie(),no1,no2,no3,no4,no5,no6,no7,no8,DEFORME);
400 }
401 }
402
403 }
404 }
405 }
406 cout<<" Enregistrement"<<endl;
407 gest.enregistrer(magicfilename);
408 }
409 void CRIAQOPERATORS::curvtur_crit_remvsmp(char* magicfilename,char* correspondfilename,char* gnifinspointfile,char* out_gnifinspointfile_removondefect,double search_radius,double curvdif_coef,int gmsh_affiche,double relet_search_rad,int relet_curvature)
410 {
411 MG_FILE gest(magicfilename);
412 map<unsigned long, unsigned long> coresspondndidlst;
413 FILE* in1=fopen(correspondfilename,"rt");
414 if (in1==NULL) cout<<"correspondfile is not available"<<endl;
415 char mess[500];
416 char *res=fgets(mess,500,in1);
417 if(feof(in1))
418 cout<<"correspondfile has not been well written"<<endl;
419 res=fgets(mess,500,in1);
420 if(feof(in1))
421 cout<<"correspondfile has not been well written"<<endl;
422 int cadmeshno;
423 int defcadmeshno;
424 int nb1=sscanf(mess,"%d %d",&cadmeshno,&defcadmeshno);
425 while (!feof(in1))
426 {
427 char chaine[500];
428 res=fgets(chaine,500,in1);
429 if(res!=NULL)
430 {
431 unsigned long cadndid;
432 unsigned long defcadndid;
433 int nb=sscanf(chaine,"%lu %lu",&cadndid,&defcadndid);
434 if (nb!=-1 && nb!=2) cout<<"Wrong file format"<<endl;
435 else if (nb==2)
436 {
437 coresspondndidlst.insert(pair<unsigned long, unsigned long> (defcadndid,cadndid) );
438 }
439 }
440 }
441 fclose(in1);
442
443 cout<<"cadmeshno= "<<cadmeshno<<" defcadmeshno= "<<defcadmeshno<<endl;
444 MG_MAILLAGE* cadmgmai;
445 if (cadmeshno==0) cadmgmai=gest.get_mg_maillage(cadmeshno); else cadmgmai=gest.get_mg_maillageid(cadmeshno);
446 MG_MAILLAGE* defcadmgmai;
447 if (defcadmeshno==0) defcadmgmai=gest.get_mg_maillage(defcadmeshno); else defcadmgmai=gest.get_mg_maillageid(defcadmeshno);
448
449 cout<<"octree initialization "<<endl;
450 //CAD octree initialization
451 LISTE_MG_NOEUD::iterator itcadndcurv;
452 double xmincad=1e308,ymincad=1e308,zmincad=1e308,xmaxcad=-1e308,ymaxcad=-1e308,zmaxcad=-1e308;
453 TPL_MAP_ENTITE<MG_NOEUD*> lstcadnoeud;
454 for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
455 {
456 if (cadndcurv->get_x()<xmincad) xmincad=cadndcurv->get_x();
457 if (cadndcurv->get_y()<ymincad) ymincad=cadndcurv->get_y();
458 if (cadndcurv->get_z()<zmincad) zmincad=cadndcurv->get_z();
459 if (cadndcurv->get_x()>xmaxcad) xmaxcad=cadndcurv->get_x();
460 if (cadndcurv->get_y()>ymaxcad) ymaxcad=cadndcurv->get_y();
461 if (cadndcurv->get_z()>zmaxcad) zmaxcad=cadndcurv->get_z();
462 lstcadnoeud.ajouter(cadndcurv);
463 }
464 OT_VECTEUR_3D vecmincad(xmincad,ymincad,zmincad);
465 OT_VECTEUR_3D vecmmaxcad(xmaxcad,ymaxcad,zmaxcad);
466 OT_VECTEUR_3D vecad(vecmmaxcad,vecmincad);
467 OT_VECTEUR_3D mincad(xmincad,ymincad,zmincad); OT_VECTEUR_3D maxcad(xmaxcad,ymaxcad,zmaxcad); OT_VECTEUR_3D averagecad=(mincad+maxcad)/2.; OT_VECTEUR_3D lengthvecad(mincad,maxcad);
468 double lengthcad=sqrt(lengthvecad*lengthvecad); double bxrcad=1.1;
469 xmincad=averagecad.get_x()-(lengthcad*bxrcad);ymincad=averagecad.get_y()-(lengthcad*bxrcad);zmincad=averagecad.get_z()-(lengthcad*bxrcad);
470 xmaxcad=averagecad.get_x()+(lengthcad*bxrcad);ymaxcad=averagecad.get_y()+(lengthcad*bxrcad);zmaxcad=averagecad.get_z()+(lengthcad*bxrcad);
471 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreecad;
472 octreecad.initialiser(&lstcadnoeud,1,xmincad,ymincad,zmincad,xmaxcad,ymaxcad,zmaxcad);
473 for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
474 octreecad.inserer(cadndcurv);
475 //deformed_CAD octree initialization
476 LISTE_MG_NOEUD::iterator itdefcadndcurv;
477 double xmindefcad=1e308,ymindefcad=1e308,zmindefcad=1e308,xmaxdefcad=-1e308,ymaxdefcad=-1e308,zmaxdefcad=-1e308;
478 TPL_MAP_ENTITE<MG_NOEUD*> lstdefcadnoeud;
479 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
480 {
481 if (defcadndcurv->get_x()<xmindefcad) xmindefcad=defcadndcurv->get_x();
482 if (defcadndcurv->get_y()<ymindefcad) ymindefcad=defcadndcurv->get_y();
483 if (defcadndcurv->get_z()<zmindefcad) zmindefcad=defcadndcurv->get_z();
484 if (defcadndcurv->get_x()>xmaxdefcad) xmaxdefcad=defcadndcurv->get_x();
485 if (defcadndcurv->get_y()>ymaxdefcad) ymaxdefcad=defcadndcurv->get_y();
486 if (defcadndcurv->get_z()>zmaxdefcad) zmaxdefcad=defcadndcurv->get_z();
487 lstdefcadnoeud.ajouter(defcadndcurv);
488 }
489 OT_VECTEUR_3D vecmindefcad(xmindefcad,ymindefcad,zmindefcad);OT_VECTEUR_3D vecmmaxdefcad(xmaxdefcad,ymaxdefcad,zmaxdefcad);
490 OT_VECTEUR_3D vecdefcad(vecmmaxdefcad,vecmindefcad);
491 OT_VECTEUR_3D mindefcad(xmindefcad,ymindefcad,zmindefcad); OT_VECTEUR_3D maxdefcad(xmaxdefcad,ymaxdefcad,zmaxdefcad); OT_VECTEUR_3D averagedefcad=(mindefcad+maxdefcad)/2.; OT_VECTEUR_3D lengthvecdefcad(mindefcad,maxdefcad);
492 double lengthdefcad=sqrt(lengthvecdefcad*lengthvecdefcad); double bxrdefcad=1.1;
493 xmindefcad=averagedefcad.get_x()-(lengthdefcad*bxrdefcad);ymindefcad=averagedefcad.get_y()-(lengthdefcad*bxrdefcad);zmindefcad=averagedefcad.get_z()-(lengthdefcad*bxrdefcad);
494 xmaxdefcad=averagedefcad.get_x()+(lengthdefcad*bxrdefcad);ymaxdefcad=averagedefcad.get_y()+(lengthdefcad*bxrdefcad);zmaxdefcad=averagedefcad.get_z()+(lengthdefcad*bxrdefcad);
495 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreedefcad;
496 octreedefcad.initialiser(&lstdefcadnoeud,1,xmindefcad,ymindefcad,zmindefcad,xmaxdefcad,ymaxdefcad,zmaxdefcad);
497 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
498 octreedefcad.inserer(defcadndcurv);
499
500 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_cadmgmai;
501 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_cadmgmai;
502 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_cadmgmai;
503 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_defcadmgmai;
504 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_defcadmgmai;
505 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_defcadmgmai;
506 map<MG_NOEUD*,double > lstkmin_cad;
507 map<MG_NOEUD*,double > lstkmax_cad;
508 map<MG_NOEUD*,double > lstkgau_cad;
509 map<MG_NOEUD*,double > lstkmin_defcad;
510 map<MG_NOEUD*,double > lstkmax_defcad;
511 map<MG_NOEUD*,double > lstkgau_defcad;
512 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_cadmgmai;
513 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_cadmgmai;
514 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_cadmgmai;
515 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_defcadmgmai;
516 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_defcadmgmai;
517 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_defcadmgmai;
518 std::map<std::string,double> liste_kmin;
519 std::map<std::string,double> liste_kmax;
520 std::map<std::string,double> liste_gau;
521 std::map<std::string,double> liste_courburemax1;
522 std::map<std::string,double> liste_courburemax2;
523 std::map<std::string,double> liste_courburemax3;
524 std::map<std::string,double> liste_courburemax4;
525 std::map<std::string,double> liste_courburemax5;
526 int opensurafece=1;
527
528 cout<<"calcul courbure cadmgmai"<<endl;
529 // calcul courbure cadmgmai ********************************
530 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
531 {
532 double kmin1=0.;
533 double kmax1=0.;
534 double kmin2=0.;
535 double kmax2=0.;
536 MG_MAILLAGE_OUTILS *cou;
537 cou->calcul_courbure_face_arete_sommet(cadmgnd,kmin1,kmax1,kmin2,kmax2,liste_kmin,liste_kmax,liste_gau,liste_courburemax1,liste_courburemax2,liste_courburemax3,liste_courburemax4,liste_courburemax5,opensurafece);
538 }
539 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
540 {
541
542 unsigned long idface=cadmgnd->get_lien_topologie()->get_id();
543 unsigned long idnoeud=cadmgnd->get_id();
544 char mess[500];
545 sprintf(mess,"%lu_%lu",idnoeud,idface);
546 for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
547 {
548 if(mess==(*itkmin).first)
549 {
550 lstkmin_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,cadmgnd) );
551 lstkmin_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkmin).second));
552 }
553 }
554 for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
555 {
556 if(mess==(*itkmax).first)
557 {
558 lstkmax_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,cadmgnd) );
559 lstkmax_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkmax).second));
560 }
561 }
562 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
563 {
564 if(mess==(*itkgau).first)
565 {
566 lstkgau_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,cadmgnd) );
567 lstkgau_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkgau).second));
568 }
569 }
570 }
571 //calc reletive curvature CAD
572 map<MG_NOEUD*,double >::iterator itlstkmin_cad;
573 map<MG_NOEUD*,double >::iterator itlstkmax_cad;
574 map<MG_NOEUD*,double >::iterator itlstkgau_cad;
575 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
576 {
577 itlstkmin_cad=lstkmin_cad.find(cadmgnd);
578 double relet_kmincad=(*itlstkmin_cad).second;
579 itlstkmax_cad=lstkmax_cad.find(cadmgnd);
580 double relet_kmaxcad=(*itlstkmax_cad).second;
581 itlstkgau_cad=lstkgau_cad.find(cadmgnd);
582 double relet_kgaucad=(*itlstkgau_cad).second;
583 TPL_MAP_ENTITE<MG_NOEUD*> lstnei_relcad;
584 int relcad_neindnb=lstnei_relcad.get_nb();
585 double relet_search_rad1=relet_search_rad;
586 while(relcad_neindnb<1)
587 {
588 octreecad.rechercher(cadmgnd->get_x(),cadmgnd->get_y(),cadmgnd->get_z(),relet_search_rad1,lstnei_relcad);
589 relcad_neindnb=lstnei_relcad.get_nb();
590 relet_search_rad1=relet_search_rad1+0.1*relet_search_rad;
591 }
592 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
593 for(MG_NOEUD* cadndnei=lstnei_relcad.get_premier(itndnei);cadndnei!=NULL;cadndnei=lstnei_relcad.get_suivant(itndnei))
594 {
595 itlstkmin_cad=lstkmin_cad.find(cadndnei);
596 relet_kmincad=relet_kmincad+(*itlstkmin_cad).second;
597 itlstkmax_cad=lstkmax_cad.find(cadndnei);
598 relet_kmaxcad=relet_kmaxcad+(*itlstkmax_cad).second;
599 itlstkgau_cad=lstkgau_cad.find(cadndnei);
600 relet_kgaucad=relet_kgaucad+(*itlstkgau_cad).second;
601 }
602 relet_kmincad=relet_kmincad/lstnei_relcad.get_nb();
603 relet_kmaxcad=relet_kmaxcad/lstnei_relcad.get_nb();
604 relet_kgaucad=relet_kgaucad/lstnei_relcad.get_nb();
605 lstkmin_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmincad,cadmgnd));
606 lstkmax_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmaxcad,cadmgnd));
607 lstkgau_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kgaucad,cadmgnd));
608 }
609 // affichage reletive sur GMSH ******************************
610 if (gmsh_affiche>1)
611 {
612 cout<<"affiche: calcul_courbure_cadmgmai_relet "<<endl;
613 std::ostringstream oss;
614 oss << "calcul_courbure_cadmgmai_curvdif_relet_coef:" <<curvdif_coef ;
615 std::string namefic = oss.str();
616 char *cstr = new char[namefic.length() + 1];
617 strcpy(cstr, namefic.c_str());
618 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
619 gest.ajouter_mg_solution(sol1);
620 sol1->change_legende(0,"Kmin_relet");
621 sol1->change_legende(1,"Kmax_relet");
622 sol1->change_legende(2,"K_gau_relet");
623 LISTE_MG_TRIANGLE::iterator ittri;
624 int compte=0;
625 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
626 {
627 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
628 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
629 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
630 MG_NOEUD *no1=tri->get_noeud1();
631 MG_NOEUD *no2=tri->get_noeud2();
632 MG_NOEUD *no3=tri->get_noeud3();
633 double valeur0;
634 double valeur1;
635 double valeur2;
636 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
637 {
638 if (no1==(*itlstkmin_relt_cadmgmai).second)
639 valeur0=(*itlstkmin_relt_cadmgmai).first;
640 }
641 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
642 {
643 if (no1==(*itlstkmax_relt_cadmgmai).second)
644 valeur1=(*itlstkmax_relt_cadmgmai).first;
645 }
646 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
647 {
648 if (no1==(*itlstkgau_relt_cadmgmai).second)
649 valeur2=(*itlstkgau_relt_cadmgmai).first;
650 }
651 sol1->ecrire(valeur0,compte,0,0);
652 sol1->ecrire(valeur1,compte,1,0);
653 sol1->ecrire(valeur2,compte,2,0);
654 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
655 {
656 if (no2==(*itlstkmin_relt_cadmgmai).second)
657 valeur0=(*itlstkmin_relt_cadmgmai).first;
658 }
659 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
660 {
661 if (no2==(*itlstkmax_relt_cadmgmai).second)
662 valeur1=(*itlstkmax_relt_cadmgmai).first;
663 }
664 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
665 {
666 if (no2==(*itlstkgau_relt_cadmgmai).second)
667 valeur2=(*itlstkgau_relt_cadmgmai).first;
668 }
669 sol1->ecrire(valeur0,compte,0,1);
670 sol1->ecrire(valeur1,compte,1,1);
671 sol1->ecrire(valeur2,compte,2,1);
672 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
673 {
674 if (no3==(*itlstkmin_relt_cadmgmai).second)
675 valeur0=(*itlstkmin_relt_cadmgmai).first;
676 }
677 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
678 {
679 if (no3==(*itlstkmax_relt_cadmgmai).second)
680 valeur1=(*itlstkmax_relt_cadmgmai).first;
681 }
682 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
683 {
684 if (no3==(*itlstkgau_relt_cadmgmai).second)
685 valeur2=(*itlstkgau_relt_cadmgmai).first;
686 }
687 sol1->ecrire(valeur0,compte,0,2);
688 sol1->ecrire(valeur1,compte,1,2);
689 sol1->ecrire(valeur2,compte,2,2);
690 compte++;
691 }
692 }
693 // affichage sur GMSH ******************************
694 if (gmsh_affiche>1)
695 {
696 cout<<"affiche: calcul_courbure_cadmgmai "<<endl;
697 std::ostringstream oss;
698 oss << "calcul_courbure_cadmgmai_curvdif_coef:" <<curvdif_coef ;
699 std::string namefic = oss.str();
700 char *cstr = new char[namefic.length() + 1];
701 strcpy(cstr, namefic.c_str());
702 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
703 gest.ajouter_mg_solution(sol1);
704 sol1->change_legende(0,"Kmin");
705 sol1->change_legende(1,"Kmax");
706 sol1->change_legende(2,"K_gau");
707 LISTE_MG_TRIANGLE::iterator ittri;
708 int compte=0;
709 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
710 {
711 MG_NOEUD *no1=tri->get_noeud1();
712 MG_NOEUD *no2=tri->get_noeud2();
713 MG_NOEUD *no3=tri->get_noeud3();
714 char mess[500];
715 sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
716 double valeur0=liste_kmin[mess];
717 double valeur1=liste_kmax[mess];
718 double valeur2=liste_gau[mess];
719 sol1->ecrire(valeur0,compte,0,0);
720 sol1->ecrire(valeur1,compte,1,0);
721 sol1->ecrire(valeur2,compte,2,0);
722 sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
723 valeur0=liste_kmin[mess];
724 valeur1=liste_kmax[mess];
725 valeur2=liste_gau[mess];
726 sol1->ecrire(valeur0,compte,0,1);
727 sol1->ecrire(valeur1,compte,1,1);
728 sol1->ecrire(valeur2,compte,2,1);
729 sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
730 valeur0=liste_kmin[mess];
731 valeur1=liste_kmax[mess];
732 valeur2=liste_gau[mess];
733 sol1->ecrire(valeur0,compte,0,2);
734 sol1->ecrire(valeur1,compte,1,2);
735 sol1->ecrire(valeur2,compte,2,2);
736 compte++;
737 }
738 }
739 liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
740
741 cout<<"calcul courbure defcadmgmai"<<endl;
742 // calcul courbure defcadmgmai ********************************
743
744 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
745 {
746 double kmin1=0.;
747 double kmax1=0.;
748 double kmin2=0.;
749 double kmax2=0.;
750 MG_MAILLAGE_OUTILS *cou;
751 cou->calcul_courbure_face_arete_sommet(defcadmgnd,kmin1,kmax1,kmin2,kmax2,liste_kmin,liste_kmax,liste_gau,liste_courburemax1,liste_courburemax2,liste_courburemax3,liste_courburemax4,liste_courburemax5,opensurafece);
752 }
753 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
754 {
755 unsigned long idface=defcadmgnd->get_lien_topologie()->get_id();
756 unsigned long idnoeud=defcadmgnd->get_id();
757 char mess[500];
758 sprintf(mess,"%lu_%lu",idnoeud,idface);
759 for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
760 {
761 if(mess==(*itkmin).first)
762 {
763 lstkmin_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,defcadmgnd) );
764 lstkmin_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkmin).second));
765 }
766 }
767 for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
768 {
769 if(mess==(*itkmax).first)
770 {
771 lstkmax_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,defcadmgnd) );
772 lstkmax_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkmax).second));
773 }
774 }
775 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
776 {
777 if(mess==(*itkgau).first)
778 {
779 lstkgau_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,defcadmgnd) );
780 lstkgau_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkgau).second));
781 }
782 }
783 }
784 //calc reletive curvature defCAD
785 map<MG_NOEUD*,double >::iterator itlstkmin_defcad;
786 map<MG_NOEUD*,double >::iterator itlstkmax_defcad;
787 map<MG_NOEUD*,double >::iterator itlstkgau_defcad;
788 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
789 {
790 itlstkmin_defcad=lstkmin_defcad.find(defcadmgnd);
791 double relet_kmindefcad=(*itlstkmin_defcad).second;
792 itlstkmax_defcad=lstkmax_defcad.find(defcadmgnd);
793 double relet_kmaxdefcad=(*itlstkmax_defcad).second;
794 itlstkgau_defcad=lstkgau_cad.find(defcadmgnd);
795 double relet_kgaudefcad=(*itlstkgau_defcad).second;
796 TPL_MAP_ENTITE<MG_NOEUD*> lstnei_reldefcad;
797 int reldefcad_neindnb=lstnei_reldefcad.get_nb();
798 double relet_search_rad1=relet_search_rad;
799 while(reldefcad_neindnb<1)
800 {
801 octreecad.rechercher(defcadmgnd->get_x(),defcadmgnd->get_y(),defcadmgnd->get_z(),relet_search_rad1,lstnei_reldefcad);
802 reldefcad_neindnb=lstnei_reldefcad.get_nb();
803 relet_search_rad1=relet_search_rad1+0.1*relet_search_rad;
804 }
805 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
806 for(MG_NOEUD* defcadndnei=lstnei_reldefcad.get_premier(itndnei);defcadndnei!=NULL;defcadndnei=lstnei_reldefcad.get_suivant(itndnei))
807 {
808 itlstkmin_cad=lstkmin_cad.find(defcadndnei);
809 relet_kmindefcad=relet_kmindefcad+(*itlstkmin_defcad).second;
810 itlstkmax_cad=lstkmax_cad.find(defcadndnei);
811 relet_kmaxdefcad=relet_kmaxdefcad+(*itlstkmax_defcad).second;
812 itlstkgau_cad=lstkgau_cad.find(defcadndnei);
813 relet_kgaudefcad=relet_kgaudefcad+(*itlstkgau_defcad).second;
814 }
815 relet_kmindefcad=relet_kmindefcad/lstnei_reldefcad.get_nb();
816 relet_kmaxdefcad=relet_kmaxdefcad/lstnei_reldefcad.get_nb();
817 relet_kgaudefcad=relet_kgaudefcad/lstnei_reldefcad.get_nb();
818 lstkmin_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmindefcad,defcadmgnd));
819 lstkmax_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmaxdefcad,defcadmgnd));
820 lstkgau_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kgaudefcad,defcadmgnd));
821 }
822 // affichage reletive defcad sur GMSH ******************************
823 if (gmsh_affiche>1)
824 {
825 cout<<"affiche: calcul_courbure_cadmgmai_relet "<<endl;
826 std::ostringstream oss;
827 oss << "calcul_courbure_cadmgmai_curvdif_relet_coef:" <<curvdif_coef ;
828 std::string namefic = oss.str();
829 char *cstr = new char[namefic.length() + 1];
830 strcpy(cstr, namefic.c_str());
831 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
832 gest.ajouter_mg_solution(sol1);
833 sol1->change_legende(0,"Kmin_relet");
834 sol1->change_legende(1,"Kmax_relet");
835 sol1->change_legende(2,"K_gau_relet");
836 LISTE_MG_TRIANGLE::iterator ittri;
837 int compte=0;
838 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
839 {
840 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
841 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
842 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
843 MG_NOEUD *no1=tri->get_noeud1();
844 MG_NOEUD *no2=tri->get_noeud2();
845 MG_NOEUD *no3=tri->get_noeud3();
846 double valeur0;
847 double valeur1;
848 double valeur2;
849 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
850 {
851 if (no1==(*itlstkmin_relt_cadmgmai).second)
852 valeur0=(*itlstkmin_relt_cadmgmai).first;
853 }
854 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
855 {
856 if (no1==(*itlstkmax_relt_cadmgmai).second)
857 valeur1=(*itlstkmax_relt_cadmgmai).first;
858 }
859 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
860 {
861 if (no1==(*itlstkgau_relt_cadmgmai).second)
862 valeur2=(*itlstkgau_relt_cadmgmai).first;
863 }
864 sol1->ecrire(valeur0,compte,0,0);
865 sol1->ecrire(valeur1,compte,1,0);
866 sol1->ecrire(valeur2,compte,2,0);
867 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
868 {
869 if (no2==(*itlstkmin_relt_cadmgmai).second)
870 valeur0=(*itlstkmin_relt_cadmgmai).first;
871 }
872 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
873 {
874 if (no2==(*itlstkmax_relt_cadmgmai).second)
875 valeur1=(*itlstkmax_relt_cadmgmai).first;
876 }
877 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
878 {
879 if (no2==(*itlstkgau_relt_cadmgmai).second)
880 valeur2=(*itlstkgau_relt_cadmgmai).first;
881 }
882 sol1->ecrire(valeur0,compte,0,1);
883 sol1->ecrire(valeur1,compte,1,1);
884 sol1->ecrire(valeur2,compte,2,1);
885 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
886 {
887 if (no3==(*itlstkmin_relt_cadmgmai).second)
888 valeur0=(*itlstkmin_relt_cadmgmai).first;
889 }
890 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
891 {
892 if (no3==(*itlstkmax_relt_cadmgmai).second)
893 valeur1=(*itlstkmax_relt_cadmgmai).first;
894 }
895 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
896 {
897 if (no3==(*itlstkgau_relt_cadmgmai).second)
898 valeur2=(*itlstkgau_relt_cadmgmai).first;
899 }
900 sol1->ecrire(valeur0,compte,0,2);
901 sol1->ecrire(valeur1,compte,1,2);
902 sol1->ecrire(valeur2,compte,2,2);
903 compte++;
904 }
905 }
906 // affichage sur GMSH ******************************
907 if (gmsh_affiche>1)
908 {
909 cout<<"affiche: calcul_courbure_defcadmgmai "<<endl;
910 std::ostringstream oss;
911 oss << "calcul_courbure_defcadmgmai_curvdif_coef:" <<curvdif_coef ;
912 std::string namefic = oss.str();
913 char *cstr = new char[namefic.length() + 1];
914 strcpy(cstr, namefic.c_str());
915 MG_SOLUTION* sol2=new MG_SOLUTION(defcadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
916 gest.ajouter_mg_solution(sol2);
917 sol2->change_legende(0,"Kmin");
918 sol2->change_legende(1,"Kmax");
919 sol2->change_legende(2,"K_gau");
920 LISTE_MG_TRIANGLE::iterator ittri;
921 int compte=0;
922 for (MG_TRIANGLE* tri=defcadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=defcadmgmai->get_suivant_triangle(ittri))
923 {
924 MG_NOEUD *no1=tri->get_noeud1();
925 MG_NOEUD *no2=tri->get_noeud2();
926 MG_NOEUD *no3=tri->get_noeud3();
927 char mess[500];
928 sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
929 double valeur0=liste_kmin[mess];
930 double valeur1=liste_kmax[mess];
931 double valeur2=liste_gau[mess];
932 sol2->ecrire(valeur0,compte,0,0);
933 sol2->ecrire(valeur1,compte,1,0);
934 sol2->ecrire(valeur2,compte,2,0);
935 sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
936 valeur0=liste_kmin[mess];
937 valeur1=liste_kmax[mess];
938 valeur2=liste_gau[mess];
939 sol2->ecrire(valeur0,compte,0,1);
940 sol2->ecrire(valeur1,compte,1,1);
941 sol2->ecrire(valeur2,compte,2,1);
942 sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
943 valeur0=liste_kmin[mess];
944 valeur1=liste_kmax[mess];
945 valeur2=liste_gau[mess];
946 sol2->ecrire(valeur0,compte,0,2);
947 sol2->ecrire(valeur1,compte,1,2);
948 sol2->ecrire(valeur2,compte,2,2);
949 compte++;
950 }
951
952 }
953 liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
954
955
956 ///make correspondence between cadmgmai and defcadmgmai nodes
957 map<unsigned long, unsigned long>::iterator itcoresspondndidlst;
958 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
959 {
960 itcoresspondndidlst=coresspondndidlst.find(defcadndcurv->get_id());
961 defcadndcurv->change_nouveau_numero((*itcoresspondndidlst).second);
962 }
963
964 cout<<"solution calculation"<<endl;
965 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_diff;
966 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_diff;
967 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_diff;
968 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_cadmgmai;
969 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_cadmgmai;
970 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_cadmgmai;
971 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_defcadmgmai;
972 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_defcadmgmai;
973 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_defcadmgmai;
974 cout<<"lstkmin_cadmgmai.size()= "<<lstkmin_cadmgmai.size()<<endl;
975 cout<<"lstkmin_defcadmgmai.size()= "<<lstkmin_defcadmgmai.size()<<endl;
976 cout<<"kmin diff. calc. started"<<endl;
977
978 for(itlstkmin_cadmgmai=lstkmin_cadmgmai.begin();itlstkmin_cadmgmai!=lstkmin_cadmgmai.end();itlstkmin_cadmgmai++)
979 {
980 MG_NOEUD* cadndcurv=(*itlstkmin_cadmgmai).second;
981 double kmindcad;
982 double kmindcad_def;
983 kmindcad=(*itlstkmin_cadmgmai).first;
984 for(itlstkmin_defcadmgmai=lstkmin_defcadmgmai.begin();itlstkmin_defcadmgmai!=lstkmin_defcadmgmai.end();itlstkmin_defcadmgmai++)
985 {
986 MG_NOEUD* defcadndcurv=(*itlstkmin_defcadmgmai).second;
987 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
988 kmindcad_def=(*itlstkmin_defcadmgmai).first;
989 }
990
991 double kmin_diff=kmindcad_def-kmindcad;
992 lstkmin_diff.insert(pair<double,MG_NOEUD*>(kmin_diff,cadndcurv) );
993 }
994 cout<<"kmax diff. calc. started"<<endl;
995 for(itlstkmax_cadmgmai=lstkmax_cadmgmai.begin();itlstkmax_cadmgmai!=lstkmax_cadmgmai.end();itlstkmax_cadmgmai++)
996 {
997 MG_NOEUD* cadndcurv=(*itlstkmax_cadmgmai).second;
998 double kmaxndcad;
999 double kmaxndcad_def;
1000 kmaxndcad=(*itlstkmax_cadmgmai).first;
1001 for(itlstkmax_defcadmgmai=lstkmax_defcadmgmai.begin();itlstkmax_defcadmgmai!=lstkmax_defcadmgmai.end();itlstkmax_defcadmgmai++)
1002 {
1003 MG_NOEUD* defcadndcurv=(*itlstkmax_defcadmgmai).second;
1004 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1005 {
1006 kmaxndcad_def=(*itlstkmax_defcadmgmai).first;
1007 }
1008 }
1009 double kmax_diff=kmaxndcad_def-kmaxndcad;
1010 lstkmax_diff.insert(pair<double,MG_NOEUD*>(kmax_diff,cadndcurv) );
1011 }
1012 cout<<"kgau diff. calc. started"<<endl;
1013 for(itlstkgau_cadmgmai=lstkgau_cadmgmai.begin();itlstkgau_cadmgmai!=lstkgau_cadmgmai.end();itlstkgau_cadmgmai++)
1014 {
1015 MG_NOEUD* cadndcurv=(*itlstkgau_cadmgmai).second;
1016 double kgaundcad;
1017 double kgaundcad_def;
1018 kgaundcad=(*itlstkgau_cadmgmai).first;
1019 for(itlstkgau_defcadmgmai=lstkgau_defcadmgmai.begin();itlstkgau_defcadmgmai!=lstkgau_defcadmgmai.end();itlstkgau_defcadmgmai++)
1020 {
1021 MG_NOEUD* defcadndcurv=(*itlstkgau_defcadmgmai).second;
1022 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1023 {
1024 kgaundcad_def=(*itlstkgau_defcadmgmai).first;
1025 }
1026 }
1027 double kgau_diff=kgaundcad_def-kgaundcad;
1028 lstkgau_diff.insert(pair<double,MG_NOEUD*>(kgau_diff,cadndcurv) );
1029 }
1030 // mean diff
1031 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_diff;
1032 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_diff;
1033 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_diff;
1034 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
1035 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
1036 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
1037 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_defcadmgmai;
1038 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_defcadmgmai;
1039 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_defcadmgmai;
1040 cout<<"kmin _relt diff. calc. started"<<endl;
1041 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
1042 {
1043 MG_NOEUD* cadndcurv=(*itlstkmin_relt_cadmgmai).second;
1044 double kmindcad;
1045 double kmindcad_relt_def;
1046 kmindcad=(*itlstkmin_relt_cadmgmai).first;
1047 for(itlstkmin_relt_defcadmgmai=lstkmin_relt_defcadmgmai.begin();itlstkmin_relt_defcadmgmai!=lstkmin_relt_defcadmgmai.end();itlstkmin_relt_defcadmgmai++)
1048 {
1049 MG_NOEUD* defcadndcurv=(*itlstkmin_relt_defcadmgmai).second;
1050 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1051 kmindcad_relt_def=(*itlstkmin_relt_defcadmgmai).first;
1052 }
1053
1054 double kmin_relt_diff=kmindcad_relt_def-kmindcad;
1055 lstkmin_relt_diff.insert(pair<double,MG_NOEUD*>(kmin_relt_diff,cadndcurv) );
1056 }
1057 cout<<"kmax _relt diff. calc. started"<<endl;
1058 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
1059 {
1060 MG_NOEUD* cadndcurv=(*itlstkmax_relt_cadmgmai).second;
1061 double kmaxndcad;
1062 double kmaxndcad_relt_def;
1063 kmaxndcad=(*itlstkmax_relt_cadmgmai).first;
1064 for(itlstkmax_relt_defcadmgmai=lstkmax_relt_defcadmgmai.begin();itlstkmax_relt_defcadmgmai!=lstkmax_relt_defcadmgmai.end();itlstkmax_relt_defcadmgmai++)
1065 {
1066 MG_NOEUD* defcadndcurv=(*itlstkmax_relt_defcadmgmai).second;
1067 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1068 {
1069 kmaxndcad_relt_def=(*itlstkmax_relt_defcadmgmai).first;
1070 }
1071 }
1072 double kmax_relt_diff=kmaxndcad_relt_def-kmaxndcad;
1073 lstkmax_relt_diff.insert(pair<double,MG_NOEUD*>(kmax_relt_diff,cadndcurv) );
1074 }
1075 cout<<"kgau_relt diff. calc. started"<<endl;
1076 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
1077 {
1078 MG_NOEUD* cadndcurv=(*itlstkgau_relt_cadmgmai).second;
1079 double kgaundcad;
1080 double kgaundcad_relt_def;
1081 kgaundcad=(*itlstkgau_relt_cadmgmai).first;
1082 for(itlstkgau_relt_defcadmgmai=lstkgau_relt_defcadmgmai.begin();itlstkgau_relt_defcadmgmai!=lstkgau_relt_defcadmgmai.end();itlstkgau_relt_defcadmgmai++)
1083 {
1084 MG_NOEUD* defcadndcurv=(*itlstkgau_relt_defcadmgmai).second;
1085 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1086 {
1087 kgaundcad_relt_def=(*itlstkgau_relt_defcadmgmai).first;
1088 }
1089 }
1090 double kgau_relt_diff=kgaundcad_relt_def-kgaundcad;
1091 lstkgau_relt_diff.insert(pair<double,MG_NOEUD*>(kgau_relt_diff,cadndcurv) );
1092 }
1093 // affichage reletive diff sur GMSH ******************************
1094 if (gmsh_affiche>0)
1095 {
1096 cout<<"affiche: calcul_relet_difference_courbure "<<endl;
1097 std::ostringstream oss;
1098 oss << "KMaxMinGaudiff_curvdifcoef_relet:" <<curvdif_coef ;
1099 std::string namefic = oss.str();
1100 char *cstr = new char[namefic.length() + 1];
1101 strcpy(cstr, namefic.c_str());
1102 MG_SOLUTION* sol4=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"Kdiff_relt_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1103 gest.ajouter_mg_solution(sol4);
1104 sol4->change_legende(0,"Kmin_diff");
1105 sol4->change_legende(1,"Kmax_diff");
1106 sol4->change_legende(2,"Kgau_diff");
1107 LISTE_MG_TRIANGLE::iterator ittri;
1108 int compte=0;
1109 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
1110 {
1111 MG_NOEUD *no1=tri->get_noeud1();
1112 MG_NOEUD *no2=tri->get_noeud2();
1113 MG_NOEUD *no3=tri->get_noeud3();
1114 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diff;
1115 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diff;
1116 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_diff;
1117 double valeurKmin1, valeurKmin2, valeurKmin3;
1118 double valeurKmax1, valeurKmax2, valeurKmax3;
1119 double valeurKgau1, valeurKgau2, valeurKgau3;
1120 for (itlstkmin_relt_diff=lstkmin_relt_diff.begin();itlstkmin_relt_diff!=lstkmin_relt_diff.end();itlstkmin_relt_diff++)
1121 {
1122 if (no1==(*itlstkmin_relt_diff).second)
1123 valeurKmin1=(*itlstkmin_relt_diff).first;
1124 if (no2==(*itlstkmin_relt_diff).second)
1125 valeurKmin2=(*itlstkmin_relt_diff).first;
1126 if (no3==(*itlstkmin_relt_diff).second)
1127 valeurKmin3=(*itlstkmin_relt_diff).first;
1128 }
1129 for (itlstkmax_relt_diff=lstkmax_relt_diff.begin();itlstkmax_relt_diff!=lstkmax_relt_diff.end();itlstkmax_relt_diff++)
1130 {
1131 if (no1==(*itlstkmax_relt_diff).second)
1132 valeurKmax1=(*itlstkmax_relt_diff).first;
1133 if (no2==(*itlstkmax_relt_diff).second)
1134 valeurKmax2=(*itlstkmax_relt_diff).first;
1135 if (no3==(*itlstkmax_relt_diff).second)
1136 valeurKmax3=(*itlstkmax_relt_diff).first;
1137 }
1138 for (itlstkgau_relt_diff=lstkgau_relt_diff.begin();itlstkgau_relt_diff!=lstkgau_relt_diff.end();itlstkgau_relt_diff++)
1139 {
1140 if (no1==(*itlstkgau_relt_diff).second)
1141 valeurKgau1=(*itlstkgau_relt_diff).first;
1142 if (no2==(*itlstkgau_relt_diff).second)
1143 valeurKgau2=(*itlstkgau_relt_diff).first;
1144 if (no3==(*itlstkgau_relt_diff).second)
1145 valeurKgau3=(*itlstkgau_relt_diff).first;
1146 }
1147 sol4->ecrire(valeurKmin1,compte,0,0);
1148 sol4->ecrire(valeurKmax1,compte,1,0);
1149 sol4->ecrire(valeurKgau1,compte,2,0);
1150
1151 sol4->ecrire(valeurKmin2,compte,0,1);
1152 sol4->ecrire(valeurKmax2,compte,1,1);
1153 sol4->ecrire(valeurKgau2,compte,2,1);
1154
1155 sol4->ecrire(valeurKmin3,compte,0,2);
1156 sol4->ecrire(valeurKmax3,compte,1,2);
1157 sol4->ecrire(valeurKgau3,compte,2,2);
1158 compte++;
1159 }
1160 }
1161
1162 // affichage sur GMSH ******************************
1163 if (gmsh_affiche>1)
1164 {
1165 cout<<"affiche: calcul_difference_courbure "<<endl;
1166 std::ostringstream oss;
1167 oss << "KMaxMinGaudiff_curvdifcoef:" <<curvdif_coef ;
1168 std::string namefic = oss.str();
1169 char *cstr = new char[namefic.length() + 1];
1170 strcpy(cstr, namefic.c_str());
1171 MG_SOLUTION* sol3=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"Kdiff_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1172 gest.ajouter_mg_solution(sol3);
1173 sol3->change_legende(0,"Kmin_diff");
1174 sol3->change_legende(1,"Kmax_diff");
1175 sol3->change_legende(2,"Kgau_diff");
1176 LISTE_MG_TRIANGLE::iterator ittri;
1177 int compte=0;
1178 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
1179 {
1180 MG_NOEUD *no1=tri->get_noeud1();
1181 MG_NOEUD *no2=tri->get_noeud2();
1182 MG_NOEUD *no3=tri->get_noeud3();
1183 //char mess[500];
1184 //sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
1185 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff;
1186 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff;
1187 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_diff;
1188 double valeurKmin1, valeurKmin2, valeurKmin3;
1189 double valeurKmax1, valeurKmax2, valeurKmax3;
1190 double valeurKgau1, valeurKgau2, valeurKgau3;
1191 for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
1192 {
1193 if (no1==(*itlstkmin_diff).second)
1194 valeurKmin1=(*itlstkmin_diff).first;
1195 if (no2==(*itlstkmin_diff).second)
1196 valeurKmin2=(*itlstkmin_diff).first;
1197 if (no3==(*itlstkmin_diff).second)
1198 valeurKmin3=(*itlstkmin_diff).first;
1199 }
1200 for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
1201 {
1202 if (no1==(*itlstkmax_diff).second)
1203 valeurKmax1=(*itlstkmax_diff).first;
1204 if (no2==(*itlstkmax_diff).second)
1205 valeurKmax2=(*itlstkmax_diff).first;
1206 if (no3==(*itlstkmax_diff).second)
1207 valeurKmax3=(*itlstkmax_diff).first;
1208 }
1209 for (itlstkgau_diff=lstkgau_diff.begin();itlstkgau_diff!=lstkgau_diff.end();itlstkgau_diff++)
1210 {
1211 if (no1==(*itlstkgau_diff).second)
1212 valeurKgau1=(*itlstkgau_diff).first;
1213 if (no2==(*itlstkgau_diff).second)
1214 valeurKgau2=(*itlstkgau_diff).first;
1215 if (no3==(*itlstkgau_diff).second)
1216 valeurKgau3=(*itlstkgau_diff).first;
1217 }
1218 sol3->ecrire(valeurKmin1,compte,0,0);
1219 sol3->ecrire(valeurKmax1,compte,1,0);
1220 sol3->ecrire(valeurKgau1,compte,2,0);
1221
1222 sol3->ecrire(valeurKmin2,compte,0,1);
1223 sol3->ecrire(valeurKmax2,compte,1,1);
1224 sol3->ecrire(valeurKgau2,compte,2,1);
1225
1226 sol3->ecrire(valeurKmin3,compte,0,2);
1227 sol3->ecrire(valeurKmax3,compte,1,2);
1228 sol3->ecrire(valeurKgau3,compte,2,2);
1229 compte++;
1230 }
1231
1232 }
1233
1234 char chaine[1000];
1235 char* p;
1236 p=strrchr(magicfilename,'.');
1237 strncpy(chaine,magicfilename,p-magicfilename);
1238 std::string namfic=chaine;
1239 namfic=namfic + "courbcal.magic";
1240 gest.enregistrer(namfic.c_str());
1241 cout<<"read insert points in lstpinsert"<<endl;
1242 //read insert points in lstpinsert
1243 std::vector<double*> lstpinsert;
1244 double prop=0.001;
1245 FILE *in=fopen(gnifinspointfile,"rt");
1246 if (in==NULL) cout<<"file is not available"<<endl;
1247 while (!feof(in))
1248 {
1249 char chaine[500];
1250 char* res=fgets(chaine,500,in);
1251 if(res!=NULL)
1252 {
1253 double x,y,z;
1254 double q1,q2,q3;
1255 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
1256 q1=prop*q1;
1257 q2=prop*q2;
1258 q3=prop*q3;
1259 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
1260 else if (nb==6)
1261 {
1262 double* pcoordbc=new double[6];
1263 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
1264 lstpinsert.push_back(pcoordbc);
1265 }
1266 }
1267 }
1268 fclose(in);
1269 if (relet_curvature<1)
1270 {
1271 //criterion
1272 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_diff=lstkmin_diff.rbegin();
1273 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_diff=lstkmax_diff.rbegin();
1274 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff=lstkmin_diff.begin();
1275 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff=lstkmax_diff.begin();
1276 double kmin_diff_min=(*ritlstkmin_diff).first;
1277 double kmin_diff_max=(*itlstkmin_diff).first;
1278 double kmax_diff_min=(*ritlstkmax_diff).first;
1279 double kmax_diff_max=(*itlstkmax_diff).first;
1280 cout<<"kmin_diff_min= "<<kmin_diff_min<<" kmin_diff_max= "<<kmin_diff_max<<endl;
1281 cout<<"kmax_diff_min= "<<kmax_diff_min<<" kmax_diff_max= "<<kmax_diff_max<<endl;
1282
1283 double crikmin_min=curvdif_coef*kmin_diff_min;
1284 double crikmin_max=curvdif_coef*kmin_diff_max;
1285 double crikmax_min=curvdif_coef*kmax_diff_min;
1286 double crikmax_max=curvdif_coef*kmax_diff_max;
1287 cout<<"crikmin_min= "<<crikmin_min<<" crikmin_max= "<<crikmin_max<<" crikmax_min= "<<crikmax_min<<" crikmax_max= "<<crikmax_max<<endl;
1288 cout<<"lstkmin_diff.size()= "<<lstkmin_diff.size()<<endl;
1289 cout<<"lstkmax_diff.size()= "<<lstkmax_diff.size()<<endl;
1290
1291 cout<<"for Kmin"<<endl;
1292 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1293 for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
1294 {
1295 {
1296 if((crikmin_max<(*itlstkmin_diff).first) || (crikmin_min>(*itlstkmin_diff).first))
1297 {
1298 MG_NOEUD* piefect=(*itlstkmin_diff).second;
1299 int neindnb=lstneipdefect.get_nb();
1300 double search_radius1=search_radius;
1301 while(neindnb==0)
1302 {
1303 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1304 neindnb=lstneipdefect.get_nb();
1305 search_radius1=search_radius1+0.1*search_radius;
1306 }
1307 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1308 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1309 {
1310 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1311 {
1312 double* xyzpins;
1313 xyzpins=(*itlstpinsert);
1314 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1315 lstpinsert.erase(itlstpinsert);
1316 }
1317 }
1318 lstneipdefect.vide();
1319 }
1320 }
1321 }
1322 cout<<"for Kmax"<<endl;
1323 for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
1324 {
1325 if((crikmax_max<(*itlstkmax_diff).first) || (crikmax_min>(*itlstkmax_diff).first))
1326 {
1327 MG_NOEUD* piefect=(*itlstkmax_diff).second;
1328 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1329 int neindnb=lstneipdefect.get_nb();
1330 double search_radius1=search_radius;
1331 while(neindnb==0)
1332 {
1333 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1334 neindnb=lstneipdefect.get_nb();
1335 search_radius1=search_radius1+0.1*search_radius;
1336 }
1337 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1338 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1339 {
1340 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1341 {
1342 double* xyzpins;
1343 xyzpins=(*itlstpinsert);
1344 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1345 lstpinsert.erase(itlstpinsert);
1346 }
1347 }
1348
1349 }
1350 }
1351 }
1352 if (relet_curvature>0)
1353 {
1354 //criterion
1355 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_relt_diff=lstkmin_relt_diff.rbegin();
1356 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_relt_diff=lstkmax_relt_diff.rbegin();
1357 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diff=lstkmin_relt_diff.begin();
1358 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diff=lstkmax_relt_diff.begin();
1359 double kmin_relt_diff_min=(*ritlstkmin_relt_diff).first;
1360 double kmin_relt_diff_max=(*itlstkmin_relt_diff).first;
1361 double kmax_relt_diff_min=(*ritlstkmax_relt_diff).first;
1362 double kmax_relt_diff_max=(*itlstkmax_relt_diff).first;
1363 cout<<"kmin_relt_diff_min= "<<kmin_relt_diff_min<<" kmin_relt_diff_max= "<<kmin_relt_diff_max<<endl;
1364 cout<<"kmax_relt_diff_min= "<<kmax_relt_diff_min<<" kmax_relt_diff_max= "<<kmax_relt_diff_max<<endl;
1365 /*
1366 double crikmin_min=curvdif_coef*kmin_relt_diff_min;
1367 double crikmin_max=curvdif_coef*kmin_relt_diff_max;
1368 double crikmax_min=curvdif_coef*kmax_relt_diff_min;
1369 double crikmax_max=curvdif_coef*kmax_relt_diff_max;*/
1370 double crikmin_min=-curvdif_coef;
1371 double crikmin_max=curvdif_coef;
1372 double crikmax_min=-curvdif_coef;
1373 double crikmax_max=curvdif_coef;
1374
1375 cout<<"crikmin_min= "<<crikmin_min<<" crikmin_max= "<<crikmin_max<<" crikmax_min= "<<crikmax_min<<" crikmax_max= "<<crikmax_max<<endl;
1376 cout<<"lstkmin_diff.size()= "<<lstkmin_diff.size()<<endl;
1377 cout<<"lstkmax_diff.size()= "<<lstkmax_diff.size()<<endl;
1378
1379 cout<<"for Kmin_relet_diff"<<endl;
1380 cout<<"lstkmin_relt_diff.size()= "<<lstkmin_relt_diff.size()<<endl;
1381 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1382 for (itlstkmin_relt_diff=lstkmin_relt_diff.begin();itlstkmin_relt_diff!=lstkmin_relt_diff.end();itlstkmin_relt_diff++)
1383 {
1384 {
1385 if((crikmin_max<(*itlstkmin_relt_diff).first) || (crikmin_min>(*itlstkmin_relt_diff).first))
1386 {
1387 MG_NOEUD* piefect=(*itlstkmin_relt_diff).second;
1388 int neindnb=lstneipdefect.get_nb();
1389 double search_radius1=search_radius;
1390 while(neindnb==0)
1391 {
1392 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1393 neindnb=lstneipdefect.get_nb();
1394 search_radius1=search_radius1+0.1*search_radius;
1395 }
1396 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1397 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1398 {
1399 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1400 {
1401 double* xyzpins;
1402 xyzpins=(*itlstpinsert);
1403
1404 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1405 {
1406 lstpinsert.erase(itlstpinsert);
1407 itlstpinsert=lstpinsert.begin();
1408 }
1409
1410 }
1411 }
1412 lstneipdefect.vide();
1413 }
1414 }
1415 }
1416 cout<<"for Kmax_relet_diff"<<endl;
1417
1418 for (itlstkmax_relt_diff=lstkmax_relt_diff.begin();itlstkmax_relt_diff!=lstkmax_relt_diff.end();itlstkmax_relt_diff++)
1419 {
1420 if((crikmax_max<(*itlstkmax_relt_diff).first) || (crikmax_min>(*itlstkmax_relt_diff).first))
1421 {
1422 MG_NOEUD* piefect=(*itlstkmax_relt_diff).second;
1423 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1424 int neindnb=lstneipdefect.get_nb();
1425 double search_radius1=search_radius;
1426 while(neindnb==0)
1427 {
1428 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1429 neindnb=lstneipdefect.get_nb();
1430 search_radius1=search_radius1+0.1*search_radius;
1431 }
1432 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1433 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1434 {
1435 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1436 {
1437 double* xyzpins;
1438 xyzpins=(*itlstpinsert);
1439 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1440 {
1441 lstpinsert.erase(itlstpinsert);
1442 itlstpinsert=lstpinsert.begin();
1443 }
1444 }
1445 }
1446
1447 }
1448 }
1449 }
1450 FILE* in2=fopen(out_gnifinspointfile_removondefect,"wt");
1451 int countfuck=0;
1452 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1453 {
1454 double* xyzpins1;
1455 xyzpins1=(*itlstpinsert);
1456 fprintf(in2,"%le %le %le %le %le %le\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
1457 }
1458 fclose(in2);
1459 }
1460 void CRIAQOPERATORS::vm_crit_remvsmp(int femmeshno,char* magicfilename,int femsolid,int femsubsolno,char* gnifinspointfile,char* out_gnifinspointfile_removondefect,double search_radius,double vm_coef)
1461 {
1462 MG_FILE gest(magicfilename);
1463 FEM_MAILLAGE* femmai;
1464 if (femmeshno==0) femmai=gest.get_fem_maillage(femmeshno); else femmai=gest.get_fem_maillageid(femmeshno);
1465 FEM_SOLUTION* femsol=gest.get_fem_solutionid(femsolid);
1466 femsol->active_solution(femsubsolno);
1467
1468 std::map<double,FEM_NOEUD*,std::greater<double> > mpsol;
1469 LISTE_FEM_NOEUD::iterator itfemnds;
1470 for(FEM_NOEUD* nod=femmai->get_premier_noeud(itfemnds);nod!=NULL;nod=femmai->get_suivant_noeud(itfemnds))
1471 {
1472 nod->get_mg_element_maillage()->get_id();
1473 mpsol.insert(pair<double,FEM_NOEUD*> (nod->get_solution(),nod));
1474 //cout<<"nod->get_solution()= "<<nod->get_solution()<<endl;
1475 //if(nod->get_solution()<=1.e-20 && nod->get_solution()!=0.)
1476 //cout<<nod->get_id()<<" : "<<nod->get_solution()<<endl;
1477 }
1478 std::map<double,FEM_NOEUD*,std::greater<double> >::iterator itmpsol=mpsol.begin();
1479
1480 double maxi=(*itmpsol).first;
1481 itmpsol=mpsol.end();
1482 double mini=(*itmpsol).first;
1483 //double crit=vm_coef*(maxi+mini)/2.;
1484 double crit=vm_coef;
1485 cout<<"critreion value= "<<crit<<endl;
1486 std::vector<double*> lstpinsert;
1487 double prop=0.001;
1488 FILE *in=fopen(gnifinspointfile,"rt");
1489 if (in==NULL) cout<<"file is not available"<<endl;
1490 while (!feof(in))
1491 {
1492 char chaine[500];
1493 char* res=fgets(chaine,500,in);
1494 if(res!=NULL)
1495 {
1496 double x,y,z;
1497 double q1,q2,q3;
1498 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
1499 q1=prop*q1;
1500 q2=prop*q2;
1501 q3=prop*q3;
1502 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
1503 else if (nb==6)
1504 {
1505 double* pcoordbc=new double[6];
1506 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
1507 lstpinsert.push_back(pcoordbc);
1508 }
1509 }
1510 }
1511 fclose(in);
1512
1513
1514 //octree initialization
1515 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
1516 TPL_MAP_ENTITE<FEM_NOEUD*> lstnoeud;
1517 LISTE_FEM_NOEUD::iterator it;
1518 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
1519 {
1520 if (no->get_x()<xmin) xmin=no->get_x();
1521 if (no->get_y()<ymin) ymin=no->get_y();
1522 if (no->get_z()<zmin) zmin=no->get_z();
1523 if (no->get_x()>xmax) xmax=no->get_x();
1524 if (no->get_y()>ymax) ymax=no->get_y();
1525 if (no->get_z()>zmax) zmax=no->get_z();
1526 lstnoeud.ajouter(no);
1527 }
1528 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
1529 OT_VECTEUR_3D vec(vecmmax,vecmin);
1530
1531 //double search_radius=0.001*(vec.get_longueur());
1532 //double search_radius=2.; //sasan this should be as a parameter
1533 OT_VECTEUR_3D min(xmin,ymin,zmin); OT_VECTEUR_3D max(xmax,ymax,zmax); OT_VECTEUR_3D average=(min+max)/2.; OT_VECTEUR_3D lengthvec(min,max);
1534 double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
1535 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
1536 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
1537
1538 TPL_OCTREE<FEM_NOEUD*,FEM_NOEUD*> octree;
1539 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
1540 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
1541 octree.inserer(no);
1542
1543 for (itmpsol=mpsol.begin();itmpsol!=mpsol.end();itmpsol++)
1544 {
1545 if(crit<(*itmpsol).first)
1546 {
1547 FEM_NOEUD* pdefect=(*itmpsol).second;
1548 TPL_MAP_ENTITE<FEM_NOEUD*> lstneipdefect;
1549 int neindnb=lstneipdefect.get_nb();
1550 double search_radius1=search_radius;
1551 while(neindnb==0)
1552 {
1553 octree.rechercher(pdefect->get_x(),pdefect->get_y(),pdefect->get_z(),search_radius1,lstneipdefect);
1554 neindnb=lstneipdefect.get_nb();
1555 search_radius1=search_radius1+0.1*search_radius;
1556 }
1557 TPL_MAP_ENTITE<FEM_NOEUD*>::ITERATEUR itfendnei;
1558 for(FEM_NOEUD* fendnei=lstneipdefect.get_premier(itfendnei);fendnei!=NULL;fendnei=lstneipdefect.get_suivant(itfendnei))
1559 {
1560 // std::map<double*,double*,std::less<double*> >::iterator itlstpinsert=lstpinsert.begin();//itlstpinsert!=lstpinsert.end();itlstpinsert++
1561 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1562 {
1563 double* xyzpins;
1564 xyzpins=(*itlstpinsert);
1565 if(fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2])
1566 {
1567 lstpinsert.erase(itlstpinsert);
1568 itlstpinsert=lstpinsert.begin();
1569 }
1570 }
1571 }
1572
1573 }
1574
1575 }
1576
1577 FILE* in1=fopen(out_gnifinspointfile_removondefect,"wt");
1578 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1579 {
1580 double* xyzpins1;
1581 xyzpins1=(*itlstpinsert);
1582 fprintf(in1,"%le %le %le %le %le %le\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
1583 }
1584 fclose(in1);
1585 }
1586 void CRIAQOPERATORS::surfmaker_e1(char* outputfilename,int meshno,char* magicfilename)
1587 {
1588 MG_FILE gest(magicfilename);
1589 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1590 MG_MAILLAGE* mai;
1591 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1592 //MG_FILE gest((char*)"longflxprtwithpockets_3d_3mm.magic");
1593 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1594 //MG_MAILLAGE* mai=gest.get_mg_maillageid(5674824);
1595 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1596 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1597 gestnew->ajouter_mg_geometrie(geonew);
1598 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1599 gestnew->ajouter_mg_maillage(mainew);
1600
1601 LISTE_MG_NOEUD::iterator itnod;
1602 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1603 {
1604 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1605 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1606 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1607 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1608
1609 if(facevert->get_id()==76
1610 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
1611 || aretver->get_id()==81 || aretver->get_id()==83 || aretver->get_id()==10|| aretver->get_id()==12|| aretver->get_id()==90|| aretver->get_id()==97
1612 /* facevert->get_id()==133
1613 || aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
1614 || aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
1615 || aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
1616 || aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
1617 || aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
1618 || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
1619 || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
1620 || sometver->get_id()==368|| sometver->get_id()==361|| sometver->get_id()==106|| sometver->get_id()==122|| sometver->get_id()==74|| sometver->get_id()==90
1621 || sometver->get_id()==233|| sometver->get_id()==240|| sometver->get_id()==247|| sometver->get_id()==254|| sometver->get_id()==261|| sometver->get_id()==268
1622 || sometver->get_id()==226|| sometver->get_id()==224|| sometver->get_id()==190|| sometver->get_id()==197|| sometver->get_id()==204|| sometver->get_id()==211
1623 || sometver->get_id()==183|| sometver->get_id()==181|| sometver->get_id()==154|| sometver->get_id()==147|| sometver->get_id()==140|| sometver->get_id()==161
1624 || sometver->get_id()==168|| sometver->get_id()==138|| sometver->get_id()==318|| sometver->get_id()==311|| sometver->get_id()==304|| sometver->get_id()==297
1625 || sometver->get_id()==325|| sometver->get_id()==332|| sometver->get_id()==290|| sometver->get_id()==288|| sometver->get_id()==42|| sometver->get_id()==58
1626 || sometver->get_id()==352|| sometver->get_id()==354|| sometver->get_id()==10|| sometver->get_id()==26*/
1627
1628 )
1629 {
1630 double x=vertices->get_x();
1631 double y=vertices->get_y();
1632 double z=vertices->get_z();
1633 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1634 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1635 mainew->ajouter_mg_noeud(newno);
1636 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1637 }
1638 }
1639
1640 LISTE_MG_SEGMENT::iterator itSeg;
1641 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1642 {
1643 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1644 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1645 //%390=SEGMENT($13,$275,$277,1010); => %13=ARETE(3,$8,$14,$15,1,0); %275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010); %277=NOEUD($13,89.09047601136933,-249.4243468871926,0.000000000000000,1010);
1646 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1647 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1648 if (faceseg->get_id()==76
1649 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
1650 //faceseg->get_id()==133
1651 //|| aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
1652 //|| aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
1653 //|| aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
1654 //|| aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
1655 //|| aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
1656 // || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
1657 // || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
1658
1659 )
1660 {
1661 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1662 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1663 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1664 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1665 mainew->ajouter_mg_segment(seg);
1666 }
1667 }
1668
1669 LISTE_MG_TRIANGLE::iterator itTri;
1670 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1671 {
1672 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1673 if (facetri->get_id()==76)
1674 {
1675 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1676 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1677 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1678 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1679 }
1680 }
1681
1682 //gestnew->enregistrer("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
1683 gestnew->enregistrer(outputfilename);
1684 //////////////////
1685
1686 ////////////////////////
1687
1688
1689 /*
1690 mainew->supprimer_mg_triangleid(106625);
1691 mainew->supprimer_mg_triangleid(106662);
1692 mainew->supprimer_mg_triangleid(106626);
1693 mainew->supprimer_mg_triangleid(106701);
1694 mainew->supprimer_mg_triangleid(106702);
1695 mainew->supprimer_mg_triangleid(106639);*/
1696 //cout<<"output mesh no.= 495557 "<<endl;
1697 //gest.enregistrer("2dsurfmesh_cad.magic"); //CAD model output
1698 //scanned part output
1699
1700
1701 }
1702 void CRIAQOPERATORS::surfmaker_e2(char* outputfilename,int meshno,char* magicfilename)
1703 {
1704 // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
1705 MG_FILE gest(magicfilename);
1706 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1707 MG_MAILLAGE* mai;
1708 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1709 //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
1710 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1711 //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
1712 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1713 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1714 gestnew->ajouter_mg_geometrie(geonew);
1715 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1716 gestnew->ajouter_mg_maillage(mainew);
1717
1718 LISTE_MG_NOEUD::iterator itnod;
1719 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1720 {
1721 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1722 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1723 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1724 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1725 if(facevert->get_id()==76
1726 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13||aretver->get_id()==110
1727 || sometver->get_id()==10|| sometver->get_id()==12|| sometver->get_id()==81|| sometver->get_id()==83|| sometver->get_id()==90|| sometver->get_id()==97)
1728 {
1729 double x=vertices->get_x();
1730 double y=vertices->get_y();
1731 double z=vertices->get_z();
1732 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1733 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1734 mainew->ajouter_mg_noeud(newno);
1735 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1736 }
1737 }
1738
1739 LISTE_MG_SEGMENT::iterator itSeg;
1740 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1741 {
1742 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1743 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1744 //%390=SEGMENT($13,$275,$277,1010); => %13=ARETE(3,$8,$14,$15,1,0); %275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010); %277=NOEUD($13,89.09047601136933,-249.4243468871926,0.000000000000000,1010);
1745 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1746 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1747 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1748 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1749 if (faceseg->get_id()==76 ||
1750 aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13|| aretver->get_id()==110)
1751 {
1752 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1753 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1754 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1755 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1756 mainew->ajouter_mg_segment(seg);
1757 }
1758 }
1759
1760 LISTE_MG_TRIANGLE::iterator itTri;
1761 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1762 {
1763 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1764 if (facetri->get_id()==76)
1765 {
1766 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1767 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1768 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1769 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1770 }
1771 }
1772
1773 //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
1774 gestnew->enregistrer(outputfilename);
1775 }
1776 void CRIAQOPERATORS::surfmaker_e2t(char* outputfilename,int meshno,char* magicfilename)
1777 {
1778 // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
1779 MG_FILE gest(magicfilename);
1780 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1781 MG_MAILLAGE* mai;
1782 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1783 //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
1784 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1785 //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
1786 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1787 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1788 gestnew->ajouter_mg_geometrie(geonew);
1789 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1790 gestnew->ajouter_mg_maillage(mainew);
1791
1792 LISTE_MG_NOEUD::iterator itnod;
1793 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1794 {
1795 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1796 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1797 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1798 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1799 if(facevert->get_id()==37
1800 || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
1801 || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
1802 || sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==51|| sometver->get_id()==58|| sometver->get_id()==42|| sometver->get_id()==44
1803 || sometver->get_id()==87|| sometver->get_id()==73|| sometver->get_id()==80|| sometver->get_id()==71|| sometver->get_id()==100|| sometver->get_id()==107
1804 //for e2t
1805 //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
1806 //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
1807 //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
1808 //|| sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==65|| sometver->get_id()==58|| sometver->get_id()==51|| sometver->get_id()==42
1809 //|| sometver->get_id()==44|| sometver->get_id()==72|| sometver->get_id()==115|| sometver->get_id()==87|| sometver->get_id()==108|| sometver->get_id()==101
1810 //|| sometver->get_id()==94|| sometver->get_id()==85|| sometver->get_id()==128|| sometver->get_id()==135
1811 )
1812 {
1813 double x=vertices->get_x();
1814 double y=vertices->get_y();
1815 double z=vertices->get_z();
1816 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1817 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1818 mainew->ajouter_mg_noeud(newno);
1819 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1820 }
1821 }
1822
1823 LISTE_MG_SEGMENT::iterator itSeg;
1824 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1825 {
1826 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1827 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1828 //%390=SEGMENT($13,$275,$277,1010); => %13=ARETE(3,$8,$14,$15,1,0); %275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010); %277=NOEUD($13,89.09047601136933,-249.4243468871926,0.000000000000000,1010);
1829 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1830 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1831 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1832 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1833 if (faceseg->get_id()==37
1834 || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
1835 || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
1836 //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
1837 //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
1838 //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
1839
1840 )
1841 {
1842 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1843 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1844 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1845 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1846 mainew->ajouter_mg_segment(seg);
1847 }
1848 }
1849
1850 LISTE_MG_TRIANGLE::iterator itTri;
1851 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1852 {
1853 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1854 if (facetri->get_id()==37)
1855 {
1856 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1857 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1858 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1859 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1860 }
1861 }
1862
1863 //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
1864 gestnew->enregistrer(outputfilename);
1865 }
1866 void CRIAQOPERATORS::surfmaker_e3(char* outputfilename,int meshno,char* magicfilename)
1867 {
1868 //surfmesh maker (smplwithpocket+smpl withpocket)
1869 MG_FILE gest(magicfilename);
1870 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1871 MG_MAILLAGE* mai;
1872 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1873 //MG_FILE gest((char*)"smplwithpocket_3d_13mm.magic");
1874 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1875 //MG_MAILLAGE* mai=gest.get_mg_maillageid(2982821);
1876 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1877 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1878 gestnew->ajouter_mg_geometrie(geonew);
1879 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1880 gestnew->ajouter_mg_maillage(mainew);
1881
1882 LISTE_MG_NOEUD::iterator itnod;
1883 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1884 {
1885 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1886 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1887 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1888 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1889 if(facevert->get_id()==5
1890 || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
1891 || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13
1892 || sometver->get_id()==10|| sometver->get_id()==26|| sometver->get_id()==41|| sometver->get_id()==55|| sometver->get_id()==39|| sometver->get_id()==48
1893 || sometver->get_id()==84|| sometver->get_id()==77|| sometver->get_id()==70|| sometver->get_id()==68|| sometver->get_id()==12|| sometver->get_id()==19)
1894 {
1895 double x=vertices->get_x();
1896 double y=vertices->get_y();
1897 double z=vertices->get_z();
1898 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1899 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1900 mainew->ajouter_mg_noeud(newno);
1901 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1902 }
1903 }
1904
1905 LISTE_MG_SEGMENT::iterator itSeg;
1906 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1907 {
1908 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1909 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1910 //%390=SEGMENT($13,$275,$277,1010); => %13=ARETE(3,$8,$14,$15,1,0); %275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010); %277=NOEUD($13,89.09047601136933,-249.4243468871926,0.000000000000000,1010);
1911 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1912 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1913 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1914 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1915 if (faceseg->get_id()==5
1916 || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
1917 || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13)
1918 {
1919 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1920 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1921 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1922 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1923 mainew->ajouter_mg_segment(seg);
1924 }
1925 }
1926
1927 LISTE_MG_TRIANGLE::iterator itTri;
1928 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1929 {
1930 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1931 if (facetri->get_id()==5)
1932 {
1933 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1934 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1935 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1936 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1937 }
1938 }
1939
1940 //gestnew->enregistrer("scnsurf_smplwithpocket_3d_13mm_232mmdeform.magic");
1941 gestnew->enregistrer(outputfilename);
1942 }
1943 void CRIAQOPERATORS::gnifformatmaker(char* elementxtoutfile,char* nodtxtoutfile,int meshno,char* magicfilename)
1944 {
1945 // gnifformatmaker
1946 MG_FILE gest(magicfilename);
1947 MG_MAILLAGE* mai;
1948 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1949 //MG_FILE gest((char*)"scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
1950 // MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
1951 //std::string fichiermaillage="CAD_output_elements.txt";
1952 //FILE* in=fopen(fichiermaillage.c_str(),"wt");
1953 //FILE* in1=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_nodes.txt","wt");
1954 FILE* in1=fopen(nodtxtoutfile,"wt");
1955 //FILE* in1=fopen("scannedsurface_nodes.txt","wt");
1956 LISTE_MG_NOEUD::iterator itnod;
1957 unsigned long firstno=mai->get_premier_noeud(itnod)->get_id();
1958 firstno=firstno-1;
1959 cout<<firstno<<endl;
1960 int counter1=1;
1961 cout<<"mai->get_nb_mg_noeud()="<<mai->get_nb_mg_noeud()<<endl;
1962 for (MG_NOEUD* nod=mai->get_premier_noeud(itnod);nod!=NULL;nod=mai->get_suivant_noeud(itnod))
1963 {
1964 nod->change_nouveau_numero(counter1);
1965 //nod->change_id(counter1);
1966 //fprintf(in1,"%d node coordinate %le %le %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
1967 //fprintf(in,"%d node coordinate %le %le %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
1968 fprintf(in1,"%19d%32.9le%16.9le%8d\n",nod->get_nouveau_numero(), nod->get_x(),nod->get_y(),nod->get_nouveau_numero());
1969 fprintf(in1,"%7d%16.9le\n",nod->get_nouveau_numero(), nod->get_z());
1970 counter1++;
1971 }
1972 //FILE* in2=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_elements.txt","wt"); // CAD text output elements
1973 FILE* in2=fopen(elementxtoutfile,"wt");
1974 //FILE* in2=fopen("scannedsurface_elements.txt","wt"); //scanned text output elements
1975 int counter=1;
1976 LISTE_MG_TRIANGLE::iterator ittri;
1977 for (MG_TRIANGLE* tri=mai->get_premier_triangle(ittri);tri!=NULL;tri=mai->get_suivant_triangle(ittri))
1978 {
1979 fprintf(in2,"%10d 1%8d%8d%8d\n",counter,tri->get_noeud1()->get_nouveau_numero(),tri->get_noeud2()->get_nouveau_numero(),tri->get_noeud3()->get_nouveau_numero() );
1980 counter++;
1981 }
1982 fclose(in1);
1983 fclose(in2);
1984 }
1985 void CRIAQOPERATORS::rmovscnprtfromdefrmdcad(char* outputfilename,int meshno,char* magicfilename)
1986 {
1987 MG_FILE gest(magicfilename);
1988 MG_MAILLAGE* mai;
1989 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1990 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
1991 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1992 newgest->ajouter_mg_geometrie(geonew);
1993 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1994 newgest->ajouter_mg_maillage(mainew);
1995
1996 LISTE_MG_NOEUD::iterator itnod;
1997 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1998 {
1999 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2000 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2001 //if(facevert->get_id()!=76 && topnd->get_dimension()!=3) //e1
2002 //if(facevert->get_id()!=5 && topnd->get_dimension()!=3) //e2
2003 {
2004 double x=vertices->get_x();
2005 double y=vertices->get_y();
2006 double z=vertices->get_z();
2007 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2008 mainew->ajouter_mg_noeud(newno);
2009 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2010 }
2011 }
2012
2013 LISTE_MG_SEGMENT::iterator itSeg;
2014 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2015 {
2016 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2017 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2018 //if (faceseg->get_id()!=76 && topseg->get_dimension()!=3)
2019 if(faceseg->get_id()!=5 && topseg->get_dimension()!=3) //e2
2020 {
2021 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2022 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2023 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2024 mainew->ajouter_mg_segment(seg);
2025 }
2026 }
2027
2028 LISTE_MG_TRIANGLE::iterator itTri;
2029 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2030 {
2031 MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
2032 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2033 // if (facetri->get_id()!=76 && toptri->get_dimension()!=3)
2034 if (facetri->get_id()!=5 && toptri->get_dimension()!=3) //e2
2035 {
2036 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2037 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2038 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2039 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2040 }
2041 }
2042 newgest->enregistrer(outputfilename);
2043 //gest.enregistrer("deformedcad_sansscannedpart.magic");
2044
2045 }
2046 void CRIAQOPERATORS::msh2dmakerfrommsh3d(char* outputfilename,int meshno,char* magicfilename)
2047 {
2048 //to make a 2D mesh out of 3D mesh :)
2049 /*
2050 MG_MAILLAGE* mainew=mai->dupliquer(&gest);
2051 LISTE_MG_TETRA::iterator ittet;
2052 for(MG_TETRA* )
2053 {
2054
2055 }
2056
2057 cout<<"mainew->get_nb_mg_noeud()= "<<mainew->get_nb_mg_noeud()<<endl;
2058 cout<<"mainew->get_nb_mg_segment()= "<<mainew->get_nb_mg_segment()<<endl;
2059 cout<<"mainew->get_nb_mg_triangle()= "<<mainew->get_nb_mg_triangle()<<endl;
2060 cout<<"mainew->get_nb_mg_tetra()= "<<mainew->get_nb_mg_tetra()<<endl;
2061
2062 LISTE_MG_TRIANGLE::iterator ittri;
2063 for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
2064 {
2065 MG_ELEMENT_TOPOLOGIQUE *top=triangle->get_lien_topologie();
2066 int topdimension=top->get_dimension();
2067 if (topdimension==3)
2068 mainew->supprimer_mg_triangleid(triangle->get_id());
2069 }
2070
2071 LISTE_MG_TETRA::iterator ittet;
2072 for (MG_TETRA* tetra=mainew->get_premier_tetra(ittet);tetra!=NULL;tetra=mainew->get_suivant_tetra(ittet))
2073 mainew->supprimer_mg_tetraid(tetra->get_id());
2074 //MG_FACE* face=geo->get_mg_faceid(5);
2075
2076
2077 LISTE_MG_SEGMENT::iterator itseg;
2078 for (MG_SEGMENT* segment=mainew->get_premier_segment(itseg);segment!=NULL;segment=mainew->get_suivant_segment(itseg))
2079 {
2080 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2081 if (faceseg->get_id()!=181)
2082 mainew->supprimer_mg_segmentid(segment->get_id());
2083
2084 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2085 if(topseg->get_dimension()==3)
2086 cout<<"topseg->get_dimension()==3"<<endl;
2087 }
2088
2089 LISTE_MG_NOEUD::iterator itnod;
2090 for (MG_NOEUD* vertices=mainew->get_premier_noeud(itnod);vertices!=NULL;vertices=mainew->get_suivant_noeud(itnod))
2091 {
2092 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2093 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2094 //if (facevert->get_id()!=181)
2095 if (topnd->get_dimension()==0)
2096 mainew->supprimer_mg_segmentid(vertices->get_id());
2097 }
2098
2099 for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
2100 {
2101 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2102 if (facetri->get_id()!=181)
2103 mainew->supprimer_mg_triangleid(triangle->get_id());
2104 }
2105 */
2106
2107 MG_FILE gest(magicfilename);
2108 MG_MAILLAGE* mai;
2109 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2110 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
2111 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2112 newgest->ajouter_mg_geometrie(geonew);
2113 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2114 newgest->ajouter_mg_maillage(mainew);
2115
2116 LISTE_MG_NOEUD::iterator itNod;
2117 for (MG_NOEUD* nd=mai->get_premier_noeud(itNod);nd!=NULL;nd=mai->get_suivant_noeud(itNod))
2118 {
2119 MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
2120 if(topnd->get_dimension()<3)
2121 {
2122 double x=nd->get_x();
2123 double y=nd->get_y();
2124 double z=nd->get_z();
2125 MG_NOEUD *newno=new MG_NOEUD(nd->get_lien_topologie(),x,y,z,nd->get_origine());
2126 mainew->ajouter_mg_noeud(newno);
2127 nd->change_nouveau_numero(newno->get_id());
2128 }
2129 }
2130 LISTE_MG_SEGMENT::iterator itSeg;
2131 for (MG_SEGMENT* segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2132 {
2133 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2134 if(topseg->get_dimension()<3)
2135 {
2136 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2137 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2138 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2139 mainew->ajouter_mg_segment(seg);
2140 }
2141 }
2142 LISTE_MG_TRIANGLE::iterator itTri;
2143 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2144 {
2145 MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
2146 if(toptri->get_dimension()<3)
2147 {
2148 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2149 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2150 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2151 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2152 }
2153 }
2154 newgest->enregistrer(outputfilename);
2155 }
2156 void CRIAQOPERATORS::bumpmaker(char* outputfilename,int bumpndid, double bumptip,int meshno,char* magicfilename)
2157 {
2158 MG_FILE gest(magicfilename);
2159 //MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2160 MG_MAILLAGE* mai;
2161 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2162 //MG_FILE gest((char*)"scnsurf_smplwithpocket_3d_13mm_64mmdeform.magic");
2163 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2164 //MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
2165 MG_NOEUD* bptipnd;
2166 TPL_MAP_ENTITE<MG_NOEUD*> usednd;
2167 LISTE_MG_NOEUD::iterator itnod;
2168 for (MG_NOEUD* nd=mai->get_premier_noeud(itnod);nd!=NULL;nd=mai->get_suivant_noeud(itnod))
2169 {
2170 MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
2171 if (topnd->get_dimension() <3 && nd->get_id()==bumpndid)
2172 {
2173 bptipnd=nd;
2174 double new_xyz[3];
2175 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+bumptip;
2176 nd->change_coord(new_xyz);
2177 usednd.ajouter(nd);
2178 }
2179 }
2180 TPL_MAP_ENTITE<MG_NOEUD*> usedndnd;
2181 TPL_MAP_ENTITE<MG_NOEUD*> neignd;
2182 for(int ineignd=0;ineignd<bptipnd->get_lien_segment()->get_nb();ineignd++)
2183 {
2184 MG_SEGMENT* segnei=bptipnd->get_lien_segment()->get(ineignd);
2185 if(segnei->get_noeud1()!=bptipnd) neignd.ajouter(segnei->get_noeud1());
2186 else if(segnei->get_noeud2()!=bptipnd) neignd.ajouter(segnei->get_noeud2());
2187 }
2188 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd;
2189 for (MG_NOEUD* nd=neignd.get_premier(itneignd);nd!=NULL;nd=neignd.get_suivant(itneignd))
2190 {
2191 double new_xyz[3];
2192 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*3./4.);
2193 nd->change_coord(new_xyz);
2194 usednd.ajouter(nd);
2195 usedndnd.ajouter(nd);
2196 }
2197
2198 TPL_MAP_ENTITE<MG_NOEUD*> neignd1;
2199 TPL_MAP_ENTITE<MG_NOEUD*> usedndnd1;
2200 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusednd;
2201 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd;
2202 for(MG_NOEUD* nd=usedndnd.get_premier(itusedndnd);nd!=NULL;nd=usedndnd.get_suivant(itusedndnd))
2203 {
2204 for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
2205 {
2206 MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
2207 int sgnd1=0;
2208 int sgnd2=0;
2209 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2210 {
2211 if(segnei->get_noeud1()==nd1) sgnd1++;
2212 }
2213 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2214 {
2215 if(segnei->get_noeud2()==nd1) sgnd2++;
2216 }
2217 if(sgnd1==0) neignd1.ajouter(segnei->get_noeud1());
2218 else if(sgnd2==0) neignd1.ajouter(segnei->get_noeud2());
2219 }
2220 }
2221 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd1;
2222 for (MG_NOEUD* nd=neignd1.get_premier(itneignd1);nd!=NULL;nd=neignd1.get_suivant(itneignd1))
2223 {
2224 double new_xyz[3];
2225 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*2./4.);
2226 nd->change_coord(new_xyz);
2227 usednd.ajouter(nd);
2228 usedndnd1.ajouter(nd);
2229 }
2230
2231 TPL_MAP_ENTITE<MG_NOEUD*> neignd2;
2232 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd1;
2233 for(MG_NOEUD* nd=usedndnd1.get_premier(itusedndnd1);nd!=NULL;nd=usedndnd1.get_suivant(itusedndnd1))
2234 {
2235 for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
2236 {
2237 MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
2238 int sgnd1=0;
2239 int sgnd2=0;
2240 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2241 {
2242 if(segnei->get_noeud1()==nd1) sgnd1++;
2243 }
2244 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2245 {
2246 if(segnei->get_noeud2()==nd1) sgnd2++;
2247 }
2248 if(sgnd1==0) neignd2.ajouter(segnei->get_noeud1());
2249 else if(sgnd2==0) neignd2.ajouter(segnei->get_noeud2());
2250 }
2251 }
2252 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd2;
2253 for (MG_NOEUD* nd=neignd2.get_premier(itneignd2);nd!=NULL;nd=neignd2.get_suivant(itneignd2))
2254 {
2255 double new_xyz[3];
2256 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*1./4.);
2257 nd->change_coord(new_xyz);
2258 }
2259
2260
2261 //gest.enregistrer("scnsurf_smplwithpocket_3d_13mm_64mmdeform_withbump5mm.magic");
2262 gest.enregistrer(outputfilename);
2263 }
2264 int CRIAQOPERATORS::import_triangulation_gnif(char* outputfilename,char* triangulationfile)
2265 {
2266 FILE* in=fopen(triangulationfile,"rt");
2267 if (in==NULL) return 0;
2268
2269
2270 MG_GESTIONNAIRE gesttmp;
2271 MG_MAILLAGE* mai=new MG_MAILLAGE(NULL);
2272 gesttmp.ajouter_mg_maillage(mai);
2273 char mess[500];
2274
2275 double xmax=-1e308;
2276 double xmin=1e308;
2277 double ymax=-1e308;
2278 double ymin=1e308;
2279 double zmax=-1e308;
2280 double zmin=1e308;
2281 while (!feof(in))
2282 {
2283 double x,y,z;
2284 char nom[20];
2285 char *res=fgets(mess,500,in);
2286 if (feof(in)) break;
2287 if(res!=NULL)
2288 {
2289 sscanf(mess,"%le %le %le",&x,&y,&z);
2290 if (x<xmin) xmin=x;
2291 if (x>xmax) xmax=x;
2292 if (y<ymin) ymin=y;
2293 if (y>ymax) ymax=y;
2294 if (z<zmin) zmin=z;
2295 if (z>zmax) zmax=z;
2296 if (feof(in)) return 1;
2297 MG_NOEUD* noeud1=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
2298 noeud1->change_nouveau_numero(-1);
2299 res=fgets(mess,500,in);
2300 if (feof(in)) break;
2301 sscanf(mess,"%le %le %le",&x,&y,&z);
2302 if (x<xmin) xmin=x;
2303 if (x>xmax) xmax=x;
2304 if (y<ymin) ymin=y;
2305 if (y>ymax) ymax=y;
2306 if (z<zmin) zmin=z;
2307 if (z>zmax) zmax=z;
2308 if (feof(in)) return 1;
2309 res=fgets(mess,500,in);
2310 if (feof(in)) break;
2311 MG_NOEUD* noeud2=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
2312 noeud2->change_nouveau_numero(-1);
2313 sscanf(mess,"%le %le %le",&x,&y,&z);
2314 if (x<xmin) xmin=x;
2315 if (x>xmax) xmax=x;
2316 if (y<ymin) ymin=y;
2317 if (y>ymax) ymax=y;
2318 if (z<zmin) zmin=z;
2319 if (z>zmax) zmax=z;
2320 if (feof(in)) return 1;
2321 MG_NOEUD* noeud3=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
2322 noeud3->change_nouveau_numero(-1);
2323 mai->ajouter_mg_triangle(NULL,noeud1,noeud2,noeud3,TRIANGULATION);
2324 }
2325 }
2326 fclose(in);
2327 //to merge the nodes of each triangulation which are close (the same)
2328 double eps=1e-4;
2329 BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
2330 double rayon=boite.get_rayon()*1.1;
2331 double x=boite.get_xcentre();
2332 double y=boite.get_ycentre();
2333 double z=boite.get_zcentre();
2334 boite.reinit(x-rayon,y-rayon,z-rayon,x+rayon,y+rayon,z+rayon);
2335 TPL_GRILLE<MG_NOEUD*> grille;
2336 int nb_noeud=mai->get_nb_mg_noeud();
2337 int pas=(int)(pow(nb_noeud,0.33333333333333333))+1;
2338 grille.initialiser(boite.get_xmin(),boite.get_ymin(),boite.get_zmin(),boite.get_xmax(),boite.get_ymax(),boite.get_zmax(),pas,pas,pas);
2339 std::vector<MG_NOEUD*> lst_noeud;
2340 LISTE_MG_NOEUD::iterator it;
2341 int i=0;
2342 for (MG_NOEUD* noeud=mai->get_premier_noeud(it);noeud!=NULL;noeud=mai->get_suivant_noeud(it))
2343 {
2344 //MG_NOEUD* noeud=mai->get_mg_noeud(i);
2345 grille.inserer(noeud);
2346 noeud->change_nouveau_numero(i);
2347 lst_noeud.insert(lst_noeud.end(),noeud);
2348 i++;
2349 }
2350
2351 int nb_cell=grille.get_nb_cellule();
2352 for (int i=0;i<nb_cell;i++)
2353 {
2354 TPL_CELLULE_GRILLE<MG_NOEUD*> *cell=grille.get_cellule(i);
2355 int nb_noeud_cell=cell->get_nb_entite();
2356 for (int j=0;j<nb_noeud_cell;j++)
2357 {
2358 MG_NOEUD* noeud1=cell->get_entite(j);
2359 // if (noeud1->get_nouveau_numero()!=(-1)) continue;
2360 // noeud1->change_nouveau_numero(noeud1->get_id());
2361 double *xyz1=noeud1->get_coord();
2362 int nb=noeud1->get_lien_segment()->get_nb();
2363 double longref=0.;
2364 for (int jj=0;jj<nb;jj++)
2365 longref=longref+noeud1->get_lien_segment()->get(jj)->get_longueur();
2366 longref=longref/nb;
2367 for (int k=j+1;k<nb_noeud_cell;k++)
2368 {
2369 MG_NOEUD* noeud2=cell->get_entite(k);
2370 double *xyz2=noeud2->get_coord();
2371 OT_VECTEUR_3D vec(xyz1,xyz2);
2372 double longueur=vec.get_longueur();
2373 if (longueur<eps*longref)
2374 {
2375 lst_noeud[noeud2->get_nouveau_numero()]=noeud1;
2376 }
2377 }
2378 }
2379 }
2380 MG_GESTIONNAIRE gest;
2381 MG_MAILLAGE* mai2=new MG_MAILLAGE(NULL);
2382 gest.ajouter_mg_maillage(mai2);
2383 for (int i=0;i<nb_noeud;i++)
2384 {
2385 MG_NOEUD* noeud=lst_noeud[i];
2386 MG_NOEUD* nvnoeud;
2387 if (noeud->get_nouveau_numero()==i) nvnoeud=mai2->ajouter_mg_noeud(NULL,noeud->get_x(),noeud->get_y(),noeud->get_z(),TRIANGULATION);
2388 else nvnoeud=lst_noeud[noeud->get_nouveau_numero()];
2389 lst_noeud[i]=nvnoeud;
2390 }
2391 int nb_tri=mai->get_nb_mg_triangle();
2392 for (int i=0;i<nb_tri;i++)
2393 {
2394 MG_TRIANGLE* tri=mai->get_mg_triangle(i);
2395 MG_NOEUD* noeud1=tri->get_noeud1();
2396 MG_NOEUD* noeud2=tri->get_noeud2();
2397 MG_NOEUD* noeud3=tri->get_noeud3();
2398 mai2->ajouter_mg_triangle(NULL,lst_noeud[noeud1->get_nouveau_numero()],lst_noeud[noeud2->get_nouveau_numero()],lst_noeud[noeud3->get_nouveau_numero()],TRIANGULATION);
2399 }
2400 gest.enregistrer(outputfilename);
2401 return 1;
2402 }