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 |
|
|
//####// visumain.cpp |
15 |
|
|
//####// |
16 |
|
|
//####//------------------------------------------------------------ |
17 |
|
|
//####//------------------------------------------------------------ |
18 |
|
|
//####// COPYRIGHT 2000-2024 |
19 |
|
|
//####// jeu 13 jun 2024 11:57:20 EDT |
20 |
|
|
//####//------------------------------------------------------------ |
21 |
|
|
//####//------------------------------------------------------------ |
22 |
francois |
351 |
|
23 |
|
|
#include <iostream> |
24 |
francois |
1157 |
#include "vtkdisplay.hxx" |
25 |
|
|
#include "ndata.hxx" |
26 |
francois |
351 |
#include "mg_file.h" |
27 |
|
|
#include <map> |
28 |
francois |
363 |
#if _COMPARESTEP_ |
29 |
|
|
#include "occ_import.h" |
30 |
|
|
#endif |
31 |
francois |
351 |
|
32 |
|
|
void affiche(char* message) |
33 |
|
|
{ |
34 |
francois |
1157 |
|
35 |
francois |
351 |
std::cout << message << std::endl; |
36 |
francois |
1157 |
|
37 |
francois |
351 |
} |
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
|
|
struct groupe_couleur |
42 |
|
|
{ |
43 |
|
|
int num; |
44 |
|
|
std::map<unsigned long,unsigned long> A; |
45 |
|
|
std::map<unsigned long,unsigned long> B; |
46 |
|
|
bool est_dans_A(unsigned long val) |
47 |
|
|
{ |
48 |
|
|
std::map<unsigned long,unsigned long>::iterator it=A.find(val); |
49 |
|
|
if (it!=A.end()) return true; |
50 |
|
|
return false; |
51 |
|
|
}; |
52 |
|
|
bool est_dans_B(unsigned long val) |
53 |
|
|
{ |
54 |
|
|
std::map<unsigned long,unsigned long>::iterator it=B.find(val); |
55 |
|
|
if (it!=B.end()) return true; |
56 |
|
|
return false; |
57 |
|
|
}; |
58 |
|
|
}; |
59 |
|
|
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
struct data_fichier |
63 |
|
|
{ |
64 |
|
|
std::string nomA; |
65 |
|
|
std::string nomB; |
66 |
|
|
std::map<int,groupe_couleur> list_face_similaire; |
67 |
|
|
std::map<int,groupe_couleur> list_face_identique; |
68 |
|
|
std::map<int,groupe_couleur> list_face_localise; |
69 |
|
|
std::map<int,groupe_couleur> list_arete_localise; |
70 |
|
|
std::map<int,groupe_couleur> list_sommet_localise; |
71 |
|
|
std::map<int,groupe_couleur> list_face_modifie; |
72 |
|
|
std::map<int,groupe_couleur> list_arete_modifie; |
73 |
|
|
}; |
74 |
|
|
|
75 |
|
|
|
76 |
|
|
void ini_couleur(std::vector<color> &tabcoul,int dim) |
77 |
|
|
{ |
78 |
|
|
int ecart=255/(dim+1); |
79 |
|
|
std::map<int,int> list; |
80 |
|
|
for (int i=0;i<dim*dim*dim;i++) |
81 |
|
|
{ |
82 |
|
|
int r=rand()%dim+1; |
83 |
|
|
int g=rand()%dim+1; |
84 |
|
|
int b=rand()%dim+1; |
85 |
|
|
int c=r*ecart+255*g*ecart+255*255*b*ecart; |
86 |
|
|
std::pair<int,int> tmp(c,c); |
87 |
|
|
std::pair<std::map<int,int>::iterator,bool> ret=list.insert(tmp); |
88 |
|
|
if (ret.second==false) i--; |
89 |
|
|
else |
90 |
|
|
{ |
91 |
|
|
color cc(r*ecart,g*ecart,b*ecart); |
92 |
|
|
tabcoul.push_back(cc); |
93 |
|
|
} |
94 |
|
|
} |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
void ajouter_liste_couleur(std::map<int,groupe_couleur> &list,unsigned long valA,unsigned long valB) |
100 |
|
|
{ |
101 |
|
|
static int num_couleur=0; |
102 |
|
|
std::map<int,groupe_couleur>::iterator it; |
103 |
|
|
for (it=list.begin();it!=list.end();it++) |
104 |
|
|
{ |
105 |
|
|
bool res=it->second.est_dans_A(valA); |
106 |
|
|
if (res==true) |
107 |
|
|
{ |
108 |
|
|
it->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA)); |
109 |
|
|
it->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB)); |
110 |
|
|
return; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
|
res=it->second.est_dans_B(valB); |
114 |
|
|
if (res==true) |
115 |
|
|
{ |
116 |
|
|
it->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA)); |
117 |
|
|
it->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB)); |
118 |
|
|
return; |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
} |
122 |
|
|
groupe_couleur gc; |
123 |
|
|
std::pair<std::map<int,groupe_couleur>::iterator,bool> ret=list.insert(std::pair<int,groupe_couleur>(num_couleur,gc)); |
124 |
|
|
ret.first->second.num=num_couleur; |
125 |
|
|
ret.first->second.A.insert(std::pair<unsigned long,unsigned long>(valA,valA)); |
126 |
|
|
ret.first->second.B.insert(std::pair<unsigned long,unsigned long>(valB,valB)); |
127 |
|
|
num_couleur++; |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
void lire_fichier(char *nom,data_fichier &data) |
132 |
|
|
{ |
133 |
|
|
FILE* in=fopen(nom,"rt"); |
134 |
|
|
|
135 |
|
|
while (!feof(in)) |
136 |
|
|
{ |
137 |
|
|
char mess[255],mess2[255]; |
138 |
|
|
fgets(mess,255,in); |
139 |
|
|
if (strlen(mess)>1) |
140 |
|
|
if (mess[0]=='/') |
141 |
|
|
if (mess[1]=='/') continue; |
142 |
|
|
if (strcmp(mess,"Model A:\n")==0) |
143 |
|
|
{ |
144 |
|
|
fgets(mess,255,in); |
145 |
|
|
sscanf(mess,"%s",mess2); |
146 |
|
|
data.nomA=mess2; |
147 |
|
|
} |
148 |
|
|
else if (strcmp(mess,"Model B:\n")==0) |
149 |
|
|
{ |
150 |
|
|
fgets(mess,255,in); |
151 |
|
|
sscanf(mess,"%s",mess2); |
152 |
|
|
data.nomB=mess2; |
153 |
|
|
} |
154 |
|
|
else |
155 |
|
|
{ |
156 |
|
|
char mot1[255],mot2[255],mot3[255]; |
157 |
|
|
int nb; |
158 |
|
|
int n=sscanf(mess,"%d %s %s %s",&nb,mot1,mot2,mot3); |
159 |
|
|
std::map<int,groupe_couleur> *list=NULL; |
160 |
|
|
if (n>2) |
161 |
|
|
{ |
162 |
|
|
if (strcmp(mot1,"Similar")==0) |
163 |
|
|
if (strcmp(mot2,"faces")==0) |
164 |
|
|
list= &(data.list_face_similaire); |
165 |
|
|
if (strcmp(mot1,"Identical")==0) |
166 |
|
|
if (strcmp(mot2,"faces")==0) |
167 |
|
|
list= &(data.list_face_identique); |
168 |
|
|
if (strcmp(mot1,"Localized")==0) |
169 |
|
|
if (strcmp(mot2,"identical")==0) |
170 |
|
|
if (strcmp(mot3,"faces")==0) |
171 |
|
|
list=&(data.list_face_localise); |
172 |
|
|
if (strcmp(mot1,"Localized")==0) |
173 |
|
|
if (strcmp(mot2,"identical")==0) |
174 |
|
|
if (strcmp(mot3,"edges")==0) |
175 |
|
|
list=&(data.list_arete_localise); |
176 |
|
|
if (strcmp(mot1,"Localized")==0) |
177 |
|
|
if (strcmp(mot2,"identical")==0) |
178 |
|
|
if (strcmp(mot3,"vertices")==0) |
179 |
|
|
list=&(data.list_sommet_localise); |
180 |
|
|
if (strcmp(mot1,"Localized")==0) |
181 |
|
|
if (strcmp(mot2,"modified")==0) |
182 |
|
|
if (strcmp(mot3,"faces")==0) |
183 |
|
|
list=&(data.list_face_modifie); |
184 |
|
|
if (strcmp(mot1,"Localized")==0) |
185 |
|
|
if (strcmp(mot2,"modified")==0) |
186 |
|
|
if (strcmp(mot3,"edges")==0) |
187 |
|
|
list=&(data.list_arete_modifie); |
188 |
|
|
if (list!=NULL) |
189 |
|
|
for (int i=0;i<nb;i++) |
190 |
|
|
{ |
191 |
|
|
fgets(mess,255,in); |
192 |
|
|
unsigned long valA,valB; |
193 |
francois |
479 |
sscanf(mess,"%lu %lu",&valA,&valB); |
194 |
francois |
351 |
ajouter_liste_couleur(*list,valA,valB); |
195 |
|
|
} |
196 |
|
|
} |
197 |
|
|
} |
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
fclose(in); |
206 |
|
|
} |
207 |
|
|
|
208 |
|
|
|
209 |
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) |
210 |
francois |
351 |
{ |
211 |
|
|
unsigned long nb1=geo->get_mg_face(geo->get_nb_mg_face()-1)->get_id(); |
212 |
|
|
unsigned long nb2=geo->get_mg_arete(geo->get_nb_mg_arete()-1)->get_id(); |
213 |
|
|
unsigned long nb3=geo->get_mg_sommet(geo->get_nb_mg_sommet()-1)->get_id(); |
214 |
|
|
int nbid=nb1; |
215 |
|
|
if (nb2>nbid) nbid=nb2; |
216 |
|
|
if (nb3>nbid) nbid=nb3; |
217 |
|
|
nbid=nbid+5; |
218 |
|
|
bool affiche[nbid]; |
219 |
|
|
for (int i=0;i<nbid;i++) |
220 |
|
|
affiche[i]=false; |
221 |
|
|
std::map<int,groupe_couleur>::iterator it; |
222 |
|
|
for (it=list_face.begin();it!=list_face.end();it++) |
223 |
|
|
{ |
224 |
|
|
groupe_couleur gc=it->second; |
225 |
|
|
properties ptr=data.getproptriangles(); |
226 |
francois |
353 |
ptr.c=color(tabcoul[gc.num].R,tabcoul[gc.num].G,tabcoul[gc.num].B,255); |
227 |
francois |
351 |
ptr.edgeon=false; |
228 |
|
|
data.setproptriangles(ptr); |
229 |
|
|
std::map<unsigned long,unsigned long>::iterator it2; |
230 |
|
|
std::map<unsigned long,unsigned long> *tmp; |
231 |
|
|
if (A==true) tmp=&(gc.A); |
232 |
|
|
else tmp=&(gc.B); |
233 |
|
|
|
234 |
|
|
for (it2=tmp->begin();it2!=tmp->end();it2++) |
235 |
|
|
{ |
236 |
|
|
MG_FACE* face=geo->get_mg_faceid(it2->second); |
237 |
|
|
affiche[face->get_id()]=true; |
238 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
239 |
francois |
351 |
int nbtri=face->get_lien_maillage()->get_nb(); |
240 |
|
|
for (int i=0;i<nbtri;i++) |
241 |
|
|
{ |
242 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
243 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
244 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
245 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
246 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
247 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
248 |
|
|
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
249 |
|
|
triangle tr; |
250 |
|
|
tr.pts[0]=p1; |
251 |
|
|
tr.pts[1]=p2; |
252 |
|
|
tr.pts[2]=p3; |
253 |
|
|
data.add_triangle(tr); |
254 |
francois |
353 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
255 |
|
|
OT_VECTEUR_3D vec2(xyz1,xyz3); |
256 |
|
|
OT_VECTEUR_3D sur=vec1&vec2; |
257 |
|
|
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
258 |
|
|
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
259 |
|
|
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
260 |
|
|
deno=deno+sur.get_longueur(); |
261 |
francois |
351 |
} |
262 |
francois |
353 |
xg=xg/deno; |
263 |
|
|
yg=yg/deno; |
264 |
|
|
zg=zg/deno; |
265 |
|
|
std::map<double,MG_TRIANGLE*> classetri; |
266 |
|
|
for (int i=0;i<nbtri;i++) |
267 |
|
|
{ |
268 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
269 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
270 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
271 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
272 |
|
|
double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]); |
273 |
|
|
double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]); |
274 |
|
|
double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]); |
275 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
276 |
|
|
classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri)); |
277 |
|
|
} |
278 |
francois |
356 |
if (nbtri>0) |
279 |
|
|
{ |
280 |
|
|
MG_TRIANGLE *tri=classetri.begin()->second; |
281 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
282 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
283 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
284 |
|
|
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])); |
285 |
|
|
point pp; |
286 |
|
|
pp.pts=p; |
287 |
|
|
char mess[255]; |
288 |
|
|
sprintf(mess,"F%lu",face->get_id()); |
289 |
|
|
pp.info=mess; |
290 |
|
|
color cc=color(255-ptr.c.R,255-ptr.c.G,255-ptr.c.B); |
291 |
|
|
std::pair<point,color> tmp(pp,cc); |
292 |
|
|
data.add_text(2,tmp); |
293 |
|
|
} |
294 |
|
|
|
295 |
|
|
} |
296 |
francois |
351 |
} |
297 |
|
|
properties ptr=data.getproptriangles(); |
298 |
francois |
353 |
ptr.c=base; |
299 |
francois |
351 |
ptr.edgeon=false; |
300 |
|
|
data.setproptriangles(ptr); |
301 |
|
|
LISTE_MG_FACE::iterator itface; |
302 |
|
|
for (MG_FACE* face=geo->get_premier_face(itface);face!=NULL;face=geo->get_suivant_face(itface)) |
303 |
|
|
{ |
304 |
|
|
if (affiche[face->get_id()]==true) continue; |
305 |
|
|
affiche[face->get_id()]=true; |
306 |
|
|
int nbtri=face->get_lien_maillage()->get_nb(); |
307 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
308 |
francois |
351 |
for (int i=0;i<nbtri;i++) |
309 |
|
|
{ |
310 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
311 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
312 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
313 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
314 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
315 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
316 |
|
|
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
317 |
|
|
triangle tr; |
318 |
|
|
tr.pts[0]=p1; |
319 |
|
|
tr.pts[1]=p2; |
320 |
|
|
tr.pts[2]=p3; |
321 |
|
|
data.add_triangle(tr); |
322 |
francois |
353 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
323 |
|
|
OT_VECTEUR_3D vec2(xyz1,xyz3); |
324 |
|
|
OT_VECTEUR_3D sur=vec1&vec2; |
325 |
|
|
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
326 |
|
|
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
327 |
|
|
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
328 |
|
|
deno=deno+sur.get_longueur(); |
329 |
francois |
351 |
} |
330 |
francois |
353 |
xg=xg/deno; |
331 |
|
|
yg=yg/deno; |
332 |
|
|
zg=zg/deno; |
333 |
|
|
std::map<double,MG_TRIANGLE*> classetri; |
334 |
|
|
for (int i=0;i<nbtri;i++) |
335 |
|
|
{ |
336 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
337 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
338 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
339 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
340 |
|
|
double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]); |
341 |
|
|
double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]); |
342 |
|
|
double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]); |
343 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
344 |
|
|
classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri)); |
345 |
|
|
} |
346 |
francois |
356 |
if (nbtri>0) |
347 |
|
|
{ |
348 |
|
|
MG_TRIANGLE *tri=classetri.begin()->second; |
349 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
350 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
351 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
352 |
|
|
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])); |
353 |
|
|
point pp; |
354 |
|
|
pp.pts=p; |
355 |
|
|
char mess[255]; |
356 |
|
|
sprintf(mess,"F%lu",face->get_id()); |
357 |
|
|
pp.info=mess; |
358 |
|
|
color cc=color(255-ptr.c.R,255-ptr.c.G,255-ptr.c.B); |
359 |
|
|
std::pair<point,color> tmp(pp,cc); |
360 |
|
|
data.add_text(2,tmp); |
361 |
|
|
} |
362 |
francois |
353 |
} |
363 |
francois |
351 |
|
364 |
|
|
|
365 |
|
|
for (it=list_arete.begin();it!=list_arete.end();it++) |
366 |
|
|
{ |
367 |
|
|
groupe_couleur gc=it->second; |
368 |
|
|
properties ptr=data.getproplines(); |
369 |
|
|
ptr.c=tabcoul[gc.num]; |
370 |
|
|
ptr.thickness=5; |
371 |
|
|
data.setproplines(ptr); |
372 |
|
|
std::map<unsigned long,unsigned long>::iterator it2; |
373 |
|
|
std::map<unsigned long,unsigned long> *tmp; |
374 |
|
|
if (A==true) tmp=&(gc.A); |
375 |
|
|
else tmp=&(gc.B); |
376 |
|
|
|
377 |
|
|
for (it2=tmp->begin();it2!=tmp->end();it2++) |
378 |
|
|
{ |
379 |
|
|
MG_ARETE* are=geo->get_mg_areteid(it2->second); |
380 |
|
|
affiche[are->get_id()]=true; |
381 |
|
|
int nbseg=are->get_lien_maillage()->get_nb(); |
382 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
383 |
francois |
351 |
for (int i=0;i<nbseg;i++) |
384 |
|
|
{ |
385 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
386 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
387 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
388 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
389 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
390 |
|
|
line li; |
391 |
|
|
li.pts[0]=p1; |
392 |
|
|
li.pts[1]=p2; |
393 |
|
|
data.add_line(li); |
394 |
francois |
353 |
OT_VECTEUR_3D vec(xyz1,xyz2); |
395 |
|
|
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur(); |
396 |
|
|
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur(); |
397 |
|
|
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur(); |
398 |
|
|
deno=deno+vec.get_longueur(); |
399 |
francois |
351 |
} |
400 |
francois |
353 |
xg=xg/deno; |
401 |
|
|
yg=yg/deno; |
402 |
|
|
zg=zg/deno; |
403 |
|
|
std::map<double,MG_SEGMENT*> classeseg; |
404 |
|
|
for (int i=0;i<nbseg;i++) |
405 |
|
|
{ |
406 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
407 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
408 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
409 |
|
|
double x=0.5*(xyz1[0]+xyz2[0]); |
410 |
|
|
double y=0.5*(xyz1[1]+xyz2[1]); |
411 |
|
|
double z=0.5*(xyz1[2]+xyz2[2]); |
412 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
413 |
|
|
classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg)); |
414 |
|
|
} |
415 |
francois |
356 |
if (nbseg>0) |
416 |
|
|
{ |
417 |
|
|
MG_SEGMENT* seg=classeseg.begin()->second; |
418 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
419 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
420 |
|
|
npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2])); |
421 |
|
|
point pp; |
422 |
|
|
pp.pts=p; |
423 |
|
|
char mess[255]; |
424 |
|
|
sprintf(mess,"E%lu",are->get_id()); |
425 |
|
|
pp.info=mess; |
426 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
427 |
|
|
std::pair<point,color> tmp(pp,cc); |
428 |
|
|
data.add_text(1,tmp); |
429 |
|
|
} |
430 |
francois |
351 |
} |
431 |
|
|
} |
432 |
|
|
ptr=data.getproplines(); |
433 |
francois |
353 |
ptr.c=color(255-base.R,255-base.G,255-base.B); |
434 |
francois |
351 |
ptr.thickness=2; |
435 |
|
|
data.setproplines(ptr); |
436 |
|
|
LISTE_MG_ARETE::iterator itare; |
437 |
|
|
for (MG_ARETE* are=geo->get_premier_arete(itare);are!=NULL;are=geo->get_suivant_arete(itare)) |
438 |
|
|
{ |
439 |
|
|
if (affiche[are->get_id()]==true) continue; |
440 |
|
|
affiche[are->get_id()]=true; |
441 |
|
|
int nbseg=are->get_lien_maillage()->get_nb(); |
442 |
francois |
353 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
443 |
|
|
for (int i=0;i<nbseg;i++) |
444 |
francois |
351 |
{ |
445 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
446 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
447 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
448 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
449 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
450 |
|
|
line li; |
451 |
|
|
li.pts[0]=p1; |
452 |
|
|
li.pts[1]=p2; |
453 |
|
|
data.add_line(li); |
454 |
francois |
353 |
OT_VECTEUR_3D vec(xyz1,xyz2); |
455 |
|
|
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur(); |
456 |
|
|
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur(); |
457 |
|
|
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur(); |
458 |
|
|
deno=deno+vec.get_longueur(); |
459 |
francois |
351 |
} |
460 |
francois |
353 |
xg=xg/deno; |
461 |
|
|
yg=yg/deno; |
462 |
|
|
zg=zg/deno; |
463 |
|
|
std::map<double,MG_SEGMENT*> classeseg; |
464 |
|
|
for (int i=0;i<nbseg;i++) |
465 |
|
|
{ |
466 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
467 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
468 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
469 |
|
|
double x=0.5*(xyz1[0]+xyz2[0]); |
470 |
|
|
double y=0.5*(xyz1[1]+xyz2[1]); |
471 |
|
|
double z=0.5*(xyz1[2]+xyz2[2]); |
472 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
473 |
|
|
classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg)); |
474 |
|
|
} |
475 |
francois |
356 |
if (nbseg>0) |
476 |
|
|
{ |
477 |
|
|
MG_SEGMENT* seg=classeseg.begin()->second; |
478 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
479 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
480 |
|
|
npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2])); |
481 |
|
|
point pp; |
482 |
|
|
pp.pts=p; |
483 |
|
|
char mess[255]; |
484 |
|
|
sprintf(mess,"E%lu",are->get_id()); |
485 |
|
|
pp.info=mess; |
486 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
487 |
|
|
std::pair<point,color> tmp(pp,cc); |
488 |
|
|
data.add_text(1,tmp); |
489 |
|
|
} |
490 |
francois |
353 |
} |
491 |
francois |
351 |
|
492 |
|
|
|
493 |
|
|
for (it=list_sommet.begin();it!=list_sommet.end();it++) |
494 |
|
|
{ |
495 |
|
|
groupe_couleur gc=it->second; |
496 |
|
|
properties ptr=data.getproppoints(); |
497 |
|
|
ptr.c=tabcoul[gc.num]; |
498 |
|
|
ptr.pointsize=15; |
499 |
|
|
data.setproppoints(ptr); |
500 |
|
|
std::map<unsigned long,unsigned long>::iterator it2; |
501 |
|
|
std::map<unsigned long,unsigned long> *tmp; |
502 |
|
|
if (A==true) tmp=&(gc.A); |
503 |
|
|
else tmp=&(gc.B); |
504 |
|
|
|
505 |
|
|
for (it2=tmp->begin();it2!=tmp->end();it2++) |
506 |
|
|
{ |
507 |
|
|
MG_SOMMET* som=geo->get_mg_sommetid(it2->second); |
508 |
|
|
affiche[som->get_id()]=true; |
509 |
|
|
int nbpoint=som->get_lien_maillage()->get_nb(); |
510 |
|
|
for (int i=0;i<nbpoint;i++) |
511 |
|
|
{ |
512 |
|
|
MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i); |
513 |
|
|
double *xyz1=nd->get_coord(); |
514 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
515 |
|
|
data.add_point(p1); |
516 |
francois |
353 |
point pp; |
517 |
|
|
pp.pts=p1; |
518 |
|
|
char mess[255]; |
519 |
|
|
sprintf(mess,"V%lu",som->get_id()); |
520 |
|
|
pp.info=mess; |
521 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
522 |
|
|
std::pair<point,color> tmp(pp,cc); |
523 |
|
|
data.add_text(0,tmp); |
524 |
francois |
351 |
} |
525 |
|
|
} |
526 |
|
|
} |
527 |
|
|
ptr=data.getproppoints(); |
528 |
francois |
353 |
ptr.c=color(255-base.R,255-base.G,255-base.B); |
529 |
francois |
351 |
ptr.pointsize=4; |
530 |
|
|
|
531 |
|
|
data.setproppoints(ptr); |
532 |
|
|
LISTE_MG_SOMMET::iterator itsom; |
533 |
|
|
for (MG_SOMMET* som=geo->get_premier_sommet(itsom);som!=NULL;som=geo->get_suivant_sommet(itsom)) |
534 |
|
|
{ |
535 |
|
|
if (affiche[som->get_id()]==true) continue; |
536 |
|
|
affiche[som->get_id()]=true; |
537 |
|
|
int nbpoint=som->get_lien_maillage()->get_nb(); |
538 |
|
|
for (int i=0;i<nbpoint;i++) |
539 |
|
|
{ |
540 |
|
|
MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i); |
541 |
|
|
double *xyz1=nd->get_coord(); |
542 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
543 |
|
|
data.add_point(p1); |
544 |
francois |
353 |
point pp; |
545 |
|
|
pp.pts=p1; |
546 |
|
|
char mess[255]; |
547 |
|
|
sprintf(mess,"V%lu",som->get_id()); |
548 |
|
|
pp.info=mess; |
549 |
|
|
color cc=color(ptr.c.R,ptr.c.G,ptr.c.B); |
550 |
|
|
std::pair<point,color> tmp(pp,cc); |
551 |
|
|
data.add_text(0,tmp); |
552 |
francois |
351 |
} |
553 |
|
|
|
554 |
|
|
} |
555 |
|
|
|
556 |
|
|
|
557 |
|
|
|
558 |
|
|
}; |
559 |
|
|
|
560 |
|
|
|
561 |
|
|
|
562 |
|
|
|
563 |
|
|
|
564 |
|
|
|
565 |
|
|
|
566 |
francois |
1157 |
|
567 |
francois |
351 |
int main(int argc,char **argv) |
568 |
|
|
{ |
569 |
francois |
353 |
color base=color(0,0,0); |
570 |
|
|
char chemin[1000]; |
571 |
|
|
sprintf(chemin,"%s/.vtkdisplay",getenv("HOME")); |
572 |
|
|
FILE *in=fopen(chemin,"rt"); |
573 |
|
|
if (in!=NULL) |
574 |
|
|
{ |
575 |
|
|
char mess[255]; |
576 |
|
|
fgets(mess,255,in); |
577 |
|
|
int R,G,B; |
578 |
|
|
sscanf(mess,"%d %d %d",&R,&G,&B); |
579 |
|
|
base=color(R,G,B); |
580 |
|
|
fclose(in); |
581 |
|
|
} |
582 |
francois |
351 |
printf("******************************\n"); |
583 |
|
|
printf("* Comparison visualization *\n"); |
584 |
|
|
printf("* by *\n"); |
585 |
|
|
printf("* Jean-Christophe Cuillière *\n"); |
586 |
|
|
printf("* and *\n"); |
587 |
|
|
printf("* Vincent Francois *\n"); |
588 |
|
|
printf("* ERICCA-UQTR *\n"); |
589 |
|
|
printf("******************************\n\n\n"); |
590 |
francois |
375 |
GESTIONVERSION v; |
591 |
|
|
char version[500]; |
592 |
|
|
v.print(version); |
593 |
|
|
affiche(version); |
594 |
francois |
351 |
if (argc!=4) |
595 |
|
|
{ |
596 |
francois |
1061 |
printf("Visucompare syntax error - Bad number arguments \n visucompare.exe A|B S|M|I|L nom_fichier_resultat_comparaison\n\n"); |
597 |
francois |
351 |
return 0; |
598 |
|
|
|
599 |
|
|
} |
600 |
|
|
if (!((strcmp(argv[1],"A")==0) || (strcmp(argv[1],"B")==0))) |
601 |
|
|
{ |
602 |
|
|
printf("Visucompare syntax error - first argument not valid : %s\n\n",argv[1]); |
603 |
|
|
return 0; |
604 |
|
|
|
605 |
|
|
} |
606 |
|
|
|
607 |
|
|
if (!( (strcmp(argv[2],"S")==0) || (strcmp(argv[2],"M")==0) || (strcmp(argv[2],"I")==0)|| (strcmp(argv[2],"L")==0) )) |
608 |
|
|
{ |
609 |
|
|
printf("Visucompare syntax error - Second argument not valid : %s\n\n",argv[2]); |
610 |
|
|
return 0; |
611 |
|
|
|
612 |
|
|
} |
613 |
|
|
|
614 |
|
|
|
615 |
|
|
std::map<int,groupe_couleur> list_vide; |
616 |
|
|
std::vector<color> tabcoul; |
617 |
|
|
ini_couleur(tabcoul,10); |
618 |
|
|
|
619 |
|
|
data_fichier df; |
620 |
|
|
lire_fichier(argv[3],df); |
621 |
|
|
bool A; |
622 |
francois |
363 |
#if _COMPARESTEP_ |
623 |
couturad |
944 |
MG_GESTIONNAIRE gest=NULL; |
624 |
francois |
363 |
if (strcmp(argv[1],"A")==0) |
625 |
|
|
{ |
626 |
|
|
printf("Reading file A\n"); |
627 |
|
|
OCC_IMPORT occimport; |
628 |
|
|
MG_GEOMETRIE* geo1=occimport.importer(gest,(char*)df.nomA.c_str(),FICHIERSTEP,1.,1e-6); |
629 |
|
|
A=true; |
630 |
|
|
} |
631 |
|
|
else if (strcmp(argv[1],"B")==0) |
632 |
|
|
{ |
633 |
|
|
printf("Reading file B\n"); |
634 |
|
|
OCC_IMPORT occimport; |
635 |
|
|
MG_GEOMETRIE* geo2=occimport.importer(gest,(char*)df.nomB.c_str(),FICHIERSTEP,1.,1e-6); |
636 |
|
|
A=false; |
637 |
|
|
} |
638 |
|
|
#else |
639 |
couturad |
944 |
MG_FILE *gest=NULL; |
640 |
francois |
363 |
if (strcmp(argv[1],"A")==0) {printf("Reading file A\n");gest=new MG_FILE((char*)df.nomA.c_str());A=true;} |
641 |
|
|
else if (strcmp(argv[1],"B")==0) {printf("Reading file B\n");gest=new MG_FILE((char*)df.nomB.c_str());A=false;} |
642 |
|
|
#endif |
643 |
francois |
351 |
printf(" Number of color group :\n"); |
644 |
francois |
479 |
if (strcmp(argv[2],"S")==0) printf(" Similar faces : %d Visible\n",(int)df.list_face_similaire.size()); else printf(" Similar faces : %d\n",(int)df.list_face_similaire.size()); |
645 |
|
|
if (strcmp(argv[2],"I")==0) printf(" Identical faces : %d Visible\n",(int)df.list_face_identique.size()); else printf(" Identical faces : %d\n",(int)df.list_face_identique.size()); |
646 |
|
|
if (strcmp(argv[2],"L")==0) printf(" Localized faces : %d Visible\n",(int)df.list_face_localise.size()); else printf(" Localized faces : %d\n",(int)df.list_face_localise.size()); |
647 |
|
|
if (strcmp(argv[2],"L")==0) printf(" Localized edges : %d Visible\n",(int)df.list_arete_localise.size()); else printf(" Localized faces : %d\n",(int)df.list_face_localise.size()); |
648 |
|
|
if (strcmp(argv[2],"L")==0) printf(" Localized vertices : %d Visible\n",(int)df.list_sommet_localise.size()); else printf(" Localized faces : %d\n",(int)df.list_face_localise.size()); |
649 |
|
|
if (strcmp(argv[2],"M")==0) printf(" Modified faces : %d Visible\n",(int)df.list_face_modifie.size()); else printf(" Modified faces : %d \n",(int)df.list_face_modifie.size()); |
650 |
|
|
if (strcmp(argv[2],"M")==0) printf(" Modified edges : %d Visible\n",(int)df.list_arete_modifie.size()); else printf(" Modified edges : %d\n",(int)df.list_arete_modifie.size()); |
651 |
francois |
351 |
|
652 |
francois |
363 |
#ifdef _COMPARESTEP_ |
653 |
|
|
MG_GEOMETRIE* geo=gest.get_mg_geometrie(0); |
654 |
|
|
#else |
655 |
francois |
351 |
MG_GEOMETRIE* geo=gest->get_mg_geometrie(0); |
656 |
francois |
363 |
#endif |
657 |
francois |
351 |
data_container data; |
658 |
|
|
|
659 |
|
|
|
660 |
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); |
661 |
|
|
if (strcmp(argv[2],"I")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_identique,list_vide,list_vide); |
662 |
|
|
if (strcmp(argv[2],"S")==0) affiche_structure(base,geo,A,tabcoul,data,df.list_face_similaire,list_vide,list_vide); |
663 |
|
|
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); |
664 |
|
|
|
665 |
|
|
printf("\n\n"); |
666 |
|
|
printf("Command on keyboard : \n"); |
667 |
|
|
printf(" e : End of vizualisation\n"); |
668 |
|
|
printf(" r : Reset Camera\n"); |
669 |
|
|
printf(" 1 : Vertex Numbers visible on/off\n"); |
670 |
|
|
printf(" 4 : Edge Numbers visible on/off\n"); |
671 |
|
|
printf(" 7 : Face Numbers visible on/off\n"); |
672 |
|
|
printf(" v : Vertices visible on/off\n"); |
673 |
|
|
printf(" l : Edges visible on/off\n"); |
674 |
|
|
printf(" t : Faces visible on/off\n"); |
675 |
|
|
printf(" j : Save camera on current directory\n"); |
676 |
|
|
printf(" k : Load camera from current directory\n"); |
677 |
|
|
printf(" w : Wireframe\n"); |
678 |
|
|
printf(" s : Modelframe\n"); |
679 |
francois |
358 |
printf(" - : Decrease text size\n"); |
680 |
|
|
printf(" + : Increase text size\n"); |
681 |
francois |
351 |
char titre [255]; |
682 |
|
|
strcpy(titre,"Visucompare File "); |
683 |
|
|
strcat(titre,argv[1]); |
684 |
|
|
strcat(titre," "); |
685 |
|
|
strcat(titre,argv[2]); |
686 |
|
|
strcat(titre," "); |
687 |
|
|
strcat(titre,argv[3]); |
688 |
|
|
|
689 |
|
|
|
690 |
francois |
363 |
#ifndef _COMPARESTEP_ |
691 |
francois |
351 |
delete gest; |
692 |
francois |
363 |
#endif |
693 |
francois |
1061 |
vtkdisplay d(base,titre); |
694 |
francois |
351 |
|
695 |
|
|
|
696 |
|
|
|
697 |
|
|
|
698 |
|
|
d.init_data(data); |
699 |
francois |
1018 |
d.display(); |
700 |
francois |
351 |
|
701 |
|
|
return 0; |
702 |
|
|
} |
703 |
|
|
|
704 |
|
|
|
705 |
|
|
|
706 |
|
|
#pragma package(smart_init) |