ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/criaqoperation/src/criaqoperators.cpp
Revision: 822
Committed: Sun Sep 4 20:09:12 2016 UTC (8 years, 11 months ago) by sattarpa
File size: 152106 byte(s)
Log Message:
Ajouter option de search-radius pour 'meshdistance_compare' 

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 #include <stdlib.h>
13
14 CRIAQOPERATORS::CRIAQOPERATORS():MAILLEUR(false)
15 {
16 }
17 CRIAQOPERATORS::~CRIAQOPERATORS()
18 {
19 }
20
21 void CRIAQOPERATORS::ksol_bumpnds(char* magicfilename_actual,char* magicfilename_estimate,double comp_threshold,int solidact,int solidest,char* ksoloutput_act,char* ksoloutput_est,int ndmaxbumpidact,int ndmaxbumpidest,int indiv_actref)
22 {
23 MG_FILE gest1(magicfilename_actual);
24 MG_MAILLAGE* mai1=gest1.get_mg_maillageid(1);
25 MG_SOLUTION* mgsol1=gest1.get_mg_solutionid(solidact);
26 MG_FILE gest2(magicfilename_estimate);
27 MG_MAILLAGE* mai2=gest2.get_mg_maillageid(1);
28 MG_SOLUTION* mgsol2=gest2.get_mg_solutionid(solidest);
29 mgsol1->active_solution(0);
30 mgsol2->active_solution(0);
31
32 if(indiv_actref==0)
33 {
34 MG_NOEUD* bact=mai1->get_mg_noeudid(ndmaxbumpidact);
35 TPL_MAP_ENTITE<MG_NOEUD*> ndsonactbump;
36 ndsonactbump.ajouter(bact);
37 for(int i=0;i<bact->get_lien_segment()->get_nb();i++)
38 {
39 MG_NOEUD* sgnd1=bact->get_lien_segment()->get(i)->get_noeud1();
40 MG_NOEUD* sgnd2=bact->get_lien_segment()->get(i)->get_noeud2();
41 if(sgnd1!=bact && sgnd1->get_solution()>comp_threshold)
42 ndsonactbump.ajouter(sgnd1);
43 if(sgnd2!=bact && sgnd2->get_solution()>comp_threshold)
44 ndsonactbump.ajouter(sgnd2);
45 }
46 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndsonactbump;
47 int stoplvl=0;
48 while (ndsonactbump.get_nb()>stoplvl)
49 {
50 stoplvl=ndsonactbump.get_nb();
51 for(MG_NOEUD* nd=ndsonactbump.get_premier(itndsonactbump);nd!=NULL;nd=ndsonactbump.get_suivant(itndsonactbump))
52 {
53 for(int i=0;i<nd->get_lien_segment()->get_nb();i++)
54 {
55 MG_NOEUD* sgnd1=nd->get_lien_segment()->get(i)->get_noeud1();
56 MG_NOEUD* sgnd2=nd->get_lien_segment()->get(i)->get_noeud2();
57 if(sgnd1!=nd && sgnd1->get_solution()>comp_threshold)
58 ndsonactbump.ajouter(sgnd1);
59 if(sgnd2!=nd && sgnd2->get_solution()>comp_threshold)
60 ndsonactbump.ajouter(sgnd2);
61 }
62 }
63 }
64
65
66 MG_NOEUD* best=mai2->get_mg_noeudid(ndmaxbumpidest);
67 TPL_MAP_ENTITE<MG_NOEUD*> ndsonestbump;
68 ndsonestbump.ajouter(best);
69 for(int i=0;i<best->get_lien_segment()->get_nb();i++)
70 {
71 MG_NOEUD* sgnd1=best->get_lien_segment()->get(i)->get_noeud1();
72 MG_NOEUD* sgnd2=best->get_lien_segment()->get(i)->get_noeud2();
73 if(sgnd1!=best && sgnd1->get_solution()>comp_threshold)
74 ndsonestbump.ajouter(sgnd1);
75 if(sgnd2!=best && sgnd2->get_solution()>comp_threshold)
76 ndsonestbump.ajouter(sgnd2);
77 }
78 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndsonestbump;
79 stoplvl=0;
80 while (ndsonestbump.get_nb()>stoplvl)
81 {
82 stoplvl=ndsonestbump.get_nb();
83 for(MG_NOEUD* nd=ndsonestbump.get_premier(itndsonestbump);nd!=NULL;nd=ndsonestbump.get_suivant(itndsonestbump))
84 {
85 for(int i=0;i<nd->get_lien_segment()->get_nb();i++)
86 {
87 MG_NOEUD* sgnd1=nd->get_lien_segment()->get(i)->get_noeud1();
88 MG_NOEUD* sgnd2=nd->get_lien_segment()->get(i)->get_noeud2();
89 if(sgnd1!=nd && sgnd1->get_solution()>comp_threshold)
90 ndsonestbump.ajouter(sgnd1);
91 if(sgnd2!=nd && sgnd2->get_solution()>comp_threshold)
92 ndsonestbump.ajouter(sgnd2);
93 }
94 }
95 }
96
97 FILE* insmp5=fopen(ksoloutput_act,"wt");
98 for(MG_NOEUD* nd=ndsonactbump.get_premier(itndsonactbump);nd!=NULL;nd=ndsonactbump.get_suivant(itndsonactbump))
99 fprintf(insmp5,"%le \n",nd->get_solution());
100 fclose(insmp5);
101
102 FILE* insmp6=fopen(ksoloutput_est,"wt");
103 for(MG_NOEUD* nd=ndsonestbump.get_premier(itndsonestbump);nd!=NULL;nd=ndsonestbump.get_suivant(itndsonestbump))
104 fprintf(insmp6,"%le \n",nd->get_solution());
105 fclose(insmp6);
106
107 }
108 if(indiv_actref>0)
109 {
110 MG_NOEUD* bdB1=mai1->get_mg_noeudid(ndmaxbumpidact);
111 TPL_MAP_ENTITE<MG_NOEUD*> ndsonB1flatA;
112 ndsonB1flatA.ajouter(bdB1);
113 for(int i=0;i<bdB1->get_lien_segment()->get_nb();i++)
114 {
115 MG_NOEUD* sgnd1=bdB1->get_lien_segment()->get(i)->get_noeud1();
116 MG_NOEUD* sgnd2=bdB1->get_lien_segment()->get(i)->get_noeud2();
117 if(sgnd1!=bdB1 && sgnd1->get_solution()>comp_threshold)
118 ndsonB1flatA.ajouter(sgnd1);
119 if(sgnd2!=bdB1 && sgnd2->get_solution()>comp_threshold)
120 ndsonB1flatA.ajouter(sgnd2);
121 }
122 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndsonB1flatA;
123 int stoplvl=0;
124 while (ndsonB1flatA.get_nb()>stoplvl)
125 {
126 stoplvl=ndsonB1flatA.get_nb();
127 for(MG_NOEUD* nd=ndsonB1flatA.get_premier(itndsonB1flatA);nd!=NULL;nd=ndsonB1flatA.get_suivant(itndsonB1flatA))
128 {
129 for(int i=0;i<nd->get_lien_segment()->get_nb();i++)
130 {
131 MG_NOEUD* sgnd1=nd->get_lien_segment()->get(i)->get_noeud1();
132 MG_NOEUD* sgnd2=nd->get_lien_segment()->get(i)->get_noeud2();
133 if(sgnd1!=nd && sgnd1->get_solution()>comp_threshold)
134 ndsonB1flatA.ajouter(sgnd1);
135 if(sgnd2!=nd && sgnd2->get_solution()>comp_threshold)
136 ndsonB1flatA.ajouter(sgnd2);
137 }
138 }
139 }
140
141 FILE* insmp5=fopen(ksoloutput_act,"wt");
142 for(MG_NOEUD* nd=ndsonB1flatA.get_premier(itndsonB1flatA);nd!=NULL;nd=ndsonB1flatA.get_suivant(itndsonB1flatA))
143 fprintf(insmp5,"%le \n",nd->get_solution());
144 fclose(insmp5);
145
146 FILE* insmp6=fopen(ksoloutput_est,"wt");
147 for(MG_NOEUD* nd=ndsonB1flatA.get_premier(itndsonB1flatA);nd!=NULL;nd=ndsonB1flatA.get_suivant(itndsonB1flatA))
148 {
149 for(int i=0;i<nd->get_lien_triangle()->get_nb();i++)
150 {
151 nd->get_lien_triangle()->get(i)->change_origine(MAGIC::ORIGINE::IMPOSE);
152 }
153 MG_NOEUD* nd2=mai2->get_mg_noeudid((nd->get_id()));
154 fprintf(insmp6,"%le \n",nd2->get_solution());
155 }
156 fclose(insmp6);
157 }
158
159
160 }
161
162
163
164 void CRIAQOPERATORS::gmsh_magic_corres(int femmeshno,char* magicfilename,char* correstxtfilename)
165 {/*
166 MG_FILE gest(magicfilename);
167 FEM_MAILLAGE* femmai;
168 if (femmeshno==0) femmai=gest.get_fem_maillage(femmeshno); else femmai=gest.get_fem_maillageid(femmeshno);
169
170 FILE* in1=fopen(correstxtfilename,"wt");
171 LISTE_FEM_NOEUD::iterator itnod;
172 unsigned long firstno=femai->get_premier_noeud(itnod)->get_id();
173
174 cout<<"mai->get_nb_mg_noeud()="<<femai->get_nb_fem_noeud()<<endl;
175 for (FEM_NOEUD* nod=femai->get_premier_noeud(itnod);nod!=NULL;nod=femai->get_suivant_noeud(itnod))
176 {
177 nod->get_numero_opt();
178 nod->get_mg_element_maillage()->change_nouveau_numero(counter1);
179 fprintf(in1,"%19d%32.9le%16.9le%8d\n",nod->get_mg_element_maillage()->get_nouveau_numero(), nod->get_x(),nod->get_y(),nod->get_mg_element_maillage()->get_nouveau_numero());
180 }
181
182 LISTE_FEM_NOEUD::iterator it;
183 for (FEM_NOEUD* noeud=mai->get_premier_noeud(it);noeud;noeud=mai->get_suivant_noeud(it)) //sasan
184 {
185 if (noeud->get_numero_opt()!=-1) numopt=true;
186 if (numopt)
187 {
188 f << "NO-" << noeud->get_numero() << " " << noeud->get_numero_opt() << " " << noeud->get_id() << std::endl;;
189 }*/
190
191 }
192
193 void CRIAQOPERATORS::bumparea_calcul(char* magicfilename,int nummai,int mgsolid,double tolerance,char* areamagicfilename,int defnodid)
194 {
195 MG_FILE gest(magicfilename);
196 MG_MAILLAGE* mai;
197 if (nummai==0) mai=gest.get_mg_maillage(nummai); else mai=gest.get_mg_maillageid(nummai);
198
199 MG_SOLUTION* mgsol=gest.get_mg_solutionid(mgsolid);
200 mgsol->active_solution(0);
201 MG_NOEUD* defnd;
202 LISTE_MG_NOEUD::iterator itnd;
203 for(MG_NOEUD* nd=mai->get_premier_noeud(itnd);nd!=NULL;nd=mai->get_suivant_noeud(itnd))
204 {
205 if (nd->get_id()==defnodid)
206 defnd=nd;
207 }
208 //cout<<defnd->get_solution()<<endl;
209 double max_dist=defnd->get_solution();
210 TPL_MAP_ENTITE<MG_TRIANGLE*> areatris;
211 for (int i=0;i<defnd->get_lien_triangle()->get_nb();i++)
212 {
213 MG_TRIANGLE* trii=defnd->get_lien_triangle()->get(i);
214 double avdis=(trii->get_noeud1()->get_solution()+trii->get_noeud2()->get_solution()+trii->get_noeud3()->get_solution())/3.;
215 if (avdis>tolerance)
216 areatris.ajouter(trii);
217 }
218 int stoplvl=0;
219 while (areatris.get_nb()>stoplvl)
220 {
221 stoplvl=areatris.get_nb();
222 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itareatris;
223 for(MG_TRIANGLE* trii=areatris.get_premier(itareatris);trii!=NULL;trii=areatris.get_suivant(itareatris))
224 {
225 for(int i=0;i<trii->get_segment1()->get_lien_triangle()->get_nb();i++)
226 {
227 MG_TRIANGLE* trineib=trii->get_segment1()->get_lien_triangle()->get(i);
228 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
229 if (avdis>tolerance)
230 areatris.ajouter(trineib);
231 }
232 for(int i=0;i<trii->get_segment2()->get_lien_triangle()->get_nb();i++)
233 {
234 MG_TRIANGLE* trineib=trii->get_segment2()->get_lien_triangle()->get(i);
235 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
236 if (avdis>tolerance)
237 areatris.ajouter(trineib);
238 }
239 for(int i=0;i<trii->get_segment3()->get_lien_triangle()->get_nb();i++)
240 {
241 MG_TRIANGLE* trineib=trii->get_segment3()->get_lien_triangle()->get(i);
242 double avdis=(trineib->get_noeud1()->get_solution()+trineib->get_noeud2()->get_solution()+trineib->get_noeud3()->get_solution())/3.;
243 if (avdis>tolerance)
244 areatris.ajouter(trineib);
245 }
246 }
247 }
248 double area=0.;
249 multimap<double,MG_NOEUD*,std::greater<double> > maxamplitude;
250 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itareatris;
251 for(MG_TRIANGLE* tri=areatris.get_premier(itareatris);tri!=NULL;tri=areatris.get_suivant(itareatris))
252 {
253 maxamplitude.insert(pair<double,MG_NOEUD*> (tri->get_noeud1()->get_solution(),tri->get_noeud1()));
254 maxamplitude.insert(pair<double,MG_NOEUD*> (tri->get_noeud2()->get_solution(),tri->get_noeud2()));
255 maxamplitude.insert(pair<double,MG_NOEUD*> (tri->get_noeud3()->get_solution(),tri->get_noeud3()));
256 OT_VECTEUR_3D v1(tri->get_noeud1()->get_coord(),tri->get_noeud2()->get_coord());
257 OT_VECTEUR_3D v2(tri->get_noeud1()->get_coord(),tri->get_noeud3()->get_coord());
258 OT_VECTEUR_3D area1=v1&v2;
259 double area2=0.5*area1.get_longueur();
260 area=area+area2;
261 }
262 cout<<"area= "<<area<<endl;
263 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itmaxamplitude=maxamplitude.begin();
264 cout<<"maxamplitude= "<< (*itmaxamplitude).first<<endl;
265
266 MG_MAILLAGE* mai1;
267 if (nummai==0) mai1=gest.get_mg_maillage(nummai); else mai1=gest.get_mg_maillageid(nummai);
268 TPL_MAP_ENTITE<MG_TRIANGLE*> deltris;
269 LISTE_MG_TRIANGLE::iterator ittri;
270 for (MG_TRIANGLE* tri=mai1->get_premier_triangle(ittri);tri!=NULL;tri=mai1->get_suivant_triangle(ittri))
271 {
272 //int triexist=0;
273 for(MG_TRIANGLE* triarea=areatris.get_premier(itareatris);triarea!=NULL;triarea=areatris.get_suivant(itareatris))
274 {
275 if (triarea==tri)
276 tri->change_origine(MAGIC::ORIGINE::IMPOSE);
277 //triexist++;
278 }
279 //if (triexist<1)
280 //deltris.ajouter(tri);
281 }
282 /* for(MG_TRIANGLE* tridel=deltris.get_premier(itareatris);tridel!=NULL;tridel=deltris.get_suivant(itareatris))
283 {
284 tridel->change_origine(IMPOSE);
285 //mai1->supprimer_mg_triangleid(tridel->get_id());
286 }*/
287
288 gest.ajouter_mg_maillage(mai1);
289 gest.enregistrer(areamagicfilename);
290 }
291 void CRIAQOPERATORS::samplepoints_compare(char* samplepoints1,char* samplepoints2,char* sortedsmplpnts)
292 {
293 std::vector<double*> lstsamplepoints1;
294 FILE *in1=fopen(samplepoints1,"rt");
295 if (in1==NULL) affiche((char*) "file is not available");
296 while(!feof(in1))
297 {
298 char chaine[500];
299 char* res=fgets(chaine,500,in1);
300 if(res!=NULL)
301 {
302 double x,y,z;
303 double q1,q2,q3;
304 double* pcoordbc=new double[6];
305 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
306 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
307 else if(nb==6)
308 {
309 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
310 lstsamplepoints1.push_back(pcoordbc);
311 }
312 }
313 }
314 fclose(in1);
315 std::vector<double*> lstsamplepoints2;
316 FILE *in2=fopen(samplepoints2,"rt");
317 if (in2==NULL) affiche((char*) "file is not available");
318 while(!feof(in2))
319 {
320 char chaine[500];
321 char* res=fgets(chaine,500,in2);
322 if(res!=NULL)
323 {
324 double x,y,z;
325 double q1,q2,q3;
326 double* pcoordbc=new double[6];
327 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
328 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
329 else if(nb==6)
330 {
331 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
332 lstsamplepoints2.push_back(pcoordbc);
333 }
334 }
335 }
336 fclose(in2);
337 cout<<lstsamplepoints1.size()<<endl;
338 cout<<lstsamplepoints2.size()<<endl;
339
340 std::vector<double*> lstsortedsmplpnts;
341 for(std::vector<double*>::iterator itlstsamplepoints1=lstsamplepoints1.begin();itlstsamplepoints1!=lstsamplepoints1.end();itlstsamplepoints1++)
342 {
343 double* pcoordbc=new double[7];
344 int countsmpcomp=0;
345 double* xyzsmp1=(*itlstsamplepoints1);
346 for(std::vector<double*>::iterator itlstsamplepoints2=lstsamplepoints2.begin();itlstsamplepoints2!=lstsamplepoints2.end();itlstsamplepoints2++)
347 {
348 double* xyzsmp2=(*itlstsamplepoints2);
349 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])
350 countsmpcomp++;
351 }
352 if(countsmpcomp==0)
353 {
354 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];
355 lstsortedsmplpnts.push_back(pcoordbc);
356 }
357 else if (countsmpcomp>0)
358 {
359 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];
360 lstsortedsmplpnts.push_back(pcoordbc);
361 }
362
363
364 }
365 cout<<lstsortedsmplpnts.size()<<endl;
366
367
368 FILE* insmp=fopen(sortedsmplpnts,"wt");
369 for(std::vector<double*>::iterator itlstsortedsmplpnts=lstsortedsmplpnts.begin();itlstsortedsmplpnts!=lstsortedsmplpnts.end();itlstsortedsmplpnts++)
370 {
371 double* xyzsmpsort=(*itlstsortedsmplpnts);
372 //cout<<xyzsmpsort[0]<<" "<<xyzsmpsort[1]<<endl;
373 fprintf(insmp,"%le %le %le %le %le %le %le \n",xyzsmpsort[0],xyzsmpsort[1],xyzsmpsort[2],xyzsmpsort[3],xyzsmpsort[4],xyzsmpsort[5],xyzsmpsort[6]);
374 }
375 fclose(insmp);
376
377 }
378
379 void CRIAQOPERATORS::meshdistance_compare(char* referencemagicfilename,int refmeshno,char* comparemagicfilename,int compmeshno,char* outputcomparefile,char* solfilename,double search_radius)
380 {
381 MG_FILE refgest(referencemagicfilename);
382 MG_MAILLAGE* refmgmai;
383 if (refmeshno==0) refmgmai=refgest.get_mg_maillage(refmeshno); else refmgmai=refgest.get_mg_maillageid(refmeshno);
384 MG_FILE compgest(comparemagicfilename);
385 MG_MAILLAGE* compmgmai;
386 if (compmeshno==0) compmgmai=compgest.get_mg_maillage(compmeshno); else compmgmai=compgest.get_mg_maillageid(compmeshno);
387
388 //octree initialization
389 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
390 TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
391 LISTE_MG_NOEUD::iterator it;
392 for (MG_NOEUD* no=refmgmai->get_premier_noeud(it);no!=NULL;no=refmgmai->get_suivant_noeud(it))
393 {
394 if (no->get_x()<xmin) xmin=no->get_x();
395 if (no->get_y()<ymin) ymin=no->get_y();
396 if (no->get_z()<zmin) zmin=no->get_z();
397 if (no->get_x()>xmax) xmax=no->get_x();
398 if (no->get_y()>ymax) ymax=no->get_y();
399 if (no->get_z()>zmax) zmax=no->get_z();
400 }
401 for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
402 {
403 if (no->get_x()<xmin) xmin=no->get_x();
404 if (no->get_y()<ymin) ymin=no->get_y();
405 if (no->get_z()<zmin) zmin=no->get_z();
406 if (no->get_x()>xmax) xmax=no->get_x();
407 if (no->get_y()>ymax) ymax=no->get_y();
408 if (no->get_z()>zmax) zmax=no->get_z();
409 lstnoeud.ajouter(no);
410 }
411 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
412 OT_VECTEUR_3D vec(vecmmax,vecmin);
413
414 //double search_radius=0.001*(vec.get_longueur());
415 //double search_radius=15.;
416 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);
417 double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
418 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
419 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
420
421 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octree;
422 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
423 for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
424 octree.inserer(no);
425
426 MG_SOLUTION* mgsol=new MG_SOLUTION(refmgmai,1,solfilename,1,(char*)"Normaldistance",MAGIC::ENTITE_SOLUTION::ENTITE_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
427 refgest.ajouter_mg_solution(mgsol);
428 mgsol->change_legende(0,"Normaldistance");
429 int i=0;
430 for (MG_NOEUD* nop=refmgmai->get_premier_noeud(it);nop!=NULL;nop=refmgmai->get_suivant_noeud(it))
431 {
432 TPL_MAP_ENTITE<MG_NOEUD*> lstneiclose;
433 int neindnb=lstneiclose.get_nb();
434 while(neindnb==0)
435 {
436 octree.rechercher(nop->get_x(),nop->get_y(),nop->get_z(),search_radius,lstneiclose);
437 neindnb=lstneiclose.get_nb();
438 }
439 map<double,MG_NOEUD*,std::less<double> > lstdist;
440 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itnop;
441 for(MG_NOEUD* no=lstneiclose.get_premier(itnop);no!=NULL;no=lstneiclose.get_suivant(itnop))
442 {
443 OT_VECTEUR_3D w_n_tot(0.,0.,0.);
444 double norme_w_n_tot=0.;
445 OT_VECTEUR_3D w2_n_tot(0.,0.,0.);
446 double norme_w2_n_tot=0.;
447 //int nbtri=nop->get_lien_triangle()->get_nb();//put sol on cad model
448 int nbtri=no->get_lien_triangle()->get_nb();
449 for (int i=0;i<nbtri;i++)
450 {
451 //MG_TRIANGLE* tri=(MG_TRIANGLE*)nop->get_lien_triangle()->get(i);//put sol on cad model
452 MG_TRIANGLE* tri=(MG_TRIANGLE*)no->get_lien_triangle()->get(i);
453 double *xyzn1=tri->get_noeud1()->get_coord();
454 double *xyzn2=tri->get_noeud2()->get_coord();
455 double *xyzn3=tri->get_noeud3()->get_coord();
456
457 OT_VECTEUR_3D vec1(xyzn1,xyzn3);
458 OT_VECTEUR_3D vec2(xyzn1,xyzn2);
459 OT_VECTEUR_3D n_tri=vec1&vec2; // Normale au triangle
460
461 double w=n_tri.get_longueur(); // 2 fois l'aire du triangle (pour éviter une division par 2)
462 n_tri.norme();
463 OT_VECTEUR_3D w_n=w*n_tri;
464 double norme_w_n=w_n.get_longueur();
465 w_n_tot=w_n_tot+w_n;
466 norme_w_n_tot=norme_w_n_tot+norme_w_n;
467 }
468
469 OT_VECTEUR_3D n=w_n_tot/norme_w_n_tot; // Normale à la surface au noeud
470 n.norme();
471 OT_VECTEUR_3D distvec(nop->get_coord(),no->get_coord());
472 double normaldistance=distvec*n;
473 double normaldistanceabs=fabs(normaldistance);
474 //cout<<"normaldistanceabs= "<<normaldistanceabs<<endl;
475 lstdist.insert(pair<double,MG_NOEUD*>(normaldistanceabs,nop));
476 }
477 map<double,MG_NOEUD*,std::less<double> >::iterator itlstdist=lstdist.begin();
478 double distnsclos=(*itlstdist).first;
479 MG_NOEUD* nodcls=(*itlstdist).second;
480 mgsol->ecrire(distnsclos,i,0,0);
481 i++;
482 }
483 refgest.enregistrer(outputcomparefile);
484 }
485 void CRIAQOPERATORS::deformed_correspond_mgmaiadd(char* magicfilename,int meshno,int numsol1,int numsol2,int numsol3,int numchamp1,int numchamp2,int numchamp3,double coef,char* correspondfilename)
486 {
487 MG_FILE gest(magicfilename);
488 FEM_MAILLAGE* femmai;
489 if (meshno==0) femmai=gest.get_fem_maillage(meshno); else femmai=gest.get_fem_maillageid(meshno);
490 FEM_SOLUTION* sol1=gest.get_fem_solutionid(numsol1);
491 FEM_SOLUTION* sol2=gest.get_fem_solutionid(numsol2);
492 FEM_SOLUTION* sol3=gest.get_fem_solutionid(numsol3);
493 femmai->calcul_deforme(sol1,numchamp1,sol2,numchamp2,sol3,numchamp3);
494 if (coef>1e-16)
495 {
496 cout<<" Création du maillage deforme avec correspondence text file"<<endl;
497 MG_MAILLAGE* defmgmai=new MG_MAILLAGE(gest.get_mg_geometrie(0));
498 gest.ajouter_mg_maillage(defmgmai);
499 {
500 if (femmai->get_degre()==1)
501 {
502 //gest=femmai->get_mg_maillage()->get_gestionnaire();
503 //gest->ajouter_mg_maillage(this);
504 std::vector<unsigned long*> lstcores;//sasan
505 LISTE_FEM_NOEUD::iterator it;
506 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
507 {
508 double x=no->get_x(coef);
509 double y=no->get_y(coef);
510 double z=no->get_z(coef);
511 MG_NOEUD *newno=new MG_NOEUD(no->get_lien_topologie(),x,y,z,MAGIC::ORIGINE::DEFORME);
512 defmgmai->ajouter_mg_noeud(newno);
513 no->change_numero(newno->get_id());
514 unsigned long* correscad_defcad=new unsigned long[2];//sasan
515 correscad_defcad[0]=no->get_mg_element_maillage()->get_id();//sasan
516 correscad_defcad[1]=newno->get_id();//sasan
517 lstcores.push_back(correscad_defcad);//sasan
518 }
519 //sasan
520 FILE* in1=fopen(correspondfilename,"wt");
521 fprintf(in1,"MG_MAILLAGE No. : deformed_MAILLAGE No.\n");
522 fprintf(in1,"%lu %lu\n",femmai->get_mg_maillage()->get_id(),defmgmai->get_id());
523 for(std::vector<unsigned long*>::iterator itlstpinsert=lstcores.begin();itlstpinsert!=lstcores.end();itlstpinsert++)
524 {
525 unsigned long* xyzpins1;
526 xyzpins1=(*itlstpinsert);
527 //cout<<" xyzpins1[0]= "<<xyzpins1[0]<<" xyzpins1[1]= "<<xyzpins1[1]<<endl;
528 fprintf(in1,"%lu %lu\n",xyzpins1[0],xyzpins1[1]);
529 }
530 fclose(in1);
531 //sasan till
532 LISTE_FEM_ELEMENT1::iterator it1;
533 for (FEM_ELEMENT1 *ele=femmai->get_premier_element1(it1);ele!=NULL;ele=femmai->get_suivant_element1(it1))
534 {
535 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
536 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
537 MG_SEGMENT *seg=new MG_SEGMENT(ele->get_lien_topologie(),no1,no2,MAGIC::ORIGINE::DEFORME);
538 defmgmai->ajouter_mg_segment(seg);
539 }
540 LISTE_FEM_ELEMENT2::iterator it2;
541 for (FEM_ELEMENT2 *ele=femmai->get_premier_element2(it2);ele!=NULL;ele=femmai->get_suivant_element2(it2))
542 {
543 if (ele->get_nb_fem_noeud()==3)
544 {
545 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
546 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
547 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
548 defmgmai->ajouter_mg_triangle(ele->get_lien_topologie(),no1,no2,no3,MAGIC::ORIGINE::DEFORME);
549 }
550 if (ele->get_nb_fem_noeud()==4)
551 {
552 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
553 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
554 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
555 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
556 defmgmai->ajouter_mg_quadrangle(ele->get_lien_topologie(),no1,no2,no3,no4,MAGIC::ORIGINE::DEFORME);
557 }
558 }
559 LISTE_FEM_ELEMENT3::iterator it3;
560 for (FEM_ELEMENT3 *ele=femmai->get_premier_element3(it3);ele!=NULL;ele=femmai->get_suivant_element3(it3))
561 {
562 if (ele->get_nb_fem_noeud()==4)
563 {
564 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
565 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
566 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
567 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
568 defmgmai->ajouter_mg_tetra(ele->get_lien_topologie(),no1,no2,no3,no4,MAGIC::ORIGINE::DEFORME);
569 }
570 if (ele->get_nb_fem_noeud()==8)
571 {
572 MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
573 MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
574 MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
575 MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
576 MG_NOEUD* no5=defmgmai->get_mg_noeudid(ele->get_fem_noeud(4)->get_numero());
577 MG_NOEUD* no6=defmgmai->get_mg_noeudid(ele->get_fem_noeud(5)->get_numero());
578 MG_NOEUD* no7=defmgmai->get_mg_noeudid(ele->get_fem_noeud(6)->get_numero());
579 MG_NOEUD* no8=defmgmai->get_mg_noeudid(ele->get_fem_noeud(7)->get_numero());
580 defmgmai->ajouter_mg_hexa(ele->get_lien_topologie(),no1,no2,no3,no4,no5,no6,no7,no8,MAGIC::ORIGINE::DEFORME);
581 }
582 }
583
584 }
585 }
586 }
587 cout<<" Enregistrement"<<endl;
588 gest.enregistrer(magicfilename);
589 }
590 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)
591 {
592 MG_FILE gest(magicfilename);
593 map<unsigned long, unsigned long> coresspondndidlst;
594 FILE* in1=fopen(correspondfilename,"rt");
595 if (in1==NULL) cout<<"correspondfile is not available"<<endl;
596 char mess[500];
597 char *res=fgets(mess,500,in1);
598 if(feof(in1))
599 cout<<"correspondfile has not been well written"<<endl;
600 res=fgets(mess,500,in1);
601 if(feof(in1))
602 cout<<"correspondfile has not been well written"<<endl;
603 int cadmeshno;
604 int defcadmeshno;
605 int nb1=sscanf(mess,"%d %d",&cadmeshno,&defcadmeshno);
606 while (!feof(in1))
607 {
608 char chaine[500];
609 res=fgets(chaine,500,in1);
610 if(res!=NULL)
611 {
612 unsigned long cadndid;
613 unsigned long defcadndid;
614 int nb=sscanf(chaine,"%lu %lu",&cadndid,&defcadndid);
615 if (nb!=-1 && nb!=2) cout<<"Wrong file format"<<endl;
616 else if (nb==2)
617 {
618 coresspondndidlst.insert(pair<unsigned long, unsigned long> (defcadndid,cadndid) );
619 }
620 }
621 }
622 fclose(in1);
623
624 cout<<"cadmeshno= "<<cadmeshno<<" defcadmeshno= "<<defcadmeshno<<endl;
625 MG_MAILLAGE* cadmgmai;
626 if (cadmeshno==0) cadmgmai=gest.get_mg_maillage(cadmeshno); else cadmgmai=gest.get_mg_maillageid(cadmeshno);
627 MG_MAILLAGE* defcadmgmai;
628 if (defcadmeshno==0) defcadmgmai=gest.get_mg_maillage(defcadmeshno); else defcadmgmai=gest.get_mg_maillageid(defcadmeshno);
629
630 cout<<"octree initialization "<<endl;
631 //CAD octree initialization
632 LISTE_MG_NOEUD::iterator itcadndcurv;
633 double xmincad=1e308,ymincad=1e308,zmincad=1e308,xmaxcad=-1e308,ymaxcad=-1e308,zmaxcad=-1e308;
634 TPL_MAP_ENTITE<MG_NOEUD*> lstcadnoeud;
635 for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
636 {
637 if (cadndcurv->get_x()<xmincad) xmincad=cadndcurv->get_x();
638 if (cadndcurv->get_y()<ymincad) ymincad=cadndcurv->get_y();
639 if (cadndcurv->get_z()<zmincad) zmincad=cadndcurv->get_z();
640 if (cadndcurv->get_x()>xmaxcad) xmaxcad=cadndcurv->get_x();
641 if (cadndcurv->get_y()>ymaxcad) ymaxcad=cadndcurv->get_y();
642 if (cadndcurv->get_z()>zmaxcad) zmaxcad=cadndcurv->get_z();
643 lstcadnoeud.ajouter(cadndcurv);
644 }
645 OT_VECTEUR_3D vecmincad(xmincad,ymincad,zmincad);
646 OT_VECTEUR_3D vecmmaxcad(xmaxcad,ymaxcad,zmaxcad);
647 OT_VECTEUR_3D vecad(vecmmaxcad,vecmincad);
648 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);
649 double lengthcad=sqrt(lengthvecad*lengthvecad); double bxrcad=1.1;
650 xmincad=averagecad.get_x()-(lengthcad*bxrcad);ymincad=averagecad.get_y()-(lengthcad*bxrcad);zmincad=averagecad.get_z()-(lengthcad*bxrcad);
651 xmaxcad=averagecad.get_x()+(lengthcad*bxrcad);ymaxcad=averagecad.get_y()+(lengthcad*bxrcad);zmaxcad=averagecad.get_z()+(lengthcad*bxrcad);
652 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreecad;
653 octreecad.initialiser(&lstcadnoeud,1,xmincad,ymincad,zmincad,xmaxcad,ymaxcad,zmaxcad);
654 for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
655 octreecad.inserer(cadndcurv);
656 //deformed_CAD octree initialization
657 LISTE_MG_NOEUD::iterator itdefcadndcurv;
658 double xmindefcad=1e308,ymindefcad=1e308,zmindefcad=1e308,xmaxdefcad=-1e308,ymaxdefcad=-1e308,zmaxdefcad=-1e308;
659 TPL_MAP_ENTITE<MG_NOEUD*> lstdefcadnoeud;
660 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
661 {
662 if (defcadndcurv->get_x()<xmindefcad) xmindefcad=defcadndcurv->get_x();
663 if (defcadndcurv->get_y()<ymindefcad) ymindefcad=defcadndcurv->get_y();
664 if (defcadndcurv->get_z()<zmindefcad) zmindefcad=defcadndcurv->get_z();
665 if (defcadndcurv->get_x()>xmaxdefcad) xmaxdefcad=defcadndcurv->get_x();
666 if (defcadndcurv->get_y()>ymaxdefcad) ymaxdefcad=defcadndcurv->get_y();
667 if (defcadndcurv->get_z()>zmaxdefcad) zmaxdefcad=defcadndcurv->get_z();
668 lstdefcadnoeud.ajouter(defcadndcurv);
669 }
670 OT_VECTEUR_3D vecmindefcad(xmindefcad,ymindefcad,zmindefcad);OT_VECTEUR_3D vecmmaxdefcad(xmaxdefcad,ymaxdefcad,zmaxdefcad);
671 OT_VECTEUR_3D vecdefcad(vecmmaxdefcad,vecmindefcad);
672 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);
673 double lengthdefcad=sqrt(lengthvecdefcad*lengthvecdefcad); double bxrdefcad=1.1;
674 xmindefcad=averagedefcad.get_x()-(lengthdefcad*bxrdefcad);ymindefcad=averagedefcad.get_y()-(lengthdefcad*bxrdefcad);zmindefcad=averagedefcad.get_z()-(lengthdefcad*bxrdefcad);
675 xmaxdefcad=averagedefcad.get_x()+(lengthdefcad*bxrdefcad);ymaxdefcad=averagedefcad.get_y()+(lengthdefcad*bxrdefcad);zmaxdefcad=averagedefcad.get_z()+(lengthdefcad*bxrdefcad);
676 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreedefcad;
677 octreedefcad.initialiser(&lstdefcadnoeud,1,xmindefcad,ymindefcad,zmindefcad,xmaxdefcad,ymaxdefcad,zmaxdefcad);
678 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
679 octreedefcad.inserer(defcadndcurv);
680
681 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_cadmgmai;
682 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_cadmgmai;
683 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_cadmgmai;
684 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_defcadmgmai;
685 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_defcadmgmai;
686 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_defcadmgmai;
687 map<MG_NOEUD*,double > lstkmin_cad;
688 map<MG_NOEUD*,double > lstkmax_cad;
689 map<MG_NOEUD*,double > lstkgau_cad;
690 map<MG_NOEUD*,double > lstkmin_defcad;
691 map<MG_NOEUD*,double > lstkmax_defcad;
692 map<MG_NOEUD*,double > lstkgau_defcad;
693 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_cadmgmai;
694 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_cadmgmai;
695 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_cadmgmai;
696 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_defcadmgmai;
697 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_defcadmgmai;
698 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_defcadmgmai;
699 std::map<std::string,double> liste_kmin;
700 std::map<std::string,double> liste_kmax;
701 std::map<std::string,double> liste_gau;
702 std::map<std::string,double> liste_courburemax1;
703 std::map<std::string,double> liste_courburemax2;
704 std::map<std::string,double> liste_courburemax3;
705 std::map<std::string,double> liste_courburemax4;
706 std::map<std::string,double> liste_courburemax5;
707 int opensurafece=1;
708
709 cout<<"calcul courbure cadmgmai"<<endl;
710 // calcul courbure cadmgmai ********************************
711 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
712 {
713 double kmin1=0.;
714 double kmax1=0.;
715 double kmin2=0.;
716 double kmax2=0.;
717 MG_MAILLAGE_OUTILS *cou;
718 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);
719 }
720 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
721 {
722
723 unsigned long idface=cadmgnd->get_lien_topologie()->get_id();
724 unsigned long idnoeud=cadmgnd->get_id();
725 char mess[500];
726 sprintf(mess,"%lu_%lu",idnoeud,idface);
727 for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
728 {
729 if(mess==(*itkmin).first)
730 {
731 lstkmin_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,cadmgnd) );
732 lstkmin_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkmin).second));
733 }
734 }
735 for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
736 {
737 if(mess==(*itkmax).first)
738 {
739 lstkmax_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,cadmgnd) );
740 lstkmax_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkmax).second));
741 }
742 }
743 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
744 {
745 if(mess==(*itkgau).first)
746 {
747 lstkgau_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,cadmgnd) );
748 lstkgau_cad.insert(pair<MG_NOEUD*,double>(cadmgnd,(*itkgau).second));
749 }
750 }
751 }
752 //calc reletive curvature CAD
753 map<MG_NOEUD*,double >::iterator itlstkmin_cad;
754 map<MG_NOEUD*,double >::iterator itlstkmax_cad;
755 map<MG_NOEUD*,double >::iterator itlstkgau_cad;
756 for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
757 {
758 itlstkmin_cad=lstkmin_cad.find(cadmgnd);
759 double relet_kmincad=(*itlstkmin_cad).second;
760 itlstkmax_cad=lstkmax_cad.find(cadmgnd);
761 double relet_kmaxcad=(*itlstkmax_cad).second;
762 itlstkgau_cad=lstkgau_cad.find(cadmgnd);
763 double relet_kgaucad=(*itlstkgau_cad).second;
764 TPL_MAP_ENTITE<MG_NOEUD*> lstnei_relcad;
765 int relcad_neindnb=lstnei_relcad.get_nb();
766 double relet_search_rad1=relet_search_rad;
767 while(relcad_neindnb<1)
768 {
769 octreecad.rechercher(cadmgnd->get_x(),cadmgnd->get_y(),cadmgnd->get_z(),relet_search_rad1,lstnei_relcad);
770 relcad_neindnb=lstnei_relcad.get_nb();
771 relet_search_rad1=relet_search_rad1+0.1*relet_search_rad;
772 }
773 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
774 for(MG_NOEUD* cadndnei=lstnei_relcad.get_premier(itndnei);cadndnei!=NULL;cadndnei=lstnei_relcad.get_suivant(itndnei))
775 {
776 itlstkmin_cad=lstkmin_cad.find(cadndnei);
777 relet_kmincad=relet_kmincad+(*itlstkmin_cad).second;
778 itlstkmax_cad=lstkmax_cad.find(cadndnei);
779 relet_kmaxcad=relet_kmaxcad+(*itlstkmax_cad).second;
780 itlstkgau_cad=lstkgau_cad.find(cadndnei);
781 relet_kgaucad=relet_kgaucad+(*itlstkgau_cad).second;
782 }
783 relet_kmincad=relet_kmincad/lstnei_relcad.get_nb();
784 relet_kmaxcad=relet_kmaxcad/lstnei_relcad.get_nb();
785 relet_kgaucad=relet_kgaucad/lstnei_relcad.get_nb();
786 lstkmin_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmincad,cadmgnd));
787 lstkmax_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmaxcad,cadmgnd));
788 lstkgau_relt_cadmgmai.insert(pair<double,MG_NOEUD*> (relet_kgaucad,cadmgnd));
789 }
790 // affichage reletive sur GMSH ******************************
791 if (gmsh_affiche>1)
792 {
793 cout<<"affiche: calcul_courbure_cadmgmai_relet "<<endl;
794 std::ostringstream oss;
795 oss << "calcul_courbure_cadmgmai_curvdif_relet_coef:" <<curvdif_coef ;
796 std::string namefic = oss.str();
797 char *cstr = new char[namefic.length() + 1];
798 strcpy(cstr, namefic.c_str());
799 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
800 gest.ajouter_mg_solution(sol1);
801 sol1->change_legende(0,"Kmin_relet");
802 sol1->change_legende(1,"Kmax_relet");
803 sol1->change_legende(2,"K_gau_relet");
804 LISTE_MG_TRIANGLE::iterator ittri;
805 int compte=0;
806 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
807 {
808 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
809 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
810 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
811 MG_NOEUD *no1=tri->get_noeud1();
812 MG_NOEUD *no2=tri->get_noeud2();
813 MG_NOEUD *no3=tri->get_noeud3();
814 double valeur0;
815 double valeur1;
816 double valeur2;
817 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
818 {
819 if (no1==(*itlstkmin_relt_cadmgmai).second)
820 valeur0=(*itlstkmin_relt_cadmgmai).first;
821 }
822 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
823 {
824 if (no1==(*itlstkmax_relt_cadmgmai).second)
825 valeur1=(*itlstkmax_relt_cadmgmai).first;
826 }
827 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
828 {
829 if (no1==(*itlstkgau_relt_cadmgmai).second)
830 valeur2=(*itlstkgau_relt_cadmgmai).first;
831 }
832 sol1->ecrire(valeur0,compte,0,0);
833 sol1->ecrire(valeur1,compte,1,0);
834 sol1->ecrire(valeur2,compte,2,0);
835 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
836 {
837 if (no2==(*itlstkmin_relt_cadmgmai).second)
838 valeur0=(*itlstkmin_relt_cadmgmai).first;
839 }
840 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
841 {
842 if (no2==(*itlstkmax_relt_cadmgmai).second)
843 valeur1=(*itlstkmax_relt_cadmgmai).first;
844 }
845 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
846 {
847 if (no2==(*itlstkgau_relt_cadmgmai).second)
848 valeur2=(*itlstkgau_relt_cadmgmai).first;
849 }
850 sol1->ecrire(valeur0,compte,0,1);
851 sol1->ecrire(valeur1,compte,1,1);
852 sol1->ecrire(valeur2,compte,2,1);
853 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
854 {
855 if (no3==(*itlstkmin_relt_cadmgmai).second)
856 valeur0=(*itlstkmin_relt_cadmgmai).first;
857 }
858 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
859 {
860 if (no3==(*itlstkmax_relt_cadmgmai).second)
861 valeur1=(*itlstkmax_relt_cadmgmai).first;
862 }
863 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
864 {
865 if (no3==(*itlstkgau_relt_cadmgmai).second)
866 valeur2=(*itlstkgau_relt_cadmgmai).first;
867 }
868 sol1->ecrire(valeur0,compte,0,2);
869 sol1->ecrire(valeur1,compte,1,2);
870 sol1->ecrire(valeur2,compte,2,2);
871 compte++;
872 }
873 }
874 // affichage sur GMSH ******************************
875 if (gmsh_affiche>1)
876 {
877 cout<<"affiche: calcul_courbure_cadmgmai "<<endl;
878 std::ostringstream oss;
879 oss << "calcul_courbure_cadmgmai_curvdif_coef:" <<curvdif_coef ;
880 std::string namefic = oss.str();
881 char *cstr = new char[namefic.length() + 1];
882 strcpy(cstr, namefic.c_str());
883 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
884 gest.ajouter_mg_solution(sol1);
885 sol1->change_legende(0,"Kmin");
886 sol1->change_legende(1,"Kmax");
887 sol1->change_legende(2,"K_gau");
888 LISTE_MG_TRIANGLE::iterator ittri;
889 int compte=0;
890 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
891 {
892 MG_NOEUD *no1=tri->get_noeud1();
893 MG_NOEUD *no2=tri->get_noeud2();
894 MG_NOEUD *no3=tri->get_noeud3();
895 char mess[500];
896 sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
897 double valeur0=liste_kmin[mess];
898 double valeur1=liste_kmax[mess];
899 double valeur2=liste_gau[mess];
900 sol1->ecrire(valeur0,compte,0,0);
901 sol1->ecrire(valeur1,compte,1,0);
902 sol1->ecrire(valeur2,compte,2,0);
903 sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
904 valeur0=liste_kmin[mess];
905 valeur1=liste_kmax[mess];
906 valeur2=liste_gau[mess];
907 sol1->ecrire(valeur0,compte,0,1);
908 sol1->ecrire(valeur1,compte,1,1);
909 sol1->ecrire(valeur2,compte,2,1);
910 sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
911 valeur0=liste_kmin[mess];
912 valeur1=liste_kmax[mess];
913 valeur2=liste_gau[mess];
914 sol1->ecrire(valeur0,compte,0,2);
915 sol1->ecrire(valeur1,compte,1,2);
916 sol1->ecrire(valeur2,compte,2,2);
917 compte++;
918 }
919 }
920 liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
921
922 cout<<"calcul courbure defcadmgmai"<<endl;
923 // calcul courbure defcadmgmai ********************************
924
925 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
926 {
927 double kmin1=0.;
928 double kmax1=0.;
929 double kmin2=0.;
930 double kmax2=0.;
931 MG_MAILLAGE_OUTILS *cou;
932 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);
933 }
934 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
935 {
936 unsigned long idface=defcadmgnd->get_lien_topologie()->get_id();
937 unsigned long idnoeud=defcadmgnd->get_id();
938 char mess[500];
939 sprintf(mess,"%lu_%lu",idnoeud,idface);
940 for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
941 {
942 if(mess==(*itkmin).first)
943 {
944 lstkmin_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,defcadmgnd) );
945 lstkmin_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkmin).second));
946 }
947 }
948 for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
949 {
950 if(mess==(*itkmax).first)
951 {
952 lstkmax_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,defcadmgnd) );
953 lstkmax_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkmax).second));
954 }
955 }
956 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
957 {
958 if(mess==(*itkgau).first)
959 {
960 lstkgau_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,defcadmgnd) );
961 lstkgau_defcad.insert(pair<MG_NOEUD*,double>(defcadmgnd,(*itkgau).second));
962 }
963 }
964 }
965 //calc reletive curvature defCAD
966 map<MG_NOEUD*,double >::iterator itlstkmin_defcad;
967 map<MG_NOEUD*,double >::iterator itlstkmax_defcad;
968 map<MG_NOEUD*,double >::iterator itlstkgau_defcad;
969 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
970 {
971 itlstkmin_defcad=lstkmin_defcad.find(defcadmgnd);
972 double relet_kmindefcad=(*itlstkmin_defcad).second;
973 itlstkmax_defcad=lstkmax_defcad.find(defcadmgnd);
974 double relet_kmaxdefcad=(*itlstkmax_defcad).second;
975 itlstkgau_defcad=lstkgau_cad.find(defcadmgnd);
976 double relet_kgaudefcad=(*itlstkgau_defcad).second;
977 TPL_MAP_ENTITE<MG_NOEUD*> lstnei_reldefcad;
978 int reldefcad_neindnb=lstnei_reldefcad.get_nb();
979 double relet_search_rad1=relet_search_rad;
980 while(reldefcad_neindnb<1)
981 {
982 octreecad.rechercher(defcadmgnd->get_x(),defcadmgnd->get_y(),defcadmgnd->get_z(),relet_search_rad1,lstnei_reldefcad);
983 reldefcad_neindnb=lstnei_reldefcad.get_nb();
984 relet_search_rad1=relet_search_rad1+0.1*relet_search_rad;
985 }
986 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
987 for(MG_NOEUD* defcadndnei=lstnei_reldefcad.get_premier(itndnei);defcadndnei!=NULL;defcadndnei=lstnei_reldefcad.get_suivant(itndnei))
988 {
989 itlstkmin_cad=lstkmin_cad.find(defcadndnei);
990 relet_kmindefcad=relet_kmindefcad+(*itlstkmin_defcad).second;
991 itlstkmax_cad=lstkmax_cad.find(defcadndnei);
992 relet_kmaxdefcad=relet_kmaxdefcad+(*itlstkmax_defcad).second;
993 itlstkgau_cad=lstkgau_cad.find(defcadndnei);
994 relet_kgaudefcad=relet_kgaudefcad+(*itlstkgau_defcad).second;
995 }
996 relet_kmindefcad=relet_kmindefcad/lstnei_reldefcad.get_nb();
997 relet_kmaxdefcad=relet_kmaxdefcad/lstnei_reldefcad.get_nb();
998 relet_kgaudefcad=relet_kgaudefcad/lstnei_reldefcad.get_nb();
999 lstkmin_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmindefcad,defcadmgnd));
1000 lstkmax_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kmaxdefcad,defcadmgnd));
1001 lstkgau_relt_defcadmgmai.insert(pair<double,MG_NOEUD*> (relet_kgaudefcad,defcadmgnd));
1002 }
1003 // affichage reletive defcad sur GMSH ******************************
1004 if (gmsh_affiche>1)
1005 {
1006 cout<<"affiche: calcul_courbure_cadmgmai_relet "<<endl;
1007 std::ostringstream oss;
1008 oss << "calcul_courbure_cadmgmai_curvdif_relet_coef:" <<curvdif_coef ;
1009 std::string namefic = oss.str();
1010 char *cstr = new char[namefic.length() + 1];
1011 strcpy(cstr, namefic.c_str());
1012 MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1013 gest.ajouter_mg_solution(sol1);
1014 sol1->change_legende(0,"Kmin_relet");
1015 sol1->change_legende(1,"Kmax_relet");
1016 sol1->change_legende(2,"K_gau_relet");
1017 LISTE_MG_TRIANGLE::iterator ittri;
1018 int compte=0;
1019 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
1020 {
1021 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
1022 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
1023 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
1024 MG_NOEUD *no1=tri->get_noeud1();
1025 MG_NOEUD *no2=tri->get_noeud2();
1026 MG_NOEUD *no3=tri->get_noeud3();
1027 double valeur0;
1028 double valeur1;
1029 double valeur2;
1030 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
1031 {
1032 if (no1==(*itlstkmin_relt_cadmgmai).second)
1033 valeur0=(*itlstkmin_relt_cadmgmai).first;
1034 }
1035 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
1036 {
1037 if (no1==(*itlstkmax_relt_cadmgmai).second)
1038 valeur1=(*itlstkmax_relt_cadmgmai).first;
1039 }
1040 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
1041 {
1042 if (no1==(*itlstkgau_relt_cadmgmai).second)
1043 valeur2=(*itlstkgau_relt_cadmgmai).first;
1044 }
1045 sol1->ecrire(valeur0,compte,0,0);
1046 sol1->ecrire(valeur1,compte,1,0);
1047 sol1->ecrire(valeur2,compte,2,0);
1048 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
1049 {
1050 if (no2==(*itlstkmin_relt_cadmgmai).second)
1051 valeur0=(*itlstkmin_relt_cadmgmai).first;
1052 }
1053 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
1054 {
1055 if (no2==(*itlstkmax_relt_cadmgmai).second)
1056 valeur1=(*itlstkmax_relt_cadmgmai).first;
1057 }
1058 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
1059 {
1060 if (no2==(*itlstkgau_relt_cadmgmai).second)
1061 valeur2=(*itlstkgau_relt_cadmgmai).first;
1062 }
1063 sol1->ecrire(valeur0,compte,0,1);
1064 sol1->ecrire(valeur1,compte,1,1);
1065 sol1->ecrire(valeur2,compte,2,1);
1066 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
1067 {
1068 if (no3==(*itlstkmin_relt_cadmgmai).second)
1069 valeur0=(*itlstkmin_relt_cadmgmai).first;
1070 }
1071 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
1072 {
1073 if (no3==(*itlstkmax_relt_cadmgmai).second)
1074 valeur1=(*itlstkmax_relt_cadmgmai).first;
1075 }
1076 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
1077 {
1078 if (no3==(*itlstkgau_relt_cadmgmai).second)
1079 valeur2=(*itlstkgau_relt_cadmgmai).first;
1080 }
1081 sol1->ecrire(valeur0,compte,0,2);
1082 sol1->ecrire(valeur1,compte,1,2);
1083 sol1->ecrire(valeur2,compte,2,2);
1084 compte++;
1085 }
1086 }
1087 // affichage sur GMSH ******************************
1088 if (gmsh_affiche>1)
1089 {
1090 cout<<"affiche: calcul_courbure_defcadmgmai "<<endl;
1091 std::ostringstream oss;
1092 oss << "calcul_courbure_defcadmgmai_curvdif_coef:" <<curvdif_coef ;
1093 std::string namefic = oss.str();
1094 char *cstr = new char[namefic.length() + 1];
1095 strcpy(cstr, namefic.c_str());
1096 MG_SOLUTION* sol2=new MG_SOLUTION(defcadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1097 gest.ajouter_mg_solution(sol2);
1098 sol2->change_legende(0,"Kmin");
1099 sol2->change_legende(1,"Kmax");
1100 sol2->change_legende(2,"K_gau");
1101 LISTE_MG_TRIANGLE::iterator ittri;
1102 int compte=0;
1103 for (MG_TRIANGLE* tri=defcadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=defcadmgmai->get_suivant_triangle(ittri))
1104 {
1105 MG_NOEUD *no1=tri->get_noeud1();
1106 MG_NOEUD *no2=tri->get_noeud2();
1107 MG_NOEUD *no3=tri->get_noeud3();
1108 char mess[500];
1109 sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
1110 double valeur0=liste_kmin[mess];
1111 double valeur1=liste_kmax[mess];
1112 double valeur2=liste_gau[mess];
1113 sol2->ecrire(valeur0,compte,0,0);
1114 sol2->ecrire(valeur1,compte,1,0);
1115 sol2->ecrire(valeur2,compte,2,0);
1116 sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
1117 valeur0=liste_kmin[mess];
1118 valeur1=liste_kmax[mess];
1119 valeur2=liste_gau[mess];
1120 sol2->ecrire(valeur0,compte,0,1);
1121 sol2->ecrire(valeur1,compte,1,1);
1122 sol2->ecrire(valeur2,compte,2,1);
1123 sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
1124 valeur0=liste_kmin[mess];
1125 valeur1=liste_kmax[mess];
1126 valeur2=liste_gau[mess];
1127 sol2->ecrire(valeur0,compte,0,2);
1128 sol2->ecrire(valeur1,compte,1,2);
1129 sol2->ecrire(valeur2,compte,2,2);
1130 compte++;
1131 }
1132
1133 }
1134 liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
1135
1136
1137 ///make correspondence between cadmgmai and defcadmgmai nodes
1138 map<unsigned long, unsigned long>::iterator itcoresspondndidlst;
1139 for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
1140 {
1141 itcoresspondndidlst=coresspondndidlst.find(defcadndcurv->get_id());
1142 defcadndcurv->change_nouveau_numero((*itcoresspondndidlst).second);
1143 }
1144
1145 cout<<"solution calculation"<<endl;
1146 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_diff;
1147 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_diff;
1148 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_diff;
1149 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_cadmgmai;
1150 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_cadmgmai;
1151 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_cadmgmai;
1152 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_defcadmgmai;
1153 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_defcadmgmai;
1154 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_defcadmgmai;
1155 cout<<"lstkmin_cadmgmai.size()= "<<lstkmin_cadmgmai.size()<<endl;
1156 cout<<"lstkmin_defcadmgmai.size()= "<<lstkmin_defcadmgmai.size()<<endl;
1157 cout<<"kmin diff. calc. started"<<endl;
1158
1159 for(itlstkmin_cadmgmai=lstkmin_cadmgmai.begin();itlstkmin_cadmgmai!=lstkmin_cadmgmai.end();itlstkmin_cadmgmai++)
1160 {
1161 MG_NOEUD* cadndcurv=(*itlstkmin_cadmgmai).second;
1162 double kmindcad;
1163 double kmindcad_def;
1164 kmindcad=(*itlstkmin_cadmgmai).first;
1165 for(itlstkmin_defcadmgmai=lstkmin_defcadmgmai.begin();itlstkmin_defcadmgmai!=lstkmin_defcadmgmai.end();itlstkmin_defcadmgmai++)
1166 {
1167 MG_NOEUD* defcadndcurv=(*itlstkmin_defcadmgmai).second;
1168 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1169 kmindcad_def=(*itlstkmin_defcadmgmai).first;
1170 }
1171
1172 double kmin_diff=kmindcad_def-kmindcad;
1173 lstkmin_diff.insert(pair<double,MG_NOEUD*>(kmin_diff,cadndcurv) );
1174 }
1175 cout<<"kmax diff. calc. started"<<endl;
1176 for(itlstkmax_cadmgmai=lstkmax_cadmgmai.begin();itlstkmax_cadmgmai!=lstkmax_cadmgmai.end();itlstkmax_cadmgmai++)
1177 {
1178 MG_NOEUD* cadndcurv=(*itlstkmax_cadmgmai).second;
1179 double kmaxndcad;
1180 double kmaxndcad_def;
1181 kmaxndcad=(*itlstkmax_cadmgmai).first;
1182 for(itlstkmax_defcadmgmai=lstkmax_defcadmgmai.begin();itlstkmax_defcadmgmai!=lstkmax_defcadmgmai.end();itlstkmax_defcadmgmai++)
1183 {
1184 MG_NOEUD* defcadndcurv=(*itlstkmax_defcadmgmai).second;
1185 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1186 {
1187 kmaxndcad_def=(*itlstkmax_defcadmgmai).first;
1188 }
1189 }
1190 double kmax_diff=kmaxndcad_def-kmaxndcad;
1191 lstkmax_diff.insert(pair<double,MG_NOEUD*>(kmax_diff,cadndcurv) );
1192 }
1193 cout<<"kgau diff. calc. started"<<endl;
1194 for(itlstkgau_cadmgmai=lstkgau_cadmgmai.begin();itlstkgau_cadmgmai!=lstkgau_cadmgmai.end();itlstkgau_cadmgmai++)
1195 {
1196 MG_NOEUD* cadndcurv=(*itlstkgau_cadmgmai).second;
1197 double kgaundcad;
1198 double kgaundcad_def;
1199 kgaundcad=(*itlstkgau_cadmgmai).first;
1200 for(itlstkgau_defcadmgmai=lstkgau_defcadmgmai.begin();itlstkgau_defcadmgmai!=lstkgau_defcadmgmai.end();itlstkgau_defcadmgmai++)
1201 {
1202 MG_NOEUD* defcadndcurv=(*itlstkgau_defcadmgmai).second;
1203 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1204 {
1205 kgaundcad_def=(*itlstkgau_defcadmgmai).first;
1206 }
1207 }
1208 double kgau_diff=kgaundcad_def-kgaundcad;
1209 lstkgau_diff.insert(pair<double,MG_NOEUD*>(kgau_diff,cadndcurv) );
1210 }
1211 // mean diff
1212 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_relt_diff;
1213 multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_relt_diff;
1214 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_relt_diff;
1215 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_cadmgmai;
1216 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_cadmgmai;
1217 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_cadmgmai;
1218 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_defcadmgmai;
1219 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_defcadmgmai;
1220 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_defcadmgmai;
1221 cout<<"kmin _relt diff. calc. started"<<endl;
1222 for(itlstkmin_relt_cadmgmai=lstkmin_relt_cadmgmai.begin();itlstkmin_relt_cadmgmai!=lstkmin_relt_cadmgmai.end();itlstkmin_relt_cadmgmai++)
1223 {
1224 MG_NOEUD* cadndcurv=(*itlstkmin_relt_cadmgmai).second;
1225 double kmindcad;
1226 double kmindcad_relt_def;
1227 kmindcad=(*itlstkmin_relt_cadmgmai).first;
1228 for(itlstkmin_relt_defcadmgmai=lstkmin_relt_defcadmgmai.begin();itlstkmin_relt_defcadmgmai!=lstkmin_relt_defcadmgmai.end();itlstkmin_relt_defcadmgmai++)
1229 {
1230 MG_NOEUD* defcadndcurv=(*itlstkmin_relt_defcadmgmai).second;
1231 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1232 kmindcad_relt_def=(*itlstkmin_relt_defcadmgmai).first;
1233 }
1234
1235 double kmin_relt_diff=kmindcad_relt_def-kmindcad;
1236 lstkmin_relt_diff.insert(pair<double,MG_NOEUD*>(kmin_relt_diff,cadndcurv) );
1237 }
1238 cout<<"kmax _relt diff. calc. started"<<endl;
1239 for(itlstkmax_relt_cadmgmai=lstkmax_relt_cadmgmai.begin();itlstkmax_relt_cadmgmai!=lstkmax_relt_cadmgmai.end();itlstkmax_relt_cadmgmai++)
1240 {
1241 MG_NOEUD* cadndcurv=(*itlstkmax_relt_cadmgmai).second;
1242 double kmaxndcad;
1243 double kmaxndcad_relt_def;
1244 kmaxndcad=(*itlstkmax_relt_cadmgmai).first;
1245 for(itlstkmax_relt_defcadmgmai=lstkmax_relt_defcadmgmai.begin();itlstkmax_relt_defcadmgmai!=lstkmax_relt_defcadmgmai.end();itlstkmax_relt_defcadmgmai++)
1246 {
1247 MG_NOEUD* defcadndcurv=(*itlstkmax_relt_defcadmgmai).second;
1248 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1249 {
1250 kmaxndcad_relt_def=(*itlstkmax_relt_defcadmgmai).first;
1251 }
1252 }
1253 double kmax_relt_diff=kmaxndcad_relt_def-kmaxndcad;
1254 lstkmax_relt_diff.insert(pair<double,MG_NOEUD*>(kmax_relt_diff,cadndcurv) );
1255 }
1256 cout<<"kgau_relt diff. calc. started"<<endl;
1257 for(itlstkgau_relt_cadmgmai=lstkgau_relt_cadmgmai.begin();itlstkgau_relt_cadmgmai!=lstkgau_relt_cadmgmai.end();itlstkgau_relt_cadmgmai++)
1258 {
1259 MG_NOEUD* cadndcurv=(*itlstkgau_relt_cadmgmai).second;
1260 double kgaundcad;
1261 double kgaundcad_relt_def;
1262 kgaundcad=(*itlstkgau_relt_cadmgmai).first;
1263 for(itlstkgau_relt_defcadmgmai=lstkgau_relt_defcadmgmai.begin();itlstkgau_relt_defcadmgmai!=lstkgau_relt_defcadmgmai.end();itlstkgau_relt_defcadmgmai++)
1264 {
1265 MG_NOEUD* defcadndcurv=(*itlstkgau_relt_defcadmgmai).second;
1266 if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
1267 {
1268 kgaundcad_relt_def=(*itlstkgau_relt_defcadmgmai).first;
1269 }
1270 }
1271 double kgau_relt_diff=kgaundcad_relt_def-kgaundcad;
1272 lstkgau_relt_diff.insert(pair<double,MG_NOEUD*>(kgau_relt_diff,cadndcurv) );
1273 }
1274 // affichage reletive diff sur GMSH ******************************
1275 if (gmsh_affiche>0)
1276 {
1277 cout<<"affiche: calcul_relet_difference_courbure "<<endl;
1278 std::ostringstream oss;
1279 oss << "KMaxMinGaudiff_curvdifcoef_relet:" <<curvdif_coef ;
1280 std::string namefic = oss.str();
1281 char *cstr = new char[namefic.length() + 1];
1282 strcpy(cstr, namefic.c_str());
1283 MG_SOLUTION* sol4=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"Kdiff_relt_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1284 gest.ajouter_mg_solution(sol4);
1285 sol4->change_legende(0,"Kmin_diff");
1286 sol4->change_legende(1,"Kmax_diff");
1287 sol4->change_legende(2,"Kgau_diff");
1288 LISTE_MG_TRIANGLE::iterator ittri;
1289 int compte=0;
1290 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
1291 {
1292 MG_NOEUD *no1=tri->get_noeud1();
1293 MG_NOEUD *no2=tri->get_noeud2();
1294 MG_NOEUD *no3=tri->get_noeud3();
1295 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diff;
1296 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diff;
1297 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_relt_diff;
1298 double valeurKmin1, valeurKmin2, valeurKmin3;
1299 double valeurKmax1, valeurKmax2, valeurKmax3;
1300 double valeurKgau1, valeurKgau2, valeurKgau3;
1301 for (itlstkmin_relt_diff=lstkmin_relt_diff.begin();itlstkmin_relt_diff!=lstkmin_relt_diff.end();itlstkmin_relt_diff++)
1302 {
1303 if (no1==(*itlstkmin_relt_diff).second)
1304 valeurKmin1=(*itlstkmin_relt_diff).first;
1305 if (no2==(*itlstkmin_relt_diff).second)
1306 valeurKmin2=(*itlstkmin_relt_diff).first;
1307 if (no3==(*itlstkmin_relt_diff).second)
1308 valeurKmin3=(*itlstkmin_relt_diff).first;
1309 }
1310 for (itlstkmax_relt_diff=lstkmax_relt_diff.begin();itlstkmax_relt_diff!=lstkmax_relt_diff.end();itlstkmax_relt_diff++)
1311 {
1312 if (no1==(*itlstkmax_relt_diff).second)
1313 valeurKmax1=(*itlstkmax_relt_diff).first;
1314 if (no2==(*itlstkmax_relt_diff).second)
1315 valeurKmax2=(*itlstkmax_relt_diff).first;
1316 if (no3==(*itlstkmax_relt_diff).second)
1317 valeurKmax3=(*itlstkmax_relt_diff).first;
1318 }
1319 for (itlstkgau_relt_diff=lstkgau_relt_diff.begin();itlstkgau_relt_diff!=lstkgau_relt_diff.end();itlstkgau_relt_diff++)
1320 {
1321 if (no1==(*itlstkgau_relt_diff).second)
1322 valeurKgau1=(*itlstkgau_relt_diff).first;
1323 if (no2==(*itlstkgau_relt_diff).second)
1324 valeurKgau2=(*itlstkgau_relt_diff).first;
1325 if (no3==(*itlstkgau_relt_diff).second)
1326 valeurKgau3=(*itlstkgau_relt_diff).first;
1327 }
1328 sol4->ecrire(valeurKmin1,compte,0,0);
1329 sol4->ecrire(valeurKmax1,compte,1,0);
1330 sol4->ecrire(valeurKgau1,compte,2,0);
1331
1332 sol4->ecrire(valeurKmin2,compte,0,1);
1333 sol4->ecrire(valeurKmax2,compte,1,1);
1334 sol4->ecrire(valeurKgau2,compte,2,1);
1335
1336 sol4->ecrire(valeurKmin3,compte,0,2);
1337 sol4->ecrire(valeurKmax3,compte,1,2);
1338 sol4->ecrire(valeurKgau3,compte,2,2);
1339 compte++;
1340 }
1341 }
1342
1343 // affichage sur GMSH ******************************
1344 if (gmsh_affiche>1)
1345 {
1346 cout<<"affiche: calcul_difference_courbure "<<endl;
1347 std::ostringstream oss;
1348 oss << "KMaxMinGaudiff_curvdifcoef:" <<curvdif_coef ;
1349 std::string namefic = oss.str();
1350 char *cstr = new char[namefic.length() + 1];
1351 strcpy(cstr, namefic.c_str());
1352 MG_SOLUTION* sol3=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"Kdiff_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
1353 gest.ajouter_mg_solution(sol3);
1354 sol3->change_legende(0,"Kmin_diff");
1355 sol3->change_legende(1,"Kmax_diff");
1356 sol3->change_legende(2,"Kgau_diff");
1357 LISTE_MG_TRIANGLE::iterator ittri;
1358 int compte=0;
1359 for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
1360 {
1361 MG_NOEUD *no1=tri->get_noeud1();
1362 MG_NOEUD *no2=tri->get_noeud2();
1363 MG_NOEUD *no3=tri->get_noeud3();
1364 //char mess[500];
1365 //sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
1366 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff;
1367 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff;
1368 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_diff;
1369 double valeurKmin1, valeurKmin2, valeurKmin3;
1370 double valeurKmax1, valeurKmax2, valeurKmax3;
1371 double valeurKgau1, valeurKgau2, valeurKgau3;
1372 for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
1373 {
1374 if (no1==(*itlstkmin_diff).second)
1375 valeurKmin1=(*itlstkmin_diff).first;
1376 if (no2==(*itlstkmin_diff).second)
1377 valeurKmin2=(*itlstkmin_diff).first;
1378 if (no3==(*itlstkmin_diff).second)
1379 valeurKmin3=(*itlstkmin_diff).first;
1380 }
1381 for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
1382 {
1383 if (no1==(*itlstkmax_diff).second)
1384 valeurKmax1=(*itlstkmax_diff).first;
1385 if (no2==(*itlstkmax_diff).second)
1386 valeurKmax2=(*itlstkmax_diff).first;
1387 if (no3==(*itlstkmax_diff).second)
1388 valeurKmax3=(*itlstkmax_diff).first;
1389 }
1390 for (itlstkgau_diff=lstkgau_diff.begin();itlstkgau_diff!=lstkgau_diff.end();itlstkgau_diff++)
1391 {
1392 if (no1==(*itlstkgau_diff).second)
1393 valeurKgau1=(*itlstkgau_diff).first;
1394 if (no2==(*itlstkgau_diff).second)
1395 valeurKgau2=(*itlstkgau_diff).first;
1396 if (no3==(*itlstkgau_diff).second)
1397 valeurKgau3=(*itlstkgau_diff).first;
1398 }
1399 sol3->ecrire(valeurKmin1,compte,0,0);
1400 sol3->ecrire(valeurKmax1,compte,1,0);
1401 sol3->ecrire(valeurKgau1,compte,2,0);
1402
1403 sol3->ecrire(valeurKmin2,compte,0,1);
1404 sol3->ecrire(valeurKmax2,compte,1,1);
1405 sol3->ecrire(valeurKgau2,compte,2,1);
1406
1407 sol3->ecrire(valeurKmin3,compte,0,2);
1408 sol3->ecrire(valeurKmax3,compte,1,2);
1409 sol3->ecrire(valeurKgau3,compte,2,2);
1410 compte++;
1411 }
1412
1413 }
1414
1415 char chaine[1000];
1416 char* p;
1417 p=strrchr(magicfilename,'.');
1418 strncpy(chaine,magicfilename,p-magicfilename);
1419 std::string namfic=chaine;
1420 namfic=namfic+"courbcal.magic";
1421 gest.enregistrer(namfic.c_str());
1422 cout<<"read insert points in lstpinsert"<<endl;
1423 //read insert points in lstpinsert
1424 std::vector<double*> lstpinsert;
1425 double prop=0.001;
1426 FILE *in=fopen(gnifinspointfile,"rt");
1427 if (in==NULL) cout<<"file is not available"<<endl;
1428 while (!feof(in))
1429 {
1430 char chaine[500];
1431 char* res=fgets(chaine,500,in);
1432 if(res!=NULL)
1433 {
1434 double x,y,z;
1435 double q1,q2,q3;
1436 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
1437 q1=prop*q1;
1438 q2=prop*q2;
1439 q3=prop*q3;
1440 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
1441 else if (nb==6)
1442 {
1443 double* pcoordbc=new double[6];
1444 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
1445 lstpinsert.push_back(pcoordbc);
1446 }
1447 }
1448 }
1449 fclose(in);
1450 if (relet_curvature<1)
1451 {
1452 //criterion
1453 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_diff;
1454 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_diff;
1455 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff;
1456 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff;
1457 ritlstkmin_diff=lstkmin_diff.rbegin();
1458 double kmin_diff_min=(*ritlstkmin_diff).first;
1459 itlstkmin_diff=lstkmin_diff.begin();
1460 double kmin_diff_max=(*itlstkmin_diff).first;
1461 ritlstkmax_diff=lstkmax_diff.rbegin();
1462 double kmax_diff_min=(*ritlstkmax_diff).first;
1463 itlstkmax_diff=lstkmax_diff.begin();
1464 double kmax_diff_max=(*itlstkmax_diff).first;
1465 cout<<"kmin_diff_min= "<<kmin_diff_min<<" kmin_diff_max= "<<kmin_diff_max<<endl;
1466 cout<<"kmax_diff_min= "<<kmax_diff_min<<" kmax_diff_max= "<<kmax_diff_max<<endl;
1467
1468 double crikmin_min=curvdif_coef;//sasan*kmin_diff_min;
1469 double crikmin_max=curvdif_coef;//sasan*kmin_diff_max;
1470 double crikmax_min=curvdif_coef;//sasan*kmax_diff_min;
1471 double crikmax_max=curvdif_coef;//sasan*kmax_diff_max;
1472 cout<<"crikmin_min= "<<crikmin_min<<" crikmin_max= "<<crikmin_max<<" crikmax_min= "<<crikmax_min<<" crikmax_max= "<<crikmax_max<<endl;
1473 cout<<"lstkmin_diff.size()= "<<lstkmin_diff.size()<<endl;
1474 cout<<"lstkmax_diff.size()= "<<lstkmax_diff.size()<<endl;
1475
1476 cout<<"for Kmin"<<endl;
1477 int Kmin_positive_nb=0;
1478 double Kmin_positive_mean=0.;
1479 double Kmin_positive_stdev=0.;
1480 int Kmin_negative_nb=0;
1481 double Kmin_negative_mean=0.;
1482 double Kmin_negative_stdev=0.;
1483 for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
1484 {
1485 if(((*itlstkmin_diff).first)>=0.)
1486 {
1487 Kmin_positive_nb++;
1488 Kmin_positive_mean += (*itlstkmin_diff).first;
1489 }
1490 if(((*itlstkmin_diff).first)<=0.)
1491 {
1492 Kmin_negative_nb++;
1493 Kmin_negative_mean += (*itlstkmin_diff).first;
1494 }
1495 }
1496 Kmin_positive_mean /= (1.*Kmin_positive_nb);
1497 Kmin_negative_mean /= (1.*Kmin_negative_nb);
1498 cout<<"Kmin_positive_mean= "<<Kmin_positive_mean<<" Kmin_negative_mean= "<<Kmin_negative_mean<<endl;
1499
1500 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1501 for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
1502 {
1503 {
1504 if((crikmin_max<(*itlstkmin_diff).first) || (crikmin_min>(*itlstkmin_diff).first))
1505 {
1506 MG_NOEUD* piefect=(*itlstkmin_diff).second;
1507 int neindnb=lstneipdefect.get_nb();
1508 double search_radius1=search_radius;
1509 while(neindnb==0)
1510 {
1511 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1512 neindnb=lstneipdefect.get_nb();
1513 search_radius1=search_radius1+0.1*search_radius;
1514 }
1515 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1516 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1517 {
1518 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1519 {
1520 double* xyzpins;
1521 xyzpins=(*itlstpinsert);
1522 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1523 lstpinsert.erase(itlstpinsert);
1524 }
1525 }
1526 lstneipdefect.vide();
1527 }
1528 }
1529 }
1530 cout<<"for Kmax"<<endl;
1531 int Kmax_positive_nb=0;
1532 double Kmax_positive_mean=0.;
1533 double Kmax_positive_stdev=0.;
1534 int Kmax_negative_nb=0;
1535 double Kmax_negative_mean=0.;
1536 double Kmax_negative_stdev=0.;
1537 for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
1538 {
1539 if(((*itlstkmax_diff).first)>=0.)
1540 {
1541 Kmax_positive_nb++;
1542 Kmax_positive_mean += (*itlstkmax_diff).first;
1543 }
1544 if(((*itlstkmax_diff).first)<=0.)
1545 {
1546 Kmax_negative_nb++;
1547 Kmax_negative_mean += (*itlstkmax_diff).first;
1548 }
1549 }
1550 Kmax_positive_mean /= (1.*Kmax_positive_nb);
1551 Kmax_negative_mean /= (1.*Kmax_negative_nb);
1552 cout<<"Kmax_positive_mean= "<<Kmax_positive_mean<<" Kmax_negative_mean= "<<Kmax_negative_mean<<endl;
1553
1554 for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
1555 {
1556 if((crikmax_max<(*itlstkmax_diff).first) || (crikmax_min>(*itlstkmax_diff).first))
1557 {
1558 MG_NOEUD* piefect=(*itlstkmax_diff).second;
1559 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1560 int neindnb=lstneipdefect.get_nb();
1561 double search_radius1=search_radius;
1562 while(neindnb==0)
1563 {
1564 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1565 neindnb=lstneipdefect.get_nb();
1566 search_radius1=search_radius1+0.1*search_radius;
1567 }
1568 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1569 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1570 {
1571 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1572 {
1573 double* xyzpins;
1574 xyzpins=(*itlstpinsert);
1575 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1576 lstpinsert.erase(itlstpinsert);
1577 }
1578 }
1579
1580 }
1581 }
1582 }
1583 if (relet_curvature>0)
1584 {
1585 //criterion
1586 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_relt_diff=lstkmin_relt_diff.rbegin();
1587 multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_relt_diff=lstkmax_relt_diff.rbegin();
1588 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diff=lstkmin_relt_diff.begin();
1589 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diff=lstkmax_relt_diff.begin();
1590 double kmin_relt_diff_min=(*ritlstkmin_relt_diff).first;
1591 double kmin_relt_diff_max=(*itlstkmin_relt_diff).first;
1592 double kmax_relt_diff_min=(*ritlstkmax_relt_diff).first;
1593 double kmax_relt_diff_max=(*itlstkmax_relt_diff).first;
1594 cout<<"kmin_relt_diff_min= "<<kmin_relt_diff_min<<" kmin_relt_diff_max= "<<kmin_relt_diff_max<<endl;
1595 cout<<"kmax_relt_diff_min= "<<kmax_relt_diff_min<<" kmax_relt_diff_max= "<<kmax_relt_diff_max<<endl;
1596
1597 double crikmin_min;
1598 double crikmin_max;
1599 double crikmax_min;
1600 double crikmax_max;
1601
1602 cout<<"lstkmin_diff.size()= "<<lstkmin_diff.size()<<endl;
1603 cout<<"lstkmax_diff.size()= "<<lstkmax_diff.size()<<endl;
1604
1605 cout<<"for Kmin_relet_diff"<<endl;
1606 cout<<"lstkmin_relt_diff.size()= "<<lstkmin_relt_diff.size()<<endl;
1607 int Kmin_positive_nb=0;
1608 double Kmin_positive_mean=0.;
1609 double Kmin_positive_stdev=0.;
1610 int Kmin_negative_nb=0;
1611 double Kmin_negative_mean=0.;
1612 double Kmin_negative_stdev=0.;
1613 int kmin_nb=0;
1614 double kmin_mean=0.;
1615 for (itlstkmin_relt_diff=lstkmin_relt_diff.begin();itlstkmin_relt_diff!=lstkmin_relt_diff.end();itlstkmin_relt_diff++)
1616 {
1617 kmin_nb++;
1618 kmin_mean += (*itlstkmin_relt_diff).first;
1619 if(((*itlstkmin_relt_diff).first)>=0.)
1620 {
1621 Kmin_positive_nb++;
1622 Kmin_positive_mean += (*itlstkmin_relt_diff).first;
1623 }
1624 if(((*itlstkmin_relt_diff).first)<=0.)
1625 {
1626 Kmin_negative_nb++;
1627 Kmin_negative_mean += (*itlstkmin_relt_diff).first;
1628 }
1629 }
1630 Kmin_positive_mean /= (1.*Kmin_positive_nb);
1631 Kmin_negative_mean /= (1.*Kmin_negative_nb);
1632 kmin_mean /= (1.*kmin_nb);
1633 cout<<"Kmin_positive_mean= "<<Kmin_positive_mean<<" Kmin_negative_mean= "<<Kmin_negative_mean<<" Kmin_mean= "<<kmin_mean<<endl;
1634 crikmin_min=curvdif_coef*Kmin_negative_mean;
1635 crikmin_max=curvdif_coef*Kmin_positive_mean;
1636
1637
1638 for (itlstkmin_relt_diff=lstkmin_relt_diff.begin();itlstkmin_relt_diff!=lstkmin_relt_diff.end();itlstkmin_relt_diff++)
1639 {
1640 if((crikmin_max<(*itlstkmin_relt_diff).first) || (crikmin_min>(*itlstkmin_relt_diff).first))
1641 {
1642 MG_NOEUD* piefect=(*itlstkmin_relt_diff).second;
1643 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1644 /*int neindnb=lstneipdefect.get_nb();
1645 double search_radius1=1.;
1646 while(neindnb==0)
1647 {
1648 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1649 neindnb=lstneipdefect.get_nb();
1650 search_radius1=search_radius1+0.1*1.;
1651 }*/
1652 for (int itt=0;itt<piefect->get_lien_segment()->get_nb();itt++)
1653 {
1654 MG_SEGMENT* segpiefect=piefect->get_lien_segment()->get(itt);
1655 if (segpiefect->get_noeud1()!=piefect)
1656 lstneipdefect.ajouter(segpiefect->get_noeud1());
1657 else if (segpiefect->get_noeud2()!=piefect)
1658 lstneipdefect.ajouter(segpiefect->get_noeud2());
1659 }
1660
1661
1662 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1663 int locnd_nb=0;
1664 double loc_curv=0.;
1665 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1666 {
1667 double curv=0.;
1668 if(ndnei!=piefect)
1669 {
1670 for (multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diffnei=lstkmin_relt_diff.begin();itlstkmin_relt_diffnei!=lstkmin_relt_diff.end();itlstkmin_relt_diffnei++)
1671 {
1672 if ((*itlstkmin_relt_diffnei).second==ndnei)
1673 {
1674 locnd_nb++;
1675 curv += (*itlstkmin_relt_diffnei).first;
1676 }
1677 }
1678 }
1679 curv /= locnd_nb;
1680 loc_curv=curv;
1681 }
1682
1683 int pass_kmin=0;
1684 if ((*itlstkmin_relt_diff).first>=0)
1685 {
1686 if((*itlstkmin_relt_diff).first<=4.*loc_curv)
1687 pass_kmin++;
1688 }
1689 else if ((*itlstkmin_relt_diff).first<=0)
1690 {
1691 if((*itlstkmin_relt_diff).first>=4.*loc_curv)
1692 pass_kmin++;
1693 }
1694 if (pass_kmin>0)//(loc_curv>(0.2*(*itlstkmin_relt_diff).first) || loc_curv<(0.2*(*itlstkmin_relt_diff).first))
1695 {
1696 //cout<<"loc_curv= "<<loc_curv<<" (*itlstkmin_relt_diff).first= "<<(*itlstkmin_relt_diff).first<<endl;
1697 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect2;
1698 int neindnb2=lstneipdefect2.get_nb();
1699 double search_radius2=search_radius;
1700 while(neindnb2==0)
1701 {
1702 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius2,lstneipdefect2);
1703 neindnb2=lstneipdefect2.get_nb();
1704 search_radius2=search_radius2+0.1*search_radius;
1705 }
1706 for(MG_NOEUD* ndnei=lstneipdefect2.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect2.get_suivant(itndnei))
1707 {
1708 double curv=0.;
1709 for (multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_relt_diffnei=lstkmin_relt_diff.begin();itlstkmin_relt_diffnei!=lstkmin_relt_diff.end();itlstkmin_relt_diffnei++)
1710 {
1711 if ((*itlstkmin_relt_diffnei).second==ndnei)
1712 {
1713 curv =(*itlstkmin_relt_diffnei).first;
1714 }
1715 }
1716 if(crikmin_max<curv || crikmin_min>curv)
1717 {
1718 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1719 {
1720 double* xyzpins;
1721 xyzpins=(*itlstpinsert);
1722 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1723 {
1724 lstpinsert.erase(itlstpinsert);
1725 itlstpinsert=lstpinsert.begin();
1726 }
1727 }
1728 }
1729 }
1730 lstneipdefect.vide();
1731 }
1732 }
1733 }
1734 cout<<"for Kmax_relet_diff"<<endl;
1735 int Kmax_positive_nb=0;
1736 double Kmax_positive_mean=0.;
1737 double Kmax_positive_stdev=0.;
1738 int Kmax_negative_nb=0;
1739 double Kmax_negative_mean=0.;
1740 double Kmax_negative_stdev=0.;
1741 int Kmax_nb=0;
1742 double Kmax_mean=0.;
1743 for (itlstkmax_relt_diff=lstkmax_relt_diff.begin();itlstkmax_relt_diff!=lstkmax_relt_diff.end();itlstkmax_relt_diff++)
1744 {
1745 Kmax_nb++;
1746 Kmax_mean += (*itlstkmax_relt_diff).first;
1747 if(((*itlstkmax_relt_diff).first)>=0.)
1748 {
1749 Kmax_positive_nb++;
1750 Kmax_positive_mean += (*itlstkmax_relt_diff).first;
1751 }
1752 if(((*itlstkmax_relt_diff).first)<=0.)
1753 {
1754 Kmax_negative_nb++;
1755 Kmax_negative_mean += (*itlstkmax_relt_diff).first;
1756 }
1757 }
1758 Kmax_positive_mean /= (1.*Kmax_positive_nb);
1759 Kmax_negative_mean /= (1.*Kmax_negative_nb);
1760 Kmax_mean /= (1.*Kmax_nb);
1761 cout<<"Kmax_positive_mean= "<<Kmax_positive_mean<<" Kmax_negative_mean= "<<Kmax_negative_mean<<" Kmax_mean= "<<Kmax_mean<<endl;
1762 crikmax_min=curvdif_coef*Kmax_negative_mean;
1763 crikmax_max=curvdif_coef*Kmax_positive_mean;
1764 cout<<"crikmin_min= "<<crikmin_min<<" crikmin_max= "<<crikmin_max<<" crikmax_min= "<<crikmax_min<<" crikmax_max= "<<crikmax_max<<endl;
1765
1766 for (itlstkmax_relt_diff=lstkmax_relt_diff.begin();itlstkmax_relt_diff!=lstkmax_relt_diff.end();itlstkmax_relt_diff++)
1767 {
1768 if((crikmax_max<(*itlstkmax_relt_diff).first) || (crikmax_min>(*itlstkmax_relt_diff).first))
1769 {
1770 MG_NOEUD* piefect=(*itlstkmax_relt_diff).second;
1771 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
1772 /*int neindnb=lstneipdefect.get_nb();
1773 double search_radius1=1.;
1774 while(neindnb==0)
1775 {
1776 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
1777 neindnb=lstneipdefect.get_nb();
1778 search_radius1=search_radius1+0.1*1.;
1779 }*/
1780 for (int itt=0;itt<piefect->get_lien_segment()->get_nb();itt++)
1781 {
1782 MG_SEGMENT* segpiefect=piefect->get_lien_segment()->get(itt);
1783 if (segpiefect->get_noeud1()!=piefect)
1784 lstneipdefect.ajouter(segpiefect->get_noeud1());
1785 else if (segpiefect->get_noeud2()!=piefect)
1786 lstneipdefect.ajouter(segpiefect->get_noeud2());
1787 }
1788
1789
1790 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
1791 int locnd_nb=0;
1792 double loc_curv=0.;
1793 for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
1794 {
1795 double curv=0.;
1796 if(ndnei!=piefect)
1797 {
1798 for (multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diffnei=lstkmax_relt_diff.begin();itlstkmax_relt_diffnei!=lstkmax_relt_diff.end();itlstkmax_relt_diffnei++)
1799 {
1800 if ((*itlstkmax_relt_diffnei).second==ndnei)
1801 {
1802 locnd_nb++;
1803 curv += (*itlstkmax_relt_diffnei).first;
1804 }
1805 }
1806 }
1807 curv /= locnd_nb;
1808 loc_curv=curv;
1809 }
1810
1811 int pass_kmax=0;
1812 if ((*itlstkmax_relt_diff).first>=0)
1813 {
1814 if((*itlstkmax_relt_diff).first<=4.*loc_curv)
1815 pass_kmax++;
1816 }
1817 else if ((*itlstkmax_relt_diff).first<=0)
1818 {
1819 if((*itlstkmax_relt_diff).first>=4.*loc_curv)
1820 pass_kmax++;
1821 }
1822
1823 if (pass_kmax>0)
1824 {
1825 //cout<<"loc_curv= "<<loc_curv<<" (*itlstkmax_relt_diff).first= "<<(*itlstkmax_relt_diff).first<<endl;
1826 TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect2;
1827 int neindnb2=lstneipdefect2.get_nb();
1828 double search_radius2=search_radius;
1829 while(neindnb2==0)
1830 {
1831 octreecad.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius2,lstneipdefect2);
1832 neindnb2=lstneipdefect2.get_nb();
1833 search_radius2=search_radius2+0.1*search_radius;
1834 }
1835 for(MG_NOEUD* ndnei=lstneipdefect2.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect2.get_suivant(itndnei))
1836 {
1837 double curv=0.;
1838 for (multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_relt_diffnei=lstkmax_relt_diff.begin();itlstkmax_relt_diffnei!=lstkmax_relt_diff.end();itlstkmax_relt_diffnei++)
1839 {
1840 if ((*itlstkmax_relt_diffnei).second==ndnei)
1841 {
1842 curv=(*itlstkmax_relt_diffnei).first;
1843 }
1844 }
1845 if(crikmax_max<curv || crikmax_min>curv)
1846 {
1847 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1848 {
1849 double* xyzpins;
1850 xyzpins=(*itlstpinsert);
1851 if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
1852 {
1853 lstpinsert.erase(itlstpinsert);
1854 itlstpinsert=lstpinsert.begin();
1855 }
1856 }
1857 }
1858 }
1859 }
1860 }
1861 }
1862 }
1863 FILE* in2=fopen(out_gnifinspointfile_removondefect,"wt");
1864 int countfuck=0;
1865 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1866 {
1867 double* xyzpins1;
1868 xyzpins1=(*itlstpinsert);
1869 fprintf(in2,"%le %le %le %le %le %le\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
1870 }
1871 fclose(in2);
1872 }
1873 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)
1874 {
1875 MG_FILE gest(magicfilename);
1876 FEM_MAILLAGE* femmai;
1877 if (femmeshno==0) femmai=gest.get_fem_maillage(femmeshno); else femmai=gest.get_fem_maillageid(femmeshno);
1878 FEM_SOLUTION* femsol=gest.get_fem_solutionid(femsolid);
1879 femsol->active_solution(femsubsolno);
1880
1881 std::map<double,FEM_NOEUD*,std::greater<double> > mpsol;
1882 LISTE_FEM_NOEUD::iterator itfemnds;
1883 for(FEM_NOEUD* nod=femmai->get_premier_noeud(itfemnds);nod!=NULL;nod=femmai->get_suivant_noeud(itfemnds))
1884 {
1885 //if(((MG_NOEUD*) nod->get_mg_element_maillage())->get_origine()==IMPOSE) // only calculate VM_mean for inserted nodes its good for models with noise but not good for models without noise
1886 mpsol.insert(pair<double,FEM_NOEUD*> (nod->get_solution(),nod));
1887
1888 }
1889 std::map<double,FEM_NOEUD*,std::greater<double> >::iterator itmpsol;
1890 double vm_sum=0.;
1891 for(itmpsol=mpsol.begin();itmpsol!=mpsol.end();itmpsol++)
1892 {
1893 double vm=(*itmpsol).first;
1894 vm_sum=vm_sum+vm;
1895 }
1896 double vm_mean=vm_sum/(mpsol.size());
1897 double vm_sigma=0.;
1898 for(itmpsol=mpsol.begin();itmpsol!=mpsol.end();itmpsol++)
1899 {
1900 double vm=(*itmpsol).first;
1901 vm_sigma=vm_sigma+((vm-vm_mean)*(vm-vm_mean));
1902 }
1903 vm_sigma=vm_sigma/(mpsol.size());
1904 double vm_stdev=sqrt(vm_sigma);
1905 itmpsol=mpsol.begin();
1906
1907 cout<<"VM_maximum= "<<(*itmpsol).first<<" vm_stdev= "<<vm_stdev<<" vm_mean= "<<vm_mean<<" VM_max_overSD= "<<(vm_mean/(vm_mean+vm_stdev)) <<" VM_difmax-vmsdoverVM___= "<<((*itmpsol).first-vm_stdev)/(((*itmpsol).first)/vm_mean)<<" VM___= "<<(((*itmpsol).first)/vm_mean)<<" 3*vm_stdev= "<<3*vm_stdev<<endl;
1908 cout<<"VMcritnocoef= "<<(vm_mean+(vm_stdev*(vm_mean/(vm_mean+vm_stdev))))<<endl;
1909 double crit=vm_coef*(vm_mean+(vm_stdev*(vm_mean/(vm_mean+vm_stdev))));
1910 cout<<"critreion value= "<<crit<<endl;
1911 std::vector<double*> lstpinsert;
1912 double prop=0.001;
1913 FILE *in=fopen(gnifinspointfile,"rt");
1914 if (in==NULL) cout<<"file is not available"<<endl;
1915 while (!feof(in))
1916 {
1917 char chaine[500];
1918 char* res=fgets(chaine,500,in);
1919 if(res!=NULL)
1920 {
1921 double x,y,z;
1922 double q1,q2,q3;
1923 int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
1924 q1=prop*q1;
1925 q2=prop*q2;
1926 q3=prop*q3;
1927 if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
1928 else if (nb==6)
1929 {
1930 double* pcoordbc=new double[6];
1931 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
1932 lstpinsert.push_back(pcoordbc);
1933 }
1934 }
1935 }
1936 fclose(in);
1937
1938
1939 //octree initialization
1940 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
1941 TPL_MAP_ENTITE<FEM_NOEUD*> lstnoeud;
1942 LISTE_FEM_NOEUD::iterator it;
1943 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
1944 {
1945 if (no->get_x()<xmin) xmin=no->get_x();
1946 if (no->get_y()<ymin) ymin=no->get_y();
1947 if (no->get_z()<zmin) zmin=no->get_z();
1948 if (no->get_x()>xmax) xmax=no->get_x();
1949 if (no->get_y()>ymax) ymax=no->get_y();
1950 if (no->get_z()>zmax) zmax=no->get_z();
1951 lstnoeud.ajouter(no);
1952 }
1953 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
1954 OT_VECTEUR_3D vec(vecmmax,vecmin);
1955
1956 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);
1957 double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
1958 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
1959 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
1960
1961 TPL_OCTREE<FEM_NOEUD*,FEM_NOEUD*> octree;
1962 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
1963 for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
1964 octree.inserer(no);
1965
1966 for (itmpsol=mpsol.begin();itmpsol!=mpsol.end();itmpsol++)
1967 {
1968 if(crit<(*itmpsol).first)
1969 {
1970 FEM_NOEUD* pdefect=(*itmpsol).second;
1971 TPL_MAP_ENTITE<FEM_NOEUD*> lstneipdefect;
1972 int neindnb=lstneipdefect.get_nb();
1973 double search_radius1=search_radius;
1974 while(neindnb==0)
1975 {
1976 octree.rechercher(pdefect->get_x(),pdefect->get_y(),pdefect->get_z(),search_radius1,lstneipdefect);
1977 neindnb=lstneipdefect.get_nb();
1978 search_radius1=search_radius1+0.1*search_radius;
1979 }
1980 TPL_MAP_ENTITE<FEM_NOEUD*>::ITERATEUR itfendnei;
1981 for(FEM_NOEUD* fendnei=lstneipdefect.get_premier(itfendnei);fendnei!=NULL;fendnei=lstneipdefect.get_suivant(itfendnei))
1982 {
1983 // std::map<double*,double*,std::less<double*> >::iterator itlstpinsert=lstpinsert.begin();//itlstpinsert!=lstpinsert.end();itlstpinsert++
1984 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
1985 {
1986 double* xyzpins;
1987 xyzpins=(*itlstpinsert);
1988 if(fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2])
1989 {
1990 lstpinsert.erase(itlstpinsert);
1991 itlstpinsert=lstpinsert.begin();
1992 }
1993 }
1994 }
1995
1996 }
1997
1998 }
1999
2000 FILE* in1=fopen(out_gnifinspointfile_removondefect,"wt");
2001 for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
2002 {
2003 double* xyzpins1;
2004 xyzpins1=(*itlstpinsert);
2005 fprintf(in1,"%le %le %le %le %le %le\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
2006 }
2007 fclose(in1);
2008 }
2009 void CRIAQOPERATORS::surfmaker_e1(char* outputfilename,int meshno,char* magicfilename)
2010 {
2011 MG_FILE gest(magicfilename);
2012 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2013 MG_MAILLAGE* mai;
2014 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2015 //MG_FILE gest((char*)"longflxprtwithpockets_3d_3mm.magic");
2016 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2017 //MG_MAILLAGE* mai=gest.get_mg_maillageid(5674824);
2018 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
2019 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2020 gestnew->ajouter_mg_geometrie(geonew);
2021 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2022 gestnew->ajouter_mg_maillage(mainew);
2023
2024 LISTE_MG_NOEUD::iterator itnod;
2025 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
2026 {
2027 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2028 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2029 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
2030 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
2031
2032 if(facevert->get_id()==76
2033 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
2034 || aretver->get_id()==81 || aretver->get_id()==83 || aretver->get_id()==10|| aretver->get_id()==12|| aretver->get_id()==90|| aretver->get_id()==97
2035 /* facevert->get_id()==133
2036 || aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
2037 || aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
2038 || aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
2039 || aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
2040 || aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
2041 || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
2042 || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
2043 || sometver->get_id()==368|| sometver->get_id()==361|| sometver->get_id()==106|| sometver->get_id()==122|| sometver->get_id()==74|| sometver->get_id()==90
2044 || sometver->get_id()==233|| sometver->get_id()==240|| sometver->get_id()==247|| sometver->get_id()==254|| sometver->get_id()==261|| sometver->get_id()==268
2045 || sometver->get_id()==226|| sometver->get_id()==224|| sometver->get_id()==190|| sometver->get_id()==197|| sometver->get_id()==204|| sometver->get_id()==211
2046 || sometver->get_id()==183|| sometver->get_id()==181|| sometver->get_id()==154|| sometver->get_id()==147|| sometver->get_id()==140|| sometver->get_id()==161
2047 || sometver->get_id()==168|| sometver->get_id()==138|| sometver->get_id()==318|| sometver->get_id()==311|| sometver->get_id()==304|| sometver->get_id()==297
2048 || sometver->get_id()==325|| sometver->get_id()==332|| sometver->get_id()==290|| sometver->get_id()==288|| sometver->get_id()==42|| sometver->get_id()==58
2049 || sometver->get_id()==352|| sometver->get_id()==354|| sometver->get_id()==10|| sometver->get_id()==26*/
2050
2051 )
2052 {
2053 double x=vertices->get_x();
2054 double y=vertices->get_y();
2055 double z=vertices->get_z();
2056 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
2057 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2058 mainew->ajouter_mg_noeud(newno);
2059 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2060 }
2061 }
2062
2063 LISTE_MG_SEGMENT::iterator itSeg;
2064 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2065 {
2066 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
2067 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
2068 //%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);
2069 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2070 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
2071 if (faceseg->get_id()==76
2072 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
2073 //faceseg->get_id()==133
2074 //|| aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
2075 //|| aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
2076 //|| aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
2077 //|| aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
2078 //|| aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
2079 // || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
2080 // || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
2081
2082 )
2083 {
2084 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2085 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2086 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2087 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
2088 mainew->ajouter_mg_segment(seg);
2089 }
2090 }
2091
2092 LISTE_MG_TRIANGLE::iterator itTri;
2093 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2094 {
2095 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2096 if (facetri->get_id()==76)
2097 {
2098 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2099 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2100 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2101 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2102 }
2103 }
2104
2105 //gestnew->enregistrer("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
2106 gestnew->enregistrer(outputfilename);
2107 //////////////////
2108
2109 ////////////////////////
2110
2111
2112 /*
2113 mainew->supprimer_mg_triangleid(106625);
2114 mainew->supprimer_mg_triangleid(106662);
2115 mainew->supprimer_mg_triangleid(106626);
2116 mainew->supprimer_mg_triangleid(106701);
2117 mainew->supprimer_mg_triangleid(106702);
2118 mainew->supprimer_mg_triangleid(106639);*/
2119 //cout<<"output mesh no.= 495557 "<<endl;
2120 //gest.enregistrer("2dsurfmesh_cad.magic"); //CAD model output
2121 //scanned part output
2122
2123
2124 }
2125 void CRIAQOPERATORS::surfmaker_e2(char* outputfilename,int meshno,char* magicfilename)
2126 {
2127 // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
2128 MG_FILE gest(magicfilename);
2129 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2130 MG_MAILLAGE* mai;
2131 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2132 //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
2133 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2134 //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
2135 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
2136 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2137 gestnew->ajouter_mg_geometrie(geonew);
2138 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2139 gestnew->ajouter_mg_maillage(mainew);
2140
2141 LISTE_MG_NOEUD::iterator itnod;
2142 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
2143 {
2144 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2145 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2146 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
2147 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
2148 if(facevert->get_id()==76
2149 || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13||aretver->get_id()==110
2150 || sometver->get_id()==10|| sometver->get_id()==12|| sometver->get_id()==81|| sometver->get_id()==83|| sometver->get_id()==90|| sometver->get_id()==97)
2151 {
2152 double x=vertices->get_x();
2153 double y=vertices->get_y();
2154 double z=vertices->get_z();
2155 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
2156 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2157 mainew->ajouter_mg_noeud(newno);
2158 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2159 }
2160 }
2161
2162 LISTE_MG_SEGMENT::iterator itSeg;
2163 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2164 {
2165 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
2166 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
2167 //%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);
2168 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2169 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
2170 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
2171 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
2172 if (faceseg->get_id()==76 ||
2173 aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13|| aretver->get_id()==110)
2174 {
2175 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2176 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2177 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2178 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
2179 mainew->ajouter_mg_segment(seg);
2180 }
2181 }
2182
2183 LISTE_MG_TRIANGLE::iterator itTri;
2184 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2185 {
2186 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2187 if (facetri->get_id()==76)
2188 {
2189 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2190 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2191 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2192 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2193 }
2194 }
2195
2196 //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
2197 gestnew->enregistrer(outputfilename);
2198 }
2199 void CRIAQOPERATORS::surfmaker_e2t(char* outputfilename,int meshno,char* magicfilename)
2200 {
2201 // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
2202 MG_FILE gest(magicfilename);
2203 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2204 MG_MAILLAGE* mai;
2205 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2206 //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
2207 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2208 //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
2209 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
2210 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2211 gestnew->ajouter_mg_geometrie(geonew);
2212 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2213 gestnew->ajouter_mg_maillage(mainew);
2214
2215 LISTE_MG_NOEUD::iterator itnod;
2216 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
2217 {
2218 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2219 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2220 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
2221 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
2222 if(facevert->get_id()==37
2223 || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
2224 || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
2225 || sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==51|| sometver->get_id()==58|| sometver->get_id()==42|| sometver->get_id()==44
2226 || sometver->get_id()==87|| sometver->get_id()==73|| sometver->get_id()==80|| sometver->get_id()==71|| sometver->get_id()==100|| sometver->get_id()==107
2227 //for e2t
2228 //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
2229 //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
2230 //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
2231 //|| sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==65|| sometver->get_id()==58|| sometver->get_id()==51|| sometver->get_id()==42
2232 //|| sometver->get_id()==44|| sometver->get_id()==72|| sometver->get_id()==115|| sometver->get_id()==87|| sometver->get_id()==108|| sometver->get_id()==101
2233 //|| sometver->get_id()==94|| sometver->get_id()==85|| sometver->get_id()==128|| sometver->get_id()==135
2234 )
2235 {
2236 double x=vertices->get_x();
2237 double y=vertices->get_y();
2238 double z=vertices->get_z();
2239 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
2240 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2241 mainew->ajouter_mg_noeud(newno);
2242 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2243 }
2244 }
2245
2246 LISTE_MG_SEGMENT::iterator itSeg;
2247 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2248 {
2249 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
2250 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
2251 //%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);
2252 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2253 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
2254 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
2255 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
2256 if (faceseg->get_id()==37
2257 || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
2258 || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
2259 //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
2260 //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
2261 //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
2262
2263 )
2264 {
2265 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2266 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2267 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2268 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
2269 mainew->ajouter_mg_segment(seg);
2270 }
2271 }
2272
2273 LISTE_MG_TRIANGLE::iterator itTri;
2274 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2275 {
2276 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2277 if (facetri->get_id()==37)
2278 {
2279 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2280 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2281 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2282 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2283 }
2284 }
2285
2286 //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
2287 gestnew->enregistrer(outputfilename);
2288 }
2289 void CRIAQOPERATORS::surfmaker_e3(char* outputfilename,int meshno,char* magicfilename)
2290 {
2291 //surfmesh maker (smplwithpocket+smpl withpocket)
2292 MG_FILE gest(magicfilename);
2293 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2294 MG_MAILLAGE* mai;
2295 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2296 //MG_FILE gest((char*)"smplwithpocket_3d_13mm.magic");
2297 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2298 //MG_MAILLAGE* mai=gest.get_mg_maillageid(2982821);
2299 MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
2300 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2301 gestnew->ajouter_mg_geometrie(geonew);
2302 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2303 gestnew->ajouter_mg_maillage(mainew);
2304
2305 LISTE_MG_NOEUD::iterator itnod;
2306 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
2307 {
2308 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2309 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2310 MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
2311 MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
2312 if(facevert->get_id()==5
2313 || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
2314 || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13
2315 || sometver->get_id()==10|| sometver->get_id()==26|| sometver->get_id()==41|| sometver->get_id()==55|| sometver->get_id()==39|| sometver->get_id()==48
2316 || sometver->get_id()==84|| sometver->get_id()==77|| sometver->get_id()==70|| sometver->get_id()==68|| sometver->get_id()==12|| sometver->get_id()==19)
2317 {
2318 double x=vertices->get_x();
2319 double y=vertices->get_y();
2320 double z=vertices->get_z();
2321 //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
2322 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2323 mainew->ajouter_mg_noeud(newno);
2324 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2325 }
2326 }
2327
2328 LISTE_MG_SEGMENT::iterator itSeg;
2329 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2330 {
2331 //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
2332 //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
2333 //%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);
2334 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2335 //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
2336 MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
2337 //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
2338 if (faceseg->get_id()==5
2339 || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
2340 || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13)
2341 {
2342 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2343 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2344 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2345 //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
2346 mainew->ajouter_mg_segment(seg);
2347 }
2348 }
2349
2350 LISTE_MG_TRIANGLE::iterator itTri;
2351 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2352 {
2353 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2354 if (facetri->get_id()==5)
2355 {
2356 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2357 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2358 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2359 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2360 }
2361 }
2362
2363 //gestnew->enregistrer("scnsurf_smplwithpocket_3d_13mm_232mmdeform.magic");
2364 gestnew->enregistrer(outputfilename);
2365 }
2366 void CRIAQOPERATORS::gnifformatmaker(char* elementxtoutfile,char* nodtxtoutfile,int meshno,char* magicfilename, int geometric)
2367 {
2368 // gnifformatmaker
2369 MG_FILE gest(magicfilename);
2370 if(geometric>0)
2371 {
2372 FEM_MAILLAGE* femai;
2373 if (meshno==0) femai=gest.get_fem_maillage(meshno); else femai=gest.get_fem_maillageid(meshno);
2374 FILE* in1=fopen(nodtxtoutfile,"wt");
2375 LISTE_FEM_NOEUD::iterator itnod;
2376 unsigned long firstno=femai->get_premier_noeud(itnod)->get_id();
2377 firstno=firstno-1;
2378 cout<<firstno<<endl;
2379 int counter1=1;
2380 cout<<"mai->get_nb_mg_noeud()="<<femai->get_nb_fem_noeud()<<endl;
2381 for (FEM_NOEUD* nod=femai->get_premier_noeud(itnod);nod!=NULL;nod=femai->get_suivant_noeud(itnod))
2382 {
2383 nod->get_numero_opt();
2384 nod->get_mg_element_maillage()->change_nouveau_numero(counter1);
2385 fprintf(in1,"%19d%32.9le%16.9le%8d\n",nod->get_mg_element_maillage()->get_nouveau_numero(), nod->get_x(),nod->get_y(),nod->get_mg_element_maillage()->get_nouveau_numero());
2386 fprintf(in1,"%7d%16.9le\n",nod->get_mg_element_maillage()->get_nouveau_numero(), nod->get_z());
2387 counter1++;
2388 }
2389 FILE* in2=fopen(elementxtoutfile,"wt");
2390 int counter=1;
2391 LISTE_FEM_ELEMENT2::iterator ittri;
2392 for (FEM_ELEMENT2* tri=femai->get_premier_element2(ittri);tri!=NULL;tri=femai->get_suivant_element2(ittri))
2393 {
2394 FEM_NOEUD* fend1=tri->get_fem_noeud(0);
2395 FEM_NOEUD* fend2=tri->get_fem_noeud(1);
2396 FEM_NOEUD* fend3=tri->get_fem_noeud(2);
2397 fprintf(in2,"%10d 1%8d%8d%8d\n",counter,fend1->get_mg_element_maillage()->get_nouveau_numero(),fend2->get_mg_element_maillage()->get_nouveau_numero(),fend3->get_mg_element_maillage()->get_nouveau_numero());
2398 counter++;
2399 }
2400 fclose(in1);
2401 fclose(in2);
2402 }
2403 else
2404 {
2405 MG_MAILLAGE* mai;
2406 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2407 //MG_FILE gest((char*)"scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
2408 // MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
2409 //std::string fichiermaillage="CAD_output_elements.txt";
2410 //FILE* in=fopen(fichiermaillage.c_str(),"wt");
2411 //FILE* in1=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_nodes.txt","wt");
2412 FILE* in1=fopen(nodtxtoutfile,"wt");
2413 //FILE* in1=fopen("scannedsurface_nodes.txt","wt");
2414 LISTE_MG_NOEUD::iterator itnod;
2415 unsigned long firstno=mai->get_premier_noeud(itnod)->get_id();
2416 firstno=firstno-1;
2417 cout<<firstno<<endl;
2418 int counter1=1;
2419 cout<<"mai->get_nb_mg_noeud()="<<mai->get_nb_mg_noeud()<<endl;
2420 for (MG_NOEUD* nod=mai->get_premier_noeud(itnod);nod!=NULL;nod=mai->get_suivant_noeud(itnod))
2421 {
2422 nod->change_nouveau_numero(counter1);
2423 //nod->change_id(counter1);
2424 //fprintf(in1,"%d node coordinate %le %le %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
2425 //fprintf(in,"%d node coordinate %le %le %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
2426 fprintf(in1,"%19d%32.9le%16.9le%8d\n",nod->get_nouveau_numero(), nod->get_x(),nod->get_y(),nod->get_nouveau_numero());
2427 fprintf(in1,"%7d%16.9le\n",nod->get_nouveau_numero(), nod->get_z());
2428 counter1++;
2429 }
2430 //FILE* in2=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_elements.txt","wt"); // CAD text output elements
2431 FILE* in2=fopen(elementxtoutfile,"wt");
2432 //FILE* in2=fopen("scannedsurface_elements.txt","wt"); //scanned text output elements
2433 int counter=1;
2434 LISTE_MG_TRIANGLE::iterator ittri;
2435 for (MG_TRIANGLE* tri=mai->get_premier_triangle(ittri);tri!=NULL;tri=mai->get_suivant_triangle(ittri))
2436 {
2437 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() );
2438 counter++;
2439 }
2440 fclose(in1);
2441 fclose(in2);
2442 }
2443 }
2444 void CRIAQOPERATORS::rmovscnprtfromdefrmdcad(char* outputfilename,int meshno,char* magicfilename)
2445 {
2446 MG_FILE gest(magicfilename);
2447 MG_MAILLAGE* mai;
2448 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2449 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
2450 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2451 newgest->ajouter_mg_geometrie(geonew);
2452 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2453 newgest->ajouter_mg_maillage(mainew);
2454
2455 LISTE_MG_NOEUD::iterator itnod;
2456 for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
2457 {
2458 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2459 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2460 //if(facevert->get_id()!=76 && topnd->get_dimension()!=3) //e1
2461 //if(facevert->get_id()!=5 && topnd->get_dimension()!=3) //e2
2462 {
2463 double x=vertices->get_x();
2464 double y=vertices->get_y();
2465 double z=vertices->get_z();
2466 MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
2467 mainew->ajouter_mg_noeud(newno);
2468 vertices->change_nouveau_numero(newno->get_id()); // what does this do?
2469 }
2470 }
2471
2472 LISTE_MG_SEGMENT::iterator itSeg;
2473 for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2474 {
2475 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2476 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2477 //if (faceseg->get_id()!=76 && topseg->get_dimension()!=3)
2478 if(faceseg->get_id()!=5 && topseg->get_dimension()!=3) //e2
2479 {
2480 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2481 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2482 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2483 mainew->ajouter_mg_segment(seg);
2484 }
2485 }
2486
2487 LISTE_MG_TRIANGLE::iterator itTri;
2488 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2489 {
2490 MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
2491 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2492 // if (facetri->get_id()!=76 && toptri->get_dimension()!=3)
2493 if (facetri->get_id()!=5 && toptri->get_dimension()!=3) //e2
2494 {
2495 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2496 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2497 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2498 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2499 }
2500 }
2501 newgest->enregistrer(outputfilename);
2502 //gest.enregistrer("deformedcad_sansscannedpart.magic");
2503
2504 }
2505 void CRIAQOPERATORS::msh2dmakerfrommsh3d(char* outputfilename,int meshno,char* magicfilename)
2506 {
2507 //to make a 2D mesh out of 3D mesh :)
2508 /*
2509 MG_MAILLAGE* mainew=mai->dupliquer(&gest);
2510 LISTE_MG_TETRA::iterator ittet;
2511 for(MG_TETRA* )
2512 {
2513
2514 }
2515
2516 cout<<"mainew->get_nb_mg_noeud()= "<<mainew->get_nb_mg_noeud()<<endl;
2517 cout<<"mainew->get_nb_mg_segment()= "<<mainew->get_nb_mg_segment()<<endl;
2518 cout<<"mainew->get_nb_mg_triangle()= "<<mainew->get_nb_mg_triangle()<<endl;
2519 cout<<"mainew->get_nb_mg_tetra()= "<<mainew->get_nb_mg_tetra()<<endl;
2520
2521 LISTE_MG_TRIANGLE::iterator ittri;
2522 for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
2523 {
2524 MG_ELEMENT_TOPOLOGIQUE *top=triangle->get_lien_topologie();
2525 int topdimension=top->get_dimension();
2526 if (topdimension==3)
2527 mainew->supprimer_mg_triangleid(triangle->get_id());
2528 }
2529
2530 LISTE_MG_TETRA::iterator ittet;
2531 for (MG_TETRA* tetra=mainew->get_premier_tetra(ittet);tetra!=NULL;tetra=mainew->get_suivant_tetra(ittet))
2532 mainew->supprimer_mg_tetraid(tetra->get_id());
2533 //MG_FACE* face=geo->get_mg_faceid(5);
2534
2535
2536 LISTE_MG_SEGMENT::iterator itseg;
2537 for (MG_SEGMENT* segment=mainew->get_premier_segment(itseg);segment!=NULL;segment=mainew->get_suivant_segment(itseg))
2538 {
2539 MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
2540 if (faceseg->get_id()!=181)
2541 mainew->supprimer_mg_segmentid(segment->get_id());
2542
2543 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2544 if(topseg->get_dimension()==3)
2545 cout<<"topseg->get_dimension()==3"<<endl;
2546 }
2547
2548 LISTE_MG_NOEUD::iterator itnod;
2549 for (MG_NOEUD* vertices=mainew->get_premier_noeud(itnod);vertices!=NULL;vertices=mainew->get_suivant_noeud(itnod))
2550 {
2551 MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
2552 MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
2553 //if (facevert->get_id()!=181)
2554 if (topnd->get_dimension()==0)
2555 mainew->supprimer_mg_segmentid(vertices->get_id());
2556 }
2557
2558 for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
2559 {
2560 MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
2561 if (facetri->get_id()!=181)
2562 mainew->supprimer_mg_triangleid(triangle->get_id());
2563 }
2564 */
2565
2566 MG_FILE gest(magicfilename);
2567 MG_MAILLAGE* mai;
2568 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2569 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
2570 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
2571 newgest->ajouter_mg_geometrie(geonew);
2572 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
2573 newgest->ajouter_mg_maillage(mainew);
2574
2575 LISTE_MG_NOEUD::iterator itNod;
2576 for (MG_NOEUD* nd=mai->get_premier_noeud(itNod);nd!=NULL;nd=mai->get_suivant_noeud(itNod))
2577 {
2578 MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
2579 if(topnd->get_dimension()<3)
2580 {
2581 double x=nd->get_x();
2582 double y=nd->get_y();
2583 double z=nd->get_z();
2584 MG_NOEUD *newno=new MG_NOEUD(nd->get_lien_topologie(),x,y,z,nd->get_origine());
2585 mainew->ajouter_mg_noeud(newno);
2586 nd->change_nouveau_numero(newno->get_id());
2587 }
2588 }
2589 LISTE_MG_SEGMENT::iterator itSeg;
2590 for (MG_SEGMENT* segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
2591 {
2592 MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
2593 if(topseg->get_dimension()<3)
2594 {
2595 MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
2596 MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
2597 MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
2598 mainew->ajouter_mg_segment(seg);
2599 }
2600 }
2601 LISTE_MG_TRIANGLE::iterator itTri;
2602 for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
2603 {
2604 MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
2605 if(toptri->get_dimension()<3)
2606 {
2607 MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
2608 MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
2609 MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
2610 mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
2611 }
2612 }
2613 newgest->enregistrer(outputfilename);
2614 }
2615 void CRIAQOPERATORS::bumpmaker(char* outputfilename,int bumpndid, double bumptip,int meshno,char* magicfilename)
2616 {
2617 MG_FILE gest(magicfilename);
2618 //MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
2619 MG_MAILLAGE* mai;
2620 if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
2621 //MG_FILE gest((char*)"scnsurf_smplwithpocket_3d_13mm_64mmdeform.magic");
2622 //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
2623 //MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
2624 MG_NOEUD* bptipnd;
2625 TPL_MAP_ENTITE<MG_NOEUD*> usednd;
2626 LISTE_MG_NOEUD::iterator itnod;
2627 for (MG_NOEUD* nd=mai->get_premier_noeud(itnod);nd!=NULL;nd=mai->get_suivant_noeud(itnod))
2628 {
2629 MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
2630 if (topnd->get_dimension() <3 && nd->get_id()==bumpndid)
2631 {
2632 bptipnd=nd;
2633 double new_xyz[3];
2634 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+bumptip;
2635 nd->change_coord(new_xyz);
2636 usednd.ajouter(nd);
2637 }
2638 }
2639 TPL_MAP_ENTITE<MG_NOEUD*> usedndnd;
2640 TPL_MAP_ENTITE<MG_NOEUD*> neignd;
2641 for(int ineignd=0;ineignd<bptipnd->get_lien_segment()->get_nb();ineignd++)
2642 {
2643 MG_SEGMENT* segnei=bptipnd->get_lien_segment()->get(ineignd);
2644 if(segnei->get_noeud1()!=bptipnd) neignd.ajouter(segnei->get_noeud1());
2645 else if(segnei->get_noeud2()!=bptipnd) neignd.ajouter(segnei->get_noeud2());
2646 }
2647 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd;
2648 for (MG_NOEUD* nd=neignd.get_premier(itneignd);nd!=NULL;nd=neignd.get_suivant(itneignd))
2649 {
2650 double new_xyz[3];
2651 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*3./4.);
2652 nd->change_coord(new_xyz);
2653 usednd.ajouter(nd);
2654 usedndnd.ajouter(nd);
2655 }
2656
2657 TPL_MAP_ENTITE<MG_NOEUD*> neignd1;
2658 TPL_MAP_ENTITE<MG_NOEUD*> usedndnd1;
2659 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusednd;
2660 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd;
2661 for(MG_NOEUD* nd=usedndnd.get_premier(itusedndnd);nd!=NULL;nd=usedndnd.get_suivant(itusedndnd))
2662 {
2663 for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
2664 {
2665 MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
2666 int sgnd1=0;
2667 int sgnd2=0;
2668 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2669 {
2670 if(segnei->get_noeud1()==nd1) sgnd1++;
2671 }
2672 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2673 {
2674 if(segnei->get_noeud2()==nd1) sgnd2++;
2675 }
2676 if(sgnd1==0) neignd1.ajouter(segnei->get_noeud1());
2677 else if(sgnd2==0) neignd1.ajouter(segnei->get_noeud2());
2678 }
2679 }
2680 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd1;
2681 for (MG_NOEUD* nd=neignd1.get_premier(itneignd1);nd!=NULL;nd=neignd1.get_suivant(itneignd1))
2682 {
2683 double new_xyz[3];
2684 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*2./4.);
2685 nd->change_coord(new_xyz);
2686 usednd.ajouter(nd);
2687 usedndnd1.ajouter(nd);
2688 }
2689
2690 TPL_MAP_ENTITE<MG_NOEUD*> neignd2;
2691 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd1;
2692 for(MG_NOEUD* nd=usedndnd1.get_premier(itusedndnd1);nd!=NULL;nd=usedndnd1.get_suivant(itusedndnd1))
2693 {
2694 for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
2695 {
2696 MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
2697 int sgnd1=0;
2698 int sgnd2=0;
2699 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2700 {
2701 if(segnei->get_noeud1()==nd1) sgnd1++;
2702 }
2703 for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
2704 {
2705 if(segnei->get_noeud2()==nd1) sgnd2++;
2706 }
2707 if(sgnd1==0) neignd2.ajouter(segnei->get_noeud1());
2708 else if(sgnd2==0) neignd2.ajouter(segnei->get_noeud2());
2709 }
2710 }
2711 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd2;
2712 for (MG_NOEUD* nd=neignd2.get_premier(itneignd2);nd!=NULL;nd=neignd2.get_suivant(itneignd2))
2713 {
2714 double new_xyz[3];
2715 new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*1./4.);
2716 nd->change_coord(new_xyz);
2717 }
2718
2719
2720 //gest.enregistrer("scnsurf_smplwithpocket_3d_13mm_64mmdeform_withbump5mm.magic");
2721 gest.enregistrer(outputfilename);
2722 }
2723 int CRIAQOPERATORS::import_triangulation_gnif(char* outputfilename,char* triangulationfile)
2724 {
2725 FILE* in=fopen(triangulationfile,"rt");
2726 if (in==NULL) return 0;
2727
2728
2729 MG_GESTIONNAIRE gesttmp;
2730 MG_MAILLAGE* mai=new MG_MAILLAGE(NULL);
2731 gesttmp.ajouter_mg_maillage(mai);
2732 char mess[500];
2733
2734 double xmax=-1e308;
2735 double xmin=1e308;
2736 double ymax=-1e308;
2737 double ymin=1e308;
2738 double zmax=-1e308;
2739 double zmin=1e308;
2740 while (!feof(in))
2741 {
2742 double x,y,z;
2743 char nom[20];
2744 char *res=fgets(mess,500,in);
2745 if (feof(in)) break;
2746 if(res!=NULL)
2747 {
2748 sscanf(mess,"%le %le %le",&x,&y,&z);
2749 if (x<xmin) xmin=x;
2750 if (x>xmax) xmax=x;
2751 if (y<ymin) ymin=y;
2752 if (y>ymax) ymax=y;
2753 if (z<zmin) zmin=z;
2754 if (z>zmax) zmax=z;
2755 if (feof(in)) return 1;
2756 MG_NOEUD* noeud1=mai->ajouter_mg_noeud(NULL,x,y,z,MAGIC::ORIGINE::TRIANGULATION);
2757 noeud1->change_nouveau_numero(-1);
2758 res=fgets(mess,500,in);
2759 if (feof(in)) break;
2760 sscanf(mess,"%le %le %le",&x,&y,&z);
2761 if (x<xmin) xmin=x;
2762 if (x>xmax) xmax=x;
2763 if (y<ymin) ymin=y;
2764 if (y>ymax) ymax=y;
2765 if (z<zmin) zmin=z;
2766 if (z>zmax) zmax=z;
2767 if (feof(in)) return 1;
2768 res=fgets(mess,500,in);
2769 if (feof(in)) break;
2770 MG_NOEUD* noeud2=mai->ajouter_mg_noeud(NULL,x,y,z,MAGIC::ORIGINE::TRIANGULATION);
2771 noeud2->change_nouveau_numero(-1);
2772 sscanf(mess,"%le %le %le",&x,&y,&z);
2773 if (x<xmin) xmin=x;
2774 if (x>xmax) xmax=x;
2775 if (y<ymin) ymin=y;
2776 if (y>ymax) ymax=y;
2777 if (z<zmin) zmin=z;
2778 if (z>zmax) zmax=z;
2779 if (feof(in)) return 1;
2780 MG_NOEUD* noeud3=mai->ajouter_mg_noeud(NULL,x,y,z,MAGIC::ORIGINE::TRIANGULATION);
2781 noeud3->change_nouveau_numero(-1);
2782 mai->ajouter_mg_triangle(NULL,noeud1,noeud2,noeud3,MAGIC::ORIGINE::TRIANGULATION);
2783 }
2784 }
2785 fclose(in);
2786 //to merge the nodes of each triangulation which are close (the same)
2787 double eps=1e-4;
2788 BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
2789 double rayon=boite.get_rayon()*1.1;
2790 double x=boite.get_xcentre();
2791 double y=boite.get_ycentre();
2792 double z=boite.get_zcentre();
2793 boite.reinit(x-rayon,y-rayon,z-rayon,x+rayon,y+rayon,z+rayon);
2794 TPL_GRILLE<MG_NOEUD*> grille;
2795 int nb_noeud=mai->get_nb_mg_noeud();
2796 int pas=(int)(pow(nb_noeud,0.33333333333333333))+1;
2797 grille.initialiser(boite.get_xmin(),boite.get_ymin(),boite.get_zmin(),boite.get_xmax(),boite.get_ymax(),boite.get_zmax(),pas,pas,pas);
2798 std::vector<MG_NOEUD*> lst_noeud;
2799 LISTE_MG_NOEUD::iterator it;
2800 int i=0;
2801 for (MG_NOEUD* noeud=mai->get_premier_noeud(it);noeud!=NULL;noeud=mai->get_suivant_noeud(it))
2802 {
2803 //MG_NOEUD* noeud=mai->get_mg_noeud(i);
2804 grille.inserer(noeud);
2805 noeud->change_nouveau_numero(i);
2806 lst_noeud.insert(lst_noeud.end(),noeud);
2807 i++;
2808 }
2809
2810 int nb_cell=grille.get_nb_cellule();
2811 for (int i=0;i<nb_cell;i++)
2812 {
2813 TPL_CELLULE_GRILLE<MG_NOEUD*> *cell=grille.get_cellule(i);
2814 int nb_noeud_cell=cell->get_nb_entite();
2815 for (int j=0;j<nb_noeud_cell;j++)
2816 {
2817 MG_NOEUD* noeud1=cell->get_entite(j);
2818 // if (noeud1->get_nouveau_numero()!=(-1)) continue;
2819 // noeud1->change_nouveau_numero(noeud1->get_id());
2820 double *xyz1=noeud1->get_coord();
2821 int nb=noeud1->get_lien_segment()->get_nb();
2822 double longref=0.;
2823 for (int jj=0;jj<nb;jj++)
2824 longref=longref+noeud1->get_lien_segment()->get(jj)->get_longueur();
2825 longref=longref/nb;
2826 for (int k=j+1;k<nb_noeud_cell;k++)
2827 {
2828 MG_NOEUD* noeud2=cell->get_entite(k);
2829 double *xyz2=noeud2->get_coord();
2830 OT_VECTEUR_3D vec(xyz1,xyz2);
2831 double longueur=vec.get_longueur();
2832 if (longueur<eps*longref)
2833 {
2834 lst_noeud[noeud2->get_nouveau_numero()]=noeud1;
2835 }
2836 }
2837 }
2838 }
2839 MG_GESTIONNAIRE gest;
2840 MG_MAILLAGE* mai2=new MG_MAILLAGE(NULL);
2841 gest.ajouter_mg_maillage(mai2);
2842 for (int i=0;i<nb_noeud;i++)
2843 {
2844 MG_NOEUD* noeud=lst_noeud[i];
2845 MG_NOEUD* nvnoeud;
2846 if (noeud->get_nouveau_numero()==i) nvnoeud=mai2->ajouter_mg_noeud(NULL,noeud->get_x(),noeud->get_y(),noeud->get_z(),MAGIC::ORIGINE::TRIANGULATION);
2847 else nvnoeud=lst_noeud[noeud->get_nouveau_numero()];
2848 lst_noeud[i]=nvnoeud;
2849 }
2850 int nb_tri=mai->get_nb_mg_triangle();
2851 for (int i=0;i<nb_tri;i++)
2852 {
2853 MG_TRIANGLE* tri=mai->get_mg_triangle(i);
2854 MG_NOEUD* noeud1=tri->get_noeud1();
2855 MG_NOEUD* noeud2=tri->get_noeud2();
2856 MG_NOEUD* noeud3=tri->get_noeud3();
2857 mai2->ajouter_mg_triangle(NULL,lst_noeud[noeud1->get_nouveau_numero()],lst_noeud[noeud2->get_nouveau_numero()],lst_noeud[noeud3->get_nouveau_numero()],MAGIC::ORIGINE::TRIANGULATION);
2858 }
2859 gest.enregistrer(outputfilename);
2860 return 1;
2861 }
2862 std::vector<double*> CRIAQOPERATORS::sp_project_onCAD(char* magicfilename,int nummai,char* samplepoints1)
2863 {
2864 std::vector<double*> lstsmplpoints;
2865 std::vector<double*> lstsmplpoints_afterprojectioncad;
2866
2867 FILE *in=fopen(samplepoints1,"rt");
2868 if (in==NULL) cout<<"file is not available"<<endl;//affiche((char*) "file is not available");
2869 while(!feof(in))
2870 {
2871 char chaine[500];
2872 char* res=fgets(chaine,500,in);
2873 if(res!=NULL)
2874 {
2875 double x,y,z;
2876 int nb=sscanf(chaine,"%le %le %le",&x,&y,&z);
2877 double* pcoordbc=new double[3];
2878 if (nb!=-1 && nb!=3)
2879 cout<<"Wrong file format"<<endl;
2880 if(nb==3)
2881 {
2882 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z;
2883 lstsmplpoints.push_back(pcoordbc);
2884 }
2885 }
2886 }
2887 cout<<"CAD lstsmplpoints.size()= "<<lstsmplpoints.size()<<endl;
2888
2889
2890 MG_FILE gest(magicfilename);
2891 MG_MAILLAGE* mai=gest.get_mg_maillageid(nummai);
2892 int geonb=gest.get_nb_mg_geometrie();
2893 int nogeo=0;
2894 MG_GEOMETRIE* geo;
2895 if(geonb>0)
2896 geo=gest.get_mg_geometrie(0);
2897 else if(geonb<1)
2898 {
2899 nogeo++;
2900 cout<<"no geometry is found !!!"<<endl;
2901 }
2902
2903 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
2904 TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
2905 LISTE_MG_NOEUD::iterator it;
2906 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
2907 {
2908 if (no->get_x()<xmin) xmin=no->get_x();
2909 if (no->get_y()<ymin) ymin=no->get_y();
2910 if (no->get_z()<zmin) zmin=no->get_z();
2911 if (no->get_x()>xmax) xmax=no->get_x();
2912 if (no->get_y()>ymax) ymax=no->get_y();
2913 if (no->get_z()>zmax) zmax=no->get_z();
2914 lstnoeud.ajouter(no);
2915 }
2916 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);
2917 OT_VECTEUR_3D vecmax(xmax,ymax,zmax);
2918 OT_VECTEUR_3D lengthvec(vecmin,vecmax);
2919 double search_radius=0.0000001;
2920 //double search_radius=0.001*(lengthvec.get_longueur());
2921 //char bboxdiag[1000];
2922 //sprintf(bboxdiag,"the bounding box diagonal is: %lf , and the neighborhood search radius is: %lf ",vec.get_longueur(),search_radius);
2923 //affiche((char*) bboxdiag);
2924 OT_VECTEUR_3D average=(vecmin+vecmax)/2.;
2925 double length=sqrt(lengthvec*lengthvec);
2926 double bxr=1.1;
2927 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
2928 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
2929 TPL_OCTREE<MG_TRIANGLE*,MG_NOEUD*> octree;
2930 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
2931 LISTE_MG_TRIANGLE::iterator it9;
2932 for (MG_TRIANGLE* tri=mai->get_premier_triangle(it9);tri!=NULL;tri=mai->get_suivant_triangle(it9))
2933 octree.inserer(tri);
2934 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreends;
2935 octreends.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
2936 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
2937 octreends.inserer(no);
2938
2939
2940 for(std::vector<double*>::iterator ilstsmplpoints=lstsmplpoints.begin();ilstsmplpoints!=lstsmplpoints.end();ilstsmplpoints++)
2941 {
2942 double* p=(*ilstsmplpoints);
2943 ///cout<<"p[0]= "<<p[0]<<" p[0]= "<<p[1]<<" p[0]= "<<p[2]<<endl;
2944
2945 // determine the normal of geometry in the inserting point coordination and saving in "normale"
2946 double normale[3];
2947 std::multimap<double,MG_TRIANGLE*,std::less<double> > delinsqualtri;
2948 int insideface=0;
2949 std::multimap<double,MG_FACE*,std::less<double> > lstfacepointdist;
2950 int facenb=geo->get_nb_mg_face();
2951 LISTE_MG_FACE::iterator itf;
2952 double xyz[3];
2953 xyz[0]=p[0];
2954 xyz[1]=p[1];
2955 xyz[2]=p[2];
2956 for(MG_FACE* fac=geo->get_premier_face(itf);fac!=NULL;fac=geo->get_suivant_face(itf))
2957 {
2958 double uv[2];
2959 fac->inverser(uv,xyz);
2960 double xyz2[3];
2961 fac->evaluer(uv,xyz2);
2962 OT_VECTEUR_3D vechk(xyz,xyz2);
2963 lstfacepointdist.insert(pair<double,MG_FACE*> (vechk.get_longueur(),fac));
2964 //double dis;
2965 //MG_GEOMETRIE_OUTILS f1;
2966 //int ch=f1.calcule_distance_contour_face_xyz(xyz,fac,&dis);
2967 ////cout<<"xyz= "<<xyz[0]<<" xyz= "<<xyz[1]<<" xyz= "<<xyz[2]<<" xyz2= "<<xyz2[0]<<" xyz2= "<<xyz2[1]<<" xyz2= "<<xyz2[2]<<endl;
2968 //cout<<"dis= "<<dis<<" vechk.get_longueur()= "<<vechk.get_longueur()<<endl;
2969 //if (ch==1 && dis>=0.)
2970 // if (vechk.get_longueur()<5e-3)
2971 }
2972 std::multimap<double,MG_FACE*,std::less<double> >::iterator itlstfacepointdist=lstfacepointdist.begin();
2973 if (lstfacepointdist.size()>0)
2974 {
2975 //cout<<"lstfacepointdist.size()= "<<lstfacepointdist.size()<<endl;
2976 //cout<<"(*itlstfacepointdist).first= "<<(*itlstfacepointdist).first<<endl;
2977 MG_FACE* face=(*itlstfacepointdist).second;
2978 double uv[2];
2979 face->inverser(uv,xyz);
2980 face->calcul_normale_unitaire(uv,normale);
2981 MG_COFACE *coface=face->get_mg_coface(0);
2982 int signe=coface->get_orientation();
2983
2984 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitri;
2985 int neitrinb=lstneitri.get_nb();
2986 while(neitrinb==0)
2987 {
2988 octree.rechercher(p[0],p[1],p[2],search_radius,lstneitri);
2989 neitrinb=lstneitri.get_nb();
2990 search_radius=search_radius+0.01*search_radius;
2991 }
2992 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itnormtst;
2993 OT_VECTEUR_3D normale_discrete(0.,0.,0.);
2994 for (MG_TRIANGLE* tri1=lstneitri.get_premier(itnormtst);tri1!=NULL;tri1=lstneitri.get_suivant(itnormtst))
2995 {
2996 OT_VECTEUR_3D vec1(tri1->get_noeud1()->get_coord(),tri1->get_noeud2()->get_coord());
2997 OT_VECTEUR_3D vec2(tri1->get_noeud1()->get_coord(),tri1->get_noeud3()->get_coord());
2998 OT_VECTEUR_3D normtst=(vec1&vec2); normtst.norme();
2999 normale_discrete=normtst+normale_discrete;
3000 }
3001 normale_discrete.norme();
3002 double n_ps=normale_discrete*normale;
3003 n_ps=n_ps*-1;
3004 if (n_ps>1.) n_ps=1.;
3005 if (n_ps<-1.) n_ps=-1.;
3006 double n_angle=acos(n_ps);
3007 //cout<<"n_angle= "<<n_angle<<endl;
3008 if(n_angle<(0.5*3.14159265358979323846) || n_angle>-(0.5*3.14159265358979323846))
3009 insideface++;
3010 }
3011
3012 //cout<<"insideface= "<<insideface<<endl;
3013 if(insideface<1)
3014 cout<<"insideface is not found !!!"<<endl;
3015 if(insideface>0)
3016 {
3017 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitri1;
3018 int neitrinb=lstneitri1.get_nb();
3019 double search_radius1=0.01;
3020 while(neitrinb==0)
3021 {
3022 octree.rechercher(p[0],p[1],p[2],500.*search_radius1,lstneitri1);//sasan
3023 neitrinb=lstneitri1.get_nb();
3024 search_radius1=search_radius1+0.00001*search_radius1;
3025 }
3026 //cout<<"lstneitri1.get_nb()= "<<lstneitri1.get_nb()<<endl;
3027 double pproj[3];
3028 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR inspi;
3029 int tri_found=0;
3030 int beshmar=0;
3031
3032 int virtual_project=0;
3033 for (MG_TRIANGLE* insphertri=lstneitri1.get_premier(inspi);insphertri!=NULL;insphertri=lstneitri1.get_suivant(inspi))
3034 {
3035 //cout<<insphertri->get_id()<<endl;
3036 //while (tri_found<1 || beshmar<lstneitri.get_nb())
3037 {
3038 beshmar++;
3039 MG_NOEUD* inspnd1=insphertri->get_noeud1();
3040 MG_NOEUD* inspnd2=insphertri->get_noeud2();
3041 MG_NOEUD* inspnd3=insphertri->get_noeud3();
3042 OT_VECTEUR_3D tvec1(inspnd1->get_coord(),inspnd2->get_coord());
3043 OT_VECTEUR_3D tvec2(inspnd1->get_coord(),inspnd3->get_coord());
3044 OT_VECTEUR_3D tnorm=(tvec1&tvec2); tnorm.norme();
3045 OT_VECTEUR_3D norm=normale;
3046
3047 double parallel=norm*tnorm;
3048 //cout<<"parallel= "<<parallel<<endl;
3049
3050 if (parallel>0.7 || parallel<-0.7)
3051 {
3052
3053 //cout<<"itis"<<endl;
3054 OT_VECTEUR_3D vvec(inspnd1->get_coord(),p);
3055 double t= (tnorm*vvec)/parallel;
3056 t=-t;
3057 pproj[0]=p[0]+t*norm.get_x();
3058 pproj[1]=p[1]+t*norm.get_y();
3059 pproj[2]=p[2]+t*norm.get_z();
3060 //////////////////////////////////////////////////////////////
3061 //check if the projected p is inside the triangle !!!!!
3062 MG_MAILLAGE_OUTILS tribas;
3063 int tribasval=tribas.estdansletriangle(insphertri,pproj[0],pproj[1],pproj[2]);
3064 int intri=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::INTERIEUR);
3065 int insidtri=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::STRICTINTERIEUR);
3066 int onedge=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::SUR_ARETE);
3067 //printf("projection before is: %16.14lf %16.14lf %16.14lf \n",pproj[0],pproj[1],pproj[2]);
3068 //cout<<"intri= "<<intri<<endl;
3069 if(intri==1)
3070 {
3071 virtual_project++;
3072 //cout<<"normale= "<<norm.get_x()<<" normale= "<<norm.get_y()<<" normale= "<<norm.get_z()<<endl;
3073 //printf("projection is: %16.14lf %16.14lf %16.14lf \n",pproj[0],pproj[1],pproj[2]);
3074 double* proj=new double[4];
3075 proj[0]=pproj[0]; proj[1]=pproj[1]; proj[2]=pproj[2]; proj[3]=1;
3076 OT_VECTEUR_3D disprojp(p,pproj);
3077 //cout<<"CAD distance proj-p= "<<disprojp.get_longueur()<<endl;
3078 lstsmplpoints_afterprojectioncad.push_back(proj);
3079 tri_found++;
3080 }
3081
3082
3083 }
3084
3085 }
3086 }
3087 if(virtual_project==0)
3088 {
3089 double* proj_virt=new double[4];
3090 proj_virt[0]=0; proj_virt[1]=0; proj_virt[2]=0; proj_virt[3]=0;
3091 lstsmplpoints_afterprojectioncad.push_back(proj_virt);
3092
3093 }
3094 }
3095 }
3096
3097 //for(std::vector<double*>::iterator itsprojcad=lstsmplpoints_afterprojectioncad.begin();itsprojcad!=lstsmplpoints_afterprojectioncad.end();itsprojcad++)
3098 {
3099 //double* xyz_cadproj=(*itsprojcad);
3100 //cout<<"xyz_cadproj[0]= "<<xyz_cadproj[0]<<" xyz_cadproj[1]= "<<xyz_cadproj[1]<<" xyz_cadproj[2]= "<<xyz_cadproj[2]<<endl;
3101
3102 }
3103 return lstsmplpoints_afterprojectioncad;
3104 }
3105
3106 std::vector<double*> CRIAQOPERATORS::sp_project_onSCAN(char* magicfilename,int nummai,char* samplepoints1)
3107 {
3108 std::vector<double*> lstsmplpoints;
3109 std::vector<double*> lstsmplpoints_afterprojection;
3110 FILE *in=fopen(samplepoints1,"rt");
3111 if (in==NULL) cout<<"file is not available"<<endl;//affiche((char*) "file is not available");
3112 while(!feof(in))
3113 {
3114 char chaine[500];
3115 char* res=fgets(chaine,500,in);
3116 if(res!=NULL)
3117 {
3118 double x,y,z;
3119 int nb=sscanf(chaine,"%le %le %le",&x,&y,&z);
3120 double* pcoordbc=new double[3];
3121 if (nb!=-1 && nb!=3)
3122 cout<<"Wrong file format"<<endl;
3123 if(nb==3)
3124 {
3125 pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z;
3126 lstsmplpoints.push_back(pcoordbc);
3127 }
3128 }
3129 }
3130 cout<<"SCN lstsmplpoints.size()= "<<lstsmplpoints.size()<<endl;
3131
3132
3133 MG_FILE gest(magicfilename);
3134 MG_MAILLAGE* mai=gest.get_mg_maillageid(nummai);
3135 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
3136 TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
3137 LISTE_MG_NOEUD::iterator it;
3138 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
3139 {
3140 if (no->get_x()<xmin) xmin=no->get_x();
3141 if (no->get_y()<ymin) ymin=no->get_y();
3142 if (no->get_z()<zmin) zmin=no->get_z();
3143 if (no->get_x()>xmax) xmax=no->get_x();
3144 if (no->get_y()>ymax) ymax=no->get_y();
3145 if (no->get_z()>zmax) zmax=no->get_z();
3146 lstnoeud.ajouter(no);
3147 }
3148 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);
3149 OT_VECTEUR_3D vecmax(xmax,ymax,zmax);
3150 OT_VECTEUR_3D lengthvec(vecmin,vecmax);
3151 double search_radius=10.1;//0.0000001;
3152 //double search_radius=0.001*(lengthvec.get_longueur());
3153 //char bboxdiag[1000];
3154 //sprintf(bboxdiag,"the bounding box diagonal is: %lf , and the neighborhood search radius is: %lf ",vec.get_longueur(),search_radius);
3155 //affiche((char*) bboxdiag);
3156 OT_VECTEUR_3D average=(vecmin+vecmax)/2.;
3157 double length=sqrt(lengthvec*lengthvec);
3158 double bxr=1.1; //this can be changed sasan
3159 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
3160 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
3161 TPL_OCTREE<MG_TRIANGLE*,MG_NOEUD*> octree;
3162 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
3163 LISTE_MG_TRIANGLE::iterator it9;
3164 for (MG_TRIANGLE* tri=mai->get_premier_triangle(it9);tri!=NULL;tri=mai->get_suivant_triangle(it9))
3165 octree.inserer(tri);
3166 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreends;
3167 octreends.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
3168 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
3169 octreends.inserer(no);
3170
3171
3172 for(std::vector<double*>::iterator ilstsmplpoints=lstsmplpoints.begin();ilstsmplpoints!=lstsmplpoints.end();ilstsmplpoints++)
3173 {
3174 int virtual_project=0;
3175 double* p=(*ilstsmplpoints);
3176 //cout<<"p[0]= "<<p[0]<<" p[0]= "<<p[1]<<" p[0]= "<<p[2]<<endl;
3177 // determine the normal of geometry in the inserting point coordination and saving in "normale"
3178 double normale[3];
3179 //////////////////////////////// if no geometry
3180 TPL_MAP_ENTITE<MG_NOEUD*> lstneind;
3181 int neitrinbmp=lstneind.get_nb();
3182 while(neitrinbmp==0)
3183 {
3184 octreends.rechercher(p[0],p[1],p[2],search_radius,lstneind);
3185 neitrinbmp=lstneind.get_nb();
3186 search_radius=search_radius+0.00001*search_radius;
3187 }
3188 TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itnormtstnd;
3189
3190 std::multimap<double,MG_NOEUD*,std::less<double>> lstmpneind;
3191 for (MG_NOEUD* ndnei1=lstneind.get_premier(itnormtstnd);ndnei1!=NULL;ndnei1=lstneind.get_suivant(itnormtstnd))
3192 {
3193 double dist=sqrt((ndnei1->get_x()-p[0])*(ndnei1->get_x()-p[0])+(ndnei1->get_y()-p[1])*(ndnei1->get_y()-p[1])+(ndnei1->get_z()-p[2])*(ndnei1->get_z()-p[2]));
3194 lstmpneind.insert(pair<double,MG_NOEUD*>(dist,ndnei1));
3195 }
3196 std::multimap<double,MG_NOEUD*,std::less<double>>::iterator itlstmpneind=lstmpneind.begin();
3197 //cout<<"cls dist= "<< (*itlstmpneind).first<<endl;
3198 MG_NOEUD* clsnd=(*itlstmpneind).second;
3199 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitrindcls;
3200 for(int iitlstmpneind=0;iitlstmpneind<clsnd->get_lien_triangle()->get_nb();iitlstmpneind++)
3201 lstneitrindcls.ajouter(clsnd->get_lien_triangle()->get(iitlstmpneind));
3202
3203 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itnormtst;
3204 OT_VECTEUR_3D normale_discrete(0.,0.,0.);
3205 for (MG_TRIANGLE* tri1=lstneitrindcls.get_premier(itnormtst);tri1!=NULL;tri1=lstneitrindcls.get_suivant(itnormtst))
3206 {
3207 OT_VECTEUR_3D vec1(tri1->get_noeud1()->get_coord(),tri1->get_noeud2()->get_coord());
3208 OT_VECTEUR_3D vec2(tri1->get_noeud1()->get_coord(),tri1->get_noeud3()->get_coord());
3209 OT_VECTEUR_3D normtst=(vec1&vec2); normtst.norme();
3210 normale_discrete=normtst+normale_discrete;
3211 }
3212 normale_discrete.norme();
3213 /*
3214 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitri;
3215 int neitrinb=lstneitri.get_nb();
3216 while(neitrinb==0)
3217 {
3218 octree.rechercher(p[0],p[1],p[2],search_radius,lstneitri);
3219 neitrinb=lstneitri.get_nb();
3220 //cout<<"neitrinb= "<<neitrinb<<endl;
3221 search_radius=search_radius+0.00001*search_radius;
3222 }
3223 //cout<<"lstneitri.get_nb()= "<<lstneitri.get_nb()<<endl;
3224 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR itnormtst;
3225 OT_VECTEUR_3D normale_discrete(0.,0.,0.);
3226 for (MG_TRIANGLE* tri1=lstneitri.get_premier(itnormtst);tri1!=NULL;tri1=lstneitri.get_suivant(itnormtst))
3227 {
3228 OT_VECTEUR_3D vec1(tri1->get_noeud1()->get_coord(),tri1->get_noeud2()->get_coord());
3229 OT_VECTEUR_3D vec2(tri1->get_noeud1()->get_coord(),tri1->get_noeud3()->get_coord());
3230 OT_VECTEUR_3D normtst=(vec1&vec2); normtst.norme();
3231 //cout<<"normtst.get_x()= "<<normtst.get_x()<<" normtst.get_y()= "<<normtst.get_y()<<" normtst.get_z()= "<<normtst.get_z()<<endl;
3232 normale_discrete=normtst+normale_discrete;
3233 }
3234 normale_discrete.norme();
3235 */
3236 normale[0]=normale_discrete.get_x(); normale[1]=normale_discrete.get_y(); normale[2]=normale_discrete.get_z();
3237 ///cout<<"normale[0]= "<<normale[0]<<" normale[1]= "<<normale[1]<<" normale[2]= "<<normale[2]<<endl;
3238 ////////////////////////////////
3239
3240 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitri1;
3241 int neitrinb1=lstneitri1.get_nb();
3242 double search_radius1=2.;//sasan
3243 while(neitrinb1==0)
3244 {
3245 octree.rechercher(p[0],p[1],p[2],search_radius1,lstneitri1);
3246 neitrinb1=lstneitri1.get_nb();
3247 search_radius1=search_radius1+0.00001*search_radius1;
3248 }
3249 //cout<<"lstneitri1.get_nb()= "<<lstneitri1.get_nb()<<endl;
3250 double pproj[3];
3251 TPL_MAP_ENTITE<MG_TRIANGLE*>::ITERATEUR inspi;
3252
3253 for (MG_TRIANGLE* insphertri=lstneitri1.get_premier(inspi);insphertri!=NULL;insphertri=lstneitri1.get_suivant(inspi))
3254 {
3255 //while (tri_found<1 || beshmar<lstneitri.get_nb())
3256 MG_NOEUD* inspnd1=insphertri->get_noeud1();
3257 MG_NOEUD* inspnd2=insphertri->get_noeud2();
3258 MG_NOEUD* inspnd3=insphertri->get_noeud3();
3259 OT_VECTEUR_3D tvec1(inspnd1->get_coord(),inspnd2->get_coord());
3260 OT_VECTEUR_3D tvec2(inspnd1->get_coord(),inspnd3->get_coord());
3261 OT_VECTEUR_3D tnorm=(tvec1&tvec2); tnorm.norme();
3262 OT_VECTEUR_3D norm=normale;
3263 //norm.change_x(0.854556);norm.change_y(0.499603);norm.change_z(-0.141879);
3264 //cout<<"norm= "<<norm<<endl;
3265 double parallel=norm*tnorm;
3266 //cout<<"parallel= "<<parallel<<endl;
3267
3268 if (parallel>0.7 || parallel<-0.7)
3269 {
3270 //cout<<"itis"<<endl;
3271 OT_VECTEUR_3D vvec(inspnd1->get_coord(),p);
3272 double t= (tnorm*vvec)/parallel;
3273 t=-t;
3274 pproj[0]=p[0]+t*norm.get_x();
3275 pproj[1]=p[1]+t*norm.get_y();
3276 pproj[2]=p[2]+t*norm.get_z();
3277 //////////////////////////////////////////////////////////////
3278 //check if the projected p is inside the triangle !!!!!
3279 MG_MAILLAGE_OUTILS tribas;
3280 int tribasval=tribas.estdansletriangle(insphertri,pproj[0],pproj[1],pproj[2]);
3281 int intri=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::INTERIEUR);
3282 int insidtri=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::STRICTINTERIEUR);
3283 int onedge=tribas.compare_etat_triangle(tribasval,MG_MAILLAGE_OUTILS::SUR_ARETE);
3284 //printf("projection before is: %16.14lf %16.14lf %16.14lf \n",pproj[0],pproj[1],pproj[2]);
3285 //cout<<"intri= "<<intri<<endl;
3286 if(intri==1)
3287 {
3288 virtual_project++;
3289 //cout<<"intri==1"<<endl;
3290 //printf("projection is: %16.14lf %16.14lf %16.14lf \n",pproj[0],pproj[1],pproj[2]);
3291 OT_VECTEUR_3D disprojp(p,pproj);
3292 //cout<<"V1 SCAN distance proj-p= "<<disprojp.get_longueur()<<" p[0]" << p[0]<<" p[1] " << p[1] <<" p[2] "<< p[2] <<endl;
3293 double* proj=new double[4];
3294 proj[0]=pproj[0]; proj[1]=pproj[1]; proj[2]=pproj[2]; proj[3]=1;
3295 //lstsmplpoints_afterprojection.insert(pair<double,double*> (disprojp.get_longueur(),proj));
3296 lstsmplpoints_afterprojection.push_back(proj);
3297 }
3298
3299 }
3300
3301 }
3302
3303 if(virtual_project==0)
3304 {
3305 double* proj_virt=new double[4];
3306 proj_virt[0]=0; proj_virt[1]=0; proj_virt[2]=0; proj_virt[3]=0;
3307 lstsmplpoints_afterprojection.push_back(proj_virt);
3308 //cout<<"V0 SCAN distance proj-p= "<<0<<" p[0]" << p[0]<<" p[1] " << p[1] <<" p[2] "<< p[2] <<endl;
3309 }
3310
3311 }
3312 return lstsmplpoints_afterprojection;
3313 }
3314
3315
3316 void CRIAQOPERATORS::sp_project_onCAD_SCAN(char* magicfilenamecad,int nummaicad,char* samplepointscad,char* magicfilenamescn,int nummaiscn,char* samplepointsscn,char* outputspbcfilename)
3317 {
3318 std::vector<double*> sprojcad;
3319 sprojcad=sp_project_onCAD(magicfilenamecad,nummaicad,samplepointscad);
3320 std::vector<double*> sprojscn;
3321 sprojscn=sp_project_onSCAN(magicfilenamescn,nummaiscn,samplepointsscn);
3322
3323 int sizesm;
3324 if(sprojcad.size()==sprojscn.size())
3325 sizesm=sprojcad.size();
3326 else
3327 cout<<"not sprojcad.size()==sprojscn.size() !!!!!!!!!!!"<<endl;
3328 cout<<"sprojcad.size()= "<<sprojcad.size()<<endl;
3329 cout<<"sprojscn.size()= "<<sprojscn.size()<<endl;
3330 FILE* insmp=fopen(outputspbcfilename,"wt");/*
3331 for(std::vector<double*>::iterator itsprojcad=sprojcad.begin();itsprojcad!=sprojcad.end();itsprojcad++)
3332 {
3333 double* xyz_cadproj=(*itsprojcad);
3334 cout<<"xyz_cadproj[0]= "<<xyz_cadproj[0]<<endl;
3335
3336 }*/
3337 std::vector<double*>::iterator itsprojcad=sprojcad.begin();
3338 std::vector<double*>::iterator itsprojscn=sprojscn.begin();
3339
3340 for(int iitt=0;iitt<sizesm;iitt++)
3341 {
3342 if(iitt>0)
3343 {
3344 itsprojcad++;
3345 itsprojscn++;
3346 }
3347 double* xyz_cadproj=(*itsprojcad);
3348 double* xyz_scnproj=(*itsprojscn);
3349 if(xyz_cadproj[3]==1 && xyz_scnproj[3]==1)
3350 {
3351 fprintf(insmp,"%le %le %le %le %le %le \n",xyz_cadproj[0],xyz_cadproj[1],xyz_cadproj[2],(xyz_scnproj[0]-xyz_cadproj[0]),(xyz_scnproj[1]-xyz_cadproj[1]),(xyz_scnproj[2]-xyz_cadproj[2]));
3352 }
3353
3354 }
3355 fclose(insmp);
3356
3357
3358 }
3359
3360 void CRIAQOPERATORS::ajouter_nois_normdir(char* magicfilename,int nummai,char* noisefile,char* outputfilename)
3361 {
3362 MG_FILE gest(magicfilename);
3363 MG_MAILLAGE* mai;
3364 if (nummai==0) mai=gest.get_mg_maillage(nummai); else mai=gest.get_mg_maillageid(nummai);
3365 /*
3366 double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
3367 TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
3368 LISTE_MG_NOEUD::iterator it;
3369 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
3370 {
3371 if (no->get_x()<xmin) xmin=no->get_x();
3372 if (no->get_y()<ymin) ymin=no->get_y();
3373 if (no->get_z()<zmin) zmin=no->get_z();
3374 if (no->get_x()>xmax) xmax=no->get_x();
3375 if (no->get_y()>ymax) ymax=no->get_y();
3376 if (no->get_z()>zmax) zmax=no->get_z();
3377 lstnoeud.ajouter(no);
3378 }
3379 OT_VECTEUR_3D vecmin(xmin,ymin,zmin);
3380 OT_VECTEUR_3D vecmax(xmax,ymax,zmax);
3381 OT_VECTEUR_3D lengthvec(vecmin,vecmax);
3382 double search_radius=5.0;//0.0000001;
3383 //double search_radius=0.001*(lengthvec.get_longueur());
3384 //char bboxdiag[1000];
3385 //sprintf(bboxdiag,"the bounding box diagonal is: %lf , and the neighborhood search radius is: %lf ",vec.get_longueur(),search_radius);
3386 //affiche((char*) bboxdiag);
3387 OT_VECTEUR_3D average=(vecmin+vecmax)/2.;
3388 double length=sqrt(lengthvec*lengthvec);
3389 double bxr=2.0; //this can be changed sasan
3390 xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
3391 xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
3392 TPL_OCTREE<MG_TRIANGLE*,MG_NOEUD*> octree;
3393 octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
3394 LISTE_MG_TRIANGLE::iterator it9;
3395 for (MG_TRIANGLE* tri=mai->get_premier_triangle(it9);tri!=NULL;tri=mai->get_suivant_triangle(it9))
3396 octree.inserer(tri);
3397 TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octreends;
3398 octreends.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
3399 for (MG_NOEUD* no=mai->get_premier_noeud(it);no!=NULL;no=mai->get_suivant_noeud(it))
3400 octreends.inserer(no);
3401 */
3402
3403 TPL_LISTE_ENTITE<double> randomnumbr;
3404 FILE *in=fopen(noisefile,"rt");
3405 if (in==NULL)
3406 cout<< "file is not available"<<endl;
3407 while (!feof(in))
3408 {
3409 char chaine[500];
3410 char* res=fgets(chaine,500,in);
3411 if(res!=NULL)
3412 {
3413 double rndnbr;
3414 int nb=sscanf(chaine,"%le",&rndnbr);
3415 if (nb!=-1 && nb!=1)
3416 cout<<"Wrong file format"<<endl;
3417 else if (nb!=-1 && nb==1)
3418 {
3419 randomnumbr.ajouter(rndnbr);
3420 }
3421 }
3422 }
3423 fclose(in);
3424 cout<<"randomnumbr.get_nb()= "<<randomnumbr.get_nb()<<endl;
3425 cout<<"mai->get_nb_mg_noeud()= "<<mai->get_nb_mg_noeud()<<endl;
3426 LISTE_MG_NOEUD::iterator itnd;
3427 MG_NOEUD* noeu=mai->get_premier_noeud(itnd);
3428 for(int i=0;i<randomnumbr.get_nb();i++)
3429 {
3430 //cout<<"i= "<<i<<endl;
3431 double rndno=randomnumbr.get(i);
3432 //for(MG_NOEUD* noeu=mai->get_premier_noeud(itnd);noeu!=NULL;noeu=mai->get_suivant_noeud(itnd))
3433 {
3434 TPL_MAP_ENTITE<MG_TRIANGLE*> lstneitri;
3435 /*double search_rad1=search_radius;
3436 int neitrinb=lstneitri.get_nb();
3437 while(neitrinb==0)
3438 {
3439 octree.rechercher(noeu->get_x(),noeu->get_y(),noeu->get_z(),search_rad1,lstneitri);
3440 neitrinb=lstneitri.get_nb();
3441 search_rad1=search_rad1+0.00001*search_rad1;
3442 }
3443 cout<<"lstneitri.get_nb()= "<<lstneitri.get_nb()<<endl;
3444 */
3445 OT_VECTEUR_3D w_n_tot(0.,0.,0.);
3446 double norme_w_n_tot=0.;
3447 OT_VECTEUR_3D w2_n_tot(0.,0.,0.);
3448 double norme_w2_n_tot=0.;
3449 int nbtri=noeu->get_lien_triangle()->get_nb();
3450 for (int ii=0;ii<nbtri;ii++)
3451 {
3452 MG_TRIANGLE* tri=(MG_TRIANGLE*)noeu->get_lien_triangle()->get(ii);
3453 //tri->change_origine(IMPOSE);
3454 double *xyzn1=tri->get_noeud1()->get_coord();
3455 double *xyzn2=tri->get_noeud2()->get_coord();
3456 double *xyzn3=tri->get_noeud3()->get_coord();
3457 OT_VECTEUR_3D vec1(xyzn1,xyzn3);
3458 OT_VECTEUR_3D vec2(xyzn1,xyzn2);
3459 OT_VECTEUR_3D n_tri=vec1&vec2; // Normale au triangle
3460
3461 double w=n_tri.get_longueur(); // 2 fois l'aire du triangle (pour éviter une division par 2)
3462 n_tri.norme();
3463 OT_VECTEUR_3D w_n=w*n_tri;
3464 double norme_w_n=w_n.get_longueur();
3465 w_n_tot=w_n_tot+w_n;
3466 norme_w_n_tot=norme_w_n_tot+norme_w_n;
3467 }
3468
3469 OT_VECTEUR_3D normale_discrete=w_n_tot/norme_w_n_tot; // Normale à la surface au noeud
3470 normale_discrete.norme();
3471
3472 double xyz_new[3];
3473 xyz_new[0]=noeu->get_x()+(rndno*normale_discrete.get_x());
3474 xyz_new[1]=noeu->get_y()+(rndno*normale_discrete.get_y());
3475 xyz_new[2]=noeu->get_z()+(rndno*normale_discrete.get_z());
3476 noeu->change_coord(xyz_new);
3477 }
3478 noeu=mai->get_suivant_noeud(itnd);
3479 }
3480 gest.enregistrer(outputfilename);
3481 }
3482
3483
3484