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 |
francois |
356 |
#include "occ_import.h" |
34 |
francois |
353 |
#include <map> |
35 |
|
|
//--------------------------------------------------------------------------- |
36 |
|
|
|
37 |
|
|
void affiche(char* message) |
38 |
|
|
{ |
39 |
|
|
#ifdef WINDOWS_VERSION |
40 |
|
|
Form1->Memo1->Lines->Add(message); |
41 |
|
|
#else |
42 |
|
|
std::cout << message << std::endl; |
43 |
|
|
#endif |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
|
|
|
49 |
francois |
358 |
void affiche_structure(color cface,color carete,color ctext,MG_GEOMETRIE* geo,MG_MAILLAGE* mai,data_container &data,bool idori) |
50 |
francois |
353 |
{ |
51 |
|
|
properties ptr=data.getproptriangles(); |
52 |
|
|
ptr.c=cface; |
53 |
|
|
ptr.edgeon=false; |
54 |
|
|
data.setproptriangles(ptr); |
55 |
|
|
LISTE_MG_FACE::iterator itf; |
56 |
|
|
for (MG_FACE* face=geo->get_premier_face(itf);face!=NULL;face=geo->get_suivant_face(itf)) |
57 |
|
|
{ |
58 |
|
|
double xg=0.,yg=0.,zg=0.,deno=0.; |
59 |
|
|
int nbtri=face->get_lien_maillage()->get_nb(); |
60 |
|
|
for (int i=0;i<nbtri;i++) |
61 |
|
|
{ |
62 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
63 |
francois |
358 |
if (mai->get_mg_triangleid(tri->get_id())!=tri) continue; |
64 |
francois |
353 |
double *xyz1=tri->get_noeud1()->get_coord(); |
65 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
66 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
67 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
68 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
69 |
|
|
npoint p3(xyz3[0],xyz3[1],xyz3[2]); |
70 |
|
|
triangle tr; |
71 |
|
|
tr.pts[0]=p1; |
72 |
|
|
tr.pts[1]=p2; |
73 |
|
|
tr.pts[2]=p3; |
74 |
|
|
data.add_triangle(tr); |
75 |
|
|
OT_VECTEUR_3D vec1(xyz1,xyz2); |
76 |
|
|
OT_VECTEUR_3D vec2(xyz1,xyz3); |
77 |
|
|
OT_VECTEUR_3D sur=vec1&vec2; |
78 |
|
|
xg=xg+0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0])*sur.get_longueur(); |
79 |
|
|
yg=yg+0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1])*sur.get_longueur(); |
80 |
|
|
zg=zg+0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2])*sur.get_longueur(); |
81 |
|
|
deno=deno+sur.get_longueur(); |
82 |
|
|
} |
83 |
|
|
xg=xg/deno; |
84 |
|
|
yg=yg/deno; |
85 |
|
|
zg=zg/deno; |
86 |
|
|
std::map<double,MG_TRIANGLE*> classetri; |
87 |
|
|
for (int i=0;i<nbtri;i++) |
88 |
|
|
{ |
89 |
|
|
MG_TRIANGLE* tri=(MG_TRIANGLE*)face->get_lien_maillage()->get(i); |
90 |
francois |
358 |
if (mai->get_mg_triangleid(tri->get_id())!=tri) continue; |
91 |
francois |
353 |
double *xyz1=tri->get_noeud1()->get_coord(); |
92 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
93 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
94 |
|
|
double x=0.3333333333*(xyz1[0]+xyz2[0]+xyz3[0]); |
95 |
|
|
double y=0.3333333333*(xyz1[1]+xyz2[1]+xyz3[1]); |
96 |
|
|
double z=0.3333333333*(xyz1[2]+xyz2[2]+xyz3[2]); |
97 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
98 |
|
|
classetri.insert(std::pair<double,MG_TRIANGLE*>(vec.get_longueur2(),tri)); |
99 |
|
|
} |
100 |
francois |
358 |
if (classetri.size()>0) |
101 |
francois |
356 |
{ |
102 |
|
|
MG_TRIANGLE *tri=classetri.begin()->second; |
103 |
|
|
double *xyz1=tri->get_noeud1()->get_coord(); |
104 |
|
|
double *xyz2=tri->get_noeud2()->get_coord(); |
105 |
|
|
double *xyz3=tri->get_noeud3()->get_coord(); |
106 |
|
|
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])); |
107 |
|
|
point pp; |
108 |
|
|
pp.pts=p; |
109 |
|
|
char mess[255]; |
110 |
|
|
if (idori==false) sprintf(mess,"F%lu",face->get_id()); else sprintf(mess,"%s",face->get_idoriginal().c_str()); |
111 |
|
|
pp.info=mess; |
112 |
|
|
std::pair<point,color> tmp(pp,ctext); |
113 |
|
|
data.add_text(2,tmp); |
114 |
|
|
} |
115 |
francois |
353 |
} |
116 |
|
|
|
117 |
|
|
ptr=data.getproplines(); |
118 |
|
|
ptr.c=carete; |
119 |
|
|
ptr.thickness=2; |
120 |
|
|
data.setproplines(ptr); |
121 |
|
|
|
122 |
|
|
LISTE_MG_ARETE::iterator ita; |
123 |
|
|
for (MG_ARETE* are=geo->get_premier_arete(ita);are!=NULL;are=geo->get_suivant_arete(ita)) |
124 |
|
|
{ |
125 |
|
|
int nbseg=are->get_lien_maillage()->get_nb(); |
126 |
|
|
double xg=0.,yg=0.,zg=0.,deno=0.; |
127 |
|
|
for (int i=0;i<nbseg;i++) |
128 |
|
|
{ |
129 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
130 |
francois |
358 |
if (mai->get_mg_segmentid(seg->get_id())!=seg) continue; |
131 |
francois |
353 |
double *xyz1=seg->get_noeud1()->get_coord(); |
132 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
133 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
134 |
|
|
npoint p2(xyz2[0],xyz2[1],xyz2[2]); |
135 |
|
|
line li; |
136 |
|
|
li.pts[0]=p1; |
137 |
|
|
li.pts[1]=p2; |
138 |
|
|
data.add_line(li); |
139 |
|
|
OT_VECTEUR_3D vec(xyz1,xyz2); |
140 |
|
|
xg=xg+0.5*(xyz1[0]+xyz2[0])*vec.get_longueur(); |
141 |
|
|
yg=yg+0.5*(xyz1[1]+xyz2[1])*vec.get_longueur(); |
142 |
|
|
zg=zg+0.5*(xyz1[2]+xyz2[2])*vec.get_longueur(); |
143 |
|
|
deno=deno+vec.get_longueur(); |
144 |
|
|
} |
145 |
|
|
xg=xg/deno; |
146 |
|
|
yg=yg/deno; |
147 |
|
|
zg=zg/deno; |
148 |
|
|
std::map<double,MG_SEGMENT*> classeseg; |
149 |
|
|
for (int i=0;i<nbseg;i++) |
150 |
|
|
{ |
151 |
|
|
MG_SEGMENT* seg=(MG_SEGMENT*)are->get_lien_maillage()->get(i); |
152 |
francois |
358 |
if (mai->get_mg_segmentid(seg->get_id())!=seg) continue; |
153 |
francois |
353 |
double *xyz1=seg->get_noeud1()->get_coord(); |
154 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
155 |
|
|
double x=0.5*(xyz1[0]+xyz2[0]); |
156 |
|
|
double y=0.5*(xyz1[1]+xyz2[1]); |
157 |
|
|
double z=0.5*(xyz1[2]+xyz2[2]); |
158 |
|
|
OT_VECTEUR_3D vec(x-xg,y-yg,z-zg); |
159 |
|
|
classeseg.insert(std::pair<double,MG_SEGMENT*>(vec.get_longueur2(),seg)); |
160 |
|
|
} |
161 |
francois |
358 |
if (classeseg.size()>0) |
162 |
francois |
356 |
{ |
163 |
|
|
MG_SEGMENT* seg=classeseg.begin()->second; |
164 |
|
|
double *xyz1=seg->get_noeud1()->get_coord(); |
165 |
|
|
double *xyz2=seg->get_noeud2()->get_coord(); |
166 |
|
|
npoint p(0.5*(xyz1[0]+xyz2[0]),0.5*(xyz1[1]+xyz2[1]),0.5*(xyz1[2]+xyz2[2])); |
167 |
|
|
point pp; |
168 |
|
|
pp.pts=p; |
169 |
|
|
char mess[255]; |
170 |
|
|
if (idori==false) sprintf(mess,"E%lu",are->get_id()); else sprintf(mess,"%s",are->get_idoriginal().c_str()); |
171 |
|
|
pp.info=mess; |
172 |
|
|
std::pair<point,color> tmp(pp,ctext); |
173 |
|
|
data.add_text(1,tmp); |
174 |
|
|
} |
175 |
francois |
353 |
} |
176 |
|
|
|
177 |
|
|
|
178 |
|
|
ptr=data.getproppoints(); |
179 |
|
|
ptr.c=carete; |
180 |
francois |
358 |
ptr.pointsize=10; |
181 |
francois |
353 |
data.setproppoints(ptr); |
182 |
|
|
LISTE_MG_SOMMET::iterator its; |
183 |
|
|
for (MG_SOMMET* som=geo->get_premier_sommet(its);som!=NULL;som=geo->get_suivant_sommet(its)) |
184 |
|
|
{ |
185 |
|
|
int nbpoint=som->get_lien_maillage()->get_nb(); |
186 |
|
|
for (int i=0;i<nbpoint;i++) |
187 |
|
|
{ |
188 |
|
|
MG_NOEUD* nd=(MG_NOEUD*)som->get_lien_maillage()->get(i); |
189 |
francois |
358 |
if (mai->get_mg_noeudid(nd->get_id())!=nd) continue; |
190 |
francois |
353 |
double *xyz1=nd->get_coord(); |
191 |
|
|
npoint p1(xyz1[0],xyz1[1],xyz1[2]); |
192 |
|
|
data.add_point(p1); |
193 |
|
|
point pp; |
194 |
|
|
pp.pts=p1; |
195 |
|
|
char mess[255]; |
196 |
francois |
356 |
if (idori==false) sprintf(mess,"V%lu",som->get_id()); else sprintf(mess,"%s",som->get_idoriginal().c_str()); |
197 |
francois |
353 |
pp.info=mess; |
198 |
|
|
std::pair<point,color> tmp(pp,ctext); |
199 |
|
|
data.add_text(0,tmp); |
200 |
|
|
} |
201 |
|
|
} |
202 |
|
|
|
203 |
|
|
|
204 |
|
|
|
205 |
|
|
|
206 |
|
|
}; |
207 |
|
|
|
208 |
|
|
|
209 |
|
|
|
210 |
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
|
|
|
214 |
|
|
#ifdef WINDOWS_VERSION |
215 |
|
|
int amain(int argc,char **argv) |
216 |
|
|
#else |
217 |
|
|
int main(int argc,char **argv) |
218 |
|
|
#endif |
219 |
|
|
{ |
220 |
|
|
color base=color(0,0,0); |
221 |
|
|
color carete(255,255,255); |
222 |
|
|
color cface(125,125,125); |
223 |
|
|
color ctext(255,255,255); |
224 |
|
|
char chemin[1000]; |
225 |
|
|
sprintf(chemin,"%s/.vtkdisplay",getenv("HOME")); |
226 |
|
|
FILE *in=fopen(chemin,"rt"); |
227 |
|
|
if (in!=NULL) |
228 |
|
|
{ |
229 |
|
|
char mess[255]; |
230 |
|
|
fgets(mess,255,in); |
231 |
|
|
int R,G,B; |
232 |
|
|
int nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
233 |
|
|
if (nb==3) base=color(R,G,B); |
234 |
|
|
if (!feof(in)) |
235 |
|
|
{ |
236 |
|
|
fgets(mess,255,in); |
237 |
|
|
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
238 |
|
|
if (nb==3) cface=color(R,G,B); |
239 |
|
|
if (!feof(in)) |
240 |
|
|
{ |
241 |
|
|
fgets(mess,255,in); |
242 |
|
|
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
243 |
|
|
if (nb==3) carete=color(R,G,B); |
244 |
|
|
if (!feof(in)) |
245 |
|
|
{ |
246 |
|
|
fgets(mess,255,in); |
247 |
|
|
nb=sscanf(mess,"%d %d %d",&R,&G,&B); |
248 |
|
|
if (nb==3) ctext=color(R,G,B); |
249 |
|
|
} |
250 |
|
|
} |
251 |
|
|
} |
252 |
|
|
fclose(in); |
253 |
|
|
} |
254 |
|
|
printf("******************************\n"); |
255 |
|
|
printf("* Visualization *\n"); |
256 |
|
|
printf("* by *\n"); |
257 |
|
|
printf("* Jean-Christophe Cuillière *\n"); |
258 |
|
|
printf("* and *\n"); |
259 |
|
|
printf("* Vincent Francois *\n"); |
260 |
|
|
printf("* ERICCA-UQTR *\n"); |
261 |
|
|
printf("******************************\n\n\n"); |
262 |
|
|
|
263 |
francois |
356 |
|
264 |
|
|
|
265 |
cuillier |
354 |
if (!((argc==2) || (argc==3))) |
266 |
francois |
353 |
{ |
267 |
|
|
printf("Visumagic syntax error - Bad number arguments\n\n"); |
268 |
|
|
return 0; |
269 |
|
|
|
270 |
|
|
} |
271 |
francois |
356 |
char fichier[255]; |
272 |
|
|
strcpy(fichier,argv[1]); |
273 |
|
|
|
274 |
|
|
char *p=strchr(fichier,'.'); |
275 |
|
|
char extension[255]; |
276 |
|
|
strcpy(extension,p+1); |
277 |
|
|
|
278 |
|
|
bool idori; |
279 |
|
|
MG_GESTIONNAIRE *gest; |
280 |
|
|
if ((strcmp(extension,"step")==0) || (strcmp(extension,"stp")==0) || (strcmp(extension,"STP")==0) || (strcmp(extension,"STEP")==0)) |
281 |
|
|
{ |
282 |
|
|
MG_GESTIONNAIRE *gest2=new MG_GESTIONNAIRE; |
283 |
|
|
OCC_IMPORT occimport; |
284 |
|
|
MG_GEOMETRIE* mggeo=occimport.importer(*gest2,fichier,FICHIERSTEP,0.001,1e-6) ; |
285 |
|
|
occimport.importer(*gest2,mggeo,1,2); |
286 |
|
|
gest=gest2; |
287 |
francois |
358 |
idori=false; |
288 |
|
|
if (strcmp(argv[argc-1],"-s")==0) |
289 |
|
|
{ |
290 |
|
|
*(p+1)='m'; |
291 |
|
|
*(p+2)='a'; |
292 |
|
|
*(p+3)='g'; |
293 |
|
|
*(p+4)='i'; |
294 |
|
|
*(p+5)='c'; |
295 |
|
|
*(p+6)=0; |
296 |
|
|
gest->enregistrer(fichier); |
297 |
|
|
} |
298 |
francois |
356 |
} |
299 |
|
|
else |
300 |
|
|
{ |
301 |
|
|
MG_FILE* gest2=new MG_FILE(fichier); |
302 |
|
|
gest=gest2; |
303 |
|
|
idori=false; |
304 |
|
|
} |
305 |
francois |
358 |
|
306 |
francois |
353 |
|
307 |
|
|
int num=0; |
308 |
|
|
if (argc==3) num=atoi(argv[2]); |
309 |
|
|
MG_GEOMETRIE* geo=gest->get_mg_geometrie(num); |
310 |
|
|
data_container data; |
311 |
francois |
358 |
MG_MAILLAGE* mai=NULL; |
312 |
|
|
int nbmai=gest->get_nb_mg_maillage(); |
313 |
|
|
bool sommet=false,arete=false,face=false; |
314 |
|
|
for (int i=0;i<nbmai;i++) |
315 |
|
|
{ |
316 |
|
|
bool sommettmp=false,aretetmp=false,facetmp=false; |
317 |
|
|
MG_MAILLAGE* maitmp=gest->get_mg_maillage(i); |
318 |
|
|
if (maitmp->get_nb_mg_noeud()>0) sommettmp=true; |
319 |
|
|
if (maitmp->get_nb_mg_segment()>0) aretetmp=true; |
320 |
|
|
if (maitmp->get_nb_mg_triangle()>0) facetmp=true; |
321 |
|
|
int nbtruetmp=0,nbtrue=0; |
322 |
|
|
if (sommet==true) nbtrue++; |
323 |
|
|
if (arete==true) nbtrue++; |
324 |
|
|
if (face==true) nbtrue++; |
325 |
|
|
if (sommettmp==true) nbtruetmp++; |
326 |
|
|
if (aretetmp==true) nbtruetmp++; |
327 |
|
|
if (facetmp==true) nbtruetmp++; |
328 |
|
|
if (nbtruetmp>nbtrue) |
329 |
|
|
{ |
330 |
|
|
mai=maitmp; |
331 |
|
|
sommet=sommettmp; |
332 |
|
|
arete=aretetmp; |
333 |
|
|
face=facetmp; |
334 |
|
|
} |
335 |
|
|
} |
336 |
francois |
353 |
printf("\n\n"); |
337 |
|
|
printf("Command on keyboard : \n"); |
338 |
|
|
printf(" e : End of vizualisation\n"); |
339 |
|
|
printf(" r : Reset Camera\n"); |
340 |
|
|
printf(" 1 : Vertex Numbers visible on/off\n"); |
341 |
|
|
printf(" 4 : Edge Numbers visible on/off\n"); |
342 |
|
|
printf(" 7 : Face Numbers visible on/off\n"); |
343 |
|
|
printf(" v : Vertices visible on/off\n"); |
344 |
|
|
printf(" l : Edges visible on/off\n"); |
345 |
|
|
printf(" t : Faces visible on/off\n"); |
346 |
|
|
printf(" j : Save camera on current directory\n"); |
347 |
|
|
printf(" k : Load camera from current directory\n"); |
348 |
|
|
printf(" w : Wireframe\n"); |
349 |
|
|
printf(" s : Modelframe\n"); |
350 |
francois |
358 |
printf(" - : Decrease text size\n"); |
351 |
|
|
printf(" + : Increase text size\n"); |
352 |
francois |
353 |
|
353 |
francois |
356 |
char titre [500]; |
354 |
francois |
353 |
strcpy(titre,"Visumagic "); |
355 |
francois |
356 |
strcat(titre,fichier); |
356 |
francois |
358 |
if (mai!=NULL) affiche_structure(cface,carete,ctext,geo,mai,data,idori); |
357 |
francois |
356 |
delete gest; |
358 |
francois |
353 |
|
359 |
|
|
vtkdisplay d(base,titre); |
360 |
|
|
|
361 |
|
|
|
362 |
|
|
|
363 |
|
|
|
364 |
|
|
d.init_data(data); |
365 |
|
|
d.display(true); |
366 |
|
|
|
367 |
francois |
356 |
|
368 |
francois |
353 |
return 0; |
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
|
372 |
|
|
|
373 |
|
|
#pragma package(smart_init) |