ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/mgoperation/src/visumagic.cpp
Revision: 353
Committed: Mon Aug 6 19:16:47 2012 UTC (12 years, 10 months ago) by francois
File size: 8962 byte(s)
Log Message:
Visu pour comparateur + visu generale des fichiers magic + correction importation triangulation dans OCC

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