ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/mgoperation/src/visuorigine.cpp
Revision: 1157
Committed: Thu Jun 13 22:18:27 2024 UTC (14 months, 2 weeks ago) by francois
File size: 10882 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

# User Rev Content
1 francois 1157 //####//------------------------------------------------------------
2     //####//------------------------------------------------------------
3     //####// MAGiC
4     //####// Jean Christophe Cuilliere et Vincent FRANCOIS
5     //####// Departement de Genie Mecanique - UQTR
6     //####//------------------------------------------------------------
7     //####// MAGIC est un projet de recherche de l equipe ERICCA
8     //####// du departement de genie mecanique de l Universite du Quebec a Trois Rivieres
9     //####// http://www.uqtr.ca/ericca
10     //####// http://www.uqtr.ca/
11     //####//------------------------------------------------------------
12     //####//------------------------------------------------------------
13     //####//
14     //####// visuorigine.cpp
15     //####//
16     //####//------------------------------------------------------------
17     //####//------------------------------------------------------------
18     //####// COPYRIGHT 2000-2024
19     //####// jeu 13 jun 2024 11:57:20 EDT
20     //####//------------------------------------------------------------
21     //####//------------------------------------------------------------
22 francois 792 #include "gestionversion.h"
23    
24     #include <iostream>
25 francois 1157 #include "vtkdisplay.hxx"
26     #include "ndata.hxx"
27 francois 792 #include "mg_file.h"
28     #include "occ_import.h"
29     #include <map>
30    
31     void affiche(char* message)
32     {
33     std::cout << message << std::endl;
34 francois 1061
35 francois 792 }
36    
37    
38    
39    
40     void affiche_structure(color cface,color carete,color ctext,color cdeplacement,color cforce,color cpression,color ctemperature, color cflux,MG_MAILLAGE* mai,data_container &data)
41     {
42 couturad 951 std::vector<color> tabcouleur;
43 francois 792 color one(191,253,181);
44     color two(255,160,0);
45     color three(253,35,16);
46     color four(255,200,0);
47     color five(0,216,255);
48     color six(0,52,255);
49     color seven(0,176,255);
50     color eight(228,255,0);
51     color nine(0,116,255);
52     color ten(188,255,0);
53     color eleven(184,0,255);
54     color twelve(255,120,0);
55     tabcouleur.push_back(one);
56     tabcouleur.push_back(two);
57     tabcouleur.push_back(three);
58     tabcouleur.push_back(four);
59     tabcouleur.push_back(five);
60     tabcouleur.push_back(six);
61     tabcouleur.push_back(seven);
62     tabcouleur.push_back(eight);
63     tabcouleur.push_back(nine);
64     tabcouleur.push_back(ten);
65     tabcouleur.push_back(eleven);
66     tabcouleur.push_back(twelve);
67    
68    
69     properties ptr=data.getproptriangles();
70     ptr.c=cface;
71     ptr.edgeon=true;
72     ptr.edgecolor=carete;
73     ptr.edgethickness=1;
74     data.setproptriangles(ptr);
75     LISTE_MG_TRIANGLE::iterator ittri;
76     for (MG_TRIANGLE* tri=mai->get_premier_triangle(ittri);tri!=NULL;tri=mai->get_suivant_triangle(ittri))
77     {
78     properties ptr=data.getproptriangles();
79    
80     ptr.c=tabcouleur[(tri->get_origine()-1000)/10];
81     data.setproptriangles(ptr);
82     double *xyz1=tri->get_noeud1()->get_coord();
83     double *xyz2=tri->get_noeud2()->get_coord();
84     double *xyz3=tri->get_noeud3()->get_coord();
85     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
86     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
87     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
88     triangle tr;
89     tr.pts[0]=p1;
90     tr.pts[1]=p2;
91     tr.pts[2]=p3;
92     data.add_triangle(tr);
93     OT_VECTEUR_3D vec1(xyz1,xyz2);
94     OT_VECTEUR_3D vec2(xyz1,xyz3);
95     OT_VECTEUR_3D sur=vec1&vec2;
96     double xg=0.,yg=0.,zg=0.,deno=0.;
97     xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur();
98     yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur();
99     zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur();
100     deno=deno+sur.get_longueur();
101     xg=xg/deno;
102     yg=yg/deno;
103     zg=zg/deno;
104     npoint p(xg,yg,zg);
105     point pp;
106     pp.pts=p;
107     char mess[255];
108     sprintf(mess,"%lu",tri->get_id());
109     pp.info=mess;
110     std::pair<point,color> tmp(pp,ctext);
111     //data.add_text(2,tmp);
112     }
113    
114     ptr=data.getpropquads();
115     ptr.c=cface;
116     ptr.edgeon=true;
117     ptr.edgecolor=carete;
118     ptr.edgethickness=1;
119     data.setpropquads(ptr);
120     LISTE_MG_QUADRANGLE::iterator itqua;
121     for (MG_QUADRANGLE* qua=mai->get_premier_quadrangle(itqua);qua!=NULL;qua=mai->get_suivant_quadrangle(itqua))
122     {
123     properties ptr=data.getpropquads();
124    
125     ptr.c=tabcouleur[(qua->get_origine()-1000)/10];
126     data.setpropquads(ptr);
127     double *xyz1=qua->get_noeud1()->get_coord();
128     double *xyz2=qua->get_noeud2()->get_coord();
129     double *xyz3=qua->get_noeud3()->get_coord();
130     double *xyz4=qua->get_noeud4()->get_coord();
131     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
132     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
133     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
134     npoint p4(xyz4[0],xyz4[1],xyz4[2]);
135     quad qu;
136     qu.pts[0]=p1;
137     qu.pts[1]=p2;
138     qu.pts[2]=p3;
139     qu.pts[3]=p4;
140     data.add_quad(qu);
141     OT_VECTEUR_3D vec1(xyz1,xyz2);
142     OT_VECTEUR_3D vec2(xyz1,xyz3);
143     OT_VECTEUR_3D sur=vec1&vec2;
144     double xg=0.,yg=0.,zg=0.,deno=0.;
145     xg=xg+0.25*(xyz1[0]+xyz2[0]+xyz3[0]+xyz4[0])*sur.get_longueur();
146     yg=yg+0.25*(xyz1[1]+xyz2[1]+xyz3[1]+xyz4[1])*sur.get_longueur();
147     zg=zg+0.25*(xyz1[2]+xyz2[2]+xyz3[2]+xyz4[2])*sur.get_longueur();
148     deno=deno+sur.get_longueur();
149     xg=xg/deno;
150     yg=yg/deno;
151     zg=zg/deno;
152     npoint p(xg,yg,zg);
153     point pp;
154     pp.pts=p;
155     char mess[255];
156     sprintf(mess,"%lu",qua->get_id());
157     pp.info=mess;
158     std::pair<point,color> tmp(pp,ctext);
159     //data.add_text(2,tmp);
160     }
161    
162     ptr=data.getproplines();
163     ptr.c=carete;
164     ptr.edgethickness=2;
165     data.setproplines(ptr);
166     LISTE_MG_SEGMENT::iterator itseg;
167     for (MG_SEGMENT* seg=mai->get_premier_segment(itseg);seg!=NULL;seg=mai->get_suivant_segment(itseg))
168     {
169     if (seg->get_lien_topologie()!=NULL)
170     if (seg->get_lien_topologie()->get_dimension()!=1) continue;
171     properties ptr=data.getproplines();
172     ptr.c=tabcouleur[(seg->get_origine()-1000)/10];
173     data.setproplines(ptr);
174     double *xyz1=seg->get_noeud1()->get_coord();
175     double *xyz2=seg->get_noeud2()->get_coord();
176     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
177     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
178     line li;
179     li.pts[0]=p1;
180     li.pts[1]=p2;
181     data.add_line(li);
182     OT_VECTEUR_3D vec1(xyz1,xyz2);
183     double xg=0.,yg=0.,zg=0.,deno=0.;
184     xg=xg+0.5*(xyz1[0]+xyz2[0])*vec1.get_longueur();
185     yg=yg+0.5*(xyz1[1]+xyz2[1])*vec1.get_longueur();
186     zg=zg+0.5*(xyz1[2]+xyz2[2])*vec1.get_longueur();
187     deno=deno+vec1.get_longueur();
188     xg=xg/deno;
189     yg=yg/deno;
190     zg=zg/deno;
191     npoint p(xg,yg,zg);
192     point pp;
193     pp.pts=p;
194     char mess[255];
195     sprintf(mess,"%lu",seg->get_id());
196     pp.info=mess;
197     std::pair<point,color> tmp(pp,ctext);
198     //data.add_text(1,tmp);
199     }
200    
201    
202    
203     ptr=data.getproppoints();
204     ptr.pointsize=10;
205     data.setproppoints(ptr);
206     LISTE_MG_NOEUD::iterator itno;
207     for (MG_NOEUD* no=mai->get_premier_noeud(itno);no!=NULL;no=mai->get_suivant_noeud(itno))
208     {
209     properties ptr=data.getproppoints();
210     ptr.c=tabcouleur[(no->get_origine()-1000)/10];
211     data.setproppoints(ptr);
212     double *xyz=no->get_coord();
213     npoint p1(xyz[0],xyz[1],xyz[2]);
214     data.add_point(p1);
215     char mess[255];
216     sprintf(mess,"%lu",no->get_id());
217     point pp;
218     pp.pts=p1;
219     pp.info=mess;
220     std::pair<point,color> tmp(pp,ctext);
221     //data.add_text(0,tmp);
222     }
223    
224     };
225    
226    
227    
228    
229    
230    
231    
232 francois 1061
233 francois 792 int main(int argc,char **argv)
234 francois 1061
235 francois 792 {
236     color base=color(0,0,0);
237     color carete(255,255,255);
238     color cface(125,125,125);
239     color ctext(255,255,255);
240     color cdeplacement(255,151,1);
241     color cforce(255,1,1);
242     color cpression(33,249,13);
243     color ctemperature(246,07,193);
244     color cflux(252,250,03);
245    
246     char chemin[1000];
247     sprintf(chemin,"%s/.vtkdisplay",getenv("HOME"));
248     FILE *in=fopen(chemin,"rt");
249     if (in!=NULL)
250     {
251     char mess[255];
252     fgets(mess,255,in);
253     int R,G,B;
254     int nb=sscanf(mess,"%d %d %d",&R,&G,&B);
255     if (nb==3) base=color(R,G,B);
256     if (!feof(in))
257     {
258     fgets(mess,255,in);
259     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
260     if (nb==3) cface=color(R,G,B);
261     if (!feof(in))
262     {
263     fgets(mess,255,in);
264     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
265     if (nb==3) carete=color(R,G,B);
266     if (!feof(in))
267     {
268     fgets(mess,255,in);
269     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
270     if (nb==3) ctext=color(R,G,B);
271     if (!feof(in))
272     {
273     fgets(mess,255,in);
274     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
275     if (nb==3) cdeplacement=color(R,G,B);
276     if (!feof(in))
277     {
278     fgets(mess,255,in);
279     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
280     if (nb==3) cforce=color(R,G,B);
281     if (!feof(in))
282     {
283     fgets(mess,255,in);
284     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
285     if (nb==3) cpression=color(R,G,B);
286     if (!feof(in))
287     {
288     fgets(mess,255,in);
289     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
290     if (nb==3) ctemperature=color(R,G,B);
291     if (!feof(in))
292     {
293     fgets(mess,255,in);
294     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
295     if (nb==3) cflux=color(R,G,B);
296    
297     }
298     }
299    
300     }
301    
302     }
303     }
304     }
305     }
306     }
307     fclose(in);
308     }
309     printf("******************************\n");
310     printf("* Origine Visualization *\n");
311     printf("* by *\n");
312     printf("* Jean-Christophe Cuillière *\n");
313     printf("* and *\n");
314     printf("* Vincent Francois *\n");
315     printf("* ERICCA-UQTR *\n");
316     printf("******************************\n\n\n");
317    
318    
319    
320     if (!((argc==2) || (argc==3)))
321     {
322 francois 1061 printf("Visumagic syntax error - Bad number arguments\n visuorigine.exe fichier [numero du maillage]\n\n");
323 francois 792 return 0;
324    
325     }
326     char fichier[255];
327     strcpy(fichier,argv[1]);
328    
329     char *p=strchr(fichier,'.');
330     char extension[255];
331     strcpy(extension,p+1);
332    
333     MG_GESTIONNAIRE *gest;
334     MG_FILE* gest2=new MG_FILE(fichier);
335     gest=gest2;
336    
337    
338     int num=0;
339     if (argc==3) num=atoi(argv[2]);
340     data_container data;
341     MG_MAILLAGE* mai=gest->get_mg_maillage(num);
342     char titre [500];
343     printf("\n\n");
344     printf("Command on keyboard : \n");
345     printf(" e : End of vizualisation\n");
346     printf(" r : Reset Camera\n");
347     printf(" 1 : Vertex Numbers visible on/off\n");
348     printf(" 4 : Edge Numbers visible on/off\n");
349     printf(" 7 : Face Numbers visible on/off\n");
350     printf(" v : Vertices visible on/off\n");
351     printf(" l : Edges visible on/off\n");
352     printf(" t : Faces visible on/off\n");
353     printf(" j : Save camera on current directory\n");
354     printf(" k : Load camera from current directory\n");
355     printf(" w : Wireframe\n");
356     printf(" s : Modelframe\n");
357     printf(" - : Decrease text size\n");
358     printf(" + : Increase text size\n");
359 francois 1116 printf(" 5 : Clipping plane off\n");
360     printf(" 8 : Clipping plane forward\n");
361     printf(" 9 : Clipping plane backward\n");
362 francois 792
363     strcpy(titre,"Visuorimagic ");
364     strcat(titre,fichier);
365     if (mai!=NULL) affiche_structure(cface,carete,ctext,cdeplacement,cforce,cpression,ctemperature,cflux,mai,data);
366     delete gest;
367    
368 francois 1061 vtkdisplay d(base,titre);
369 francois 792
370    
371    
372    
373     d.init_data(data);
374 francois 1018 d.display();
375 francois 792
376    
377     return 0;
378     }
379    
380    
381    
382 francois 1061