ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/app/compare/src/visumain.cpp
Revision: 351
Committed: Tue Jul 31 19:12:56 2012 UTC (12 years, 9 months ago) by francois
File size: 15180 byte(s)
Log Message:
Adaptation du comparateur en vue de la publi numerique. Plus visualisateur propre en VTK

File Contents

# User Rev Content
1 francois 351 //------------------------------------------------------------
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     struct groupe_couleur
48     {
49     int num;
50     std::map<unsigned long,unsigned long> A;
51     std::map<unsigned long,unsigned long> B;
52     bool est_dans_A(unsigned long val)
53     {
54     std::map<unsigned long,unsigned long>::iterator it=A.find(val);
55     if (it!=A.end()) return true;
56     return false;
57     };
58     bool est_dans_B(unsigned long val)
59     {
60     std::map<unsigned long,unsigned long>::iterator it=B.find(val);
61     if (it!=B.end()) return true;
62     return false;
63     };
64     };
65    
66    
67    
68     struct data_fichier
69     {
70     std::string nomA;
71     std::string nomB;
72     std::map<int,groupe_couleur> list_face_similaire;
73     std::map<int,groupe_couleur> list_face_identique;
74     std::map<int,groupe_couleur> list_face_localise;
75     std::map<int,groupe_couleur> list_arete_localise;
76     std::map<int,groupe_couleur> list_sommet_localise;
77     std::map<int,groupe_couleur> list_face_modifie;
78     std::map<int,groupe_couleur> list_arete_modifie;
79     };
80    
81    
82     void ini_couleur(std::vector<color> &tabcoul,int dim)
83     {
84     int ecart=255/(dim+1);
85     std::map<int,int> list;
86     for (int i=0;i<dim*dim*dim;i++)
87     {
88     int r=rand()%dim+1;
89     int g=rand()%dim+1;
90     int b=rand()%dim+1;
91     int c=r*ecart+255*g*ecart+255*255*b*ecart;
92     std::pair<int,int> tmp(c,c);
93     std::pair<std::map<int,int>::iterator,bool> ret=list.insert(tmp);
94     if (ret.second==false) i--;
95     else
96     {
97     color cc(r*ecart,g*ecart,b*ecart);
98     tabcoul.push_back(cc);
99     }
100     }
101     }
102    
103    
104    
105     void ajouter_liste_couleur(std::map<int,groupe_couleur> &list,unsigned long valA,unsigned long valB)
106     {
107     static int num_couleur=0;
108     std::map<int,groupe_couleur>::iterator it;
109     for (it=list.begin();it!=list.end();it++)
110     {
111     bool res=it->second.est_dans_A(valA);
112     if (res==true)
113     {
114     it->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA));
115     it->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB));
116     return;
117     }
118    
119     res=it->second.est_dans_B(valB);
120     if (res==true)
121     {
122     it->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA));
123     it->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB));
124     return;
125     }
126    
127     }
128     groupe_couleur gc;
129     std::pair<std::map<int,groupe_couleur>::iterator,bool> ret=list.insert(std::pair<int,groupe_couleur>(num_couleur,gc));
130     ret.first->second.num=num_couleur;
131     ret.first->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA));
132     ret.first->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB));
133     num_couleur++;
134     }
135    
136    
137     void lire_fichier(char *nom,data_fichier &data)
138     {
139     FILE* in=fopen(nom,"rt");
140    
141     while (!feof(in))
142     {
143     char mess[255],mess2[255];
144     fgets(mess,255,in);
145     if (strlen(mess)>1)
146     if (mess[0]=='/')
147     if (mess[1]=='/') continue;
148     if (strcmp(mess,"Model A:\n")==0)
149     {
150     fgets(mess,255,in);
151     sscanf(mess,"%s",mess2);
152     data.nomA=mess2;
153     }
154     else if (strcmp(mess,"Model B:\n")==0)
155     {
156     fgets(mess,255,in);
157     sscanf(mess,"%s",mess2);
158     data.nomB=mess2;
159     }
160     else
161     {
162     char mot1[255],mot2[255],mot3[255];
163     int nb;
164     int n=sscanf(mess,"%d %s %s %s",&nb,mot1,mot2,mot3);
165     std::map<int,groupe_couleur> *list=NULL;
166     if (n>2)
167     {
168     if (strcmp(mot1,"Similar")==0)
169     if (strcmp(mot2,"faces")==0)
170     list= &(data.list_face_similaire);
171     if (strcmp(mot1,"Identical")==0)
172     if (strcmp(mot2,"faces")==0)
173     list= &(data.list_face_identique);
174     if (strcmp(mot1,"Localized")==0)
175     if (strcmp(mot2,"identical")==0)
176     if (strcmp(mot3,"faces")==0)
177     list=&(data.list_face_localise);
178     if (strcmp(mot1,"Localized")==0)
179     if (strcmp(mot2,"identical")==0)
180     if (strcmp(mot3,"edges")==0)
181     list=&(data.list_arete_localise);
182     if (strcmp(mot1,"Localized")==0)
183     if (strcmp(mot2,"identical")==0)
184     if (strcmp(mot3,"vertices")==0)
185     list=&(data.list_sommet_localise);
186     if (strcmp(mot1,"Localized")==0)
187     if (strcmp(mot2,"modified")==0)
188     if (strcmp(mot3,"faces")==0)
189     list=&(data.list_face_modifie);
190     if (strcmp(mot1,"Localized")==0)
191     if (strcmp(mot2,"modified")==0)
192     if (strcmp(mot3,"edges")==0)
193     list=&(data.list_arete_modifie);
194     if (list!=NULL)
195     for (int i=0;i<nb;i++)
196     {
197     fgets(mess,255,in);
198     unsigned long valA,valB;
199     sscanf(mess,"%lu %lu%",&valA,&valB);
200     ajouter_liste_couleur(*list,valA,valB);
201     }
202     }
203     }
204    
205    
206    
207     }
208    
209    
210    
211     fclose(in);
212     }
213    
214    
215     void affiche_structure(MG_GEOMETRIE* geo,bool A,std::vector<color> &tabcoul,data_container &data, std::map<int,groupe_couleur> &list_face, std::map<int,groupe_couleur> &list_arete, std::map<int,groupe_couleur> &list_sommet)
216     {
217     unsigned long nb1=geo->get_mg_face(geo->get_nb_mg_face()-1)->get_id();
218     unsigned long nb2=geo->get_mg_arete(geo->get_nb_mg_arete()-1)->get_id();
219     unsigned long nb3=geo->get_mg_sommet(geo->get_nb_mg_sommet()-1)->get_id();
220     int nbid=nb1;
221     if (nb2>nbid) nbid=nb2;
222     if (nb3>nbid) nbid=nb3;
223     nbid=nbid+5;
224     bool affiche[nbid];
225     for (int i=0;i<nbid;i++)
226     affiche[i]=false;
227     std::map<int,groupe_couleur>::iterator it;
228     for (it=list_face.begin();it!=list_face.end();it++)
229     {
230     groupe_couleur gc=it->second;
231     properties ptr=data.getproptriangles();
232     ptr.c=tabcoul[gc.num];
233     ptr.edgeon=false;
234     data.setproptriangles(ptr);
235     std::map<unsigned long,unsigned long>::iterator it2;
236     std::map<unsigned long,unsigned long> *tmp;
237     if (A==true) tmp=&(gc.A);
238     else tmp=&(gc.B);
239    
240     for (it2=tmp->begin();it2!=tmp->end();it2++)
241     {
242     MG_FACE* face=geo->get_mg_faceid(it2->second);
243     affiche[face->get_id()]=true;
244     int nbtri=face->get_lien_maillage()->get_nb();
245     for (int i=0;i<nbtri;i++)
246     {
247     MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i);
248     double *xyz1=tri->get_noeud1()->get_coord();
249     double *xyz2=tri->get_noeud2()->get_coord();
250     double *xyz3=tri->get_noeud3()->get_coord();
251     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
252     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
253     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
254     triangle tr;
255     tr.pts[0]=p1;
256     tr.pts[1]=p2;
257     tr.pts[2]=p3;
258     data.add_triangle(tr);
259     }
260     }
261     }
262     properties ptr=data.getproptriangles();
263     ptr.c=color(0,0,0);
264     ptr.edgeon=false;
265     data.setproptriangles(ptr);
266     LISTE_MG_FACE::iterator itface;
267     for (MG_FACE* face=geo->get_premier_face(itface);face!=NULL;face=geo->get_suivant_face(itface))
268     {
269     if (affiche[face->get_id()]==true) continue;
270     affiche[face->get_id()]=true;
271     int nbtri=face->get_lien_maillage()->get_nb();
272     for (int i=0;i<nbtri;i++)
273     {
274     MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i);
275     double *xyz1=tri->get_noeud1()->get_coord();
276     double *xyz2=tri->get_noeud2()->get_coord();
277     double *xyz3=tri->get_noeud3()->get_coord();
278     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
279     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
280     npoint p3(xyz3[0],xyz3[1],xyz3[2]);
281     triangle tr;
282     tr.pts[0]=p1;
283     tr.pts[1]=p2;
284     tr.pts[2]=p3;
285     data.add_triangle(tr);
286     }
287     }
288    
289    
290     for (it=list_arete.begin();it!=list_arete.end();it++)
291     {
292     groupe_couleur gc=it->second;
293     properties ptr=data.getproplines();
294     ptr.c=tabcoul[gc.num];
295     ptr.thickness=5;
296     data.setproplines(ptr);
297     std::map<unsigned long,unsigned long>::iterator it2;
298     std::map<unsigned long,unsigned long> *tmp;
299     if (A==true) tmp=&(gc.A);
300     else tmp=&(gc.B);
301    
302     for (it2=tmp->begin();it2!=tmp->end();it2++)
303     {
304     MG_ARETE* are=geo->get_mg_areteid(it2->second);
305     affiche[are->get_id()]=true;
306     int nbseg=are->get_lien_maillage()->get_nb();
307     for (int i=0;i<nbseg;i++)
308     {
309     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
310     double *xyz1=seg->get_noeud1()->get_coord();
311     double *xyz2=seg->get_noeud2()->get_coord();
312     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
313     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
314     line li;
315     li.pts[0]=p1;
316     li.pts[1]=p2;
317     data.add_line(li);
318     }
319     }
320     }
321     ptr=data.getproplines();
322     ptr.c=color(255,255,255);
323     ptr.thickness=2;
324     data.setproplines(ptr);
325     LISTE_MG_ARETE::iterator itare;
326     for (MG_ARETE* are=geo->get_premier_arete(itare);are!=NULL;are=geo->get_suivant_arete(itare))
327     {
328     if (affiche[are->get_id()]==true) continue;
329     affiche[are->get_id()]=true;
330     int nbseg=are->get_lien_maillage()->get_nb();
331     for (int i=0;i<nbseg;i++)
332     {
333     MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i);
334     double *xyz1=seg->get_noeud1()->get_coord();
335     double *xyz2=seg->get_noeud2()->get_coord();
336     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
337     npoint p2(xyz2[0],xyz2[1],xyz2[2]);
338     line li;
339     li.pts[0]=p1;
340     li.pts[1]=p2;
341     data.add_line(li);
342     }
343     }
344    
345    
346     for (it=list_sommet.begin();it!=list_sommet.end();it++)
347     {
348     groupe_couleur gc=it->second;
349     properties ptr=data.getproppoints();
350     ptr.c=tabcoul[gc.num];
351     ptr.pointsize=15;
352     data.setproppoints(ptr);
353     std::map<unsigned long,unsigned long>::iterator it2;
354     std::map<unsigned long,unsigned long> *tmp;
355     if (A==true) tmp=&(gc.A);
356     else tmp=&(gc.B);
357    
358     for (it2=tmp->begin();it2!=tmp->end();it2++)
359     {
360     MG_SOMMET* som=geo->get_mg_sommetid(it2->second);
361     affiche[som->get_id()]=true;
362     int nbpoint=som->get_lien_maillage()->get_nb();
363     for (int i=0;i<nbpoint;i++)
364     {
365     MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i);
366     double *xyz1=nd->get_coord();
367     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
368     data.add_point(p1);
369     }
370     }
371     }
372     ptr=data.getproppoints();
373     ptr.c=color(255,255,255);
374     ptr.pointsize=4;
375    
376     data.setproppoints(ptr);
377     LISTE_MG_SOMMET::iterator itsom;
378     for (MG_SOMMET* som=geo->get_premier_sommet(itsom);som!=NULL;som=geo->get_suivant_sommet(itsom))
379     {
380     if (affiche[som->get_id()]==true) continue;
381     affiche[som->get_id()]=true;
382     int nbpoint=som->get_lien_maillage()->get_nb();
383     for (int i=0;i<nbpoint;i++)
384     {
385     MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i);
386     double *xyz1=nd->get_coord();
387     npoint p1(xyz1[0],xyz1[1],xyz1[2]);
388     data.add_point(p1);
389     }
390    
391     }
392    
393    
394    
395     };
396    
397    
398    
399    
400    
401    
402    
403     #ifdef WINDOWS_VERSION
404     int amain(int argc,char **argv)
405     #else
406     int main(int argc,char **argv)
407     #endif
408     {
409     printf("******************************\n");
410     printf("* Comparison visualization *\n");
411     printf("* by *\n");
412     printf("* Jean-Christophe Cuillière *\n");
413     printf("* and *\n");
414     printf("* Vincent Francois *\n");
415     printf("* ERICCA-UQTR *\n");
416     printf("******************************\n\n\n");
417    
418     if (argc!=4)
419     {
420     printf("Visucompare syntax error - Bad number arguments\n\n");
421     return 0;
422    
423     }
424     if (!((strcmp(argv[1],"A")==0) || (strcmp(argv[1],"B")==0)))
425     {
426     printf("Visucompare syntax error - first argument not valid : %s\n\n",argv[1]);
427     return 0;
428    
429     }
430    
431     if (!( (strcmp(argv[2],"S")==0) || (strcmp(argv[2],"M")==0) || (strcmp(argv[2],"I")==0)|| (strcmp(argv[2],"L")==0) ))
432     {
433     printf("Visucompare syntax error - Second argument not valid : %s\n\n",argv[2]);
434     return 0;
435    
436     }
437    
438    
439     std::map<int,groupe_couleur> list_vide;
440     std::vector<color> tabcoul;
441     ini_couleur(tabcoul,10);
442    
443     data_fichier df;
444     lire_fichier(argv[3],df);
445     bool A;
446     MG_FILE *gest;
447     if (strcmp(argv[1],"A")==0) {printf("Reading file A\n");gest=new MG_FILE((char*)df.nomA.c_str());A=true;}
448     else if (strcmp(argv[1],"B")==0) {printf("Reading file B\n");gest=new MG_FILE((char*)df.nomB.c_str());A=false;}
449    
450     printf(" Number of color group :\n");
451     if (strcmp(argv[2],"S")==0) printf(" Similar faces : %d Visible\n",df.list_face_similaire.size()); else printf(" Similar faces : %d\n",df.list_face_similaire.size());
452     if (strcmp(argv[2],"I")==0) printf(" Identical faces : %d Visible\n",df.list_face_identique.size()); else printf(" Identical faces : %d\n",df.list_face_identique.size());
453     if (strcmp(argv[2],"L")==0) printf(" Localized faces : %d Visible\n",df.list_face_localise.size()); else printf(" Localized faces : %d\n",df.list_face_localise.size());
454     if (strcmp(argv[2],"L")==0) printf(" Localized edges : %d Visible\n",df.list_arete_localise.size()); else printf(" Localized faces : %d\n",df.list_face_localise.size());
455     if (strcmp(argv[2],"L")==0) printf(" Localized vertices : %d Visible\n",df.list_sommet_localise.size()); else printf(" Localized faces : %d\n",df.list_face_localise.size());
456     if (strcmp(argv[2],"M")==0) printf(" Modified faces : %d Visible\n",df.list_face_modifie.size()); else printf(" Modified faces : %d \n",df.list_face_modifie.size());
457     if (strcmp(argv[2],"M")==0) printf(" Modified edges : %d Visible\n",df.list_arete_modifie.size()); else printf(" Modified edges : %d\n",df.list_arete_modifie.size());
458    
459    
460     MG_GEOMETRIE* geo=gest->get_mg_geometrie(0);
461     data_container data;
462    
463    
464     if (strcmp(argv[2],"M")==0) affiche_structure(geo,A,tabcoul,data,df.list_face_modifie,df.list_arete_modifie,list_vide);
465     if (strcmp(argv[2],"I")==0) affiche_structure(geo,A,tabcoul,data,df.list_face_identique,list_vide,list_vide);
466     if (strcmp(argv[2],"S")==0) affiche_structure(geo,A,tabcoul,data,df.list_face_similaire,list_vide,list_vide);
467     if (strcmp(argv[2],"L")==0) affiche_structure(geo,A,tabcoul,data,df.list_face_localise,df.list_arete_localise,df.list_sommet_localise);
468    
469    
470     char titre [255];
471     strcpy(titre,"Visucompare File ");
472     strcat(titre,argv[1]);
473     strcat(titre," ");
474     strcat(titre,argv[2]);
475     strcat(titre," ");
476     strcat(titre,argv[3]);
477    
478    
479     delete gest;
480     vtkdisplay d(color(0,0,0),titre);
481    
482    
483    
484    
485     d.init_data(data);
486     d.display(true);
487    
488     return 0;
489     }
490    
491    
492    
493     #pragma package(smart_init)