ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/mgoperation/src/visumagic.cpp
Revision: 356
Committed: Fri Aug 10 15:07:05 2012 UTC (12 years, 10 months ago) by francois
File size: 9880 byte(s)
Log Message:
Visualisation des fichiser step + correctiom bug visualisation lorsque des mailles manquent

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 356 void affiche_structure(color cface,color carete,color ctext,MG_GEOMETRIE* geo,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     LISTE_MG_FACE::iterator itf;
56     for (MG_FACE* face=geo->get_premier_face(itf);face!=NULL;face=geo->get_suivant_face(itf))
57     {
58     double xg=0.,yg=0.,zg=0.,deno=0.;
59     int nbtri=face->get_lien_maillage()->get_nb();
60     for (int i=0;i<nbtri;i++)
61     {
62     MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i);
63     double *xyz1=tri->get_noeud1()->get_coord();
64     double *xyz2=tri->get_noeud2()->get_coord();
65     double *xyz3=tri->get_noeud3()->get_coord();
66     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
67     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
68     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
69     triangle tr;
70     tr.pts[0]=p1;
71     tr.pts[1]=p2;
72     tr.pts[2]=p3;
73     data.add_triangle(tr);
74     OT_VECTEUR_3D vec1(xyz1,xyz2);
75     OT_VECTEUR_3D vec2(xyz1,xyz3);
76     OT_VECTEUR_3D sur=vec1&vec2;
77     xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur();
78     yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur();
79     zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur();
80     deno=deno+sur.get_longueur();
81     }
82     xg=xg/deno;
83     yg=yg/deno;
84     zg=zg/deno;
85     std::map<double,MG_TRIANGLE*> classetri;
86     for (int i=0;i<nbtri;i++)
87     {
88     MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i);
89     double *xyz1=tri->get_noeud1()->get_coord();
90     double *xyz2=tri->get_noeud2()->get_coord();
91     double *xyz3=tri->get_noeud3()->get_coord();
92     double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]);
93     double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]);
94     double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]);
95     OT_VECTEUR_3D vec(x-xg,y-yg,z-zg);
96     classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri));
97     }
98 francois 356 if (nbtri>0)
99     {
100     MG_TRIANGLE *tri=classetri.begin()->second;
101     double *xyz1=tri->get_noeud1()->get_coord();
102     double *xyz2=tri->get_noeud2()->get_coord();
103     double *xyz3=tri->get_noeud3()->get_coord();
104     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]));
105     point pp;
106     pp.pts=p;
107     char mess[255];
108     if (idori==false) sprintf(mess,"F%lu",face->get_id()); else sprintf(mess,"%s",face->get_idoriginal().c_str());
109     pp.info=mess;
110     std::pair<point,color> tmp(pp,ctext);
111     data.add_text(2,tmp);
112     }
113 francois 353 }
114    
115     ptr=data.getproplines();
116     ptr.c=carete;
117     ptr.thickness=2;
118     data.setproplines(ptr);
119    
120     LISTE_MG_ARETE::iterator ita;
121     for (MG_ARETE* are=geo->get_premier_arete(ita);are!=NULL;are=geo->get_suivant_arete(ita))
122     {
123     int nbseg=are->get_lien_maillage()->get_nb();
124     double xg=0.,yg=0.,zg=0.,deno=0.;
125     for (int i=0;i<nbseg;i++)
126     {
127     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
128     double *xyz1=seg->get_noeud1()->get_coord();
129     double *xyz2=seg->get_noeud2()->get_coord();
130     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
131     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
132     line li;
133     li.pts[0]=p1;
134     li.pts[1]=p2;
135     data.add_line(li);
136     OT_VECTEUR_3D vec(xyz1,xyz2);
137     xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur();
138     yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur();
139     zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur();
140     deno=deno+vec.get_longueur();
141     }
142     xg=xg/deno;
143     yg=yg/deno;
144     zg=zg/deno;
145     std::map<double,MG_SEGMENT*> classeseg;
146     for (int i=0;i<nbseg;i++)
147     {
148     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
149     double *xyz1=seg->get_noeud1()->get_coord();
150     double *xyz2=seg->get_noeud2()->get_coord();
151     double x=0.5*(xyz1[0]+xyz2[0]);
152     double y=0.5*(xyz1[1]+xyz2[1]);
153     double z=0.5*(xyz1[2]+xyz2[2]);
154     OT_VECTEUR_3D vec(x-xg,y-yg,z-zg);
155     classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg));
156     }
157 francois 356 if (nbseg>0)
158     {
159     MG_SEGMENT* seg=classeseg.begin()->second;
160     double *xyz1=seg->get_noeud1()->get_coord();
161     double *xyz2=seg->get_noeud2()->get_coord();
162     npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2]));
163     point pp;
164     pp.pts=p;
165     char mess[255];
166     if (idori==false) sprintf(mess,"E%lu",are->get_id()); else sprintf(mess,"%s",are->get_idoriginal().c_str());
167     pp.info=mess;
168     std::pair<point,color> tmp(pp,ctext);
169     data.add_text(1,tmp);
170     }
171 francois 353 }
172    
173    
174     ptr=data.getproppoints();
175     ptr.c=carete;
176     ptr.pointsize=15;
177     data.setproppoints(ptr);
178     LISTE_MG_SOMMET::iterator its;
179     for (MG_SOMMET* som=geo->get_premier_sommet(its);som!=NULL;som=geo->get_suivant_sommet(its))
180     {
181     int nbpoint=som->get_lien_maillage()->get_nb();
182     for (int i=0;i<nbpoint;i++)
183     {
184     MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i);
185     double *xyz1=nd->get_coord();
186     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
187     data.add_point(p1);
188     point pp;
189     pp.pts=p1;
190     char mess[255];
191 francois 356 if (idori==false) sprintf(mess,"V%lu",som->get_id()); else sprintf(mess,"%s",som->get_idoriginal().c_str());
192 francois 353 pp.info=mess;
193     std::pair<point,color> tmp(pp,ctext);
194     data.add_text(0,tmp);
195     }
196     }
197    
198    
199    
200    
201     };
202    
203    
204    
205    
206    
207    
208    
209     #ifdef WINDOWS_VERSION
210     int amain(int argc,char **argv)
211     #else
212     int main(int argc,char **argv)
213     #endif
214     {
215     color base=color(0,0,0);
216     color carete(255,255,255);
217     color cface(125,125,125);
218     color ctext(255,255,255);
219     char chemin[1000];
220     sprintf(chemin,"%s/.vtkdisplay",getenv("HOME"));
221     FILE *in=fopen(chemin,"rt");
222     if (in!=NULL)
223     {
224     char mess[255];
225     fgets(mess,255,in);
226     int R,G,B;
227     int nb=sscanf(mess,"%d %d %d",&R,&G,&B);
228     if (nb==3) base=color(R,G,B);
229     if (!feof(in))
230     {
231     fgets(mess,255,in);
232     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
233     if (nb==3) cface=color(R,G,B);
234     if (!feof(in))
235     {
236     fgets(mess,255,in);
237     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
238     if (nb==3) carete=color(R,G,B);
239     if (!feof(in))
240     {
241     fgets(mess,255,in);
242     nb=sscanf(mess,"%d %d %d",&R,&G,&B);
243     if (nb==3) ctext=color(R,G,B);
244     }
245     }
246     }
247     fclose(in);
248     }
249     printf("******************************\n");
250     printf("* Visualization *\n");
251     printf("* by *\n");
252     printf("* Jean-Christophe Cuillière *\n");
253     printf("* and *\n");
254     printf("* Vincent Francois *\n");
255     printf("* ERICCA-UQTR *\n");
256     printf("******************************\n\n\n");
257    
258 francois 356
259    
260 cuillier 354 if (!((argc==2) || (argc==3)))
261 francois 353 {
262     printf("Visumagic syntax error - Bad number arguments\n\n");
263     return 0;
264    
265     }
266 francois 356 char fichier[255];
267     strcpy(fichier,argv[1]);
268    
269     char *p=strchr(fichier,'.');
270     char extension[255];
271     strcpy(extension,p+1);
272    
273     bool idori;
274     MG_GESTIONNAIRE *gest;
275     if ((strcmp(extension,"step")==0) || (strcmp(extension,"stp")==0) || (strcmp(extension,"STP")==0) || (strcmp(extension,"STEP")==0))
276     {
277     MG_GESTIONNAIRE *gest2=new MG_GESTIONNAIRE;
278     OCC_IMPORT occimport;
279     MG_GEOMETRIE* mggeo=occimport.importer(*gest2,fichier,FICHIERSTEP,0.001,1e-6) ;
280     occimport.importer(*gest2,mggeo,1,2);
281     gest=gest2;
282     idori=true;
283     }
284     else
285     {
286     MG_FILE* gest2=new MG_FILE(fichier);
287     gest=gest2;
288     idori=false;
289     }
290 francois 353
291     int num=0;
292     if (argc==3) num=atoi(argv[2]);
293     MG_GEOMETRIE* geo=gest->get_mg_geometrie(num);
294     data_container data;
295    
296     printf("\n\n");
297     printf("Command on keyboard : \n");
298     printf(" e : End of vizualisation\n");
299     printf(" r : Reset Camera\n");
300     printf(" 1 : Vertex Numbers visible on/off\n");
301     printf(" 4 : Edge Numbers visible on/off\n");
302     printf(" 7 : Face Numbers visible on/off\n");
303     printf(" v : Vertices visible on/off\n");
304     printf(" l : Edges visible on/off\n");
305     printf(" t : Faces visible on/off\n");
306     printf(" j : Save camera on current directory\n");
307     printf(" k : Load camera from current directory\n");
308     printf(" w : Wireframe\n");
309     printf(" s : Modelframe\n");
310    
311 francois 356 char titre [500];
312 francois 353 strcpy(titre,"Visumagic ");
313 francois 356 strcat(titre,fichier);
314     affiche_structure(cface,carete,ctext,geo,data,idori);
315     delete gest;
316 francois 353
317     vtkdisplay d(base,titre);
318    
319    
320    
321    
322     d.init_data(data);
323     d.display(true);
324    
325 francois 356
326 francois 353 return 0;
327     }
328    
329    
330    
331     #pragma package(smart_init)