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 |
francois |
353 |
void affiche_structure(color base,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 |
francois |
351 |
{ |
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 |
francois |
353 |
ptr.c=color(tabcoul[gc.num].R,tabcoul[gc.num].G,tabcoul[gc.num].B,255); |
233 |
francois |
351 |
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 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
245 |
francois |
351 |
int nbtri=face->get_lien_maillage()->get_nb(); |
246 |
|
|
for (int i=0;i<nbtri;i++) |
247 |
|
|
{ |
248 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
249 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
250 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
251 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
252 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
253 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
254 |
|
|
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
255 |
|
|
triangle tr; |
256 |
|
|
tr.pts[0]=p1; |
257 |
|
|
tr.pts[1]=p2; |
258 |
|
|
tr.pts[2]=p3; |
259 |
|
|
data.add_triangle(tr); |
260 |
francois |
353 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
261 |
|
|
OT_VECTEUR_3D vec2(xyz1,xyz3); |
262 |
|
|
OT_VECTEUR_3D sur=vec1&vec2; |
263 |
|
|
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
264 |
|
|
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
265 |
|
|
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
266 |
|
|
deno=deno+sur.get_longueur(); |
267 |
francois |
351 |
} |
268 |
francois |
353 |
xg=xg/deno; |
269 |
|
|
yg=yg/deno; |
270 |
|
|
zg=zg/deno; |
271 |
|
|
std::map<double,MG_TRIANGLE*> classetri; |
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 |
|
|
double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]); |
279 |
|
|
double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]); |
280 |
|
|
double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]); |
281 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
282 |
|
|
classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri)); |
283 |
|
|
} |
284 |
francois |
356 |
if (nbtri>0) |
285 |
|
|
{ |
286 |
|
|
MG_TRIANGLE *tri=classetri.begin()->second; |
287 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
288 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
289 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
290 |
|
|
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])); |
291 |
|
|
point pp; |
292 |
|
|
pp.pts=p; |
293 |
|
|
char mess[255]; |
294 |
|
|
sprintf(mess,"F%lu",face->get_id()); |
295 |
|
|
pp.info=mess; |
296 |
|
|
color cc=color(255-ptr.c.R,255-ptr.c.G,255-ptr.c.B); |
297 |
|
|
std::pair<point,color> tmp(pp,cc); |
298 |
|
|
data.add_text(2,tmp); |
299 |
|
|
} |
300 |
|
|
|
301 |
|
|
} |
302 |
francois |
351 |
} |
303 |
|
|
properties ptr=data.getproptriangles(); |
304 |
francois |
353 |
ptr.c=base; |
305 |
francois |
351 |
ptr.edgeon=false; |
306 |
|
|
data.setproptriangles(ptr); |
307 |
|
|
LISTE_MG_FACE::iterator itface; |
308 |
|
|
for (MG_FACE* face=geo->get_premier_face(itface);face!=NULL;face=geo->get_suivant_face(itface)) |
309 |
|
|
{ |
310 |
|
|
if (affiche[face->get_id()]==true) continue; |
311 |
|
|
affiche[face->get_id()]=true; |
312 |
|
|
int nbtri=face->get_lien_maillage()->get_nb(); |
313 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
314 |
francois |
351 |
for (int i=0;i<nbtri;i++) |
315 |
|
|
{ |
316 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
317 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
318 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
319 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
320 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
321 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
322 |
|
|
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
323 |
|
|
triangle tr; |
324 |
|
|
tr.pts[0]=p1; |
325 |
|
|
tr.pts[1]=p2; |
326 |
|
|
tr.pts[2]=p3; |
327 |
|
|
data.add_triangle(tr); |
328 |
francois |
353 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
329 |
|
|
OT_VECTEUR_3D vec2(xyz1,xyz3); |
330 |
|
|
OT_VECTEUR_3D sur=vec1&vec2; |
331 |
|
|
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
332 |
|
|
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
333 |
|
|
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
334 |
|
|
deno=deno+sur.get_longueur(); |
335 |
francois |
351 |
} |
336 |
francois |
353 |
xg=xg/deno; |
337 |
|
|
yg=yg/deno; |
338 |
|
|
zg=zg/deno; |
339 |
|
|
std::map<double,MG_TRIANGLE*> classetri; |
340 |
|
|
for (int i=0;i<nbtri;i++) |
341 |
|
|
{ |
342 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
343 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
344 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
345 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
346 |
|
|
double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]); |
347 |
|
|
double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]); |
348 |
|
|
double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]); |
349 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
350 |
|
|
classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri)); |
351 |
|
|
} |
352 |
francois |
356 |
if (nbtri>0) |
353 |
|
|
{ |
354 |
|
|
MG_TRIANGLE *tri=classetri.begin()->second; |
355 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
356 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
357 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
358 |
|
|
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])); |
359 |
|
|
point pp; |
360 |
|
|
pp.pts=p; |
361 |
|
|
char mess[255]; |
362 |
|
|
sprintf(mess,"F%lu",face->get_id()); |
363 |
|
|
pp.info=mess; |
364 |
|
|
color cc=color(255-ptr.c.R,255-ptr.c.G,255-ptr.c.B); |
365 |
|
|
std::pair<point,color> tmp(pp,cc); |
366 |
|
|
data.add_text(2,tmp); |
367 |
|
|
} |
368 |
francois |
353 |
} |
369 |
francois |
351 |
|
370 |
|
|
|
371 |
|
|
for (it=list_arete.begin();it!=list_arete.end();it++) |
372 |
|
|
{ |
373 |
|
|
groupe_couleur gc=it->second; |
374 |
|
|
properties ptr=data.getproplines(); |
375 |
|
|
ptr.c=tabcoul[gc.num]; |
376 |
|
|
ptr.thickness=5; |
377 |
|
|
data.setproplines(ptr); |
378 |
|
|
std::map<unsigned long,unsigned long>::iterator it2; |
379 |
|
|
std::map<unsigned long,unsigned long> *tmp; |
380 |
|
|
if (A==true) tmp=&(gc.A); |
381 |
|
|
else tmp=&(gc.B); |
382 |
|
|
|
383 |
|
|
for (it2=tmp->begin();it2!=tmp->end();it2++) |
384 |
|
|
{ |
385 |
|
|
MG_ARETE* are=geo->get_mg_areteid(it2->second); |
386 |
|
|
affiche[are->get_id()]=true; |
387 |
|
|
int nbseg=are->get_lien_maillage()->get_nb(); |
388 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
389 |
francois |
351 |
for (int i=0;i<nbseg;i++) |
390 |
|
|
{ |
391 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
392 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
393 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
394 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
395 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
396 |
|
|
line li; |
397 |
|
|
li.pts[0]=p1; |
398 |
|
|
li.pts[1]=p2; |
399 |
|
|
data.add_line(li); |
400 |
francois |
353 |
OT_VECTEUR_3D vec(xyz1,xyz2); |
401 |
|
|
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur(); |
402 |
|
|
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur(); |
403 |
|
|
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur(); |
404 |
|
|
deno=deno+vec.get_longueur(); |
405 |
francois |
351 |
} |
406 |
francois |
353 |
xg=xg/deno; |
407 |
|
|
yg=yg/deno; |
408 |
|
|
zg=zg/deno; |
409 |
|
|
std::map<double,MG_SEGMENT*> classeseg; |
410 |
|
|
for (int i=0;i<nbseg;i++) |
411 |
|
|
{ |
412 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
413 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
414 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
415 |
|
|
double x=0.5*(xyz1[0]+xyz2[0]); |
416 |
|
|
double y=0.5*(xyz1[1]+xyz2[1]); |
417 |
|
|
double z=0.5*(xyz1[2]+xyz2[2]); |
418 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
419 |
|
|
classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg)); |
420 |
|
|
} |
421 |
francois |
356 |
if (nbseg>0) |
422 |
|
|
{ |
423 |
|
|
MG_SEGMENT* seg=classeseg.begin()->second; |
424 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
425 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
426 |
|
|
npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2])); |
427 |
|
|
point pp; |
428 |
|
|
pp.pts=p; |
429 |
|
|
char mess[255]; |
430 |
|
|
sprintf(mess,"E%lu",are->get_id()); |
431 |
|
|
pp.info=mess; |
432 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
433 |
|
|
std::pair<point,color> tmp(pp,cc); |
434 |
|
|
data.add_text(1,tmp); |
435 |
|
|
} |
436 |
francois |
351 |
} |
437 |
|
|
} |
438 |
|
|
ptr=data.getproplines(); |
439 |
francois |
353 |
ptr.c=color(255-base.R,255-base.G,255-base.B); |
440 |
francois |
351 |
ptr.thickness=2; |
441 |
|
|
data.setproplines(ptr); |
442 |
|
|
LISTE_MG_ARETE::iterator itare; |
443 |
|
|
for (MG_ARETE* are=geo->get_premier_arete(itare);are!=NULL;are=geo->get_suivant_arete(itare)) |
444 |
|
|
{ |
445 |
|
|
if (affiche[are->get_id()]==true) continue; |
446 |
|
|
affiche[are->get_id()]=true; |
447 |
|
|
int nbseg=are->get_lien_maillage()->get_nb(); |
448 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
449 |
|
|
for (int i=0;i<nbseg;i++) |
450 |
francois |
351 |
{ |
451 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
452 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
453 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
454 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
455 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
456 |
|
|
line li; |
457 |
|
|
li.pts[0]=p1; |
458 |
|
|
li.pts[1]=p2; |
459 |
|
|
data.add_line(li); |
460 |
francois |
353 |
OT_VECTEUR_3D vec(xyz1,xyz2); |
461 |
|
|
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur(); |
462 |
|
|
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur(); |
463 |
|
|
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur(); |
464 |
|
|
deno=deno+vec.get_longueur(); |
465 |
francois |
351 |
} |
466 |
francois |
353 |
xg=xg/deno; |
467 |
|
|
yg=yg/deno; |
468 |
|
|
zg=zg/deno; |
469 |
|
|
std::map<double,MG_SEGMENT*> classeseg; |
470 |
|
|
for (int i=0;i<nbseg;i++) |
471 |
|
|
{ |
472 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
473 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
474 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
475 |
|
|
double x=0.5*(xyz1[0]+xyz2[0]); |
476 |
|
|
double y=0.5*(xyz1[1]+xyz2[1]); |
477 |
|
|
double z=0.5*(xyz1[2]+xyz2[2]); |
478 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
479 |
|
|
classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg)); |
480 |
|
|
} |
481 |
francois |
356 |
if (nbseg>0) |
482 |
|
|
{ |
483 |
|
|
MG_SEGMENT* seg=classeseg.begin()->second; |
484 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
485 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
486 |
|
|
npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2])); |
487 |
|
|
point pp; |
488 |
|
|
pp.pts=p; |
489 |
|
|
char mess[255]; |
490 |
|
|
sprintf(mess,"E%lu",are->get_id()); |
491 |
|
|
pp.info=mess; |
492 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
493 |
|
|
std::pair<point,color> tmp(pp,cc); |
494 |
|
|
data.add_text(1,tmp); |
495 |
|
|
} |
496 |
francois |
353 |
} |
497 |
francois |
351 |
|
498 |
|
|
|
499 |
|
|
for (it=list_sommet.begin();it!=list_sommet.end();it++) |
500 |
|
|
{ |
501 |
|
|
groupe_couleur gc=it->second; |
502 |
|
|
properties ptr=data.getproppoints(); |
503 |
|
|
ptr.c=tabcoul[gc.num]; |
504 |
|
|
ptr.pointsize=15; |
505 |
|
|
data.setproppoints(ptr); |
506 |
|
|
std::map<unsigned long,unsigned long>::iterator it2; |
507 |
|
|
std::map<unsigned long,unsigned long> *tmp; |
508 |
|
|
if (A==true) tmp=&(gc.A); |
509 |
|
|
else tmp=&(gc.B); |
510 |
|
|
|
511 |
|
|
for (it2=tmp->begin();it2!=tmp->end();it2++) |
512 |
|
|
{ |
513 |
|
|
MG_SOMMET* som=geo->get_mg_sommetid(it2->second); |
514 |
|
|
affiche[som->get_id()]=true; |
515 |
|
|
int nbpoint=som->get_lien_maillage()->get_nb(); |
516 |
|
|
for (int i=0;i<nbpoint;i++) |
517 |
|
|
{ |
518 |
|
|
MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i); |
519 |
|
|
double *xyz1=nd->get_coord(); |
520 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
521 |
|
|
data.add_point(p1); |
522 |
francois |
353 |
point pp; |
523 |
|
|
pp.pts=p1; |
524 |
|
|
char mess[255]; |
525 |
|
|
sprintf(mess,"V%lu",som->get_id()); |
526 |
|
|
pp.info=mess; |
527 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
528 |
|
|
std::pair<point,color> tmp(pp,cc); |
529 |
|
|
data.add_text(0,tmp); |
530 |
francois |
351 |
} |
531 |
|
|
} |
532 |
|
|
} |
533 |
|
|
ptr=data.getproppoints(); |
534 |
francois |
353 |
ptr.c=color(255-base.R,255-base.G,255-base.B); |
535 |
francois |
351 |
ptr.pointsize=4; |
536 |
|
|
|
537 |
|
|
data.setproppoints(ptr); |
538 |
|
|
LISTE_MG_SOMMET::iterator itsom; |
539 |
|
|
for (MG_SOMMET* som=geo->get_premier_sommet(itsom);som!=NULL;som=geo->get_suivant_sommet(itsom)) |
540 |
|
|
{ |
541 |
|
|
if (affiche[som->get_id()]==true) continue; |
542 |
|
|
affiche[som->get_id()]=true; |
543 |
|
|
int nbpoint=som->get_lien_maillage()->get_nb(); |
544 |
|
|
for (int i=0;i<nbpoint;i++) |
545 |
|
|
{ |
546 |
|
|
MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i); |
547 |
|
|
double *xyz1=nd->get_coord(); |
548 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
549 |
|
|
data.add_point(p1); |
550 |
francois |
353 |
point pp; |
551 |
|
|
pp.pts=p1; |
552 |
|
|
char mess[255]; |
553 |
|
|
sprintf(mess,"V%lu",som->get_id()); |
554 |
|
|
pp.info=mess; |
555 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
556 |
|
|
std::pair<point,color> tmp(pp,cc); |
557 |
|
|
data.add_text(0,tmp); |
558 |
francois |
351 |
} |
559 |
|
|
|
560 |
|
|
} |
561 |
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
}; |
565 |
|
|
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
|
569 |
|
|
|
570 |
|
|
|
571 |
|
|
|
572 |
|
|
#ifdef WINDOWS_VERSION |
573 |
|
|
int amain(int argc,char **argv) |
574 |
|
|
#else |
575 |
|
|
int main(int argc,char **argv) |
576 |
|
|
#endif |
577 |
|
|
{ |
578 |
francois |
353 |
color base=color(0,0,0); |
579 |
|
|
char chemin[1000]; |
580 |
|
|
sprintf(chemin,"%s/.vtkdisplay",getenv("HOME")); |
581 |
|
|
FILE *in=fopen(chemin,"rt"); |
582 |
|
|
if (in!=NULL) |
583 |
|
|
{ |
584 |
|
|
char mess[255]; |
585 |
|
|
fgets(mess,255,in); |
586 |
|
|
int R,G,B; |
587 |
|
|
sscanf(mess,"%d %d %d",&R,&G,&B); |
588 |
|
|
base=color(R,G,B); |
589 |
|
|
fclose(in); |
590 |
|
|
} |
591 |
francois |
351 |
printf("******************************\n"); |
592 |
|
|
printf("* Comparison visualization *\n"); |
593 |
|
|
printf("* by *\n"); |
594 |
|
|
printf("* Jean-Christophe Cuillière *\n"); |
595 |
|
|
printf("* and *\n"); |
596 |
|
|
printf("* Vincent Francois *\n"); |
597 |
|
|
printf("* ERICCA-UQTR *\n"); |
598 |
|
|
printf("******************************\n\n\n"); |
599 |
|
|
|
600 |
|
|
if (argc!=4) |
601 |
|
|
{ |
602 |
|
|
printf("Visucompare syntax error - Bad number arguments\n\n"); |
603 |
|
|
return 0; |
604 |
|
|
|
605 |
|
|
} |
606 |
|
|
if (!((strcmp(argv[1],"A")==0) || (strcmp(argv[1],"B")==0))) |
607 |
|
|
{ |
608 |
|
|
printf("Visucompare syntax error - first argument not valid : %s\n\n",argv[1]); |
609 |
|
|
return 0; |
610 |
|
|
|
611 |
|
|
} |
612 |
|
|
|
613 |
|
|
if (!( (strcmp(argv[2],"S")==0) || (strcmp(argv[2],"M")==0) || (strcmp(argv[2],"I")==0)|| (strcmp(argv[2],"L")==0) )) |
614 |
|
|
{ |
615 |
|
|
printf("Visucompare syntax error - Second argument not valid : %s\n\n",argv[2]); |
616 |
|
|
return 0; |
617 |
|
|
|
618 |
|
|
} |
619 |
|
|
|
620 |
|
|
|
621 |
|
|
std::map<int,groupe_couleur> list_vide; |
622 |
|
|
std::vector<color> tabcoul; |
623 |
|
|
ini_couleur(tabcoul,10); |
624 |
|
|
|
625 |
|
|
data_fichier df; |
626 |
|
|
lire_fichier(argv[3],df); |
627 |
|
|
bool A; |
628 |
|
|
MG_FILE *gest; |
629 |
|
|
if (strcmp(argv[1],"A")==0) {printf("Reading file A\n");gest=new MG_FILE((char*)df.nomA.c_str());A=true;} |
630 |
|
|
else if (strcmp(argv[1],"B")==0) {printf("Reading file B\n");gest=new MG_FILE((char*)df.nomB.c_str());A=false;} |
631 |
|
|
|
632 |
|
|
printf(" Number of color group :\n"); |
633 |
|
|
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()); |
634 |
|
|
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()); |
635 |
|
|
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()); |
636 |
|
|
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()); |
637 |
|
|
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()); |
638 |
|
|
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()); |
639 |
|
|
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()); |
640 |
|
|
|
641 |
|
|
|
642 |
|
|
MG_GEOMETRIE* geo=gest->get_mg_geometrie(0); |
643 |
|
|
data_container data; |
644 |
|
|
|
645 |
|
|
|
646 |
francois |
353 |
if (strcmp(argv[2],"M")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_modifie,df.list_arete_modifie,list_vide); |
647 |
|
|
if (strcmp(argv[2],"I")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_identique,list_vide,list_vide); |
648 |
|
|
if (strcmp(argv[2],"S")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_similaire,list_vide,list_vide); |
649 |
|
|
if (strcmp(argv[2],"L")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_localise,df.list_arete_localise,df.list_sommet_localise); |
650 |
|
|
|
651 |
|
|
printf("\n\n"); |
652 |
|
|
printf("Command on keyboard : \n"); |
653 |
|
|
printf(" e : End of vizualisation\n"); |
654 |
|
|
printf(" r : Reset Camera\n"); |
655 |
|
|
printf(" 1 : Vertex Numbers visible on/off\n"); |
656 |
|
|
printf(" 4 : Edge Numbers visible on/off\n"); |
657 |
|
|
printf(" 7 : Face Numbers visible on/off\n"); |
658 |
|
|
printf(" v : Vertices visible on/off\n"); |
659 |
|
|
printf(" l : Edges visible on/off\n"); |
660 |
|
|
printf(" t : Faces visible on/off\n"); |
661 |
|
|
printf(" j : Save camera on current directory\n"); |
662 |
|
|
printf(" k : Load camera from current directory\n"); |
663 |
|
|
printf(" w : Wireframe\n"); |
664 |
|
|
printf(" s : Modelframe\n"); |
665 |
|
|
|
666 |
francois |
351 |
char titre [255]; |
667 |
|
|
strcpy(titre,"Visucompare File "); |
668 |
|
|
strcat(titre,argv[1]); |
669 |
|
|
strcat(titre," "); |
670 |
|
|
strcat(titre,argv[2]); |
671 |
|
|
strcat(titre," "); |
672 |
|
|
strcat(titre,argv[3]); |
673 |
|
|
|
674 |
|
|
|
675 |
|
|
delete gest; |
676 |
francois |
353 |
vtkdisplay d(base,titre); |
677 |
francois |
351 |
|
678 |
|
|
|
679 |
|
|
|
680 |
|
|
|
681 |
|
|
d.init_data(data); |
682 |
|
|
d.display(true); |
683 |
|
|
|
684 |
|
|
return 0; |
685 |
|
|
} |
686 |
|
|
|
687 |
|
|
|
688 |
|
|
|
689 |
|
|
#pragma package(smart_init) |