1 |
//------------------------------------------------------------ |
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 |
|
25 |
#include <iostream> |
26 |
#include "vtkdisplay.h" |
27 |
#include "ndata.h" |
28 |
#include "mg_file.h" |
29 |
#include "occ_import.h" |
30 |
#include <map> |
31 |
//--------------------------------------------------------------------------- |
32 |
|
33 |
void affiche(char* message) |
34 |
{ |
35 |
std::cout << message << std::endl; |
36 |
|
37 |
} |
38 |
|
39 |
|
40 |
|
41 |
|
42 |
void affiche_structure(color cface,color carete,color ctext,color cdeplacement,color cforce,color cpression,color ctemperature, color cflux,MG_MAILLAGE* mai,data_container &data) |
43 |
{ |
44 |
std::vector<color> tabcouleur; |
45 |
color one(191,253,181); |
46 |
color two(255,160,0); |
47 |
color three(253,35,16); |
48 |
color four(255,200,0); |
49 |
color five(0,216,255); |
50 |
color six(0,52,255); |
51 |
color seven(0,176,255); |
52 |
color eight(228,255,0); |
53 |
color nine(0,116,255); |
54 |
color ten(188,255,0); |
55 |
color eleven(184,0,255); |
56 |
color twelve(255,120,0); |
57 |
tabcouleur.push_back(one); |
58 |
tabcouleur.push_back(two); |
59 |
tabcouleur.push_back(three); |
60 |
tabcouleur.push_back(four); |
61 |
tabcouleur.push_back(five); |
62 |
tabcouleur.push_back(six); |
63 |
tabcouleur.push_back(seven); |
64 |
tabcouleur.push_back(eight); |
65 |
tabcouleur.push_back(nine); |
66 |
tabcouleur.push_back(ten); |
67 |
tabcouleur.push_back(eleven); |
68 |
tabcouleur.push_back(twelve); |
69 |
|
70 |
|
71 |
properties ptr=data.getproptriangles(); |
72 |
ptr.c=cface; |
73 |
ptr.edgeon=true; |
74 |
ptr.edgecolor=carete; |
75 |
ptr.edgethickness=1; |
76 |
data.setproptriangles(ptr); |
77 |
LISTE_MG_TRIANGLE::iterator ittri; |
78 |
for (MG_TRIANGLE* tri=mai->get_premier_triangle(ittri);tri!=NULL;tri=mai->get_suivant_triangle(ittri)) |
79 |
{ |
80 |
properties ptr=data.getproptriangles(); |
81 |
|
82 |
ptr.c=tabcouleur[(tri->get_origine()-1000)/10]; |
83 |
data.setproptriangles(ptr); |
84 |
double *xyz1=tri->get_noeud1()->get_coord(); |
85 |
double *xyz2=tri->get_noeud2()->get_coord(); |
86 |
double *xyz3=tri->get_noeud3()->get_coord(); |
87 |
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
88 |
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
89 |
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
90 |
triangle tr; |
91 |
tr.pts[0]=p1; |
92 |
tr.pts[1]=p2; |
93 |
tr.pts[2]=p3; |
94 |
data.add_triangle(tr); |
95 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
96 |
OT_VECTEUR_3D vec2(xyz1,xyz3); |
97 |
OT_VECTEUR_3D sur=vec1&vec2; |
98 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
99 |
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
100 |
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
101 |
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
102 |
deno=deno+sur.get_longueur(); |
103 |
xg=xg/deno; |
104 |
yg=yg/deno; |
105 |
zg=zg/deno; |
106 |
npoint p(xg,yg,zg); |
107 |
point pp; |
108 |
pp.pts=p; |
109 |
char mess[255]; |
110 |
sprintf(mess,"%lu",tri->get_id()); |
111 |
pp.info=mess; |
112 |
std::pair<point,color> tmp(pp,ctext); |
113 |
//data.add_text(2,tmp); |
114 |
} |
115 |
|
116 |
ptr=data.getpropquads(); |
117 |
ptr.c=cface; |
118 |
ptr.edgeon=true; |
119 |
ptr.edgecolor=carete; |
120 |
ptr.edgethickness=1; |
121 |
data.setpropquads(ptr); |
122 |
LISTE_MG_QUADRANGLE::iterator itqua; |
123 |
for (MG_QUADRANGLE* qua=mai->get_premier_quadrangle(itqua);qua!=NULL;qua=mai->get_suivant_quadrangle(itqua)) |
124 |
{ |
125 |
properties ptr=data.getpropquads(); |
126 |
|
127 |
ptr.c=tabcouleur[(qua->get_origine()-1000)/10]; |
128 |
data.setpropquads(ptr); |
129 |
double *xyz1=qua->get_noeud1()->get_coord(); |
130 |
double *xyz2=qua->get_noeud2()->get_coord(); |
131 |
double *xyz3=qua->get_noeud3()->get_coord(); |
132 |
double *xyz4=qua->get_noeud4()->get_coord(); |
133 |
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
134 |
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
135 |
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
136 |
npoint p4(xyz4[0],xyz4[1],xyz4[2]); |
137 |
quad qu; |
138 |
qu.pts[0]=p1; |
139 |
qu.pts[1]=p2; |
140 |
qu.pts[2]=p3; |
141 |
qu.pts[3]=p4; |
142 |
data.add_quad(qu); |
143 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
144 |
OT_VECTEUR_3D vec2(xyz1,xyz3); |
145 |
OT_VECTEUR_3D sur=vec1&vec2; |
146 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
147 |
xg=xg+0.25*(xyz1[0]+xyz2[0]+xyz3[0]+xyz4[0])*sur.get_longueur(); |
148 |
yg=yg+0.25*(xyz1[1]+xyz2[1]+xyz3[1]+xyz4[1])*sur.get_longueur(); |
149 |
zg=zg+0.25*(xyz1[2]+xyz2[2]+xyz3[2]+xyz4[2])*sur.get_longueur(); |
150 |
deno=deno+sur.get_longueur(); |
151 |
xg=xg/deno; |
152 |
yg=yg/deno; |
153 |
zg=zg/deno; |
154 |
npoint p(xg,yg,zg); |
155 |
point pp; |
156 |
pp.pts=p; |
157 |
char mess[255]; |
158 |
sprintf(mess,"%lu",qua->get_id()); |
159 |
pp.info=mess; |
160 |
std::pair<point,color> tmp(pp,ctext); |
161 |
//data.add_text(2,tmp); |
162 |
} |
163 |
|
164 |
ptr=data.getproplines(); |
165 |
ptr.c=carete; |
166 |
ptr.edgethickness=2; |
167 |
data.setproplines(ptr); |
168 |
LISTE_MG_SEGMENT::iterator itseg; |
169 |
for (MG_SEGMENT* seg=mai->get_premier_segment(itseg);seg!=NULL;seg=mai->get_suivant_segment(itseg)) |
170 |
{ |
171 |
if (seg->get_lien_topologie()!=NULL) |
172 |
if (seg->get_lien_topologie()->get_dimension()!=1) continue; |
173 |
properties ptr=data.getproplines(); |
174 |
ptr.c=tabcouleur[(seg->get_origine()-1000)/10]; |
175 |
data.setproplines(ptr); |
176 |
double *xyz1=seg->get_noeud1()->get_coord(); |
177 |
double *xyz2=seg->get_noeud2()->get_coord(); |
178 |
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
179 |
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
180 |
line li; |
181 |
li.pts[0]=p1; |
182 |
li.pts[1]=p2; |
183 |
data.add_line(li); |
184 |
OT_VECTEUR_3D vec1(xyz1,xyz2); |
185 |
double xg=0.,yg=0.,zg=0.,deno=0.; |
186 |
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec1.get_longueur(); |
187 |
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec1.get_longueur(); |
188 |
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec1.get_longueur(); |
189 |
deno=deno+vec1.get_longueur(); |
190 |
xg=xg/deno; |
191 |
yg=yg/deno; |
192 |
zg=zg/deno; |
193 |
npoint p(xg,yg,zg); |
194 |
point pp; |
195 |
pp.pts=p; |
196 |
char mess[255]; |
197 |
sprintf(mess,"%lu",seg->get_id()); |
198 |
pp.info=mess; |
199 |
std::pair<point,color> tmp(pp,ctext); |
200 |
//data.add_text(1,tmp); |
201 |
} |
202 |
|
203 |
|
204 |
|
205 |
ptr=data.getproppoints(); |
206 |
ptr.pointsize=10; |
207 |
data.setproppoints(ptr); |
208 |
LISTE_MG_NOEUD::iterator itno; |
209 |
for (MG_NOEUD* no=mai->get_premier_noeud(itno);no!=NULL;no=mai->get_suivant_noeud(itno)) |
210 |
{ |
211 |
properties ptr=data.getproppoints(); |
212 |
ptr.c=tabcouleur[(no->get_origine()-1000)/10]; |
213 |
data.setproppoints(ptr); |
214 |
double *xyz=no->get_coord(); |
215 |
npoint p1(xyz[0],xyz[1],xyz[2]); |
216 |
data.add_point(p1); |
217 |
char mess[255]; |
218 |
sprintf(mess,"%lu",no->get_id()); |
219 |
point pp; |
220 |
pp.pts=p1; |
221 |
pp.info=mess; |
222 |
std::pair<point,color> tmp(pp,ctext); |
223 |
//data.add_text(0,tmp); |
224 |
} |
225 |
|
226 |
}; |
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
int main(int argc,char **argv) |
236 |
|
237 |
{ |
238 |
color base=color(0,0,0); |
239 |
color carete(255,255,255); |
240 |
color cface(125,125,125); |
241 |
color ctext(255,255,255); |
242 |
color cdeplacement(255,151,1); |
243 |
color cforce(255,1,1); |
244 |
color cpression(33,249,13); |
245 |
color ctemperature(246,07,193); |
246 |
color cflux(252,250,03); |
247 |
|
248 |
char chemin[1000]; |
249 |
sprintf(chemin,"%s/.vtkdisplay",getenv("HOME")); |
250 |
FILE *in=fopen(chemin,"rt"); |
251 |
if (in!=NULL) |
252 |
{ |
253 |
char mess[255]; |
254 |
fgets(mess,255,in); |
255 |
int R,G,B; |
256 |
int nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
257 |
if (nb==3) base=color(R,G,B); |
258 |
if (!feof(in)) |
259 |
{ |
260 |
fgets(mess,255,in); |
261 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
262 |
if (nb==3) cface=color(R,G,B); |
263 |
if (!feof(in)) |
264 |
{ |
265 |
fgets(mess,255,in); |
266 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
267 |
if (nb==3) carete=color(R,G,B); |
268 |
if (!feof(in)) |
269 |
{ |
270 |
fgets(mess,255,in); |
271 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
272 |
if (nb==3) ctext=color(R,G,B); |
273 |
if (!feof(in)) |
274 |
{ |
275 |
fgets(mess,255,in); |
276 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
277 |
if (nb==3) cdeplacement=color(R,G,B); |
278 |
if (!feof(in)) |
279 |
{ |
280 |
fgets(mess,255,in); |
281 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
282 |
if (nb==3) cforce=color(R,G,B); |
283 |
if (!feof(in)) |
284 |
{ |
285 |
fgets(mess,255,in); |
286 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
287 |
if (nb==3) cpression=color(R,G,B); |
288 |
if (!feof(in)) |
289 |
{ |
290 |
fgets(mess,255,in); |
291 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
292 |
if (nb==3) ctemperature=color(R,G,B); |
293 |
if (!feof(in)) |
294 |
{ |
295 |
fgets(mess,255,in); |
296 |
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
297 |
if (nb==3) cflux=color(R,G,B); |
298 |
|
299 |
} |
300 |
} |
301 |
|
302 |
} |
303 |
|
304 |
} |
305 |
} |
306 |
} |
307 |
} |
308 |
} |
309 |
fclose(in); |
310 |
} |
311 |
printf("******************************\n"); |
312 |
printf("* Origine Visualization *\n"); |
313 |
printf("* by *\n"); |
314 |
printf("* Jean-Christophe Cuillière *\n"); |
315 |
printf("* and *\n"); |
316 |
printf("* Vincent Francois *\n"); |
317 |
printf("* ERICCA-UQTR *\n"); |
318 |
printf("******************************\n\n\n"); |
319 |
|
320 |
|
321 |
|
322 |
if (!((argc==2) || (argc==3))) |
323 |
{ |
324 |
printf("Visumagic syntax error - Bad number arguments\n visuorigine.exe fichier [numero du maillage]\n\n"); |
325 |
return 0; |
326 |
|
327 |
} |
328 |
char fichier[255]; |
329 |
strcpy(fichier,argv[1]); |
330 |
|
331 |
char *p=strchr(fichier,'.'); |
332 |
char extension[255]; |
333 |
strcpy(extension,p+1); |
334 |
|
335 |
MG_GESTIONNAIRE *gest; |
336 |
MG_FILE* gest2=new MG_FILE(fichier); |
337 |
gest=gest2; |
338 |
|
339 |
|
340 |
int num=0; |
341 |
if (argc==3) num=atoi(argv[2]); |
342 |
data_container data; |
343 |
MG_MAILLAGE* mai=gest->get_mg_maillage(num); |
344 |
char titre [500]; |
345 |
printf("\n\n"); |
346 |
printf("Command on keyboard : \n"); |
347 |
printf(" e : End of vizualisation\n"); |
348 |
printf(" r : Reset Camera\n"); |
349 |
printf(" 1 : Vertex Numbers visible on/off\n"); |
350 |
printf(" 4 : Edge Numbers visible on/off\n"); |
351 |
printf(" 7 : Face Numbers visible on/off\n"); |
352 |
printf(" v : Vertices visible on/off\n"); |
353 |
printf(" l : Edges visible on/off\n"); |
354 |
printf(" t : Faces visible on/off\n"); |
355 |
printf(" j : Save camera on current directory\n"); |
356 |
printf(" k : Load camera from current directory\n"); |
357 |
printf(" w : Wireframe\n"); |
358 |
printf(" s : Modelframe\n"); |
359 |
printf(" - : Decrease text size\n"); |
360 |
printf(" + : Increase text size\n"); |
361 |
printf(" 5 : Clipping plane off\n"); |
362 |
printf(" 8 : Clipping plane forward\n"); |
363 |
printf(" 9 : Clipping plane backward\n"); |
364 |
|
365 |
strcpy(titre,"Visuorimagic "); |
366 |
strcat(titre,fichier); |
367 |
if (mai!=NULL) affiche_structure(cface,carete,ctext,cdeplacement,cforce,cpression,ctemperature,cflux,mai,data); |
368 |
delete gest; |
369 |
|
370 |
vtkdisplay d(base,titre); |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
d.init_data(data); |
376 |
d.display(); |
377 |
|
378 |
|
379 |
return 0; |
380 |
} |
381 |
|
382 |
|
383 |
|
384 |
|