ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/criaqoperation/src/criaqoperators.cpp
Revision: 646
Committed: Fri Feb 6 17:32:23 2015 UTC (10 years, 6 months ago) by sattarpa
File size: 82853 byte(s)
Log Message:
Ajouter affichage de courbure pour modèles

File Contents

# User Rev Content
1 sattarpa 554 #include <stdio.h>
2     #include "mg_file.h"
3     #include "criaqoperators.h"
4 sattarpa 596 #include "tpl_grille.h"
5     #include "ot_mathematique.h"
6     #include <math.h>
7     #include "tpl_octree.h"
8 sattarpa 609 #include "fem_maillage_outils.h"
9     #include "mg_maillage_outils.h"
10 sattarpa 646 #include <sstream>
11     #include <string.h>
12 sattarpa 554
13 sattarpa 596 CRIAQOPERATORS::CRIAQOPERATORS():MAILLEUR(false)
14 sattarpa 554 {
15     }
16 sattarpa 596
17     CRIAQOPERATORS::~CRIAQOPERATORS()
18 sattarpa 554 {
19     }
20 sattarpa 596 void CRIAQOPERATORS::meshdistance_compare(char* referencemagicfilename,int refmeshno,char* comparemagicfilename,int compmeshno,char* outputcomparefile)
21 sattarpa 554 {
22 sattarpa 596 MG_FILE refgest(referencemagicfilename);
23     MG_MAILLAGE* refmgmai;
24 sattarpa 600 if (refmeshno==0) refmgmai=refgest.get_mg_maillage(refmeshno); else refmgmai=refgest.get_mg_maillageid(refmeshno);
25 sattarpa 596 MG_FILE compgest(comparemagicfilename);
26     MG_MAILLAGE* compmgmai;
27 sattarpa 600 if (compmeshno==0) compmgmai=compgest.get_mg_maillage(compmeshno); else compmgmai=compgest.get_mg_maillageid(compmeshno);
28 sattarpa 596 /*MG_FILE refgest((char*)"cad_caseA_1mmesh_winspbc.magic");
29     MG_FILE compgest((char*)"deformedgnifcad_caseA_1mmesh_winspbc_removedmodified.magic");
30     MG_MAILLAGE* refmgmai=refgest.get_mg_maillageid(319270);
31     MG_MAILLAGE* compmgmai=compgest.get_mg_maillageid(1);*/
32     //octree initialization
33     double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
34     TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
35     LISTE_MG_NOEUD::iterator it;
36     for (MG_NOEUD* no=refmgmai->get_premier_noeud(it);no!=NULL;no=refmgmai->get_suivant_noeud(it))
37     {
38     if (no->get_x()<xmin) xmin=no->get_x();
39     if (no->get_y()<ymin) ymin=no->get_y();
40     if (no->get_z()<zmin) zmin=no->get_z();
41     if (no->get_x()>xmax) xmax=no->get_x();
42     if (no->get_y()>ymax) ymax=no->get_y();
43     if (no->get_z()>zmax) zmax=no->get_z();
44     }
45     for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
46     {
47     if (no->get_x()<xmin) xmin=no->get_x();
48     if (no->get_y()<ymin) ymin=no->get_y();
49     if (no->get_z()<zmin) zmin=no->get_z();
50     if (no->get_x()>xmax) xmax=no->get_x();
51     if (no->get_y()>ymax) ymax=no->get_y();
52     if (no->get_z()>zmax) zmax=no->get_z();
53     lstnoeud.ajouter(no);
54     }
55     OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
56     OT_VECTEUR_3D vec(vecmmax,vecmin);
57    
58     //double search_radius=0.001*(vec.get_longueur());
59     double search_radius=3.;
60     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);
61     double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
62     xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
63     xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
64    
65     TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octree;
66     octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
67     for (MG_NOEUD* no=compmgmai->get_premier_noeud(it);no!=NULL;no=compmgmai->get_suivant_noeud(it))
68     octree.inserer(no);
69    
70 sattarpa 646 MG_SOLUTION* mgsol=new MG_SOLUTION(refmgmai,1,(char*)"distance.sol",1,(char*)"Normaldistance",MAGIC::ENTITE_SOLUTION::ENTITE_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
71 sattarpa 596 refgest.ajouter_mg_solution(mgsol);
72     mgsol->change_legende(0,"Normaldistance");
73     int i=0;
74     for (MG_NOEUD* nop=refmgmai->get_premier_noeud(it);nop!=NULL;nop=refmgmai->get_suivant_noeud(it))
75     {
76     TPL_MAP_ENTITE<MG_NOEUD*> lstneiclose;
77     int neindnb=lstneiclose.get_nb();
78     while(neindnb==0)
79     {
80     octree.rechercher(nop->get_x(),nop->get_y(),nop->get_z(),search_radius,lstneiclose);
81     neindnb=lstneiclose.get_nb();
82     }
83     map<double,MG_NOEUD*,std::less<double> > lstdist;
84     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itnop;
85     for(MG_NOEUD* no=lstneiclose.get_premier(itnop);no!=NULL;no=lstneiclose.get_suivant(itnop))
86     {
87     double distns=sqrt(pow(nop->get_x()-no->get_x(),2)+pow(nop->get_y()-no->get_y(),2)+pow(nop->get_z()-no->get_z(),2));
88    
89     OT_VECTEUR_3D w_n_tot(0.,0.,0.);
90     double norme_w_n_tot=0.;
91     OT_VECTEUR_3D w2_n_tot(0.,0.,0.);
92     double norme_w2_n_tot=0.;
93     int nbtri=nop->get_lien_triangle()->get_nb();
94     for (int i=0;i<nbtri;i++)
95     {
96     MG_TRIANGLE* tri=(MG_TRIANGLE*)nop->get_lien_triangle()->get(i);
97    
98     double *xyzn1=tri->get_noeud1()->get_coord();
99     double *xyzn2=tri->get_noeud2()->get_coord();
100     double *xyzn3=tri->get_noeud3()->get_coord();
101    
102     OT_VECTEUR_3D vec1(xyzn1,xyzn3);
103     OT_VECTEUR_3D vec2(xyzn1,xyzn2);
104     OT_VECTEUR_3D n_tri=vec1&vec2; // Normale au triangle
105    
106     double w=n_tri.get_longueur(); // 2 fois l'aire du triangle (pour éviter une division par 2)
107     n_tri.norme();
108     OT_VECTEUR_3D w_n=w*n_tri;
109     double norme_w_n=w_n.get_longueur();
110     w_n_tot=w_n_tot+w_n;
111     norme_w_n_tot=norme_w_n_tot+norme_w_n;
112     }
113    
114     OT_VECTEUR_3D n=w_n_tot/norme_w_n_tot; // Normale à la surface au noeud
115     n.norme();
116     OT_VECTEUR_3D distvec(nop->get_coord(),no->get_coord());
117     double normaldistance=distvec*n;
118     double normaldistanceabs=fabs(normaldistance);
119     //cout<<"normaldistanceabs= "<<normaldistanceabs<<endl;
120     lstdist.insert(pair<double,MG_NOEUD*>(normaldistanceabs,nop));
121     }
122     map<double,MG_NOEUD*,std::less<double> >::iterator itlstdist=lstdist.begin();
123     double distnsclos=(*itlstdist).first;
124     MG_NOEUD* nodcls=(*itlstdist).second;
125     //cout<<"distnsclos= "<<distnsclos<<endl;
126     mgsol->ecrire(distnsclos,i,0,0);
127     //mgsol->ecrire(distnsclos,1,0,0);
128     i++;
129 sattarpa 554 }
130 sattarpa 596 refgest.enregistrer(outputcomparefile);
131     }
132 sattarpa 609 void CRIAQOPERATORS::deformed_correspond_mgmaiadd(char* magicfilename,int meshno,int numsol1,int numsol2,int numsol3,int numchamp1,int numchamp2,int numchamp3,double coef)
133     {
134     MG_FILE gest(magicfilename);
135     FEM_MAILLAGE* femmai;
136     if (meshno==0) femmai=gest.get_fem_maillage(meshno); else femmai=gest.get_fem_maillageid(meshno);
137     FEM_SOLUTION* sol1=gest.get_fem_solutionid(numsol1);
138     FEM_SOLUTION* sol2=gest.get_fem_solutionid(numsol2);
139     FEM_SOLUTION* sol3=gest.get_fem_solutionid(numsol3);
140     femmai->calcul_deforme(sol1,numchamp1,sol2,numchamp2,sol3,numchamp3);
141     if (coef>1e-16)
142     {
143     cout<<" Création du maillage deforme avec correspondence text file"<<endl;
144     MG_MAILLAGE* defmgmai=new MG_MAILLAGE(gest.get_mg_geometrie(0));
145     gest.ajouter_mg_maillage(defmgmai);
146     {
147     if (femmai->get_degre()==1)
148     {
149     //gest=femmai->get_mg_maillage()->get_gestionnaire();
150     //gest->ajouter_mg_maillage(this);
151     std::vector<unsigned long*> lstcores;//sasan
152     LISTE_FEM_NOEUD::iterator it;
153     for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
154     {
155     double x=no->get_x(coef);
156     double y=no->get_y(coef);
157     double z=no->get_z(coef);
158     MG_NOEUD *newno=new MG_NOEUD(no->get_lien_topologie(),x,y,z,DEFORME);
159     defmgmai->ajouter_mg_noeud(newno);
160     no->change_numero(newno->get_id());
161     unsigned long* correscad_defcad=new unsigned long[2];//sasan
162     correscad_defcad[0]=no->get_mg_element_maillage()->get_id();//sasan
163     correscad_defcad[1]=newno->get_id();//sasan
164     lstcores.push_back(correscad_defcad);//sasan
165     }
166     //sasan
167     FILE* in1=fopen("correspond_deform_mgmaill.txt","wt");
168     fprintf(in1,"MG_MAILLAGE No. : deformed_MAILLAGE No.\n",femmai->get_mg_maillage()->get_id(),defmgmai->get_id());
169     fprintf(in1,"%lu %lu\n",femmai->get_mg_maillage()->get_id(),defmgmai->get_id());
170     for(std::vector<unsigned long*>::iterator itlstpinsert=lstcores.begin();itlstpinsert!=lstcores.end();itlstpinsert++)
171     {
172     unsigned long* xyzpins1;
173     xyzpins1=(*itlstpinsert);
174     //cout<<" xyzpins1[0]= "<<xyzpins1[0]<<" xyzpins1[1]= "<<xyzpins1[1]<<endl;
175     fprintf(in1,"%lu %lu\n",xyzpins1[0],xyzpins1[1]);
176     }
177     fclose(in1);
178     //sasan till
179     LISTE_FEM_ELEMENT1::iterator it1;
180     for (FEM_ELEMENT1 *ele=femmai->get_premier_element1(it1);ele!=NULL;ele=femmai->get_suivant_element1(it1))
181     {
182     MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
183     MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
184     MG_SEGMENT *seg=new MG_SEGMENT(ele->get_lien_topologie(),no1,no2,DEFORME);
185     defmgmai->ajouter_mg_segment(seg);
186     }
187     LISTE_FEM_ELEMENT2::iterator it2;
188     for (FEM_ELEMENT2 *ele=femmai->get_premier_element2(it2);ele!=NULL;ele=femmai->get_suivant_element2(it2))
189     {
190     if (ele->get_nb_fem_noeud()==3)
191     {
192     MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
193     MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
194     MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
195     defmgmai->ajouter_mg_triangle(ele->get_lien_topologie(),no1,no2,no3,DEFORME);
196     }
197     if (ele->get_nb_fem_noeud()==4)
198     {
199     MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
200     MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
201     MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
202     MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
203     defmgmai->ajouter_mg_quadrangle(ele->get_lien_topologie(),no1,no2,no3,no4,DEFORME);
204     }
205     }
206     LISTE_FEM_ELEMENT3::iterator it3;
207     for (FEM_ELEMENT3 *ele=femmai->get_premier_element3(it3);ele!=NULL;ele=femmai->get_suivant_element3(it3))
208     {
209     if (ele->get_nb_fem_noeud()==4)
210     {
211     MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
212     MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
213     MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
214     MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
215     defmgmai->ajouter_mg_tetra(ele->get_lien_topologie(),no1,no2,no3,no4,DEFORME);
216     }
217     if (ele->get_nb_fem_noeud()==8)
218     {
219     MG_NOEUD* no1=defmgmai->get_mg_noeudid(ele->get_fem_noeud(0)->get_numero());
220     MG_NOEUD* no2=defmgmai->get_mg_noeudid(ele->get_fem_noeud(1)->get_numero());
221     MG_NOEUD* no3=defmgmai->get_mg_noeudid(ele->get_fem_noeud(2)->get_numero());
222     MG_NOEUD* no4=defmgmai->get_mg_noeudid(ele->get_fem_noeud(3)->get_numero());
223     MG_NOEUD* no5=defmgmai->get_mg_noeudid(ele->get_fem_noeud(4)->get_numero());
224     MG_NOEUD* no6=defmgmai->get_mg_noeudid(ele->get_fem_noeud(5)->get_numero());
225     MG_NOEUD* no7=defmgmai->get_mg_noeudid(ele->get_fem_noeud(6)->get_numero());
226     MG_NOEUD* no8=defmgmai->get_mg_noeudid(ele->get_fem_noeud(7)->get_numero());
227     defmgmai->ajouter_mg_hexa(ele->get_lien_topologie(),no1,no2,no3,no4,no5,no6,no7,no8,DEFORME);
228     }
229     }
230    
231     }
232     }
233     }
234     cout<<" Enregistrement"<<endl;
235     gest.enregistrer(magicfilename);
236     }
237 sattarpa 646 void CRIAQOPERATORS::curvtur_crit_remvsmp(char* magicfilename,char* correspondfilename,char* gnifinspointfile,char* out_gnifinspointfile_removondefect,double search_radius,double curvdif_coef,int gmsh_affiche)
238 sattarpa 609 {
239     MG_FILE gest(magicfilename);
240     map<unsigned long, unsigned long> coresspondndidlst;
241     FILE* in1=fopen(correspondfilename,"rt");
242     if (in1==NULL) cout<<"correspondfile is not available"<<endl;
243     char mess[500];
244     char *res=fgets(mess,500,in1);
245     res=fgets(mess,500,in1);
246     int cadmeshno;
247     int defcadmeshno;
248     int nb1=sscanf(mess,"%ld %ld",&cadmeshno,&defcadmeshno);
249     while (!feof(in1))
250     {
251     char chaine[500];
252     fgets(chaine,500,in1);
253     unsigned long cadndid;
254     unsigned long defcadndid;
255     int nb=sscanf(chaine,"%lu %lu",&cadndid,&defcadndid);
256     //cout<<"nb= "<<nb<<endl;
257     if (nb!=-1 && nb!=2) cout<<"Wrong file format"<<endl;
258     else if (nb==2)
259     {
260     //cout<<"defcadndid= "<<defcadndid<<" cadndid= "<<cadndid<<endl;
261     coresspondndidlst.insert(pair<unsigned long, unsigned long> (defcadndid,cadndid) );
262     }
263     }
264     fclose(in1);
265     cout<<"cadmeshno= "<<cadmeshno<<" defcadmeshno= "<<defcadmeshno<<endl;
266     MG_MAILLAGE* cadmgmai;
267     if (cadmeshno==0) cadmgmai=gest.get_mg_maillage(cadmeshno); else cadmgmai=gest.get_mg_maillageid(cadmeshno);
268     MG_MAILLAGE* defcadmgmai;
269     if (defcadmeshno==0) defcadmgmai=gest.get_mg_maillage(defcadmeshno); else defcadmgmai=gest.get_mg_maillageid(defcadmeshno);
270     LISTE_MG_NOEUD::iterator itdefcadndcurv;
271     //FEM_MAILLAGE_OUTILS fmu;
272     //fmu.calcul_courbure();
273     //MG_MAILLAGE_OUTILS mu;
274     //mu.calcul_courbure_discrete(gest,(char*)"discrt_cad_curvsol_casA.sol",cadmeshno,(char*)"discrt_cad_curvsol_casA",1);
275     //mu.calcul_courbure_discrete(gest,(char*)"discrt_defcad_curvsol_casA.sol",defcadmeshno,(char*)"discrt_defcad_curvsol_casA",1);
276     //gest.enregistrer(magicfilename);
277     multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_cadmgmai;
278     multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_cadmgmai;
279 sattarpa 646 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_cadmgmai;
280 sattarpa 609 multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_defcadmgmai;
281     multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_defcadmgmai;
282 sattarpa 646 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_defcadmgmai;
283 sattarpa 609 std::map<std::string,double> liste_kmin;
284     std::map<std::string,double> liste_kmax;
285     std::map<std::string,double> liste_gau;
286     std::map<std::string,double> liste_courburemax1;
287     std::map<std::string,double> liste_courburemax2;
288     std::map<std::string,double> liste_courburemax3;
289     std::map<std::string,double> liste_courburemax4;
290     std::map<std::string,double> liste_courburemax5;
291     int opensurafece=1;
292     LISTE_MG_NOEUD::iterator itcadndcurv;
293     cout<<"calcul courbure cadmgmai"<<endl;
294     // calcul courbure cadmgmai ********************************
295     for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
296     {
297     double kmin1=0.;
298     double kmax1=0.;
299     double kmin2=0.;
300     double kmax2=0.;
301     MG_MAILLAGE_OUTILS *cou;
302     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);
303     }
304     for (MG_NOEUD* cadmgnd=cadmgmai->get_premier_noeud(itcadndcurv);cadmgnd!=NULL;cadmgnd=cadmgmai->get_suivant_noeud(itcadndcurv))
305     {
306     unsigned long idface=cadmgnd->get_lien_topologie()->get_id();
307     unsigned long idnoeud=cadmgnd->get_id();
308     char mess[500];
309     sprintf(mess,"%lu_%lu",idnoeud,idface);
310     for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
311     {
312     if(mess==(*itkmin).first)
313     lstkmin_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,cadmgnd) );
314     }
315     for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
316     {
317     if(mess==(*itkmax).first)
318     lstkmax_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,cadmgnd) );
319     }
320 sattarpa 646 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
321     {
322     if(mess==(*itkgau).first)
323     lstkgau_cadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,cadmgnd) );
324     }
325 sattarpa 609 }
326 sattarpa 646 // affichage sur GMSH ******************************
327     if (gmsh_affiche>1)
328     {
329     cout<<"affiche: calcul_courbure_cadmgmai "<<endl;
330     /*char chaine[1000];
331     char chaine[1000]
332     strncpy(chaine,nomfichier,sizeof(str2));
333     std::string namefic=chaine;
334     namefic="calcul_courbure_cadmgmai" + namefic;*/
335     std::ostringstream oss;
336     oss << "calcul_courbure_cadmgmai_curvdif_coef:" <<curvdif_coef ;
337     std::string namefic = oss.str();
338     //const char* cstr=namefic.c_str();
339     char *cstr = new char[namefic.length() + 1];
340     strcpy(cstr, namefic.c_str());
341     MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
342     //MG_SOLUTION* sol1=new MG_SOLUTION(cadmgmai,3,(char*)"what the FUCKK1",1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
343     gest.ajouter_mg_solution(sol1);
344     sol1->change_legende(0,"Kmin");
345     sol1->change_legende(1,"Kmax");
346     sol1->change_legende(2,"K_gau");
347     LISTE_MG_TRIANGLE::iterator ittri;
348     int compte=0;
349     for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
350     {
351     MG_NOEUD *no1=tri->get_noeud1();
352     MG_NOEUD *no2=tri->get_noeud2();
353     MG_NOEUD *no3=tri->get_noeud3();
354     char mess[500];
355     sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
356     double valeur0=liste_kmin[mess];
357     double valeur1=liste_kmax[mess];
358     double valeur2=liste_gau[mess];
359     sol1->ecrire(valeur0,compte,0,0);
360     sol1->ecrire(valeur1,compte,1,0);
361     sol1->ecrire(valeur2,compte,2,0);
362     sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
363     valeur0=liste_kmin[mess];
364     valeur1=liste_kmax[mess];
365     valeur2=liste_gau[mess];
366     sol1->ecrire(valeur0,compte,0,1);
367     sol1->ecrire(valeur1,compte,1,1);
368     sol1->ecrire(valeur2,compte,2,1);
369     sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
370     valeur0=liste_kmin[mess];
371     valeur1=liste_kmax[mess];
372     valeur2=liste_gau[mess];
373     sol1->ecrire(valeur0,compte,0,2);
374     sol1->ecrire(valeur1,compte,1,2);
375     sol1->ecrire(valeur2,compte,2,2);
376     compte++;
377     }
378     }
379 sattarpa 609 liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
380 sattarpa 646
381 sattarpa 609 cout<<"calcul courbure defcadmgmai"<<endl;
382     // calcul courbure defcadmgmai ********************************
383 sattarpa 554
384 sattarpa 609 for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
385     {
386     double kmin1=0.;
387     double kmax1=0.;
388     double kmin2=0.;
389     double kmax2=0.;
390     MG_MAILLAGE_OUTILS *cou;
391     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);
392     }
393     for (MG_NOEUD* defcadmgnd=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadmgnd!=NULL;defcadmgnd=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
394     {
395     unsigned long idface=defcadmgnd->get_lien_topologie()->get_id();
396     unsigned long idnoeud=defcadmgnd->get_id();
397     char mess[500];
398     sprintf(mess,"%lu_%lu",idnoeud,idface);
399     for(std::map<std::string,double>::iterator itkmin=liste_kmin.begin();itkmin!=liste_kmin.end();itkmin++)
400     {
401     if(mess==(*itkmin).first)
402     lstkmin_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmin).second,defcadmgnd) );
403     }
404     for(std::map<std::string,double>::iterator itkmax=liste_kmax.begin();itkmax!=liste_kmax.end();itkmax++)
405     {
406     if(mess==(*itkmax).first)
407     lstkmax_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkmax).second,defcadmgnd) );
408     }
409 sattarpa 646 for(std::map<std::string,double>::iterator itkgau=liste_gau.begin();itkgau!=liste_gau.end();itkgau++)
410     {
411     if(mess==(*itkgau).first)
412     lstkgau_defcadmgmai.insert(pair<double,MG_NOEUD*>((*itkgau).second,defcadmgnd) );
413     }
414 sattarpa 609 }
415 sattarpa 646 // affichage sur GMSH ******************************
416     if (gmsh_affiche>1)
417     {
418     cout<<"affiche: calcul_courbure_defcadmgmai "<<endl;
419     std::ostringstream oss;
420     oss << "calcul_courbure_defcadmgmai_curvdif_coef:" <<curvdif_coef ;
421     std::string namefic = oss.str();
422     char *cstr = new char[namefic.length() + 1];
423     strcpy(cstr, namefic.c_str());
424     MG_SOLUTION* sol2=new MG_SOLUTION(defcadmgmai,3,cstr,1,(char*)"discrete_curboure_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
425     gest.ajouter_mg_solution(sol2);
426     sol2->change_legende(0,"Kmin");
427     sol2->change_legende(1,"Kmax");
428     sol2->change_legende(2,"K_gau");
429     LISTE_MG_TRIANGLE::iterator ittri;
430     int compte=0;
431     for (MG_TRIANGLE* tri=defcadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=defcadmgmai->get_suivant_triangle(ittri))
432     {
433     MG_NOEUD *no1=tri->get_noeud1();
434     MG_NOEUD *no2=tri->get_noeud2();
435     MG_NOEUD *no3=tri->get_noeud3();
436     char mess[500];
437     sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
438     double valeur0=liste_kmin[mess];
439     double valeur1=liste_kmax[mess];
440     double valeur2=liste_gau[mess];
441     sol2->ecrire(valeur0,compte,0,0);
442     sol2->ecrire(valeur1,compte,1,0);
443     sol2->ecrire(valeur2,compte,2,0);
444     sprintf(mess,"%lu_%lu",no2->get_id(),tri->get_lien_topologie()->get_id());
445     valeur0=liste_kmin[mess];
446     valeur1=liste_kmax[mess];
447     valeur2=liste_gau[mess];
448     sol2->ecrire(valeur0,compte,0,1);
449     sol2->ecrire(valeur1,compte,1,1);
450     sol2->ecrire(valeur2,compte,2,1);
451     sprintf(mess,"%lu_%lu",no3->get_id(),tri->get_lien_topologie()->get_id());
452     valeur0=liste_kmin[mess];
453     valeur1=liste_kmax[mess];
454     valeur2=liste_gau[mess];
455     sol2->ecrire(valeur0,compte,0,2);
456     sol2->ecrire(valeur1,compte,1,2);
457     sol2->ecrire(valeur2,compte,2,2);
458     compte++;
459     }
460     char chaine[1000];
461     char* p;
462     p=strrchr(magicfilename,'.');
463     strncpy(chaine,magicfilename,p-magicfilename);
464     std::string namfic=chaine;
465     namfic=namfic + "courbcal.magic";
466     gest.enregistrer(namfic.c_str());
467     }
468     liste_kmin.clear();liste_kmax.clear();liste_gau.clear();liste_courburemax1.clear();liste_courburemax2.clear();liste_courburemax3.clear();liste_courburemax4.clear();liste_courburemax5.clear();
469    
470    
471     ///make correspondence between cadmgmai and defcadmgmai nodes
472 sattarpa 609 map<unsigned long, unsigned long>::iterator itcoresspondndidlst;
473     for(MG_NOEUD* defcadndcurv=defcadmgmai->get_premier_noeud(itdefcadndcurv);defcadndcurv!=NULL;defcadndcurv=defcadmgmai->get_suivant_noeud(itdefcadndcurv))
474     {
475     itcoresspondndidlst=coresspondndidlst.find(defcadndcurv->get_id());
476     defcadndcurv->change_nouveau_numero((*itcoresspondndidlst).second);
477     }
478    
479     cout<<"solution calculation"<<endl;
480     multimap<double,MG_NOEUD*,std::greater<double> > lstkmin_diff;
481     multimap<double,MG_NOEUD*,std::greater<double> > lstkmax_diff;
482 sattarpa 646 multimap<double,MG_NOEUD*,std::greater<double> > lstkgau_diff;
483 sattarpa 609 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_cadmgmai;
484     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_cadmgmai;
485 sattarpa 646 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_cadmgmai;
486 sattarpa 609 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_defcadmgmai;
487     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_defcadmgmai;
488 sattarpa 646 multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_defcadmgmai;
489 sattarpa 609 cout<<"lstkmin_cadmgmai.size()= "<<lstkmin_cadmgmai.size()<<endl;
490     cout<<"lstkmin_defcadmgmai.size()= "<<lstkmin_defcadmgmai.size()<<endl;
491 sattarpa 646 cout<<"kmin diff. calc. started"<<endl;
492 sattarpa 609 for(itlstkmin_cadmgmai=lstkmin_cadmgmai.begin();itlstkmin_cadmgmai!=lstkmin_cadmgmai.end();itlstkmin_cadmgmai++)
493 sattarpa 554 {
494 sattarpa 609 MG_NOEUD* cadndcurv=(*itlstkmin_cadmgmai).second;
495     double kmindcad;
496     double kmindcad_def;
497     kmindcad=(*itlstkmin_cadmgmai).first;
498     for(itlstkmin_defcadmgmai=lstkmin_defcadmgmai.begin();itlstkmin_defcadmgmai!=lstkmin_defcadmgmai.end();itlstkmin_defcadmgmai++)
499     {
500     MG_NOEUD* defcadndcurv=(*itlstkmin_defcadmgmai).second;
501     if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
502     kmindcad_def=(*itlstkmin_defcadmgmai).first;
503     }
504    
505     double kmin_diff=kmindcad_def-kmindcad;
506     lstkmin_diff.insert(pair<double,MG_NOEUD*>(kmin_diff,cadndcurv) );
507     }
508 sattarpa 646 cout<<"kmax diff. calc. started"<<endl;
509 sattarpa 609 for(itlstkmax_cadmgmai=lstkmax_cadmgmai.begin();itlstkmax_cadmgmai!=lstkmax_cadmgmai.end();itlstkmax_cadmgmai++)
510     {
511     MG_NOEUD* cadndcurv=(*itlstkmax_cadmgmai).second;
512     double kmaxndcad;
513     double kmaxndcad_def;
514     kmaxndcad=(*itlstkmax_cadmgmai).first;
515     for(itlstkmax_defcadmgmai=lstkmax_defcadmgmai.begin();itlstkmax_defcadmgmai!=lstkmax_defcadmgmai.end();itlstkmax_defcadmgmai++)
516     {
517     MG_NOEUD* defcadndcurv=(*itlstkmax_defcadmgmai).second;
518     if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
519     {
520     kmaxndcad_def=(*itlstkmax_defcadmgmai).first;
521     }
522     }
523     double kmax_diff=kmaxndcad_def-kmaxndcad;
524     lstkmax_diff.insert(pair<double,MG_NOEUD*>(kmax_diff,cadndcurv) );
525     }
526 sattarpa 646 cout<<"kgau diff. calc. started"<<endl;
527     for(itlstkgau_cadmgmai=lstkgau_cadmgmai.begin();itlstkgau_cadmgmai!=lstkgau_cadmgmai.end();itlstkgau_cadmgmai++)
528     {
529     MG_NOEUD* cadndcurv=(*itlstkgau_cadmgmai).second;
530     double kgaundcad;
531     double kgaundcad_def;
532     kgaundcad=(*itlstkgau_cadmgmai).first;
533     for(itlstkgau_defcadmgmai=lstkgau_defcadmgmai.begin();itlstkgau_defcadmgmai!=lstkgau_defcadmgmai.end();itlstkgau_defcadmgmai++)
534     {
535     MG_NOEUD* defcadndcurv=(*itlstkgau_defcadmgmai).second;
536     if(defcadndcurv->get_nouveau_numero()==cadndcurv->get_id())
537     {
538     kgaundcad_def=(*itlstkgau_defcadmgmai).first;
539     }
540     }
541     double kgau_diff=kgaundcad_def-kgaundcad;
542     lstkgau_diff.insert(pair<double,MG_NOEUD*>(kgau_diff,cadndcurv) );
543     }
544     // affichage sur GMSH ******************************
545     if (gmsh_affiche>0)
546     {
547     cout<<"affiche: calcul_difference_courbure "<<endl;
548     std::ostringstream oss;
549     oss << "KMaxMinGaudiff_curvdifcoef:" <<curvdif_coef ;
550     std::string namefic = oss.str();
551     char *cstr = new char[namefic.length() + 1];
552     strcpy(cstr, namefic.c_str());
553     MG_SOLUTION* sol3=new MG_SOLUTION(cadmgmai,3,cstr,1,(char*)"Kdiff_solution",MAGIC::ENTITE_SOLUTION::ENTITE_ELEMENT2_NOEUD,MAGIC::TYPE_SOLUTION::SCALAIRE);
554     gest.ajouter_mg_solution(sol3);
555     sol3->change_legende(0,"Kmin_diff");
556     sol3->change_legende(1,"Kmax_diff");
557     sol3->change_legende(2,"Kgau_diff");
558     LISTE_MG_TRIANGLE::iterator ittri;
559     int compte=0;
560     for (MG_TRIANGLE* tri=cadmgmai->get_premier_triangle(ittri);tri!=NULL;tri=cadmgmai->get_suivant_triangle(ittri))
561     {
562     MG_NOEUD *no1=tri->get_noeud1();
563     MG_NOEUD *no2=tri->get_noeud2();
564     MG_NOEUD *no3=tri->get_noeud3();
565     //char mess[500];
566     //sprintf(mess,"%lu_%lu",no1->get_id(),tri->get_lien_topologie()->get_id());
567     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff;
568     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff;
569     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkgau_diff;
570     double valeurKmin1, valeurKmin2, valeurKmin3;
571     double valeurKmax1, valeurKmax2, valeurKmax3;
572     double valeurKgau1, valeurKgau2, valeurKgau3;
573     for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
574     {
575     if (no1==(*itlstkmin_diff).second)
576     valeurKmin1=(*itlstkmin_diff).first;
577     if (no2==(*itlstkmin_diff).second)
578     valeurKmin2=(*itlstkmin_diff).first;
579     if (no3==(*itlstkmin_diff).second)
580     valeurKmin3=(*itlstkmin_diff).first;
581     }
582     for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
583     {
584     if (no1==(*itlstkmax_diff).second)
585     valeurKmax1=(*itlstkmax_diff).first;
586     if (no2==(*itlstkmax_diff).second)
587     valeurKmax2=(*itlstkmax_diff).first;
588     if (no3==(*itlstkmax_diff).second)
589     valeurKmax3=(*itlstkmax_diff).first;
590     }
591     for (itlstkgau_diff=lstkgau_diff.begin();itlstkgau_diff!=lstkgau_diff.end();itlstkgau_diff++)
592     {
593     if (no1==(*itlstkgau_diff).second)
594     valeurKgau1=(*itlstkgau_diff).first;
595     if (no2==(*itlstkgau_diff).second)
596     valeurKgau2=(*itlstkgau_diff).first;
597     if (no3==(*itlstkgau_diff).second)
598     valeurKgau3=(*itlstkgau_diff).first;
599     }
600     sol3->ecrire(valeurKmin1,compte,0,0);
601     sol3->ecrire(valeurKmax1,compte,1,0);
602     sol3->ecrire(valeurKgau1,compte,2,0);
603 sattarpa 609
604 sattarpa 646 sol3->ecrire(valeurKmin2,compte,0,1);
605     sol3->ecrire(valeurKmax2,compte,1,1);
606     sol3->ecrire(valeurKgau2,compte,2,1);
607    
608     sol3->ecrire(valeurKmin3,compte,0,2);
609     sol3->ecrire(valeurKmax3,compte,1,2);
610     sol3->ecrire(valeurKgau3,compte,2,2);
611     compte++;
612     }
613     char chaine[1000];
614     char* p;
615     p=strrchr(magicfilename,'.');
616     strncpy(chaine,magicfilename,p-magicfilename);
617     std::string namfic=chaine;
618     namfic=namfic + "courbcal.magic";
619     gest.enregistrer(namfic.c_str());
620     }
621 sattarpa 609 cout<<"read insert points in lstpinsert"<<endl;
622     //read insert points in lstpinsert
623     std::vector<double*> lstpinsert;
624     double prop=0.001;
625     FILE *in=fopen(gnifinspointfile,"rt");
626     if (in==NULL) cout<<"file is not available"<<endl;
627     while (!feof(in))
628     {
629     char chaine[500];
630     fgets(chaine,500,in);
631     double x,y,z;
632     double q1,q2,q3;
633     int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
634     q1=prop*q1;
635     q2=prop*q2;
636     q3=prop*q3;
637     if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
638     else if (nb==6)
639     {
640     double* pcoordbc=new double[6];
641     pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
642     lstpinsert.push_back(pcoordbc);
643     }
644     }
645     fclose(in);
646     cout<<"octree initialization "<<endl;
647     //octree initialization
648     double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
649     TPL_MAP_ENTITE<MG_NOEUD*> lstnoeud;
650     //LISTE_MG_NOEUD::iterator it;
651     for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
652     {
653     if (cadndcurv->get_x()<xmin) xmin=cadndcurv->get_x();
654     if (cadndcurv->get_y()<ymin) ymin=cadndcurv->get_y();
655     if (cadndcurv->get_z()<zmin) zmin=cadndcurv->get_z();
656     if (cadndcurv->get_x()>xmax) xmax=cadndcurv->get_x();
657     if (cadndcurv->get_y()>ymax) ymax=cadndcurv->get_y();
658     if (cadndcurv->get_z()>zmax) zmax=cadndcurv->get_z();
659     lstnoeud.ajouter(cadndcurv);
660     }
661     OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
662     OT_VECTEUR_3D vec(vecmmax,vecmin);
663    
664     //double search_radius=0.001*(vec.get_longueur());
665     // double search_radius=2.;///sasan this should be as a parameter
666     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);
667     double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
668     xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
669     xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
670    
671     TPL_OCTREE<MG_NOEUD*,MG_NOEUD*> octree;
672     octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
673     for(MG_NOEUD* cadndcurv=cadmgmai->get_premier_noeud(itcadndcurv);cadndcurv!=NULL;cadndcurv=cadmgmai->get_suivant_noeud(itcadndcurv))
674     octree.inserer(cadndcurv);
675     //criterion
676     multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_cadmgmai;
677     multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_cadmgmai;
678     multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmin_defcadmgmai;
679     multimap<double,MG_NOEUD*,std::greater<double> >::reverse_iterator ritlstkmax_defcadmgmai;
680     ritlstkmin_cadmgmai=lstkmin_cadmgmai.rbegin(); double kmin_cad_min=(*ritlstkmin_cadmgmai).first;
681     itlstkmin_cadmgmai=lstkmin_cadmgmai.begin(); double kmin_cad_max=(*itlstkmin_cadmgmai).first;
682     ritlstkmax_cadmgmai=lstkmax_cadmgmai.rbegin(); double kmax_cad_min=(*ritlstkmax_cadmgmai).first;
683     itlstkmax_cadmgmai=lstkmax_cadmgmai.begin(); double kmax_cad_max=(*itlstkmax_cadmgmai).first;
684     ritlstkmin_defcadmgmai=lstkmin_defcadmgmai.rbegin(); double kmin_defcad_min=(*ritlstkmin_defcadmgmai).first;
685     itlstkmin_defcadmgmai=lstkmin_defcadmgmai.begin(); double kmin_defcad_max=(*itlstkmin_defcadmgmai).first;
686     ritlstkmax_defcadmgmai=lstkmax_defcadmgmai.rbegin(); double kmax_defcad_min=(*ritlstkmax_defcadmgmai).first;
687     itlstkmax_defcadmgmai=lstkmax_defcadmgmai.begin(); double kmax_defcad_max=(*itlstkmax_defcadmgmai).first;
688     cout<<"kmin_cad_min= "<<kmin_cad_min<<" kmin_cad_max= "<<kmin_cad_max<<endl;
689     cout<<"kmin_defcad_min= "<<kmin_defcad_min<<" kmin_defcad_max= "<<kmin_defcad_max<<endl;
690     //cout<<" kmin_defcad_min= "<<kmin_defcad_min<<" kmin_cad_min= "<<kmin_cad_min<<" kmin_defcad_max= "<<kmin_defcad_max<<" kmin_cad_max= "<<kmin_cad_max
691     double crikmin_min=curvdif_coef*(kmin_defcad_min-kmin_cad_min)+kmin_cad_min;///the coefficient should be a parameter
692     double crikmin_max=curvdif_coef*(kmin_defcad_max-kmin_cad_max)+kmin_cad_max;///the coefficient should be a parameter
693     double crikmax_min=curvdif_coef*(kmax_defcad_min-kmax_cad_min)+kmax_cad_min;///the coefficient should be a parameter
694     double crikmax_max=curvdif_coef*(kmax_defcad_max-kmax_cad_max)+kmax_cad_max;///the coefficient should be a parameter
695     cout<<"crikmin_min= "<<crikmin_min<<" crikmin_max= "<<crikmin_max<<" crikmax_min= "<<crikmax_min<<" crikmax_max= "<<crikmax_max<<endl;
696     cout<<"for Kmin"<<endl;
697     //for kmin
698     //int l=0;
699     //int ll=0;
700     cout<<"lstkmin_diff.size()= "<<lstkmin_diff.size()<<endl;
701     cout<<"lstkmax_diff.size()= "<<lstkmax_diff.size()<<endl;
702     TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
703     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmin_diff;
704     for (itlstkmin_diff=lstkmin_diff.begin();itlstkmin_diff!=lstkmin_diff.end();itlstkmin_diff++)
705     {
706     //l++; cout<<"l"<<l<<endl;
707     //if(l>7430)
708     {
709     if((crikmin_max<(*itlstkmin_diff).first) || (crikmin_min>(*itlstkmin_diff).first))
710     {
711     //ll++; cout<<"ll"<<ll<<endl;
712     MG_NOEUD* piefect=(*itlstkmin_diff).second;
713     int neindnb=lstneipdefect.get_nb();
714     double search_radius1=search_radius;
715     while(neindnb==0)
716     {
717     octree.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
718     neindnb=lstneipdefect.get_nb();
719     search_radius1=search_radius1+0.1*search_radius;
720     //cout<<"search_radius= "<<search_radius<<endl;
721     }
722     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
723     for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
724     {
725     for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
726     {
727     double* xyzpins;
728     xyzpins=(*itlstpinsert);
729     if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
730     {
731     //cout<<"fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2]"<<endl;
732     lstpinsert.erase(itlstpinsert);
733     }
734     }
735     }
736     lstneipdefect.vide();
737     }
738     }
739     }
740     cout<<"for Kmax"<<endl;
741     //for kmax
742     multimap<double,MG_NOEUD*,std::greater<double> >::iterator itlstkmax_diff;
743     for (itlstkmax_diff=lstkmax_diff.begin();itlstkmax_diff!=lstkmax_diff.end();itlstkmax_diff++)
744     {
745     if((crikmax_max<(*itlstkmax_diff).first) || (crikmax_min>(*itlstkmax_diff).first))
746     {
747     MG_NOEUD* piefect=(*itlstkmax_diff).second;
748     TPL_MAP_ENTITE<MG_NOEUD*> lstneipdefect;
749     int neindnb=lstneipdefect.get_nb();
750     double search_radius1=search_radius;
751     while(neindnb==0)
752     {
753     octree.rechercher(piefect->get_x(),piefect->get_y(),piefect->get_z(),search_radius1,lstneipdefect);
754     neindnb=lstneipdefect.get_nb();
755     search_radius1=search_radius1+0.1*search_radius;
756     }
757     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itndnei;
758     for(MG_NOEUD* ndnei=lstneipdefect.get_premier(itndnei);ndnei!=NULL;ndnei=lstneipdefect.get_suivant(itndnei))
759     {
760     for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
761     {
762     double* xyzpins;
763     xyzpins=(*itlstpinsert);
764     if(ndnei->get_x()==xyzpins[0] && ndnei->get_y()==xyzpins[1] && ndnei->get_z()==xyzpins[2])
765     {
766     //cout<<"fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2]"<<endl;
767     lstpinsert.erase(itlstpinsert);
768     }
769     }
770     }
771    
772     }
773     }
774     FILE* in2=fopen(out_gnifinspointfile_removondefect,"wt");
775     for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
776     {
777     double* xyzpins1;
778     xyzpins1=(*itlstpinsert);
779     fprintf(in2,"%lf %lf %lf %lf %lf %lf\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
780     }
781     fclose(in2);
782    
783     }
784     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)
785     {
786 sattarpa 554 MG_FILE gest(magicfilename);
787 sattarpa 596 FEM_MAILLAGE* femmai;
788     if (femmeshno==0) femmai=gest.get_fem_maillage(femmeshno); else femmai=gest.get_fem_maillageid(femmeshno);
789     FEM_SOLUTION* femsol=gest.get_fem_solutionid(femsolid);
790     femsol->active_solution(femsubsolno);
791    
792     std::map<double,FEM_NOEUD*,std::greater<double> > mpsol;
793     LISTE_FEM_NOEUD::iterator itfemnds;
794     for(FEM_NOEUD* nod=femmai->get_premier_noeud(itfemnds);nod!=NULL;nod=femmai->get_suivant_noeud(itfemnds))
795     {
796 sattarpa 609 nod->get_mg_element_maillage()->get_id();
797 sattarpa 596 mpsol.insert(pair<double,FEM_NOEUD*> (nod->get_solution(),nod));
798     //cout<<"nod->get_solution()= "<<nod->get_solution()<<endl;
799     //if(nod->get_solution()<=1.e-20 && nod->get_solution()!=0.)
800     //cout<<nod->get_id()<<" : "<<nod->get_solution()<<endl;
801     }
802     std::map<double,FEM_NOEUD*,std::greater<double> >::iterator itmpsol=mpsol.begin();
803    
804     double maxi=(*itmpsol).first;
805     itmpsol=mpsol.end();
806     double mini=(*itmpsol).first;
807 sattarpa 609 double crit=vm_coef*(maxi+mini)/2.;
808 sattarpa 596 //cout<<"critreion value= "<<crit<<endl;
809     std::vector<double*> lstpinsert;
810     double prop=0.001;
811     FILE *in=fopen(gnifinspointfile,"rt");
812     if (in==NULL) cout<<"file is not available"<<endl;
813     while (!feof(in))
814     {
815     char chaine[500];
816     fgets(chaine,500,in);
817     double x,y,z;
818     double q1,q2,q3;
819     int nb=sscanf(chaine,"%le %le %le %le %le %le",&x,&y,&z,&q1,&q2,&q3);
820     q1=prop*q1;
821     q2=prop*q2;
822     q3=prop*q3;
823     if (nb!=-1 && nb!=6) cout<<"Wrong file format"<<endl;
824     else if (nb==6)
825     {
826     double* pcoordbc=new double[6];
827     pcoordbc[0]=x; pcoordbc[1]=y; pcoordbc[2]=z; pcoordbc[3]=q1; pcoordbc[4]=q2; pcoordbc[5]=q3;
828     lstpinsert.push_back(pcoordbc);
829     }
830     }
831     fclose(in);
832    
833    
834     //octree initialization
835     double xmin=1e308,ymin=1e308,zmin=1e308,xmax=-1e308,ymax=-1e308,zmax=-1e308;
836     TPL_MAP_ENTITE<FEM_NOEUD*> lstnoeud;
837     LISTE_FEM_NOEUD::iterator it;
838     for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
839     {
840     if (no->get_x()<xmin) xmin=no->get_x();
841     if (no->get_y()<ymin) ymin=no->get_y();
842     if (no->get_z()<zmin) zmin=no->get_z();
843     if (no->get_x()>xmax) xmax=no->get_x();
844     if (no->get_y()>ymax) ymax=no->get_y();
845     if (no->get_z()>zmax) zmax=no->get_z();
846     lstnoeud.ajouter(no);
847     }
848     OT_VECTEUR_3D vecmin(xmin,ymin,zmin);OT_VECTEUR_3D vecmmax(xmax,ymax,zmax);
849     OT_VECTEUR_3D vec(vecmmax,vecmin);
850    
851     //double search_radius=0.001*(vec.get_longueur());
852 sattarpa 609 //double search_radius=2.; //sasan this should be as a parameter
853 sattarpa 596 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);
854     double length=sqrt(lengthvec*lengthvec); double bxr=1.1;
855     xmin=average.get_x()-(length*bxr);ymin=average.get_y()-(length*bxr);zmin=average.get_z()-(length*bxr);
856     xmax=average.get_x()+(length*bxr);ymax=average.get_y()+(length*bxr);zmax=average.get_z()+(length*bxr);
857    
858     TPL_OCTREE<FEM_NOEUD*,FEM_NOEUD*> octree;
859     octree.initialiser(&lstnoeud,1,xmin,ymin,zmin,xmax,ymax,zmax);
860     for (FEM_NOEUD* no=femmai->get_premier_noeud(it);no!=NULL;no=femmai->get_suivant_noeud(it))
861     octree.inserer(no);
862    
863     for (itmpsol=mpsol.begin();itmpsol!=mpsol.end();itmpsol++)
864     {
865     if(crit<(*itmpsol).first)
866     {
867     FEM_NOEUD* pdefect=(*itmpsol).second;
868     TPL_MAP_ENTITE<FEM_NOEUD*> lstneipdefect;
869     int neindnb=lstneipdefect.get_nb();
870 sattarpa 609 double search_radius1=search_radius;
871 sattarpa 596 while(neindnb==0)
872     {
873 sattarpa 609 octree.rechercher(pdefect->get_x(),pdefect->get_y(),pdefect->get_z(),search_radius1,lstneipdefect);
874 sattarpa 596 neindnb=lstneipdefect.get_nb();
875 sattarpa 609 search_radius1=search_radius1+0.1*search_radius;
876 sattarpa 596 }
877     TPL_MAP_ENTITE<FEM_NOEUD*>::ITERATEUR itfendnei;
878     for(FEM_NOEUD* fendnei=lstneipdefect.get_premier(itfendnei);fendnei!=NULL;fendnei=lstneipdefect.get_suivant(itfendnei))
879     {
880     // std::map<double*,double*,std::less<double*> >::iterator itlstpinsert=lstpinsert.begin();//itlstpinsert!=lstpinsert.end();itlstpinsert++
881     for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
882     {
883     double* xyzpins;
884     xyzpins=(*itlstpinsert);
885     if(fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2])
886     {
887     //cout<<"fendnei->get_x()==xyzpins[0] && fendnei->get_y()==xyzpins[1] && fendnei->get_z()==xyzpins[2]"<<endl;
888     lstpinsert.erase(itlstpinsert);
889     }
890     }
891     }
892    
893     }
894    
895     }
896    
897     FILE* in1=fopen(out_gnifinspointfile_removondefect,"wt");
898     for(std::vector<double*>::iterator itlstpinsert=lstpinsert.begin();itlstpinsert!=lstpinsert.end();itlstpinsert++)
899     {
900     double* xyzpins1;
901     xyzpins1=(*itlstpinsert);
902     fprintf(in1,"%lf %lf %lf %lf %lf %lf\n",xyzpins1[0],xyzpins1[1],xyzpins1[2],xyzpins1[3]*1000.,xyzpins1[4]*1000.,xyzpins1[5]*1000.);
903     }
904     fclose(in1);
905     }
906     void CRIAQOPERATORS::surfmaker_e1(char* outputfilename,int meshno,char* magicfilename)
907     {
908     MG_FILE gest(magicfilename);
909 sattarpa 554 MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
910     MG_MAILLAGE* mai;
911     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
912     //MG_FILE gest((char*)"longflxprtwithpockets_3d_3mm.magic");
913     //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
914     //MG_MAILLAGE* mai=gest.get_mg_maillageid(5674824);
915     MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
916     MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
917     gestnew->ajouter_mg_geometrie(geonew);
918     MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
919     gestnew->ajouter_mg_maillage(mainew);
920    
921     LISTE_MG_NOEUD::iterator itnod;
922     for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
923     {
924     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
925     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
926     MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
927     MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
928 sattarpa 596
929     if(facevert->get_id()==76
930     || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
931     || aretver->get_id()==81 || aretver->get_id()==83 || aretver->get_id()==10|| aretver->get_id()==12|| aretver->get_id()==90|| aretver->get_id()==97
932     /* facevert->get_id()==133
933 sattarpa 554 || aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
934     || aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
935     || aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
936     || aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
937     || aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
938     || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
939     || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
940     || sometver->get_id()==368|| sometver->get_id()==361|| sometver->get_id()==106|| sometver->get_id()==122|| sometver->get_id()==74|| sometver->get_id()==90
941     || sometver->get_id()==233|| sometver->get_id()==240|| sometver->get_id()==247|| sometver->get_id()==254|| sometver->get_id()==261|| sometver->get_id()==268
942     || sometver->get_id()==226|| sometver->get_id()==224|| sometver->get_id()==190|| sometver->get_id()==197|| sometver->get_id()==204|| sometver->get_id()==211
943     || sometver->get_id()==183|| sometver->get_id()==181|| sometver->get_id()==154|| sometver->get_id()==147|| sometver->get_id()==140|| sometver->get_id()==161
944     || sometver->get_id()==168|| sometver->get_id()==138|| sometver->get_id()==318|| sometver->get_id()==311|| sometver->get_id()==304|| sometver->get_id()==297
945     || sometver->get_id()==325|| sometver->get_id()==332|| sometver->get_id()==290|| sometver->get_id()==288|| sometver->get_id()==42|| sometver->get_id()==58
946 sattarpa 596 || sometver->get_id()==352|| sometver->get_id()==354|| sometver->get_id()==10|| sometver->get_id()==26*/
947    
948     )
949 sattarpa 554 {
950     double x=vertices->get_x();
951     double y=vertices->get_y();
952     double z=vertices->get_z();
953     //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
954     MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
955     mainew->ajouter_mg_noeud(newno);
956     vertices->change_nouveau_numero(newno->get_id()); // what does this do?
957     }
958     }
959    
960     LISTE_MG_SEGMENT::iterator itSeg;
961     for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
962     {
963     //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
964     //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
965     //%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);
966     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
967     MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
968 sattarpa 596 if (faceseg->get_id()==76
969     || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==13 || aretver->get_id()==110||aretver->get_id()==98
970     //faceseg->get_id()==133
971     //|| aretver->get_id()==355 || aretver->get_id()==362|| aretver->get_id()==374|| aretver->get_id()==298 || aretver->get_id()==291||aretver->get_id()==338
972     //|| aretver->get_id()==326 || aretver->get_id()==333|| aretver->get_id()==319|| aretver->get_id()==312 || aretver->get_id()==305||aretver->get_id()==169
973     //|| aretver->get_id()==162 || aretver->get_id()==141|| aretver->get_id()==174|| aretver->get_id()==148 || aretver->get_id()==155||aretver->get_id()==217
974     //|| aretver->get_id()==212 || aretver->get_id()==191|| aretver->get_id()==184|| aretver->get_id()==64 || aretver->get_id()==280||aretver->get_id()==32
975     //|| aretver->get_id()==387 || aretver->get_id()==198|| aretver->get_id()==205|| aretver->get_id()==269 || aretver->get_id()==262||aretver->get_id()==234
976     // || aretver->get_id()==227 || aretver->get_id()==255|| aretver->get_id()==248|| aretver->get_id()==241 || aretver->get_id()==380||aretver->get_id()==96
977     // || aretver->get_id()==369 || aretver->get_id()==344|| aretver->get_id()==128|| aretver->get_id()==274
978    
979     )
980 sattarpa 554 {
981     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
982     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
983     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
984     //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
985     mainew->ajouter_mg_segment(seg);
986     }
987     }
988    
989     LISTE_MG_TRIANGLE::iterator itTri;
990     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
991     {
992     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
993 sattarpa 596 if (facetri->get_id()==76)
994 sattarpa 554 {
995     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
996     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
997     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
998     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
999     }
1000     }
1001    
1002     //gestnew->enregistrer("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
1003     gestnew->enregistrer(outputfilename);
1004     //////////////////
1005    
1006     ////////////////////////
1007    
1008    
1009     /*
1010     mainew->supprimer_mg_triangleid(106625);
1011     mainew->supprimer_mg_triangleid(106662);
1012     mainew->supprimer_mg_triangleid(106626);
1013     mainew->supprimer_mg_triangleid(106701);
1014     mainew->supprimer_mg_triangleid(106702);
1015     mainew->supprimer_mg_triangleid(106639);*/
1016     //cout<<"output mesh no.= 495557 "<<endl;
1017     //gest.enregistrer("2dsurfmesh_cad.magic"); //CAD model output
1018     //scanned part output
1019    
1020    
1021     }
1022     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1023 sattarpa 596 void CRIAQOPERATORS::surfmaker_e2(char* outputfilename,int meshno,char* magicfilename)
1024 sattarpa 554 {
1025     // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
1026     MG_FILE gest(magicfilename);
1027     MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1028     MG_MAILLAGE* mai;
1029     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1030     //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
1031     //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1032     //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
1033     MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1034     MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1035     gestnew->ajouter_mg_geometrie(geonew);
1036     MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1037     gestnew->ajouter_mg_maillage(mainew);
1038    
1039     LISTE_MG_NOEUD::iterator itnod;
1040     for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1041     {
1042     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1043     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1044     MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1045     MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1046     if(facevert->get_id()==76
1047     || aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13||aretver->get_id()==110
1048     || sometver->get_id()==10|| sometver->get_id()==12|| sometver->get_id()==81|| sometver->get_id()==83|| sometver->get_id()==90|| sometver->get_id()==97)
1049     {
1050     double x=vertices->get_x();
1051     double y=vertices->get_y();
1052     double z=vertices->get_z();
1053     //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1054     MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1055     mainew->ajouter_mg_noeud(newno);
1056     vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1057     }
1058     }
1059    
1060     LISTE_MG_SEGMENT::iterator itSeg;
1061     for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1062     {
1063     //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1064     //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1065     //%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);
1066     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1067     //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1068     MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1069     //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1070     if (faceseg->get_id()==76 ||
1071     aretver->get_id()==84 || aretver->get_id()==103|| aretver->get_id()==91|| aretver->get_id()==98 || aretver->get_id()==13|| aretver->get_id()==110)
1072     {
1073     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1074     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1075     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1076     //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1077     mainew->ajouter_mg_segment(seg);
1078     }
1079     }
1080    
1081     LISTE_MG_TRIANGLE::iterator itTri;
1082     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1083     {
1084     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1085     if (facetri->get_id()==76)
1086     {
1087     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1088     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1089     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1090     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1091     }
1092     }
1093    
1094     //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
1095     gestnew->enregistrer(outputfilename);
1096     }
1097 sattarpa 596 void CRIAQOPERATORS::surfmaker_e2t(char* outputfilename,int meshno,char* magicfilename)
1098 sattarpa 554 {
1099     // surfmeshgenerator a partially scanned (deformed CAD model) for GNIF examples for simple exam with hole (badisplacenmentvector + smplwithpocket)
1100     MG_FILE gest(magicfilename);
1101     MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1102     MG_MAILLAGE* mai;
1103     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1104     //MG_FILE gest((char*)"2d_smplwithole_23mm.magic");
1105     //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1106     //MG_MAILLAGE* mai=gest.get_mg_maillageid(1197);
1107     MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1108     MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1109     gestnew->ajouter_mg_geometrie(geonew);
1110     MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1111     gestnew->ajouter_mg_maillage(mainew);
1112    
1113     LISTE_MG_NOEUD::iterator itnod;
1114     for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1115     {
1116     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1117     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1118     MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1119     MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1120     if(facevert->get_id()==37
1121     || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
1122     || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
1123     || sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==51|| sometver->get_id()==58|| sometver->get_id()==42|| sometver->get_id()==44
1124     || sometver->get_id()==87|| sometver->get_id()==73|| sometver->get_id()==80|| sometver->get_id()==71|| sometver->get_id()==100|| sometver->get_id()==107
1125     //for e2t
1126     //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
1127     //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
1128     //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
1129     //|| sometver->get_id()==10|| sometver->get_id()==19|| sometver->get_id()==65|| sometver->get_id()==58|| sometver->get_id()==51|| sometver->get_id()==42
1130     //|| sometver->get_id()==44|| sometver->get_id()==72|| sometver->get_id()==115|| sometver->get_id()==87|| sometver->get_id()==108|| sometver->get_id()==101
1131     //|| sometver->get_id()==94|| sometver->get_id()==85|| sometver->get_id()==128|| sometver->get_id()==135
1132     )
1133     {
1134     double x=vertices->get_x();
1135     double y=vertices->get_y();
1136     double z=vertices->get_z();
1137     //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1138     MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1139     mainew->ajouter_mg_noeud(newno);
1140     vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1141     }
1142     }
1143    
1144     LISTE_MG_SEGMENT::iterator itSeg;
1145     for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1146     {
1147     //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1148     //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1149     //%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);
1150     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1151     //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1152     MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1153     //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1154     if (faceseg->get_id()==37
1155     || aretver->get_id()==20 || aretver->get_id()==108|| aretver->get_id()==113|| aretver->get_id()==101 || aretver->get_id()==59||aretver->get_id()==64
1156     || aretver->get_id()==45 || aretver->get_id()==52|| aretver->get_id()==93|| aretver->get_id()==74 || aretver->get_id()==81||aretver->get_id()==88
1157     //|| aretver->get_id()==20 || aretver->get_id()==141|| aretver->get_id()==129|| aretver->get_id()==136 || aretver->get_id()==66||aretver->get_id()==59
1158     //|| aretver->get_id()==73 || aretver->get_id()==78|| aretver->get_id()==45|| aretver->get_id()==52 || aretver->get_id()==95||aretver->get_id()==102
1159     //|| aretver->get_id()==88 || aretver->get_id()==121|| aretver->get_id()==116|| aretver->get_id()==109
1160    
1161     )
1162     {
1163     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1164     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1165     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1166     //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1167     mainew->ajouter_mg_segment(seg);
1168     }
1169     }
1170    
1171     LISTE_MG_TRIANGLE::iterator itTri;
1172     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1173     {
1174     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1175     if (facetri->get_id()==37)
1176     {
1177     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1178     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1179     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1180     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1181     }
1182     }
1183    
1184     //gestnew->enregistrer("cadsurfmsh_smplwithole_23mm.magic");
1185     gestnew->enregistrer(outputfilename);
1186     }
1187     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1188 sattarpa 596 void CRIAQOPERATORS::surfmaker_e3(char* outputfilename,int meshno,char* magicfilename)
1189 sattarpa 554 {
1190     //surfmesh maker (smplwithpocket+smpl withpocket)
1191     MG_FILE gest(magicfilename);
1192     MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1193     MG_MAILLAGE* mai;
1194     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1195     //MG_FILE gest((char*)"smplwithpocket_3d_13mm.magic");
1196     //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1197     //MG_MAILLAGE* mai=gest.get_mg_maillageid(2982821);
1198     MG_GESTIONNAIRE* gestnew=new MG_GESTIONNAIRE();
1199     MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1200     gestnew->ajouter_mg_geometrie(geonew);
1201     MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1202     gestnew->ajouter_mg_maillage(mainew);
1203    
1204     LISTE_MG_NOEUD::iterator itnod;
1205     for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1206     {
1207     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1208     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1209     MG_ARETE* aretver=(MG_ARETE*) (vertices->get_lien_topologie());
1210     MG_SOMMET* sometver=(MG_SOMMET*) (vertices->get_lien_topologie());
1211     if(facevert->get_id()==5
1212     || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
1213     || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13
1214     || sometver->get_id()==10|| sometver->get_id()==26|| sometver->get_id()==41|| sometver->get_id()==55|| sometver->get_id()==39|| sometver->get_id()==48
1215     || sometver->get_id()==84|| sometver->get_id()==77|| sometver->get_id()==70|| sometver->get_id()==68|| sometver->get_id()==12|| sometver->get_id()==19)
1216     {
1217     double x=vertices->get_x();
1218     double y=vertices->get_y();
1219     double z=vertices->get_z();
1220     //MG_NOEUD *newno=new MG_NOEUD(NULL,x,y,z,vertices->get_origine());
1221     MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1222     mainew->ajouter_mg_noeud(newno);
1223     vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1224     }
1225     }
1226    
1227     LISTE_MG_SEGMENT::iterator itSeg;
1228     for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1229     {
1230     //%275=NOEUD($10,93.94800850483597,-250.0000000000000,0.000000000000000,1010);
1231     //NOEUD linked with a topology (get_lien_topologie => $10 ) -> and %10=SOMMET(1,$9,0); %9=POINT_OCC(1);
1232     //%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);
1233     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1234     //cout<<"faceseg->get_id()= "<<faceseg->get_id()<<endl;
1235     MG_ARETE* aretver=(MG_ARETE*) (segment->get_lien_topologie());
1236     //cout<<"aretver->get_id()= "<<aretver->get_id()<<endl;
1237     if (faceseg->get_id()==5
1238     || aretver->get_id()==32 || aretver->get_id()==61|| aretver->get_id()==42|| aretver->get_id()==56 || aretver->get_id()==49||aretver->get_id()==27
1239     || aretver->get_id()==85 || aretver->get_id()==90|| aretver->get_id()==78|| aretver->get_id()==71 || aretver->get_id()==20||aretver->get_id()==13)
1240     {
1241     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1242     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1243     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1244     //MG_SEGMENT *seg=new MG_SEGMENT(NULL,no1,no2,segment->get_origine());
1245     mainew->ajouter_mg_segment(seg);
1246     }
1247     }
1248    
1249     LISTE_MG_TRIANGLE::iterator itTri;
1250     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1251     {
1252     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1253     if (facetri->get_id()==5)
1254     {
1255     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1256     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1257     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1258     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1259     }
1260     }
1261    
1262     //gestnew->enregistrer("scnsurf_smplwithpocket_3d_13mm_232mmdeform.magic");
1263     gestnew->enregistrer(outputfilename);
1264     }
1265     //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1266 sattarpa 596 void CRIAQOPERATORS::gnifformatmaker(char* elementxtoutfile,char* nodtxtoutfile,int meshno,char* magicfilename)
1267 sattarpa 554 {
1268     // gnifformatmaker
1269     MG_FILE gest(magicfilename);
1270     MG_MAILLAGE* mai;
1271     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1272     //MG_FILE gest((char*)"scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump.magic");
1273     // MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
1274     //std::string fichiermaillage="CAD_output_elements.txt";
1275     //FILE* in=fopen(fichiermaillage.c_str(),"wt");
1276     //FILE* in1=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_nodes.txt","wt");
1277     FILE* in1=fopen(nodtxtoutfile,"wt");
1278     //FILE* in1=fopen("scannedsurface_nodes.txt","wt");
1279     LISTE_MG_NOEUD::iterator itnod;
1280     unsigned long firstno=mai->get_premier_noeud(itnod)->get_id();
1281     firstno=firstno-1;
1282     cout<<firstno<<endl;
1283     int counter1=1;
1284     cout<<"mai->get_nb_mg_noeud()="<<mai->get_nb_mg_noeud()<<endl;
1285     for (MG_NOEUD* nod=mai->get_premier_noeud(itnod);nod!=NULL;nod=mai->get_suivant_noeud(itnod))
1286     {
1287     nod->change_nouveau_numero(counter1);
1288     //nod->change_id(counter1);
1289     //fprintf(in1,"%d node coordinate %le %le %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
1290     //fprintf(in,"%d node coordinate %lf %lf %le\n",nod->get_id(), nod->get_x(),nod->get_y(), nod->get_z() );
1291     fprintf(in1,"%19d%32.9lf%16.9lf%8d\n",nod->get_nouveau_numero(), nod->get_x(),nod->get_y(),nod->get_nouveau_numero());
1292     fprintf(in1,"%7d%16.9lf\n",nod->get_nouveau_numero(), nod->get_z());
1293     counter1++;
1294     }
1295     //FILE* in2=fopen("scnsurf_longflxprtwithpockets_3d_3mm_8mmdef_0bump_elements.txt","wt"); // CAD text output elements
1296     FILE* in2=fopen(elementxtoutfile,"wt");
1297     //FILE* in2=fopen("scannedsurface_elements.txt","wt"); //scanned text output elements
1298     int counter=1;
1299     LISTE_MG_TRIANGLE::iterator ittri;
1300     for (MG_TRIANGLE* tri=mai->get_premier_triangle(ittri);tri!=NULL;tri=mai->get_suivant_triangle(ittri))
1301     {
1302     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() );
1303     counter++;
1304     }
1305     fclose(in1);
1306     fclose(in2);
1307     }
1308     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1309 sattarpa 596 void CRIAQOPERATORS::rmovscnprtfromdefrmdcad(char* outputfilename,int meshno,char* magicfilename)
1310 sattarpa 554 {
1311     MG_FILE gest(magicfilename);
1312     MG_MAILLAGE* mai;
1313     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1314 sattarpa 596 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
1315 sattarpa 554 MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1316 sattarpa 596 newgest->ajouter_mg_geometrie(geonew);
1317 sattarpa 554 MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1318 sattarpa 596 newgest->ajouter_mg_maillage(mainew);
1319    
1320 sattarpa 554 LISTE_MG_NOEUD::iterator itnod;
1321     for (MG_NOEUD* vertices=mai->get_premier_noeud(itnod);vertices!=NULL;vertices=mai->get_suivant_noeud(itnod))
1322     {
1323     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1324     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1325 sattarpa 596 //if(facevert->get_id()!=76 && topnd->get_dimension()!=3) //e1
1326     //if(facevert->get_id()!=5 && topnd->get_dimension()!=3) //e2
1327 sattarpa 554 {
1328     double x=vertices->get_x();
1329     double y=vertices->get_y();
1330     double z=vertices->get_z();
1331     MG_NOEUD *newno=new MG_NOEUD(vertices->get_lien_topologie(),x,y,z,vertices->get_origine());
1332     mainew->ajouter_mg_noeud(newno);
1333     vertices->change_nouveau_numero(newno->get_id()); // what does this do?
1334     }
1335     }
1336 sattarpa 596
1337 sattarpa 554 LISTE_MG_SEGMENT::iterator itSeg;
1338     for (MG_SEGMENT * segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1339     {
1340     MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
1341     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1342 sattarpa 596 //if (faceseg->get_id()!=76 && topseg->get_dimension()!=3)
1343     if(faceseg->get_id()!=5 && topseg->get_dimension()!=3) //e2
1344 sattarpa 554 {
1345     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1346     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1347     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1348     mainew->ajouter_mg_segment(seg);
1349     }
1350     }
1351 sattarpa 596
1352 sattarpa 554 LISTE_MG_TRIANGLE::iterator itTri;
1353     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1354     {
1355     MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
1356     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1357 sattarpa 596 // if (facetri->get_id()!=76 && toptri->get_dimension()!=3)
1358     if (facetri->get_id()!=5 && toptri->get_dimension()!=3) //e2
1359 sattarpa 554 {
1360     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1361     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1362     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1363     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1364     }
1365     }
1366 sattarpa 596 newgest->enregistrer(outputfilename);
1367 sattarpa 554 //gest.enregistrer("deformedcad_sansscannedpart.magic");
1368    
1369     }
1370     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1371    
1372 sattarpa 596 void CRIAQOPERATORS::msh2dmakerfrommsh3d(char* outputfilename,int meshno,char* magicfilename)
1373 sattarpa 554 {
1374     //to make a 2D mesh out of 3D mesh :)
1375     /*
1376     MG_MAILLAGE* mainew=mai->dupliquer(&gest);
1377     LISTE_MG_TETRA::iterator ittet;
1378     for(MG_TETRA* )
1379     {
1380    
1381     }
1382    
1383     cout<<"mainew->get_nb_mg_noeud()= "<<mainew->get_nb_mg_noeud()<<endl;
1384     cout<<"mainew->get_nb_mg_segment()= "<<mainew->get_nb_mg_segment()<<endl;
1385     cout<<"mainew->get_nb_mg_triangle()= "<<mainew->get_nb_mg_triangle()<<endl;
1386     cout<<"mainew->get_nb_mg_tetra()= "<<mainew->get_nb_mg_tetra()<<endl;
1387    
1388     LISTE_MG_TRIANGLE::iterator ittri;
1389     for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
1390     {
1391     MG_ELEMENT_TOPOLOGIQUE *top=triangle->get_lien_topologie();
1392     int topdimension=top->get_dimension();
1393     if (topdimension==3)
1394     mainew->supprimer_mg_triangleid(triangle->get_id());
1395     }
1396    
1397     LISTE_MG_TETRA::iterator ittet;
1398     for (MG_TETRA* tetra=mainew->get_premier_tetra(ittet);tetra!=NULL;tetra=mainew->get_suivant_tetra(ittet))
1399     mainew->supprimer_mg_tetraid(tetra->get_id());
1400     //MG_FACE* face=geo->get_mg_faceid(5);
1401    
1402    
1403     LISTE_MG_SEGMENT::iterator itseg;
1404     for (MG_SEGMENT* segment=mainew->get_premier_segment(itseg);segment!=NULL;segment=mainew->get_suivant_segment(itseg))
1405     {
1406     MG_FACE* faceseg=(MG_FACE*) (segment->get_lien_topologie());
1407     if (faceseg->get_id()!=181)
1408     mainew->supprimer_mg_segmentid(segment->get_id());
1409    
1410     MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
1411     if(topseg->get_dimension()==3)
1412     cout<<"topseg->get_dimension()==3"<<endl;
1413     }
1414    
1415     LISTE_MG_NOEUD::iterator itnod;
1416     for (MG_NOEUD* vertices=mainew->get_premier_noeud(itnod);vertices!=NULL;vertices=mainew->get_suivant_noeud(itnod))
1417     {
1418     MG_ELEMENT_TOPOLOGIQUE *topnd=vertices->get_lien_topologie();
1419     MG_FACE* facevert=(MG_FACE*) (vertices->get_lien_topologie());
1420     //if (facevert->get_id()!=181)
1421     if (topnd->get_dimension()==0)
1422     mainew->supprimer_mg_segmentid(vertices->get_id());
1423     }
1424    
1425     for (MG_TRIANGLE* triangle=mainew->get_premier_triangle(ittri);triangle!=NULL;triangle=mainew->get_suivant_triangle(ittri))
1426     {
1427     MG_FACE* facetri=(MG_FACE*) (triangle->get_lien_topologie());
1428     if (facetri->get_id()!=181)
1429     mainew->supprimer_mg_triangleid(triangle->get_id());
1430     }
1431     */
1432 sattarpa 596
1433     MG_FILE gest(magicfilename);
1434     MG_MAILLAGE* mai;
1435     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1436 sattarpa 554 MG_GESTIONNAIRE* newgest=new MG_GESTIONNAIRE();
1437     MG_GEOMETRIE* geonew=mai->get_mg_geometrie();
1438     newgest->ajouter_mg_geometrie(geonew);
1439     MG_MAILLAGE* mainew=new MG_MAILLAGE(geonew);
1440     newgest->ajouter_mg_maillage(mainew);
1441    
1442     LISTE_MG_NOEUD::iterator itNod;
1443     for (MG_NOEUD* nd=mai->get_premier_noeud(itNod);nd!=NULL;nd=mai->get_suivant_noeud(itNod))
1444     {
1445     MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
1446     if(topnd->get_dimension()<3)
1447     {
1448     double x=nd->get_x();
1449     double y=nd->get_y();
1450     double z=nd->get_z();
1451     MG_NOEUD *newno=new MG_NOEUD(nd->get_lien_topologie(),x,y,z,nd->get_origine());
1452     mainew->ajouter_mg_noeud(newno);
1453     nd->change_nouveau_numero(newno->get_id());
1454     }
1455     }
1456     LISTE_MG_SEGMENT::iterator itSeg;
1457     for (MG_SEGMENT* segment =mai->get_premier_segment(itSeg); segment; segment=mai->get_suivant_segment(itSeg))
1458     {
1459     MG_ELEMENT_TOPOLOGIQUE *topseg=segment->get_lien_topologie();
1460     if(topseg->get_dimension()<3)
1461     {
1462     MG_NOEUD* no1=mainew->get_mg_noeudid(segment->get_noeud1()->get_nouveau_numero());
1463     MG_NOEUD* no2=mainew->get_mg_noeudid(segment->get_noeud2()->get_nouveau_numero());
1464     MG_SEGMENT *seg=new MG_SEGMENT(segment->get_lien_topologie(),no1,no2,segment->get_origine());
1465     mainew->ajouter_mg_segment(seg);
1466     }
1467     }
1468     LISTE_MG_TRIANGLE::iterator itTri;
1469     for (MG_TRIANGLE * triangle =mai->get_premier_triangle(itTri); triangle; triangle=mai->get_suivant_triangle(itTri))
1470     {
1471     MG_ELEMENT_TOPOLOGIQUE *toptri=triangle->get_lien_topologie();
1472     if(toptri->get_dimension()<3)
1473     {
1474     MG_NOEUD* no1=mainew->get_mg_noeudid(triangle->get_noeud1()->get_nouveau_numero());
1475     MG_NOEUD* no2=mainew->get_mg_noeudid(triangle->get_noeud2()->get_nouveau_numero());
1476     MG_NOEUD* no3=mainew->get_mg_noeudid(triangle->get_noeud3()->get_nouveau_numero());
1477     mainew->ajouter_mg_triangle(triangle->get_lien_topologie(),no1,no2,no3,triangle->get_origine());
1478     }
1479     }
1480 sattarpa 596 newgest->enregistrer(outputfilename);
1481 sattarpa 554 }
1482     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1483 sattarpa 596 void CRIAQOPERATORS::bumpmaker(char* outputfilename,int bumpndid, double bumptip,int meshno,char* magicfilename)
1484 sattarpa 554 {
1485     MG_FILE gest(magicfilename);
1486     //MG_GEOMETRIE* geo=gest.get_mg_geometrie(0);
1487     MG_MAILLAGE* mai;
1488     if (meshno==0) mai=gest.get_mg_maillage(meshno); else mai=gest.get_mg_maillageid(meshno);
1489     //MG_FILE gest((char*)"scnsurf_smplwithpocket_3d_13mm_64mmdeform.magic");
1490     //MG_GEOMETRIE* geo=gest.get_mg_geometrieid(1);
1491     //MG_MAILLAGE* mai=gest.get_mg_maillageid(2);
1492     MG_NOEUD* bptipnd;
1493     TPL_MAP_ENTITE<MG_NOEUD*> usednd;
1494     LISTE_MG_NOEUD::iterator itnod;
1495     for (MG_NOEUD* nd=mai->get_premier_noeud(itnod);nd!=NULL;nd=mai->get_suivant_noeud(itnod))
1496     {
1497     MG_ELEMENT_TOPOLOGIQUE *topnd=nd->get_lien_topologie();
1498     if (topnd->get_dimension() <3 && nd->get_id()==bumpndid)
1499     {
1500     bptipnd=nd;
1501     double new_xyz[3];
1502     new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+bumptip;
1503     nd->change_coord(new_xyz);
1504     usednd.ajouter(nd);
1505     }
1506     }
1507     TPL_MAP_ENTITE<MG_NOEUD*> usedndnd;
1508     TPL_MAP_ENTITE<MG_NOEUD*> neignd;
1509     for(int ineignd=0;ineignd<bptipnd->get_lien_segment()->get_nb();ineignd++)
1510     {
1511     MG_SEGMENT* segnei=bptipnd->get_lien_segment()->get(ineignd);
1512     if(segnei->get_noeud1()!=bptipnd) neignd.ajouter(segnei->get_noeud1());
1513     else if(segnei->get_noeud2()!=bptipnd) neignd.ajouter(segnei->get_noeud2());
1514     }
1515     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd;
1516     for (MG_NOEUD* nd=neignd.get_premier(itneignd);nd!=NULL;nd=neignd.get_suivant(itneignd))
1517     {
1518     double new_xyz[3];
1519     new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*3./4.);
1520     nd->change_coord(new_xyz);
1521     usednd.ajouter(nd);
1522     usedndnd.ajouter(nd);
1523     }
1524    
1525     TPL_MAP_ENTITE<MG_NOEUD*> neignd1;
1526     TPL_MAP_ENTITE<MG_NOEUD*> usedndnd1;
1527     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusednd;
1528     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd;
1529     for(MG_NOEUD* nd=usedndnd.get_premier(itusedndnd);nd!=NULL;nd=usedndnd.get_suivant(itusedndnd))
1530     {
1531     for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
1532     {
1533     MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
1534     int sgnd1=0;
1535     int sgnd2=0;
1536     for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
1537     {
1538     if(segnei->get_noeud1()==nd1) sgnd1++;
1539     }
1540     for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
1541     {
1542     if(segnei->get_noeud2()==nd1) sgnd2++;
1543     }
1544     if(sgnd1==0) neignd1.ajouter(segnei->get_noeud1());
1545     else if(sgnd2==0) neignd1.ajouter(segnei->get_noeud2());
1546     }
1547     }
1548     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd1;
1549     for (MG_NOEUD* nd=neignd1.get_premier(itneignd1);nd!=NULL;nd=neignd1.get_suivant(itneignd1))
1550     {
1551     double new_xyz[3];
1552     new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*2./4.);
1553     nd->change_coord(new_xyz);
1554     usednd.ajouter(nd);
1555     usedndnd1.ajouter(nd);
1556     }
1557    
1558     TPL_MAP_ENTITE<MG_NOEUD*> neignd2;
1559     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itusedndnd1;
1560     for(MG_NOEUD* nd=usedndnd1.get_premier(itusedndnd1);nd!=NULL;nd=usedndnd1.get_suivant(itusedndnd1))
1561     {
1562     for(int ineignd=0;ineignd<nd->get_lien_segment()->get_nb();ineignd++)
1563     {
1564     MG_SEGMENT* segnei=nd->get_lien_segment()->get(ineignd);
1565     int sgnd1=0;
1566     int sgnd2=0;
1567     for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
1568     {
1569     if(segnei->get_noeud1()==nd1) sgnd1++;
1570     }
1571     for(MG_NOEUD* nd1=usednd.get_premier(itusednd);nd1!=NULL;nd1=usednd.get_suivant(itusednd))
1572     {
1573     if(segnei->get_noeud2()==nd1) sgnd2++;
1574     }
1575     if(sgnd1==0) neignd2.ajouter(segnei->get_noeud1());
1576     else if(sgnd2==0) neignd2.ajouter(segnei->get_noeud2());
1577     }
1578     }
1579     TPL_MAP_ENTITE<MG_NOEUD*>::ITERATEUR itneignd2;
1580     for (MG_NOEUD* nd=neignd2.get_premier(itneignd2);nd!=NULL;nd=neignd2.get_suivant(itneignd2))
1581     {
1582     double new_xyz[3];
1583     new_xyz[0]=nd->get_x(); new_xyz[1]=nd->get_y(); new_xyz[2]=nd->get_z()+(bumptip*1./4.);
1584     nd->change_coord(new_xyz);
1585     }
1586    
1587    
1588     //gest.enregistrer("scnsurf_smplwithpocket_3d_13mm_64mmdeform_withbump5mm.magic");
1589     gest.enregistrer(outputfilename);
1590     }
1591 sattarpa 596 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1592     int CRIAQOPERATORS::import_triangulation_gnif(char* outputfilename,char* triangulationfile)
1593     {
1594     FILE* in=fopen(triangulationfile,"rt");
1595     if (in==NULL) return 0;
1596 sattarpa 554
1597    
1598 sattarpa 596 MG_GESTIONNAIRE gesttmp;
1599     MG_MAILLAGE* mai=new MG_MAILLAGE(NULL);
1600     gesttmp.ajouter_mg_maillage(mai);
1601     char mess[500];
1602 sattarpa 554
1603 sattarpa 596 double xmax=-1e308;
1604     double xmin=1e308;
1605     double ymax=-1e308;
1606     double ymin=1e308;
1607     double zmax=-1e308;
1608     double zmin=1e308;
1609     while (!feof(in))
1610     {
1611     double x,y,z;
1612     char nom[20];
1613     char *res=fgets(mess,500,in);
1614     if (feof(in)) break;
1615     //cout<<"mes1= "<<mess<<endl;
1616     sscanf(mess,"%lf %lf %lf",&x,&y,&z);
1617     if (x<xmin) xmin=x;
1618     if (x>xmax) xmax=x;
1619     if (y<ymin) ymin=y;
1620     if (y>ymax) ymax=y;
1621     if (z<zmin) zmin=z;
1622     if (z>zmax) zmax=z;
1623     if (feof(in)) return 1;
1624     MG_NOEUD* noeud1=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
1625     noeud1->change_nouveau_numero(-1);
1626     res=fgets(mess,500,in);
1627     if (feof(in)) break;
1628     //cout<<"mes2= "<<mess<<endl;
1629     sscanf(mess,"%lf %lf %lf",&x,&y,&z);
1630     if (x<xmin) xmin=x;
1631     if (x>xmax) xmax=x;
1632     if (y<ymin) ymin=y;
1633     if (y>ymax) ymax=y;
1634     if (z<zmin) zmin=z;
1635     if (z>zmax) zmax=z;
1636     if (feof(in)) return 1;
1637     res=fgets(mess,500,in);
1638     if (feof(in)) break;
1639     //cout<<"mes3= "<<mess<<endl;
1640     MG_NOEUD* noeud2=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
1641     noeud2->change_nouveau_numero(-1);
1642     sscanf(mess,"%lf %lf %lf",&x,&y,&z);
1643     if (x<xmin) xmin=x;
1644     if (x>xmax) xmax=x;
1645     if (y<ymin) ymin=y;
1646     if (y>ymax) ymax=y;
1647     if (z<zmin) zmin=z;
1648     if (z>zmax) zmax=z;
1649     if (feof(in)) return 1;
1650     MG_NOEUD* noeud3=mai->ajouter_mg_noeud(NULL,x,y,z,TRIANGULATION);
1651     noeud3->change_nouveau_numero(-1);
1652     mai->ajouter_mg_triangle(NULL,noeud1,noeud2,noeud3,TRIANGULATION);
1653     //cout<<"feof(in)= "<<feof(in)<<endl;
1654     }
1655     fclose(in);
1656     //to merge the nodes of each triangulation which are close (the same)
1657     double eps=1e-4;
1658     BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
1659     double rayon=boite.get_rayon()*1.1;
1660     double x=boite.get_xcentre();
1661     double y=boite.get_ycentre();
1662     double z=boite.get_zcentre();
1663     boite.reinit(x-rayon,y-rayon,z-rayon,x+rayon,y+rayon,z+rayon);
1664     TPL_GRILLE<MG_NOEUD*> grille;
1665     int nb_noeud=mai->get_nb_mg_noeud();
1666     int pas=(int)(pow(nb_noeud,0.33333333333333333))+1;
1667     grille.initialiser(boite.get_xmin(),boite.get_ymin(),boite.get_zmin(),boite.get_xmax(),boite.get_ymax(),boite.get_zmax(),pas,pas,pas);
1668     std::vector<MG_NOEUD*> lst_noeud;
1669     LISTE_MG_NOEUD::iterator it;
1670     int i=0;
1671     for (MG_NOEUD* noeud=mai->get_premier_noeud(it);noeud!=NULL;noeud=mai->get_suivant_noeud(it))
1672     {
1673     //MG_NOEUD* noeud=mai->get_mg_noeud(i);
1674     grille.inserer(noeud);
1675     noeud->change_nouveau_numero(i);
1676     lst_noeud.insert(lst_noeud.end(),noeud);
1677     i++;
1678     }
1679 sattarpa 554
1680 sattarpa 596 int nb_cell=grille.get_nb_cellule();
1681     for (int i=0;i<nb_cell;i++)
1682     {
1683     TPL_CELLULE_GRILLE<MG_NOEUD*> *cell=grille.get_cellule(i);
1684     int nb_noeud_cell=cell->get_nb_entite();
1685     for (int j=0;j<nb_noeud_cell;j++)
1686     {
1687     MG_NOEUD* noeud1=cell->get_entite(j);
1688     // if (noeud1->get_nouveau_numero()!=(-1)) continue;
1689     // noeud1->change_nouveau_numero(noeud1->get_id());
1690     double *xyz1=noeud1->get_coord();
1691     int nb=noeud1->get_lien_segment()->get_nb();
1692     double longref=0.;
1693     for (int jj=0;jj<nb;jj++)
1694     longref=longref+noeud1->get_lien_segment()->get(jj)->get_longueur();
1695     longref=longref/nb;
1696     for (int k=j+1;k<nb_noeud_cell;k++)
1697     {
1698     MG_NOEUD* noeud2=cell->get_entite(k);
1699     double *xyz2=noeud2->get_coord();
1700     OT_VECTEUR_3D vec(xyz1,xyz2);
1701     double longueur=vec.get_longueur();
1702     if (longueur<eps*longref)
1703     {
1704     lst_noeud[noeud2->get_nouveau_numero()]=noeud1;
1705     }
1706     }
1707     }
1708     }
1709     MG_GESTIONNAIRE gest;
1710     MG_MAILLAGE* mai2=new MG_MAILLAGE(NULL);
1711     gest.ajouter_mg_maillage(mai2);
1712     for (int i=0;i<nb_noeud;i++)
1713     {
1714     MG_NOEUD* noeud=lst_noeud[i];
1715     MG_NOEUD* nvnoeud;
1716     if (noeud->get_nouveau_numero()==i) nvnoeud=mai2->ajouter_mg_noeud(NULL,noeud->get_x(),noeud->get_y(),noeud->get_z(),TRIANGULATION);
1717     else nvnoeud=lst_noeud[noeud->get_nouveau_numero()];
1718     lst_noeud[i]=nvnoeud;
1719     }
1720     int nb_tri=mai->get_nb_mg_triangle();
1721     for (int i=0;i<nb_tri;i++)
1722     {
1723     MG_TRIANGLE* tri=mai->get_mg_triangle(i);
1724     MG_NOEUD* noeud1=tri->get_noeud1();
1725     MG_NOEUD* noeud2=tri->get_noeud2();
1726     MG_NOEUD* noeud3=tri->get_noeud3();
1727     mai2->ajouter_mg_triangle(NULL,lst_noeud[noeud1->get_nouveau_numero()],lst_noeud[noeud2->get_nouveau_numero()],lst_noeud[noeud3->get_nouveau_numero()],TRIANGULATION);
1728     }
1729     gest.enregistrer(outputfilename);
1730     return 1;
1731     }
1732 sattarpa 554
1733    
1734    
1735    
1736    
1737    
1738    
1739    
1740    
1741    
1742    
1743    
1744    
1745    
1746    
1747    
1748    
1749    
1750    
1751    
1752    
1753    
1754    
1755 sattarpa 596
1756    
1757    
1758