ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/mgoperation/src/visumagic.cpp
Revision: 576
Committed: Wed Oct 22 18:13:01 2014 UTC (10 years, 7 months ago) by francois
File size: 14434 byte(s)
Log Message:
ajout d'une geometrie virtuelle dans le maillage structure pour pouvoir saisir des conditions aux limites. ajout de conditions aux limites pour le thermique

File Contents

# User Rev Content
1 francois 353 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuilli�e et Vincent FRANCOIS
5     // D�artement de G�ie M�anique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du d�artement
8     // de g�ie m�anique de l'Universit�du Qu�ec �
9     // Trois Rivi�es
10     // Les librairies ne peuvent �re utilis�s sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // main.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 �11H25
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23     #include "gestionversion.h"
24     #ifdef WINDOWS_VERSION
25     #include "fenetre.h"
26     #endif
27    
28     #pragma hdrstop
29     #include <iostream>
30     #include "vtkdisplay.h"
31     #include "nutil.h"
32     #include "mg_file.h"
33 francois 356 #include "occ_import.h"
34 francois 353 #include <map>
35     //---------------------------------------------------------------------------
36    
37     void affiche(char* message)
38     {
39     #ifdef WINDOWS_VERSION
40     Form1->Memo1->Lines->Add(message);
41     #else
42     std::cout << message << std::endl;
43     #endif
44     }
45    
46    
47    
48    
49 francois 358 void affiche_structure(color cface,color carete,color ctext,MG_GEOMETRIE* geo,MG_MAILLAGE* mai,data_container &data,bool idori)
50 francois 353 {
51     properties ptr=data.getproptriangles();
52     ptr.c=cface;
53     ptr.edgeon=false;
54     data.setproptriangles(ptr);
55 francois 576 ptr=data.getpropquads();
56     ptr.c=cface;
57     ptr.edgeon=false;
58     data.setpropquads(ptr);
59    
60 francois 353 LISTE_MG_FACE::iterator itf;
61     for (MG_FACE* face=geo->get_premier_face(itf);face!=NULL;face=geo->get_suivant_face(itf))
62     {
63     double xg=0.,yg=0.,zg=0.,deno=0.;
64     int nbtri=face->get_lien_maillage()->get_nb();
65     for (int i=0;i<nbtri;i++)
66     {
67 francois 576 MG_ELEMENT_MAILLAGE* ele=face->get_lien_maillage()->get(i);
68     if (ele->get_type_entite()==IDMG_TRIANGLE)
69     {
70     MG_TRIANGLE* tri=(MG_TRIANGLE*)ele;
71     if (mai->get_mg_triangleid(tri->get_id())!=tri) continue;
72     double *xyz1=tri->get_noeud1()->get_coord();
73     double *xyz2=tri->get_noeud2()->get_coord();
74     double *xyz3=tri->get_noeud3()->get_coord();
75     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
76     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
77     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
78     triangle tr;
79     tr.pts[0]=p1;
80     tr.pts[1]=p2;
81     tr.pts[2]=p3;
82     data.add_triangle(tr);
83     OT_VECTEUR_3D vec1(xyz1,xyz2);
84     OT_VECTEUR_3D vec2(xyz1,xyz3);
85     OT_VECTEUR_3D sur=vec1&vec2;
86     xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur();
87     yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur();
88     zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur();
89     deno=deno+sur.get_longueur();
90     }
91     if (ele->get_type_entite()==IDMG_QUADRANGLE)
92     {
93     MG_QUADRANGLE* qua=(MG_QUADRANGLE*)ele;
94     if (mai->get_mg_quadrangleid(qua->get_id())!=qua) continue;
95     double *xyz1=qua->get_noeud1()->get_coord();
96     double *xyz2=qua->get_noeud2()->get_coord();
97     double *xyz3=qua->get_noeud3()->get_coord();
98     double *xyz4=qua->get_noeud4()->get_coord();
99     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
100     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
101     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
102     npoint p4(xyz4[0],xyz4[1],xyz4[2]);
103     quad qd;
104     qd.pts[0]=p1;
105     qd.pts[1]=p2;
106     qd.pts[2]=p3;
107     qd.pts[3]=p4;
108     data.add_quad(qd);
109     OT_VECTEUR_3D vec1(xyz1,xyz2);
110     OT_VECTEUR_3D vec2(xyz1,xyz3);
111     OT_VECTEUR_3D vec3(xyz1,xyz4);
112     OT_VECTEUR_3D sur=vec1&vec2;
113     OT_VECTEUR_3D sur2=vec2&vec3;
114     xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur();
115     yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur();
116     zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur();
117     xg=xg+0.3333333333*(xyz1[0]+xyz4[0]+xyz3[0])*sur2.get_longueur();
118     yg=yg+0.3333333333*(xyz1[1]+xyz4[1]+xyz3[1])*sur2.get_longueur();
119     zg=zg+0.3333333333*(xyz1[2]+xyz4[2]+xyz3[2])*sur2.get_longueur();
120     deno=deno+sur.get_longueur()+sur2.get_longueur();
121     }
122 francois 353 }
123     xg=xg/deno;
124     yg=yg/deno;
125     zg=zg/deno;
126 francois 576 std::map<double,MG_ELEMENT_MAILLAGE*> classe;
127 francois 353 for (int i=0;i<nbtri;i++)
128     {
129 francois 576 MG_ELEMENT_MAILLAGE* ele=face->get_lien_maillage()->get(i);
130     if (ele->get_type_entite()==IDMG_TRIANGLE)
131     {
132     MG_TRIANGLE* tri=(MG_TRIANGLE*)ele;
133     if (mai->get_mg_triangleid(tri->get_id())!=tri) continue;
134     double *xyz1=tri->get_noeud1()->get_coord();
135     double *xyz2=tri->get_noeud2()->get_coord();
136     double *xyz3=tri->get_noeud3()->get_coord();
137     double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]);
138     double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]);
139     double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]);
140     OT_VECTEUR_3D vec(x-xg,y-yg,z-zg);
141     classe.insert(std::pair<double,MG_ELEMENT_MAILLAGE*>(vec.get_longueur2(),tri));
142     }
143     if (ele->get_type_entite()==IDMG_QUADRANGLE)
144     {
145     MG_QUADRANGLE* qua=(MG_QUADRANGLE*)ele;
146     if (mai->get_mg_quadrangleid(qua->get_id())!=qua) continue;
147     double *xyz1=qua->get_noeud1()->get_coord();
148     double *xyz2=qua->get_noeud2()->get_coord();
149     double *xyz3=qua->get_noeud3()->get_coord();
150     double *xyz4=qua->get_noeud4()->get_coord();
151     double x=0.25*(xyz1[0]+xyz2[0]+xyz3[0]+xyz4[0]);
152     double y=0.25*(xyz1[1]+xyz2[1]+xyz3[1]+xyz4[1]);
153     double z=0.25*(xyz1[2]+xyz2[2]+xyz3[2]+xyz4[2]);
154     OT_VECTEUR_3D vec(x-xg,y-yg,z-zg);
155     classe.insert(std::pair<double,MG_ELEMENT_MAILLAGE*>(vec.get_longueur2(),qua));
156     }
157     }
158     if (classe.size()>0)
159     {
160     MG_ELEMENT_MAILLAGE *ele=classe.begin()->second;
161     if (ele->get_type_entite()==IDMG_TRIANGLE)
162     {
163     MG_TRIANGLE *tri=(MG_TRIANGLE*)ele;
164 francois 353 double *xyz1=tri->get_noeud1()->get_coord();
165     double *xyz2=tri->get_noeud2()->get_coord();
166     double *xyz3=tri->get_noeud3()->get_coord();
167 francois 576 npoint p(0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]),0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]),0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]));
168     point pp;
169     pp.pts=p;
170     char mess[255];
171     if (idori==false) sprintf(mess,"F%lu",face->get_id()); else sprintf(mess,"%s",face->get_idoriginal().c_str());
172     pp.info=mess;
173     std::pair<point,color> tmp(pp,ctext);
174     data.add_text(2,tmp);
175 francois 353 }
176 francois 576 if (ele->get_type_entite()==IDMG_QUADRANGLE)
177     {
178     MG_QUADRANGLE *qua=(MG_QUADRANGLE*)ele;
179     double *xyz1=qua->get_noeud1()->get_coord();
180     double *xyz2=qua->get_noeud2()->get_coord();
181     double *xyz3=qua->get_noeud3()->get_coord();
182     double *xyz4=qua->get_noeud4()->get_coord();
183     npoint p(0.25*(xyz1[0]+xyz2[0]+xyz3[0]+xyz4[0]),0.25*(xyz1[1]+xyz2[1]+xyz3[1]+xyz4[1]),0.25*(xyz1[2]+xyz2[2]+xyz3[2]+xyz4[2]));
184     point pp;
185     pp.pts=p;
186     char mess[255];
187     if (idori==false) sprintf(mess,"F%lu",face->get_id()); else sprintf(mess,"%s",face->get_idoriginal().c_str());
188     pp.info=mess;
189     std::pair<point,color> tmp(pp,ctext);
190     data.add_text(2,tmp);
191     }
192 francois 356 }
193 francois 353 }
194    
195     ptr=data.getproplines();
196     ptr.c=carete;
197     ptr.thickness=2;
198     data.setproplines(ptr);
199    
200     LISTE_MG_ARETE::iterator ita;
201     for (MG_ARETE* are=geo->get_premier_arete(ita);are!=NULL;are=geo->get_suivant_arete(ita))
202     {
203     int nbseg=are->get_lien_maillage()->get_nb();
204     double xg=0.,yg=0.,zg=0.,deno=0.;
205     for (int i=0;i<nbseg;i++)
206     {
207     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
208 francois 358 if (mai->get_mg_segmentid(seg->get_id())!=seg) continue;
209 francois 353 double *xyz1=seg->get_noeud1()->get_coord();
210     double *xyz2=seg->get_noeud2()->get_coord();
211     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
212     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
213     line li;
214     li.pts[0]=p1;
215     li.pts[1]=p2;
216     data.add_line(li);
217     OT_VECTEUR_3D vec(xyz1,xyz2);
218     xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur();
219     yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur();
220     zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur();
221     deno=deno+vec.get_longueur();
222     }
223     xg=xg/deno;
224     yg=yg/deno;
225     zg=zg/deno;
226     std::map<double,MG_SEGMENT*> classeseg;
227     for (int i=0;i<nbseg;i++)
228     {
229     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
230 francois 358 if (mai->get_mg_segmentid(seg->get_id())!=seg) continue;
231 francois 353 double *xyz1=seg->get_noeud1()->get_coord();
232     double *xyz2=seg->get_noeud2()->get_coord();
233     double x=0.5*(xyz1[0]+xyz2[0]);
234     double y=0.5*(xyz1[1]+xyz2[1]);
235     double z=0.5*(xyz1[2]+xyz2[2]);
236     OT_VECTEUR_3D vec(x-xg,y-yg,z-zg);
237     classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg));
238     }
239 francois 358 if (classeseg.size()>0)
240 francois 356 {
241     MG_SEGMENT* seg=classeseg.begin()->second;
242     double *xyz1=seg->get_noeud1()->get_coord();
243     double *xyz2=seg->get_noeud2()->get_coord();
244     npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2]));
245     point pp;
246     pp.pts=p;
247     char mess[255];
248     if (idori==false) sprintf(mess,"E%lu",are->get_id()); else sprintf(mess,"%s",are->get_idoriginal().c_str());
249     pp.info=mess;
250     std::pair<point,color> tmp(pp,ctext);
251     data.add_text(1,tmp);
252     }
253 francois 353 }
254    
255    
256     ptr=data.getproppoints();
257     ptr.c=carete;
258 francois 358 ptr.pointsize=10;
259 francois 353 data.setproppoints(ptr);
260     LISTE_MG_SOMMET::iterator its;
261     for (MG_SOMMET* som=geo->get_premier_sommet(its);som!=NULL;som=geo->get_suivant_sommet(its))
262     {
263     int nbpoint=som->get_lien_maillage()->get_nb();
264     for (int i=0;i<nbpoint;i++)
265     {
266     MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i);
267 francois 358 if (mai->get_mg_noeudid(nd->get_id())!=nd) continue;
268 francois 353 double *xyz1=nd->get_coord();
269     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
270     data.add_point(p1);
271     point pp;
272     pp.pts=p1;
273     char mess[255];
274 francois 356 if (idori==false) sprintf(mess,"V%lu",som->get_id()); else sprintf(mess,"%s",som->get_idoriginal().c_str());
275 francois 353 pp.info=mess;
276     std::pair<point,color> tmp(pp,ctext);
277     data.add_text(0,tmp);
278     }
279     }
280    
281    
282    
283    
284     };
285    
286    
287    
288    
289    
290    
291    
292     #ifdef WINDOWS_VERSION
293     int amain(int argc,char **argv)
294     #else
295     int main(int argc,char **argv)
296     #endif
297     {
298     color base=color(0,0,0);
299     color carete(255,255,255);
300     color cface(125,125,125);
301     color ctext(255,255,255);
302     char chemin[1000];
303     sprintf(chemin,"%s/.vtkdisplay",getenv("HOME"));
304     FILE *in=fopen(chemin,"rt");
305     if (in!=NULL)
306     {
307     char mess[255];
308     fgets(mess,255,in);
309     int R,G,B;
310     int nb=sscanf(mess,"%d %d %d",&R,&G,&B);
311     if (nb==3) base=color(R,G,B);
312     if (!feof(in))
313     {
314     fgets(mess,255,in);
315     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
316     if (nb==3) cface=color(R,G,B);
317     if (!feof(in))
318     {
319     fgets(mess,255,in);
320     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
321     if (nb==3) carete=color(R,G,B);
322     if (!feof(in))
323     {
324     fgets(mess,255,in);
325     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
326     if (nb==3) ctext=color(R,G,B);
327     }
328     }
329     }
330     fclose(in);
331     }
332     printf("******************************\n");
333     printf("* Visualization *\n");
334     printf("* by *\n");
335     printf("* Jean-Christophe Cuillière *\n");
336     printf("* and *\n");
337     printf("* Vincent Francois *\n");
338     printf("* ERICCA-UQTR *\n");
339     printf("******************************\n\n\n");
340    
341 francois 356
342    
343 cuillier 354 if (!((argc==2) || (argc==3)))
344 francois 353 {
345     printf("Visumagic syntax error - Bad number arguments\n\n");
346     return 0;
347    
348     }
349 francois 356 char fichier[255];
350     strcpy(fichier,argv[1]);
351    
352     char *p=strchr(fichier,'.');
353     char extension[255];
354     strcpy(extension,p+1);
355    
356     bool idori;
357     MG_GESTIONNAIRE *gest;
358     if ((strcmp(extension,"step")==0) || (strcmp(extension,"stp")==0) || (strcmp(extension,"STP")==0) || (strcmp(extension,"STEP")==0))
359     {
360     MG_GESTIONNAIRE *gest2=new MG_GESTIONNAIRE;
361     OCC_IMPORT occimport;
362     MG_GEOMETRIE* mggeo=occimport.importer(*gest2,fichier,FICHIERSTEP,0.001,1e-6) ;
363     occimport.importer(*gest2,mggeo,1,2);
364     gest=gest2;
365 francois 358 idori=false;
366     if (strcmp(argv[argc-1],"-s")==0)
367     {
368     *(p+1)='m';
369     *(p+2)='a';
370     *(p+3)='g';
371     *(p+4)='i';
372     *(p+5)='c';
373     *(p+6)=0;
374     gest->enregistrer(fichier);
375     }
376 francois 356 }
377     else
378     {
379     MG_FILE* gest2=new MG_FILE(fichier);
380     gest=gest2;
381     idori=false;
382     }
383 francois 358
384 francois 353
385     int num=0;
386     if (argc==3) num=atoi(argv[2]);
387     MG_GEOMETRIE* geo=gest->get_mg_geometrie(num);
388     data_container data;
389 francois 358 MG_MAILLAGE* mai=NULL;
390     int nbmai=gest->get_nb_mg_maillage();
391     bool sommet=false,arete=false,face=false;
392     for (int i=0;i<nbmai;i++)
393     {
394     bool sommettmp=false,aretetmp=false,facetmp=false;
395     MG_MAILLAGE* maitmp=gest->get_mg_maillage(i);
396     if (maitmp->get_nb_mg_noeud()>0) sommettmp=true;
397     if (maitmp->get_nb_mg_segment()>0) aretetmp=true;
398     if (maitmp->get_nb_mg_triangle()>0) facetmp=true;
399     int nbtruetmp=0,nbtrue=0;
400     if (sommet==true) nbtrue++;
401     if (arete==true) nbtrue++;
402     if (face==true) nbtrue++;
403     if (sommettmp==true) nbtruetmp++;
404     if (aretetmp==true) nbtruetmp++;
405     if (facetmp==true) nbtruetmp++;
406     if (nbtruetmp>nbtrue)
407     {
408     mai=maitmp;
409     sommet=sommettmp;
410     arete=aretetmp;
411     face=facetmp;
412     }
413     }
414 francois 353 printf("\n\n");
415     printf("Command on keyboard : \n");
416     printf(" e : End of vizualisation\n");
417     printf(" r : Reset Camera\n");
418     printf(" 1 : Vertex Numbers visible on/off\n");
419     printf(" 4 : Edge Numbers visible on/off\n");
420     printf(" 7 : Face Numbers visible on/off\n");
421     printf(" v : Vertices visible on/off\n");
422     printf(" l : Edges visible on/off\n");
423     printf(" t : Faces visible on/off\n");
424     printf(" j : Save camera on current directory\n");
425     printf(" k : Load camera from current directory\n");
426     printf(" w : Wireframe\n");
427     printf(" s : Modelframe\n");
428 francois 358 printf(" - : Decrease text size\n");
429     printf(" + : Increase text size\n");
430 francois 353
431 francois 356 char titre [500];
432 francois 353 strcpy(titre,"Visumagic ");
433 francois 356 strcat(titre,fichier);
434 francois 358 if (mai!=NULL) affiche_structure(cface,carete,ctext,geo,mai,data,idori);
435 francois 356 delete gest;
436 francois 353
437     vtkdisplay d(base,titre);
438    
439    
440    
441    
442     d.init_data(data);
443     d.display(true);
444    
445 francois 356
446 francois 353 return 0;
447     }
448    
449    
450    
451     #pragma package(smart_init)