1 | // generated by Fast Light User Interface Designer (fluid) version 2.0100 |
---|
2 | |
---|
3 | #include "GeoMeshViewUI.h" |
---|
4 | #include "resource.h" |
---|
5 | #include "GeoLodTreeConstructor.h" |
---|
6 | |
---|
7 | using namespace Geometry; |
---|
8 | using namespace std; |
---|
9 | |
---|
10 | //--------------------------------------------------------------------------- |
---|
11 | // Menu File Open Callback |
---|
12 | //--------------------------------------------------------------------------- |
---|
13 | inline void GeoMeshViewUI::cb_menuFileOpen_i(fltk::Item*, void*) |
---|
14 | { |
---|
15 | // Sets menus application state to NONE. |
---|
16 | mApplicationState = NONE; |
---|
17 | |
---|
18 | // Loads a mesh file. |
---|
19 | openMeshFile(); |
---|
20 | |
---|
21 | // Deactive Lod strip visualization. |
---|
22 | geoMeshView->deactiveLodStrip(); |
---|
23 | |
---|
24 | // Deactive Lod tree visualization. |
---|
25 | geoMeshView->deactiveLodTree(); |
---|
26 | |
---|
27 | BuildLoadTextureSubMeshMenu(); |
---|
28 | |
---|
29 | // Repaint the window. |
---|
30 | mMainWindow->redraw(); |
---|
31 | } |
---|
32 | |
---|
33 | inline void GeoMeshViewUI::cb_menuFileLoadTexture_i(fltk::Item*, void*) |
---|
34 | { |
---|
35 | static char pattern[] = "*.{jpg|tga|png|bmp}"; |
---|
36 | |
---|
37 | fltk::FileChooser *fcho = new fltk::FileChooser("",pattern,fltk::FileChooser::CREATE,"Open image file"); |
---|
38 | fcho->exec(); |
---|
39 | char filename[256]=""; |
---|
40 | if (fcho->value()) |
---|
41 | { |
---|
42 | strcpy(filename,fcho->value()); |
---|
43 | geoMeshView->LoadTexture(filename); |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | void GeoMeshViewUI::cb_menuFileLoadTexture(fltk::Item *o, void *v) |
---|
48 | { |
---|
49 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) |
---|
50 | -> |
---|
51 | cb_menuFileLoadTexture_i(o,v); |
---|
52 | } |
---|
53 | |
---|
54 | |
---|
55 | inline void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh_i(fltk::Item *item, void *) |
---|
56 | { |
---|
57 | static char pattern[] = "*.{jpg|tga|png|bmp}"; |
---|
58 | |
---|
59 | const char * label = item->label(); |
---|
60 | int isubmesh = label[strlen(label)-1]-48; |
---|
61 | |
---|
62 | fltk::FileChooser *fcho = new fltk::FileChooser("",pattern,fltk::FileChooser::CREATE,"Open image file"); |
---|
63 | fcho->exec(); |
---|
64 | char filename[256]=""; |
---|
65 | if (fcho->value()) |
---|
66 | { |
---|
67 | strcpy(filename,fcho->value()); |
---|
68 | geoMeshView->LoadTextureSubMesh(isubmesh,filename); |
---|
69 | } |
---|
70 | } |
---|
71 | |
---|
72 | void GeoMeshViewUI::cb_menuFileLoadTextureSubMesh(fltk::Item *o, void *v) |
---|
73 | { |
---|
74 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->parent()->user_data())) |
---|
75 | -> |
---|
76 | cb_menuFileLoadTextureSubMesh_i(o,v); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | |
---|
81 | //--------------------------------------------------------------------------- |
---|
82 | // Repaint the FPS label. |
---|
83 | //--------------------------------------------------------------------------- |
---|
84 | void GeoMeshViewUI::refreshFPS(int fps) |
---|
85 | { |
---|
86 | static char char_value[10]; |
---|
87 | |
---|
88 | // Translate the FPS count to a char value. |
---|
89 | sprintf(char_value,"FPS %d",fps); |
---|
90 | |
---|
91 | mFPS->label(char_value); |
---|
92 | |
---|
93 | // Repaint the window. |
---|
94 | mMainWindow->redraw(); |
---|
95 | } |
---|
96 | |
---|
97 | void GeoMeshViewUI::cb_menuFileOpen(fltk::Item* o, void* v) |
---|
98 | { |
---|
99 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
100 | -> |
---|
101 | cb_menuFileOpen_i(o,v); |
---|
102 | } |
---|
103 | |
---|
104 | //--------------------------------------------------------------------------- |
---|
105 | // Save callback |
---|
106 | //--------------------------------------------------------------------------- |
---|
107 | inline void GeoMeshViewUI::cb_menuFileSave_i(fltk::Item*, void*) |
---|
108 | { |
---|
109 | GeoMeshSaver *mesh_saver; |
---|
110 | |
---|
111 | // If there is a mesh object created. |
---|
112 | if (mGeoMesh != NULL) |
---|
113 | { |
---|
114 | // Create a mesh saver with mesh bounds. |
---|
115 | mesh_saver = new GeoMeshSaver(); |
---|
116 | |
---|
117 | // Save the file mesh. |
---|
118 | mesh_saver->save(mGeoMesh, mFileName); |
---|
119 | |
---|
120 | // Free memory. |
---|
121 | delete mesh_saver; |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | void GeoMeshViewUI::cb_menuFileSave(fltk::Item* o, void* v) |
---|
126 | { |
---|
127 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
128 | -> |
---|
129 | cb_menuFileSave_i(o,v); |
---|
130 | } |
---|
131 | |
---|
132 | //--------------------------------------------------------------------------- |
---|
133 | // Save As Callback |
---|
134 | //--------------------------------------------------------------------------- |
---|
135 | inline void GeoMeshViewUI::cb_menuFileSaveAs_i(fltk::Item*, void*) |
---|
136 | { |
---|
137 | fltk::FileChooser *fcho; |
---|
138 | GeoMeshSaver *mesh_saver; |
---|
139 | char file_name[255]; |
---|
140 | char message[255]; |
---|
141 | char *ptr; |
---|
142 | int answer_yes; |
---|
143 | |
---|
144 | // Initialize answer to yes. |
---|
145 | answer_yes = 1; |
---|
146 | |
---|
147 | if (mGeoMesh != NULL) |
---|
148 | { |
---|
149 | fcho = new fltk::FileChooser("", |
---|
150 | "*.mesh", |
---|
151 | fltk::FileChooser::CREATE, |
---|
152 | "Save Mesh as"); |
---|
153 | |
---|
154 | fcho->exec(); |
---|
155 | |
---|
156 | if (fcho->value()) |
---|
157 | { |
---|
158 | // Gets file name. |
---|
159 | strcpy(file_name,fcho->value()); |
---|
160 | |
---|
161 | // Cut extension. |
---|
162 | ptr = strtok(file_name,"."); |
---|
163 | |
---|
164 | // If has extension. |
---|
165 | if (ptr) |
---|
166 | { |
---|
167 | strcpy(file_name,ptr); |
---|
168 | } |
---|
169 | |
---|
170 | // Adds mesh extension. |
---|
171 | strcat(file_name,".mesh"); |
---|
172 | |
---|
173 | // If File Exists. |
---|
174 | if (fileExists(file_name)) |
---|
175 | { |
---|
176 | // Compose message. |
---|
177 | strcpy(message,"Do you want to replace "); |
---|
178 | strcat(message,filename_name(file_name)); |
---|
179 | strcat(message,"?"); |
---|
180 | |
---|
181 | // Question. |
---|
182 | answer_yes = fltk::ask(message); |
---|
183 | } |
---|
184 | |
---|
185 | // If answer yes to replace question. |
---|
186 | // or if file not exists. |
---|
187 | if (answer_yes) |
---|
188 | { |
---|
189 | mesh_saver = new GeoMeshSaver(); |
---|
190 | |
---|
191 | mesh_saver->save(mGeoMesh,filename_name(file_name)); |
---|
192 | |
---|
193 | delete mesh_saver; |
---|
194 | } |
---|
195 | } |
---|
196 | // Repaint the window. |
---|
197 | mMainWindow->redraw(); |
---|
198 | |
---|
199 | delete fcho; |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | void GeoMeshViewUI::cb_menuFileSaveAs(fltk::Item* o, void* v) |
---|
204 | { |
---|
205 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
206 | -> |
---|
207 | cb_menuFileSaveAs_i(o,v); |
---|
208 | } |
---|
209 | |
---|
210 | //--------------------------------------------------------------------------- |
---|
211 | // Mesh info callback |
---|
212 | //--------------------------------------------------------------------------- |
---|
213 | inline void GeoMeshViewUI::cb_menuMeshInfo_i(fltk::Item*, void*) |
---|
214 | { |
---|
215 | // Show title. |
---|
216 | mProcessTitle->label("Mesh Info"); |
---|
217 | |
---|
218 | showMeshInfo(); |
---|
219 | mMainWindow->redraw(); |
---|
220 | } |
---|
221 | |
---|
222 | void GeoMeshViewUI::cb_menuMeshInfo(fltk::Item* o, void* v) |
---|
223 | { |
---|
224 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
225 | -> |
---|
226 | cb_menuMeshInfo_i(o,v); |
---|
227 | } |
---|
228 | |
---|
229 | //--------------------------------------------------------------------------- |
---|
230 | // Mesh Export to OBJ callback |
---|
231 | //--------------------------------------------------------------------------- |
---|
232 | inline void GeoMeshViewUI::cb_menuMeshExportOBJ_i(fltk::Item*, void*) |
---|
233 | { |
---|
234 | char *p; |
---|
235 | |
---|
236 | // Sets menus application state to NONE. |
---|
237 | mApplicationState = NONE; |
---|
238 | |
---|
239 | // Open file chooser dialog. |
---|
240 | p = fltk::file_chooser("Export to OBJ","*.obj",""); |
---|
241 | if (p && mGeoMesh) |
---|
242 | { |
---|
243 | mGeoMesh->exportToOBJ(p); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | void GeoMeshViewUI::cb_menuMeshExportOBJ(fltk::Item* o, void* v) |
---|
248 | { |
---|
249 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
250 | -> |
---|
251 | cb_menuMeshExportOBJ_i(o,v); |
---|
252 | } |
---|
253 | |
---|
254 | //--------------------------------------------------------------------------- |
---|
255 | // Transform to Shared Vertex callback |
---|
256 | //--------------------------------------------------------------------------- |
---|
257 | inline void GeoMeshViewUI::cb_menuTransformSharedVertex_i(fltk::Item*, void*) |
---|
258 | { |
---|
259 | Mesh *mesh_aux; |
---|
260 | |
---|
261 | // if the undo mesh is not initialized. |
---|
262 | if (mGeoMesh != NULL) |
---|
263 | { |
---|
264 | // Deletes the actual mesh. |
---|
265 | delete mUndoMesh; |
---|
266 | |
---|
267 | mUndoMesh = new Mesh(); |
---|
268 | |
---|
269 | // Restore the previous mesh. |
---|
270 | *mUndoMesh = *mGeoMesh; |
---|
271 | |
---|
272 | // Transform NoSV Mesh to a SV Mesh. |
---|
273 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
274 | |
---|
275 | // Deletes the mesh No Shared Vertex. |
---|
276 | delete mGeoMesh; |
---|
277 | |
---|
278 | // Gets the mesh Shared Vertex. |
---|
279 | mGeoMesh = mesh_aux; |
---|
280 | |
---|
281 | // Visualize the mesh stripified. |
---|
282 | geoMeshView->setMesh(mGeoMesh); |
---|
283 | |
---|
284 | // Refresh mesh information. |
---|
285 | showMeshInfo(); |
---|
286 | |
---|
287 | // Repaint the window. |
---|
288 | mMainWindow->redraw(); |
---|
289 | } |
---|
290 | } |
---|
291 | |
---|
292 | void GeoMeshViewUI::cb_menuFileTransformSharedVertex(fltk::Item* o, void* v) |
---|
293 | { |
---|
294 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
295 | -> |
---|
296 | cb_menuTransformSharedVertex_i(o,v); |
---|
297 | } |
---|
298 | |
---|
299 | //--------------------------------------------------------------------------- |
---|
300 | // Quit Callback |
---|
301 | //--------------------------------------------------------------------------- |
---|
302 | inline void GeoMeshViewUI::cb_menuFileQuit_i(fltk::Item*, void*) |
---|
303 | { |
---|
304 | delete this; |
---|
305 | } |
---|
306 | |
---|
307 | void GeoMeshViewUI::cb_menuFileQuit(fltk::Item* o, void* v) |
---|
308 | { |
---|
309 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
310 | -> |
---|
311 | cb_menuFileQuit_i(o,v); |
---|
312 | } |
---|
313 | |
---|
314 | //--------------------------------------------------------------------------- |
---|
315 | // Undo Callback |
---|
316 | //--------------------------------------------------------------------------- |
---|
317 | inline void GeoMeshViewUI::cb_menuEditUndo_i(fltk::Item*, void*) |
---|
318 | { |
---|
319 | // Undo the mesh changes. |
---|
320 | undo(); |
---|
321 | } |
---|
322 | |
---|
323 | void GeoMeshViewUI::cb_menuEditUndo(fltk::Item* o, void* v) |
---|
324 | { |
---|
325 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
326 | -> |
---|
327 | cb_menuEditUndo_i(o,v); |
---|
328 | } |
---|
329 | |
---|
330 | //--------------------------------------------------------------------------- |
---|
331 | // Fit Callback |
---|
332 | //--------------------------------------------------------------------------- |
---|
333 | inline void GeoMeshViewUI::cb_menuEditFit_i(fltk::Item*, void*) |
---|
334 | { |
---|
335 | geoMeshView->fit(); |
---|
336 | mMainWindow->redraw(); |
---|
337 | } |
---|
338 | |
---|
339 | void GeoMeshViewUI::cb_menuEditFit(fltk::Item* o, void* v) |
---|
340 | { |
---|
341 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
342 | -> |
---|
343 | cb_menuEditFit_i(o,v); |
---|
344 | } |
---|
345 | |
---|
346 | //--------------------------------------------------------------------------- |
---|
347 | // Rotate Callback |
---|
348 | //--------------------------------------------------------------------------- |
---|
349 | inline void GeoMeshViewUI::cb_menuEditRotate_i(fltk::Item *item, void*) |
---|
350 | { |
---|
351 | // If the item is activated. |
---|
352 | if (item->value()) |
---|
353 | { |
---|
354 | menuEditPan->clear_value(); |
---|
355 | geoMeshView->deactivePan(); |
---|
356 | |
---|
357 | geoMeshView->activeRotate(); |
---|
358 | } |
---|
359 | else |
---|
360 | { |
---|
361 | menuEditPan->set_value(); |
---|
362 | geoMeshView->activePan(); |
---|
363 | |
---|
364 | geoMeshView->deactiveRotate(); |
---|
365 | } |
---|
366 | |
---|
367 | // Repaint the main window. |
---|
368 | mMainWindow->redraw(); |
---|
369 | } |
---|
370 | |
---|
371 | void GeoMeshViewUI::cb_menuEditRotate(fltk::Item* o, void* v) |
---|
372 | { |
---|
373 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
374 | -> |
---|
375 | cb_menuEditRotate_i(o,v); |
---|
376 | } |
---|
377 | |
---|
378 | //--------------------------------------------------------------------------- |
---|
379 | // Pan Callback |
---|
380 | //--------------------------------------------------------------------------- |
---|
381 | inline void GeoMeshViewUI::cb_menuEditPan_i(fltk::Item *item, void*) |
---|
382 | { |
---|
383 | // If the item is activated. |
---|
384 | if (item->value()) |
---|
385 | { |
---|
386 | geoMeshView->activePan(); |
---|
387 | |
---|
388 | menuEditRotate->clear_value(); |
---|
389 | geoMeshView->deactiveRotate(); |
---|
390 | } |
---|
391 | else |
---|
392 | { |
---|
393 | geoMeshView->deactivePan(); |
---|
394 | |
---|
395 | menuEditRotate->set_value(); |
---|
396 | geoMeshView->activeRotate(); |
---|
397 | } |
---|
398 | |
---|
399 | // Repaint the main window. |
---|
400 | mMainWindow->redraw(); |
---|
401 | } |
---|
402 | |
---|
403 | void GeoMeshViewUI::cb_menuEditPan(fltk::Item* o, void* v) |
---|
404 | { |
---|
405 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
406 | -> |
---|
407 | cb_menuEditPan_i(o,v); |
---|
408 | } |
---|
409 | |
---|
410 | //--------------------------------------------------------------------------- |
---|
411 | // Zoom Callback |
---|
412 | //--------------------------------------------------------------------------- |
---|
413 | inline void GeoMeshViewUI::cb_menuEditZoom_i(fltk::Item*, void*) |
---|
414 | { |
---|
415 | } |
---|
416 | |
---|
417 | void GeoMeshViewUI::cb_menuEditZoom(fltk::Item* o, void* v) |
---|
418 | { |
---|
419 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
420 | -> |
---|
421 | cb_menuEditZoom_i(o,v); |
---|
422 | } |
---|
423 | |
---|
424 | //--------------------------------------------------------------------------- |
---|
425 | // Wire Callback |
---|
426 | //--------------------------------------------------------------------------- |
---|
427 | inline void GeoMeshViewUI::cb_menuRenderWire_i(fltk::Item *item, void*) |
---|
428 | { |
---|
429 | if (item->value()) |
---|
430 | { |
---|
431 | geoMeshView->activeWire(); |
---|
432 | } |
---|
433 | else |
---|
434 | { |
---|
435 | geoMeshView->deactiveWire(); |
---|
436 | } |
---|
437 | |
---|
438 | // Repaint the canvas. |
---|
439 | //geoMeshView->redraw(); |
---|
440 | |
---|
441 | // Repaint the main window. |
---|
442 | mMainWindow->redraw(); |
---|
443 | } |
---|
444 | |
---|
445 | void GeoMeshViewUI::cb_menuRenderWire(fltk::Item* o, void* v) |
---|
446 | { |
---|
447 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
448 | -> |
---|
449 | cb_menuRenderWire_i(o,v); |
---|
450 | } |
---|
451 | |
---|
452 | //--------------------------------------------------------------------------- |
---|
453 | // Solid Callback |
---|
454 | //--------------------------------------------------------------------------- |
---|
455 | inline void GeoMeshViewUI::cb_menuRenderSolid_i(fltk::Item *item, void*) |
---|
456 | { |
---|
457 | if (item->value()) |
---|
458 | { |
---|
459 | geoMeshView->activeSolid(); |
---|
460 | } |
---|
461 | else |
---|
462 | { |
---|
463 | geoMeshView->deactiveSolid(); |
---|
464 | } |
---|
465 | |
---|
466 | // Repaint the canvas. |
---|
467 | //geoMeshView->redraw(); |
---|
468 | |
---|
469 | // Repaint the main window. |
---|
470 | mMainWindow->redraw(); |
---|
471 | } |
---|
472 | |
---|
473 | void GeoMeshViewUI::cb_menuRenderSolid(fltk::Item* o, void* v) |
---|
474 | { |
---|
475 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
476 | -> |
---|
477 | cb_menuRenderSolid_i(o,v); |
---|
478 | } |
---|
479 | |
---|
480 | //--------------------------------------------------------------------------- |
---|
481 | // CW callback |
---|
482 | //--------------------------------------------------------------------------- |
---|
483 | inline void GeoMeshViewUI::cb_menuRenderCW_i(fltk::Item *item, void*) |
---|
484 | { |
---|
485 | // Clear the CCW state. |
---|
486 | menuRenderCCW->clear_value(); |
---|
487 | geoMeshView->deactiveCCW(); |
---|
488 | |
---|
489 | // If the item is activated. |
---|
490 | if (item->value()) |
---|
491 | { |
---|
492 | geoMeshView->activeCW(); |
---|
493 | } |
---|
494 | else |
---|
495 | { |
---|
496 | geoMeshView->deactiveCW(); |
---|
497 | } |
---|
498 | |
---|
499 | // Repaint the main window. |
---|
500 | mMainWindow->redraw(); |
---|
501 | } |
---|
502 | |
---|
503 | void GeoMeshViewUI::cb_menuRenderCW(fltk::Item* o, void* v) |
---|
504 | { |
---|
505 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
506 | -> |
---|
507 | cb_menuRenderCW_i(o,v); |
---|
508 | } |
---|
509 | |
---|
510 | //--------------------------------------------------------------------------- |
---|
511 | // CCW callback |
---|
512 | //--------------------------------------------------------------------------- |
---|
513 | inline void GeoMeshViewUI::cb_menuRenderCCW_i(fltk::Item *item, void*) |
---|
514 | { |
---|
515 | // Clear the CW state. |
---|
516 | menuRenderCW->clear_value(); |
---|
517 | geoMeshView->deactiveCW(); |
---|
518 | |
---|
519 | // If the item is activated. |
---|
520 | if (item->value()) |
---|
521 | { |
---|
522 | geoMeshView->activeCCW(); |
---|
523 | } |
---|
524 | else |
---|
525 | { |
---|
526 | geoMeshView->deactiveCCW(); |
---|
527 | } |
---|
528 | |
---|
529 | // Repaint the main window. |
---|
530 | mMainWindow->redraw(); |
---|
531 | } |
---|
532 | |
---|
533 | void GeoMeshViewUI::cb_menuRenderCCW(fltk::Item* o, void* v) |
---|
534 | { |
---|
535 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
536 | -> |
---|
537 | cb_menuRenderCCW_i(o,v); |
---|
538 | } |
---|
539 | |
---|
540 | //--------------------------------------------------------------------------- |
---|
541 | // Flat callback |
---|
542 | //--------------------------------------------------------------------------- |
---|
543 | inline void GeoMeshViewUI::cb_menuRenderFlat_i(fltk::Item*, void*) |
---|
544 | { |
---|
545 | // Deactive smooth flag. |
---|
546 | menuRenderSmooth->clear_value(); |
---|
547 | |
---|
548 | // Sets flat lighting. |
---|
549 | geoMeshView->flat(); |
---|
550 | |
---|
551 | // Repaint the main window. |
---|
552 | mMainWindow->redraw(); |
---|
553 | } |
---|
554 | |
---|
555 | void GeoMeshViewUI::cb_menuRenderFlat(fltk::Item* o, void* v) |
---|
556 | { |
---|
557 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
558 | -> |
---|
559 | cb_menuRenderFlat_i(o,v); |
---|
560 | } |
---|
561 | |
---|
562 | //--------------------------------------------------------------------------- |
---|
563 | // Smooth Callback |
---|
564 | //--------------------------------------------------------------------------- |
---|
565 | inline void GeoMeshViewUI::cb_menuRenderSmooth_i(fltk::Item*, void*) |
---|
566 | { |
---|
567 | // Deactive flat flag. |
---|
568 | menuRenderFlat->clear_value(); |
---|
569 | |
---|
570 | // Sets smooth lighting. |
---|
571 | geoMeshView->smooth(); |
---|
572 | |
---|
573 | // Repaint the main window. |
---|
574 | mMainWindow->redraw(); |
---|
575 | } |
---|
576 | |
---|
577 | void GeoMeshViewUI::cb_menuRenderSmooth(fltk::Item* o, void* v) |
---|
578 | { |
---|
579 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
580 | -> |
---|
581 | cb_menuRenderSmooth_i(o,v); |
---|
582 | } |
---|
583 | |
---|
584 | //--------------------------------------------------------------------------- |
---|
585 | // Textures callback |
---|
586 | //--------------------------------------------------------------------------- |
---|
587 | inline void GeoMeshViewUI::cb_menuRenderTextures_i(fltk::Item*, void*) |
---|
588 | { |
---|
589 | // Repaint the main window. |
---|
590 | mMainWindow->redraw(); |
---|
591 | if (geoMeshView->isTextureMappingEnabled()) |
---|
592 | geoMeshView->disableTextureMapping(); |
---|
593 | else |
---|
594 | geoMeshView->enableTextureMapping(); |
---|
595 | } |
---|
596 | |
---|
597 | void GeoMeshViewUI::cb_menuRenderTextures(fltk::Item* o, void* v) |
---|
598 | { |
---|
599 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
600 | -> |
---|
601 | cb_menuRenderTextures_i(o,v); |
---|
602 | } |
---|
603 | |
---|
604 | //--------------------------------------------------------------------------- |
---|
605 | // Stripify Callback |
---|
606 | //--------------------------------------------------------------------------- |
---|
607 | inline void GeoMeshViewUI::cb_menuStripify_i(fltk::Item*, void*) |
---|
608 | { |
---|
609 | // Show title. |
---|
610 | mProcessTitle->label("Stripify"); |
---|
611 | mProcessBar->position(0); |
---|
612 | |
---|
613 | // Hide the right panel. |
---|
614 | hideRightPanel(); |
---|
615 | |
---|
616 | // Show the stripify panel. |
---|
617 | showStripify(); |
---|
618 | |
---|
619 | // Sets menus application state to STRIPIFY. |
---|
620 | mApplicationState = STRIPIFY; |
---|
621 | |
---|
622 | // Repaint the window. |
---|
623 | mMainWindow->redraw(); |
---|
624 | } |
---|
625 | |
---|
626 | void GeoMeshViewUI::cb_menuStripify(fltk::Item* o, void* v) |
---|
627 | { |
---|
628 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
629 | -> |
---|
630 | cb_menuStripify_i(o,v); |
---|
631 | } |
---|
632 | |
---|
633 | //--------------------------------------------------------------------------- |
---|
634 | // Simplify Callback |
---|
635 | //--------------------------------------------------------------------------- |
---|
636 | inline void GeoMeshViewUI::cb_menuSimplify_i(fltk::ItemGroup*, void*) |
---|
637 | { |
---|
638 | } |
---|
639 | |
---|
640 | void GeoMeshViewUI::cb_menuSimplify(fltk::ItemGroup* o, void* v) |
---|
641 | { |
---|
642 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
643 | -> |
---|
644 | cb_menuSimplify_i(o,v); |
---|
645 | } |
---|
646 | |
---|
647 | //--------------------------------------------------------------------------- |
---|
648 | // Edge collapse Callback |
---|
649 | //--------------------------------------------------------------------------- |
---|
650 | inline void GeoMeshViewUI::cb_menuSimplifyEdgeCollapse_i(fltk::Item*, void*) |
---|
651 | { |
---|
652 | // Show title. |
---|
653 | mProcessTitle->label("Mesh Simplification"); |
---|
654 | mProcessBar->position(0); |
---|
655 | |
---|
656 | // Hide the right panel. |
---|
657 | hideRightPanel(); |
---|
658 | |
---|
659 | // Show the edge collapse panel. |
---|
660 | showEdgeCollapse(); |
---|
661 | |
---|
662 | // Sets menus application state to EDGE_COLLAPSE. |
---|
663 | mApplicationState = EDGE_COLLAPSE; |
---|
664 | |
---|
665 | // Repaint the window. |
---|
666 | mMainWindow->redraw(); |
---|
667 | |
---|
668 | } |
---|
669 | |
---|
670 | void GeoMeshViewUI::cb_menuSimplifyEdgeCollapse(fltk::Item* o, void* v) |
---|
671 | { |
---|
672 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
673 | -> |
---|
674 | cb_menuSimplifyEdgeCollapse_i(o,v); |
---|
675 | } |
---|
676 | |
---|
677 | //--------------------------------------------------------------------------- |
---|
678 | // Leaves collapse Callback |
---|
679 | //--------------------------------------------------------------------------- |
---|
680 | inline void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse_i(fltk::Item*, void*) |
---|
681 | { |
---|
682 | // Show title. |
---|
683 | mProcessTitle->label("Leaves Simplification"); |
---|
684 | mProcessBar->position(0); |
---|
685 | |
---|
686 | // Hide the right panel. |
---|
687 | hideRightPanel(); |
---|
688 | |
---|
689 | // Show the leaves collapse panel. |
---|
690 | showLeavesCollapse(); |
---|
691 | |
---|
692 | // Sets menus application state to LEAVES_COLLAPSE. |
---|
693 | mApplicationState = LEAVES_COLLAPSE; |
---|
694 | |
---|
695 | // Repaint the window. |
---|
696 | mMainWindow->redraw(); |
---|
697 | } |
---|
698 | |
---|
699 | void GeoMeshViewUI::cb_menuSimplifyLeavesCollapse(fltk::Item* o, void* v) |
---|
700 | { |
---|
701 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
702 | -> |
---|
703 | cb_menuSimplifyLeavesCollapse_i(o,v); |
---|
704 | } |
---|
705 | |
---|
706 | //--------------------------------------------------------------------------- |
---|
707 | // Tree select leaves simplification Callback |
---|
708 | //--------------------------------------------------------------------------- |
---|
709 | inline void GeoMeshViewUI::cb_menuSelectLeaves_i(fltk::Item*, void*) |
---|
710 | { |
---|
711 | // Show title. |
---|
712 | mProcessTitle->label("Select Leaves"); |
---|
713 | |
---|
714 | showMeshInfo(); |
---|
715 | mButtonProcess->show(); |
---|
716 | mButtonProcess->activate(); |
---|
717 | mApplicationState = SELECT_LEAVES; |
---|
718 | } |
---|
719 | |
---|
720 | void GeoMeshViewUI::cb_menuSelectLeaves(fltk::Item* o, void* v) |
---|
721 | { |
---|
722 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
723 | -> |
---|
724 | cb_menuSelectLeaves_i(o,v); |
---|
725 | } |
---|
726 | |
---|
727 | //--------------------------------------------------------------------------- |
---|
728 | // Auto Generate LodStrips Callback |
---|
729 | //--------------------------------------------------------------------------- |
---|
730 | inline void GeoMeshViewUI::cb_menuLodStripsGenerate_i(fltk::Item*, void*) |
---|
731 | { |
---|
732 | // Show title. |
---|
733 | mProcessTitle->label("Generate LodStrips"); |
---|
734 | mProcessBar->position(0); |
---|
735 | mBuildBar->position(0); |
---|
736 | |
---|
737 | // Hide the right panel. |
---|
738 | hideRightPanel(); |
---|
739 | |
---|
740 | // Show the LodStrips panel. |
---|
741 | showAutoGenerateLodStrips(); |
---|
742 | |
---|
743 | // Sets menus application state to LODSTRIPS_AUTO. |
---|
744 | mApplicationState = LODSTRIPS_AUTO; |
---|
745 | |
---|
746 | // Repaint the window. |
---|
747 | mMainWindow->redraw(); |
---|
748 | } |
---|
749 | |
---|
750 | void GeoMeshViewUI::cb_menuLodStripsGenerate(fltk::Item* o, void* v) |
---|
751 | { |
---|
752 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
753 | -> |
---|
754 | cb_menuLodStripsGenerate_i(o,v); |
---|
755 | } |
---|
756 | |
---|
757 | //--------------------------------------------------------------------------- |
---|
758 | // Auto Generate LodStrips Callback |
---|
759 | //--------------------------------------------------------------------------- |
---|
760 | inline void GeoMeshViewUI::cb_menuLodTreesGenerate_i(fltk::Item*, void*) |
---|
761 | { |
---|
762 | // Show title. |
---|
763 | mProcessTitle->label("Generate LodTree"); |
---|
764 | mProcessBar->position(0); |
---|
765 | mBuildBar->position(0); |
---|
766 | |
---|
767 | // Hide the right panel. |
---|
768 | hideRightPanel(); |
---|
769 | |
---|
770 | // Show the LodStrips panel. |
---|
771 | showAutoGenerateLodTrees(); |
---|
772 | |
---|
773 | // Sets menus application state to LODSTRIPS_AUTO. |
---|
774 | mApplicationState = LODTREES_AUTO; |
---|
775 | |
---|
776 | // Repaint the window. |
---|
777 | mMainWindow->redraw(); |
---|
778 | } |
---|
779 | |
---|
780 | void GeoMeshViewUI::cb_menuLodTreesGenerate(fltk::Item* o, void* v) |
---|
781 | { |
---|
782 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
783 | -> |
---|
784 | cb_menuLodTreesGenerate_i(o,v); |
---|
785 | } |
---|
786 | |
---|
787 | |
---|
788 | //--------------------------------------------------------------------------- |
---|
789 | // Visualize LodStrips Callback |
---|
790 | //--------------------------------------------------------------------------- |
---|
791 | inline void GeoMeshViewUI::cb_menuLodStripsVisualize_i(fltk::Item*, void*) |
---|
792 | { |
---|
793 | fltk::FileChooser *fcho; |
---|
794 | const char *lod_file; |
---|
795 | |
---|
796 | // Sets menus application state to NONE. |
---|
797 | mApplicationState = NONE; |
---|
798 | |
---|
799 | // Deactive Lod strip visualization. |
---|
800 | geoMeshView->deactiveLodStrip(); |
---|
801 | geoMeshView->deactiveLodTree(); |
---|
802 | |
---|
803 | // Loads a mesh file. |
---|
804 | openMeshFile(); |
---|
805 | |
---|
806 | |
---|
807 | // If an object is loaded. |
---|
808 | if (mGeoMesh != NULL) |
---|
809 | { |
---|
810 | fcho = new fltk::FileChooser("", |
---|
811 | "*.lod", |
---|
812 | fltk::FileChooser::CREATE, |
---|
813 | "Open Lod file"); |
---|
814 | |
---|
815 | fcho->exec(); |
---|
816 | |
---|
817 | // If a file was selected. |
---|
818 | if (fcho->value()) |
---|
819 | { |
---|
820 | // Build lod strips library. |
---|
821 | setLodStripsLibrary(string(fcho->value()), mGeoMesh); |
---|
822 | |
---|
823 | // Sets the aplication mode. |
---|
824 | mApplicationState = VISUALIZE_LODSTRIPS; |
---|
825 | } |
---|
826 | |
---|
827 | // Free memory. |
---|
828 | delete fcho; |
---|
829 | |
---|
830 | // Hide the right panel. |
---|
831 | hideRightPanel(); |
---|
832 | |
---|
833 | // Show title. |
---|
834 | mProcessTitle->label("Visualize LodStrips"); |
---|
835 | |
---|
836 | // Show the Visulize LodStrips panel. |
---|
837 | showLodStripSlider(); |
---|
838 | |
---|
839 | // Repaint the window. |
---|
840 | mMainWindow->redraw(); |
---|
841 | |
---|
842 | } |
---|
843 | } |
---|
844 | |
---|
845 | inline void GeoMeshViewUI::cb_menuLodTreesVisualize_i(fltk::Item*, void*) |
---|
846 | { |
---|
847 | fltk::FileChooser *fcho; |
---|
848 | const char *lod_file; |
---|
849 | |
---|
850 | // Sets menus application state to NONE. |
---|
851 | mApplicationState = NONE; |
---|
852 | |
---|
853 | // Deactive Lod strip visualization. |
---|
854 | geoMeshView->deactiveLodTree(); |
---|
855 | geoMeshView->deactiveLodStrip(); |
---|
856 | |
---|
857 | // Loads a mesh file. |
---|
858 | openMeshFile(); |
---|
859 | |
---|
860 | /*if (geoMeshView->getLeavesSubmesh()==-1) |
---|
861 | { |
---|
862 | fltk::alert("No se ha seleccionado el submesh de hojas!"); |
---|
863 | return; |
---|
864 | }*/ |
---|
865 | |
---|
866 | // If an object is loaded. |
---|
867 | if (mGeoMesh != NULL) |
---|
868 | { |
---|
869 | // POR AHORA SE SELECCIONA EL PRIMER SUBMESH QUE NO ES STRIPS COMO HOJAS |
---|
870 | int leafsSubMeshID = -1; |
---|
871 | |
---|
872 | for (int i=0; i<mGeoMesh->mSubMeshCount; i++) |
---|
873 | { |
---|
874 | if (mGeoMesh->mSubMesh[i].mType==GEO_TRIANGLE_LIST) |
---|
875 | { |
---|
876 | leafsSubMeshID=i; |
---|
877 | break; |
---|
878 | } |
---|
879 | } |
---|
880 | |
---|
881 | // If an object is loaded. |
---|
882 | if (mGeoMesh != NULL) |
---|
883 | { |
---|
884 | fcho = new fltk::FileChooser("", |
---|
885 | "*.lod", |
---|
886 | fltk::FileChooser::CREATE, |
---|
887 | "Open Lod file"); |
---|
888 | |
---|
889 | fcho->exec(); |
---|
890 | |
---|
891 | // If a file was selected. |
---|
892 | if (fcho->value()) |
---|
893 | { |
---|
894 | // Build lod strips library. |
---|
895 | |
---|
896 | std::string lodstripFile(fcho->value()); |
---|
897 | delete fcho; |
---|
898 | fcho = new fltk::FileChooser("", |
---|
899 | "*.leafseq", |
---|
900 | fltk::FileChooser::CREATE, |
---|
901 | "Open LeafSeq file"); |
---|
902 | |
---|
903 | fcho->exec(); |
---|
904 | |
---|
905 | if (fcho->value()) |
---|
906 | { |
---|
907 | std::string leafseqFile(fcho->value()); |
---|
908 | |
---|
909 | setLodTreesLibrary(lodstripFile, leafseqFile, mGeoMesh, leafsSubMeshID); |
---|
910 | |
---|
911 | // Sets the aplication mode. |
---|
912 | mApplicationState = VISUALIZE_LODTREES; |
---|
913 | } |
---|
914 | } |
---|
915 | |
---|
916 | // Free memory. |
---|
917 | delete fcho; |
---|
918 | |
---|
919 | // Hide the right panel. |
---|
920 | hideRightPanel(); |
---|
921 | |
---|
922 | // Show title. |
---|
923 | mProcessTitle->label("Visualize LodTrees"); |
---|
924 | |
---|
925 | // Show the Visulize LodTree panel. |
---|
926 | showLodStripSlider(); |
---|
927 | showLodTreeSlider(); |
---|
928 | |
---|
929 | // Repaint the window. |
---|
930 | mMainWindow->redraw(); |
---|
931 | } |
---|
932 | } |
---|
933 | } |
---|
934 | |
---|
935 | void GeoMeshViewUI::cb_menuLodTreesVisualize(fltk::Item *o, void *v) |
---|
936 | { |
---|
937 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
938 | -> |
---|
939 | cb_menuLodTreesVisualize_i(o,v); |
---|
940 | } |
---|
941 | |
---|
942 | void GeoMeshViewUI::cb_menuLodStripsVisualize(fltk::Item* o, void* v) |
---|
943 | { |
---|
944 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
945 | -> |
---|
946 | cb_menuLodStripsVisualize_i(o,v); |
---|
947 | } |
---|
948 | |
---|
949 | //--------------------------------------------------------------------------- |
---|
950 | // Open LodStrip trunk Callback |
---|
951 | //--------------------------------------------------------------------------- |
---|
952 | inline void GeoMeshViewUI::cb_menuLodTreesOpenLodStripTrunk_i(fltk::Item*, void*) |
---|
953 | { |
---|
954 | } |
---|
955 | |
---|
956 | void GeoMeshViewUI::cb_menuLodTreesOpenLodStripTrunk(fltk::Item* o, void* v) |
---|
957 | { |
---|
958 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
959 | -> |
---|
960 | cb_menuLodTreesOpenLodStripTrunk_i(o,v); |
---|
961 | } |
---|
962 | |
---|
963 | //--------------------------------------------------------------------------- |
---|
964 | // Open leaves simplification Callback |
---|
965 | //--------------------------------------------------------------------------- |
---|
966 | inline void GeoMeshViewUI::cb_menuLodTreesOpenLeavesSimplification_i(fltk::Item*, void*) |
---|
967 | { |
---|
968 | // Hide the right panel. |
---|
969 | hideRightPanel(); |
---|
970 | |
---|
971 | // Show the LodTrees panel. |
---|
972 | showOpenLeavesSimplification(); |
---|
973 | |
---|
974 | // Sets menus application state to LODTREES. |
---|
975 | mApplicationState = LODTREES; |
---|
976 | |
---|
977 | // Repaint the window. |
---|
978 | mMainWindow->redraw(); |
---|
979 | } |
---|
980 | |
---|
981 | void GeoMeshViewUI::cb_menuLodTreesOpenLeavesSimplification(fltk::Item* o, void* v) |
---|
982 | { |
---|
983 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
984 | -> |
---|
985 | cb_menuLodTreesOpenLeavesSimplification_i(o,v); |
---|
986 | } |
---|
987 | |
---|
988 | |
---|
989 | |
---|
990 | //--------------------------------------------------------------------------- |
---|
991 | // About Callback |
---|
992 | //--------------------------------------------------------------------------- |
---|
993 | inline void GeoMeshViewUI::cb_menuHelpAbout_i(fltk::Item*, void*) |
---|
994 | { |
---|
995 | new GTAboutDialog(); |
---|
996 | } |
---|
997 | |
---|
998 | void GeoMeshViewUI::cb_menuHelpAbout(fltk::Item* o, void* v) |
---|
999 | { |
---|
1000 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1001 | -> |
---|
1002 | cb_menuHelpAbout_i(o,v); |
---|
1003 | } |
---|
1004 | |
---|
1005 | VertexBuffer *origSubMeshVB=NULL; |
---|
1006 | int orig_numindices=0; |
---|
1007 | Index *orig_indices=NULL; |
---|
1008 | |
---|
1009 | //--------------------------------------------------------------------------- |
---|
1010 | // Button Process Callback |
---|
1011 | //--------------------------------------------------------------------------- |
---|
1012 | inline void GeoMeshViewUI::cb_mButtonProcess_i(fltk::Button*, void*) |
---|
1013 | { |
---|
1014 | bool error; |
---|
1015 | Mesh *mesh_aux; |
---|
1016 | |
---|
1017 | // Sets the progress bar to process bar. |
---|
1018 | progressBarType = PROCESS; |
---|
1019 | mProcessBar->position(0); |
---|
1020 | |
---|
1021 | origSubMeshVB=NULL; |
---|
1022 | |
---|
1023 | // Initialize error flag. |
---|
1024 | error = false; |
---|
1025 | |
---|
1026 | // If there is a mesh object. |
---|
1027 | if (mGeoMesh != NULL) |
---|
1028 | { |
---|
1029 | // Choose between aplication state. |
---|
1030 | switch(mApplicationState) |
---|
1031 | { |
---|
1032 | // Stripify state. |
---|
1033 | case STRIPIFY: |
---|
1034 | |
---|
1035 | // Stripify the mesh object. |
---|
1036 | stripify(); |
---|
1037 | |
---|
1038 | break; |
---|
1039 | |
---|
1040 | // Simplify edge collapse state. |
---|
1041 | case EDGE_COLLAPSE: |
---|
1042 | |
---|
1043 | // Check submeshes for triangles strips. |
---|
1044 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
1045 | { |
---|
1046 | // If current submesh is in triangle strips. |
---|
1047 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
1048 | { |
---|
1049 | error = true; |
---|
1050 | } |
---|
1051 | } |
---|
1052 | |
---|
1053 | // if the mesh is stripified. |
---|
1054 | if (error) |
---|
1055 | { |
---|
1056 | fltk::alert("Can't simplify a mesh in triagle strips."); |
---|
1057 | } |
---|
1058 | else |
---|
1059 | { |
---|
1060 | // Simplify the mesh object. |
---|
1061 | if(simplifyEdgeCollapse()) |
---|
1062 | { |
---|
1063 | delete mMeshSimplifier; |
---|
1064 | geoMeshView->restoreContext(); |
---|
1065 | } |
---|
1066 | } |
---|
1067 | break; |
---|
1068 | |
---|
1069 | // Simplify leaves |
---|
1070 | case LEAVES_COLLAPSE: |
---|
1071 | |
---|
1072 | // Simplify the mesh object. |
---|
1073 | simplifyLeavesCollapse(); |
---|
1074 | |
---|
1075 | // Create the leaves simplification sequence. |
---|
1076 | createLeavesSequence("leavesSimplification.txt"); |
---|
1077 | |
---|
1078 | break; |
---|
1079 | |
---|
1080 | // Simplify and generate simplification sequence. |
---|
1081 | case LODTREES_AUTO: |
---|
1082 | if (idMeshLeaves==(unsigned short)-1) |
---|
1083 | { |
---|
1084 | fltk::alert("Leaves submesh not selected!"); |
---|
1085 | } |
---|
1086 | else |
---|
1087 | { |
---|
1088 | origSubMeshVB=mGeoMesh->mSubMesh[idMeshLeaves].mVertexBuffer->Clone(); |
---|
1089 | orig_numindices=mGeoMesh->mSubMesh[idMeshLeaves].mIndexCount; |
---|
1090 | orig_indices=new Index[orig_numindices];
|
---|
1091 | for (int i=0; i<orig_numindices; i++)
|
---|
1092 | orig_indices[i]=mGeoMesh->mSubMesh[idMeshLeaves].mIndex[i]; |
---|
1093 | |
---|
1094 | std::cout << "Simplificando hojas..."; |
---|
1095 | simplifyLeavesCollapse(); |
---|
1096 | std::cout << "OK!" << std::endl; |
---|
1097 | |
---|
1098 | // std::cout << "Creando secuencia de simplificacion de hojas..."; |
---|
1099 | // createLeavesSequence("leavesSimplification.txt"); |
---|
1100 | // std::cout << "OK!" << std::endl; |
---|
1101 | |
---|
1102 | undo(); |
---|
1103 | |
---|
1104 | |
---|
1105 | std::cout << "Simplificando tronco..."; |
---|
1106 | std::cout << "OK!" << std::endl; |
---|
1107 | |
---|
1108 | // Transform NoSV Mesh to a SV Mesh. |
---|
1109 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
1110 | |
---|
1111 | // Deletes the mesh No Shared Vertex. |
---|
1112 | delete mGeoMesh; |
---|
1113 | |
---|
1114 | // Gets the mesh Shared Vertex. |
---|
1115 | mGeoMesh = mesh_aux; |
---|
1116 | |
---|
1117 | geoMeshView->setMesh(mGeoMesh); |
---|
1118 | |
---|
1119 | // Simplify the mesh object. |
---|
1120 | if (simplifyEdgeCollapse()) |
---|
1121 | { |
---|
1122 | // Create the simplification sequence. |
---|
1123 | createSimplificationSequence(); |
---|
1124 | |
---|
1125 | // Show build process. |
---|
1126 | activeBuildProcess(); |
---|
1127 | } |
---|
1128 | |
---|
1129 | } |
---|
1130 | |
---|
1131 | break; |
---|
1132 | |
---|
1133 | case LODSTRIPS_AUTO: |
---|
1134 | |
---|
1135 | // Check submeshes for triangles strips. |
---|
1136 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
1137 | { |
---|
1138 | // If current submesh is in triangle strips. |
---|
1139 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
1140 | { |
---|
1141 | error = true; |
---|
1142 | } |
---|
1143 | } |
---|
1144 | |
---|
1145 | // if the mesh is stripified. |
---|
1146 | if (error) |
---|
1147 | { |
---|
1148 | fltk::alert("Can't simplify a mesh in triagle strips."); |
---|
1149 | } |
---|
1150 | else |
---|
1151 | { |
---|
1152 | // Transform NoSV Mesh to a SV Mesh. |
---|
1153 | mesh_aux = mGeoMesh->toSharedVertex(); |
---|
1154 | |
---|
1155 | // Deletes the mesh No Shared Vertex. |
---|
1156 | delete mGeoMesh; |
---|
1157 | |
---|
1158 | // Gets the mesh Shared Vertex. |
---|
1159 | mGeoMesh = mesh_aux; |
---|
1160 | |
---|
1161 | // Visualize mesh. |
---|
1162 | geoMeshView->setMesh(mGeoMesh); |
---|
1163 | |
---|
1164 | // Simplify the mesh object. |
---|
1165 | if (simplifyEdgeCollapse()) |
---|
1166 | { |
---|
1167 | // Create the simplification sequence. |
---|
1168 | createSimplificationSequence(); |
---|
1169 | |
---|
1170 | delete mMeshSimplifier; |
---|
1171 | geoMeshView->restoreContext(); |
---|
1172 | |
---|
1173 | // Show build process. |
---|
1174 | activeBuildProcess(); |
---|
1175 | } |
---|
1176 | } |
---|
1177 | |
---|
1178 | break; |
---|
1179 | |
---|
1180 | // Añadido 23-12-2005 |
---|
1181 | case SELECT_LEAVES: |
---|
1182 | |
---|
1183 | idMeshLeaves = paintMesh(); |
---|
1184 | |
---|
1185 | // Set the leaves submesh. |
---|
1186 | geoMeshView->setLeavesSubMesh(idMeshLeaves); |
---|
1187 | |
---|
1188 | // Refresh mesh info. |
---|
1189 | showMeshInfo(); |
---|
1190 | |
---|
1191 | break; |
---|
1192 | } |
---|
1193 | |
---|
1194 | // Refresh geometry attributes. |
---|
1195 | refreshApplicationBar(); |
---|
1196 | } |
---|
1197 | |
---|
1198 | // Repaint the GL Window. |
---|
1199 | mMainWindow->redraw(); |
---|
1200 | } |
---|
1201 | |
---|
1202 | void GeoMeshViewUI::cb_mButtonProcess(fltk::Button* o, void* v) |
---|
1203 | { |
---|
1204 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1205 | -> |
---|
1206 | cb_mButtonProcess_i(o,v); |
---|
1207 | } |
---|
1208 | |
---|
1209 | //--------------------------------------------------------------------------- |
---|
1210 | // Button Sort Callback |
---|
1211 | //--------------------------------------------------------------------------- |
---|
1212 | inline void GeoMeshViewUI::cb_mButtonSort_i(fltk::Button*, void*) |
---|
1213 | { |
---|
1214 | } |
---|
1215 | |
---|
1216 | void GeoMeshViewUI::cb_mButtonSort(fltk::Button* o, void* v) |
---|
1217 | { |
---|
1218 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1219 | -> |
---|
1220 | cb_mButtonSort_i(o,v); |
---|
1221 | } |
---|
1222 | |
---|
1223 | //--------------------------------------------------------------------------- |
---|
1224 | // Button Build Callback |
---|
1225 | //--------------------------------------------------------------------------- |
---|
1226 | inline void GeoMeshViewUI::cb_mButtonBuild_i(fltk::Button*, void*) |
---|
1227 | { |
---|
1228 | char *file_name = NULL; |
---|
1229 | GeoMeshSaver *mesh_saver; |
---|
1230 | Serializer *oSerializer; |
---|
1231 | |
---|
1232 | // Sets the progress bar to process bar. |
---|
1233 | progressBarType = BUILD; |
---|
1234 | |
---|
1235 | // Reset the build bar. |
---|
1236 | mBuildBar->position(0); |
---|
1237 | |
---|
1238 | // If there is a mesh object. |
---|
1239 | if (mGeoMesh != NULL) |
---|
1240 | { |
---|
1241 | // Choose between aplication state. |
---|
1242 | switch(mApplicationState) |
---|
1243 | { |
---|
1244 | // Build the LOD file. |
---|
1245 | case LODTREES_AUTO: |
---|
1246 | |
---|
1247 | // Open file chooser dialog. |
---|
1248 | file_name = fltk::file_chooser("Build LOD","*",""); |
---|
1249 | |
---|
1250 | if (!file_name) |
---|
1251 | { |
---|
1252 | break; |
---|
1253 | } |
---|
1254 | |
---|
1255 | std::cout << "Creando secuencia de simplificacion de hojas..."; |
---|
1256 | |
---|
1257 | createLeavesSequence(file_name+std::string(".leafseq")); |
---|
1258 | |
---|
1259 | std::cout << "OK!" << std::endl; |
---|
1260 | |
---|
1261 | /* TreeSimplificationSequence * auxTreeSimpSequence = new TreeSimplificationSequence(); |
---|
1262 | auxTreeSimpSequence->Load(Serializer("leavesSimplification.txt",Serializer::READ)); |
---|
1263 | |
---|
1264 | if (auxTreeSimpSequence && mGeoMesh) |
---|
1265 | { |
---|
1266 | LodTreeConstructor * auxLodTreeConstructor = new LodTreeConstructor(mGeoMesh,auxTreeSimpSequence); |
---|
1267 | delete auxLodTreeConstructor; |
---|
1268 | } |
---|
1269 | else |
---|
1270 | { |
---|
1271 | fltk::alert("There is no leaf simplification sequence."); |
---|
1272 | break; |
---|
1273 | } |
---|
1274 | |
---|
1275 | |
---|
1276 | delete auxTreeSimpSequence;*/ |
---|
1277 | |
---|
1278 | case LODSTRIPS_AUTO: |
---|
1279 | |
---|
1280 | // Builder |
---|
1281 | if (!file_name) |
---|
1282 | { |
---|
1283 | file_name = fltk::file_chooser("Build LOD","*",""); |
---|
1284 | } |
---|
1285 | |
---|
1286 | // If a file was selected. |
---|
1287 | if (file_name) |
---|
1288 | { |
---|
1289 | // Undo the simplification changes. |
---|
1290 | undo(); |
---|
1291 | |
---|
1292 | // Stripify the mesh object. |
---|
1293 | stripify(); |
---|
1294 | |
---|
1295 | // Reset the build bar. |
---|
1296 | mBuildBar->position(0); |
---|
1297 | |
---|
1298 | // Simplification sequence. |
---|
1299 | oMeshSimpSequence = new MeshSimplificationSequence(); |
---|
1300 | |
---|
1301 | // Loads a simplification sequence file. |
---|
1302 | oMeshSimpSequence->Load(Serializer( "SimplifSequence.txt", |
---|
1303 | Serializer::READ)); |
---|
1304 | |
---|
1305 | // If the simplification sequence and the mesh exist. |
---|
1306 | if (oMeshSimpSequence && mGeoMesh) |
---|
1307 | { |
---|
1308 | oLodStrip = new LodStripsConstructor( mGeoMesh, |
---|
1309 | oMeshSimpSequence, |
---|
1310 | idMeshLeaves, |
---|
1311 | progress_function); |
---|
1312 | |
---|
1313 | oSerializer = new Serializer( strcat(file_name,".lod"), |
---|
1314 | Serializer::Mode::WRITE); |
---|
1315 | |
---|
1316 | oLodStrip->Save(*oSerializer); |
---|
1317 | |
---|
1318 | // Close file. |
---|
1319 | delete oSerializer; |
---|
1320 | |
---|
1321 | // Deletes the previous mesh. |
---|
1322 | delete mUndoMesh; |
---|
1323 | |
---|
1324 | mUndoMesh = new Mesh(); |
---|
1325 | |
---|
1326 | // Sets the undo mesh. |
---|
1327 | *mUndoMesh = *mGeoMesh; |
---|
1328 | |
---|
1329 | delete mGeoMesh; |
---|
1330 | |
---|
1331 | mGeoMesh = oLodStrip->GetMesh(); |
---|
1332 | |
---|
1333 | geoMeshView->setMesh(mGeoMesh); |
---|
1334 | |
---|
1335 | mesh_saver = new GeoMeshSaver(); |
---|
1336 | file_name[strlen(file_name) - 4] = '\0'; |
---|
1337 | |
---|
1338 | mesh_saver->leavesSubMesh=idMeshLeaves; |
---|
1339 | mesh_saver->leavesVB=origSubMeshVB; |
---|
1340 | mesh_saver->numindices=orig_numindices; |
---|
1341 | mesh_saver->indices=orig_indices; |
---|
1342 | mesh_saver->save(mGeoMesh,strcat(file_name,".mesh")); |
---|
1343 | |
---|
1344 | delete mesh_saver; |
---|
1345 | } |
---|
1346 | else |
---|
1347 | { |
---|
1348 | // Error message. |
---|
1349 | fltk::alert("There is no simplification sequence."); |
---|
1350 | } |
---|
1351 | |
---|
1352 | // Deletes the siplification sequence object. |
---|
1353 | delete oMeshSimpSequence; |
---|
1354 | } |
---|
1355 | break; |
---|
1356 | } |
---|
1357 | // Refresh data aplication. |
---|
1358 | refreshApplicationBar(); |
---|
1359 | } |
---|
1360 | } |
---|
1361 | |
---|
1362 | void GeoMeshViewUI::cb_mButtonBuild(fltk::Button *o, void *v) |
---|
1363 | { |
---|
1364 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1365 | -> |
---|
1366 | cb_mButtonBuild_i(o,v); |
---|
1367 | } |
---|
1368 | |
---|
1369 | //--------------------------------------------------------------------------- |
---|
1370 | // Lod Slider Callback |
---|
1371 | //--------------------------------------------------------------------------- |
---|
1372 | inline void GeoMeshViewUI::cb_mLodStripSlider_i(fltk::Slider *o, void *) |
---|
1373 | { |
---|
1374 | // Change the lod. |
---|
1375 | geoMeshView->GoToLod_LodStrip((float)o->value()); |
---|
1376 | |
---|
1377 | // Refresh data aplication. |
---|
1378 | refreshApplicationBar(); |
---|
1379 | |
---|
1380 | mMainWindow->flush(); |
---|
1381 | } |
---|
1382 | |
---|
1383 | void GeoMeshViewUI::cb_mLodStripSlider(fltk::Slider *o, void *v) |
---|
1384 | { |
---|
1385 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1386 | -> |
---|
1387 | cb_mLodStripSlider_i(o,v); |
---|
1388 | } |
---|
1389 | |
---|
1390 | //--------------------------------------------------------------------------- |
---|
1391 | // Lod Slider Callback for the foliage |
---|
1392 | //--------------------------------------------------------------------------- |
---|
1393 | inline void GeoMeshViewUI::cb_mLodTreeSlider_i(fltk::Slider *o, void *) |
---|
1394 | { |
---|
1395 | // Change the lod. |
---|
1396 | geoMeshView->GoToLod_LodTree((float)o->value()); |
---|
1397 | |
---|
1398 | // Refresh data aplication. |
---|
1399 | refreshApplicationBar(); |
---|
1400 | |
---|
1401 | mMainWindow->flush(); |
---|
1402 | } |
---|
1403 | |
---|
1404 | void GeoMeshViewUI::cb_mLodTreeSlider(fltk::Slider *o, void *v) |
---|
1405 | { |
---|
1406 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1407 | -> |
---|
1408 | cb_mLodTreeSlider_i(o,v); |
---|
1409 | } |
---|
1410 | |
---|
1411 | //--------------------------------------------------------------------------- |
---|
1412 | // Mesh Info Callback |
---|
1413 | //--------------------------------------------------------------------------- |
---|
1414 | inline void GeoMeshViewUI::cb_mMeshInfo_i(fltk::Browser *, void *) |
---|
1415 | { |
---|
1416 | paintMesh(); |
---|
1417 | } |
---|
1418 | |
---|
1419 | void GeoMeshViewUI::cb_mMeshInfo(fltk::Browser* o, void* v) |
---|
1420 | { |
---|
1421 | ((GeoMeshViewUI*) (o->parent()->parent()->parent()->user_data())) |
---|
1422 | -> |
---|
1423 | cb_mMeshInfo_i(o,v); |
---|
1424 | } |
---|
1425 | |
---|
1426 | //--------------------------------------------------------------------------- |
---|
1427 | // Logo Callback. |
---|
1428 | //--------------------------------------------------------------------------- |
---|
1429 | inline void GeoMeshViewUI::cb_mLogo_i(fltk::InvisibleBox*, void*) |
---|
1430 | { |
---|
1431 | } |
---|
1432 | |
---|
1433 | void GeoMeshViewUI::cb_mLogo(fltk::InvisibleBox* o, void* v) |
---|
1434 | { |
---|
1435 | ((GeoMeshViewUI*) (o->parent()->parent()->user_data())) |
---|
1436 | -> |
---|
1437 | cb_mLogo_i(o,v); |
---|
1438 | } |
---|
1439 | |
---|
1440 | //--------------------------------------------------------------------------- |
---|
1441 | // Active Build process. |
---|
1442 | //--------------------------------------------------------------------------- |
---|
1443 | void GeoMeshViewUI::activeBuildProcess() |
---|
1444 | { |
---|
1445 | //mButtonBuild->set_visible(); |
---|
1446 | mButtonBuild->activate(); |
---|
1447 | |
---|
1448 | //mBuildBar->set_visible(); |
---|
1449 | mBuildBar->activate(); |
---|
1450 | } |
---|
1451 | |
---|
1452 | //--------------------------------------------------------------------------- |
---|
1453 | // Show the stripify panel. |
---|
1454 | //--------------------------------------------------------------------------- |
---|
1455 | void GeoMeshViewUI::showStripify() |
---|
1456 | { |
---|
1457 | /* |
---|
1458 | mTypeLabel->set_visible(); |
---|
1459 | mTypeLabel->activate(); |
---|
1460 | |
---|
1461 | mOneCacheStrip->set_visible(); |
---|
1462 | mOneCacheStrip->activate(); |
---|
1463 | |
---|
1464 | mQualityStrips->set_visible(); |
---|
1465 | mQualityStrips->activate(); |
---|
1466 | */ |
---|
1467 | |
---|
1468 | mButtonProcess->set_visible(); |
---|
1469 | mButtonProcess->activate(); |
---|
1470 | |
---|
1471 | mProcessBar->set_visible(); |
---|
1472 | mProcessBar->activate(); |
---|
1473 | } |
---|
1474 | |
---|
1475 | //--------------------------------------------------------------------------- |
---|
1476 | // Hide the stripify panel. |
---|
1477 | //--------------------------------------------------------------------------- |
---|
1478 | void GeoMeshViewUI::hideStripify() |
---|
1479 | { |
---|
1480 | /* |
---|
1481 | mTypeLabel->hide(); |
---|
1482 | mTypeLabel->deactivate(); |
---|
1483 | */ |
---|
1484 | |
---|
1485 | mOneCacheStrip->hide(); |
---|
1486 | mOneCacheStrip->deactivate(); |
---|
1487 | |
---|
1488 | mQualityStrips->hide(); |
---|
1489 | mQualityStrips->deactivate(); |
---|
1490 | |
---|
1491 | mButtonProcess->hide(); |
---|
1492 | mButtonProcess->deactivate(); |
---|
1493 | |
---|
1494 | mProcessBar->hide(); |
---|
1495 | mProcessBar->deactivate(); |
---|
1496 | } |
---|
1497 | |
---|
1498 | //--------------------------------------------------------------------------- |
---|
1499 | // Show the Simplify Edge Collapse panel. |
---|
1500 | //--------------------------------------------------------------------------- |
---|
1501 | void GeoMeshViewUI::showEdgeCollapse() |
---|
1502 | { |
---|
1503 | mMetricLabel->set_visible(); |
---|
1504 | mMetricLabel->activate(); |
---|
1505 | |
---|
1506 | mGeometryBased->set_visible(); |
---|
1507 | mGeometryBased->activate(); |
---|
1508 | mGeometryBased->set(); |
---|
1509 | |
---|
1510 | mViewPointDriven->set_visible(); |
---|
1511 | mViewPointDriven->activate(); |
---|
1512 | |
---|
1513 | /* |
---|
1514 | mTypeLabel->set_visible(); |
---|
1515 | mTypeLabel->activate(); |
---|
1516 | |
---|
1517 | mChangeVertices->set_visible(); |
---|
1518 | mChangeVertices->activate(); |
---|
1519 | */ |
---|
1520 | |
---|
1521 | mMeshReductionLabel->set_visible(); |
---|
1522 | mMeshReductionLabel->activate(); |
---|
1523 | |
---|
1524 | mPercent->set_visible(); |
---|
1525 | mPercent->activate(); |
---|
1526 | mPercent->set(); |
---|
1527 | |
---|
1528 | mVerticesNumber->set_visible(); |
---|
1529 | mVerticesNumber->activate(); |
---|
1530 | |
---|
1531 | mMeshReduction->set_visible(); |
---|
1532 | |
---|
1533 | // Allows floating point. |
---|
1534 | mMeshReduction->type(fltk::FloatInput::FLOAT); |
---|
1535 | |
---|
1536 | mMeshReduction->activate(); |
---|
1537 | |
---|
1538 | mButtonProcess->set_visible(); |
---|
1539 | mButtonProcess->activate(); |
---|
1540 | |
---|
1541 | mProcessBar->set_visible(); |
---|
1542 | mProcessBar->activate(); |
---|
1543 | } |
---|
1544 | |
---|
1545 | //--------------------------------------------------------------------------- |
---|
1546 | // Hide the Simplify Edge Collapse |
---|
1547 | //--------------------------------------------------------------------------- |
---|
1548 | void GeoMeshViewUI::hideEdgeCollapse() |
---|
1549 | { |
---|
1550 | mMetricLabel->hide(); |
---|
1551 | mMetricLabel->deactivate(); |
---|
1552 | |
---|
1553 | mGeometryBased->hide(); |
---|
1554 | mGeometryBased->deactivate(); |
---|
1555 | |
---|
1556 | mViewPointDriven->hide(); |
---|
1557 | mViewPointDriven->deactivate(); |
---|
1558 | |
---|
1559 | /* |
---|
1560 | mTypeLabel->hide(); |
---|
1561 | mTypeLabel->deactivate(); |
---|
1562 | |
---|
1563 | mChangeVertices->hide(); |
---|
1564 | mChangeVertices->deactivate(); |
---|
1565 | */ |
---|
1566 | |
---|
1567 | mMeshReductionLabel->hide(); |
---|
1568 | mMeshReductionLabel->deactivate(); |
---|
1569 | |
---|
1570 | mPercent->hide(); |
---|
1571 | mPercent->deactivate(); |
---|
1572 | |
---|
1573 | mVerticesNumber->hide(); |
---|
1574 | mVerticesNumber->deactivate(); |
---|
1575 | |
---|
1576 | mMeshReduction->hide(); |
---|
1577 | mMeshReduction->deactivate(); |
---|
1578 | |
---|
1579 | mButtonProcess->hide(); |
---|
1580 | mButtonProcess->deactivate(); |
---|
1581 | |
---|
1582 | mProcessBar->hide(); |
---|
1583 | mProcessBar->deactivate(); |
---|
1584 | } |
---|
1585 | |
---|
1586 | //--------------------------------------------------------------------------- |
---|
1587 | // Show the Simlify Leaves Collapse. |
---|
1588 | //--------------------------------------------------------------------------- |
---|
1589 | void GeoMeshViewUI::showLeavesCollapse() |
---|
1590 | { |
---|
1591 | mMetricLabel->set_visible(); |
---|
1592 | mMetricLabel->activate(); |
---|
1593 | |
---|
1594 | mGeometryBased->set_visible(); |
---|
1595 | mGeometryBased->activate(); |
---|
1596 | mGeometryBased->set(); |
---|
1597 | |
---|
1598 | mViewPointDriven->set_visible(); |
---|
1599 | mViewPointDriven->activate(); |
---|
1600 | |
---|
1601 | /* |
---|
1602 | mTypeLabel->set_visible(); |
---|
1603 | mTypeLabel->activate(); |
---|
1604 | |
---|
1605 | mChangeTexture->set_visible(); |
---|
1606 | mChangeTexture->activate(); |
---|
1607 | */ |
---|
1608 | |
---|
1609 | mMeshReductionLabel->set_visible(); |
---|
1610 | mMeshReductionLabel->activate(); |
---|
1611 | |
---|
1612 | mPercent->set_visible(); |
---|
1613 | mPercent->activate(); |
---|
1614 | mPercent->set(); |
---|
1615 | |
---|
1616 | mVerticesNumber->set_visible(); |
---|
1617 | mVerticesNumber->activate(); |
---|
1618 | |
---|
1619 | mMeshReduction->set_visible(); |
---|
1620 | mMeshReduction->type(fltk::FloatInput::FLOAT); |
---|
1621 | mMeshReduction->activate(); |
---|
1622 | |
---|
1623 | mButtonProcess->set_visible(); |
---|
1624 | mButtonProcess->activate(); |
---|
1625 | |
---|
1626 | mProcessBar->set_visible(); |
---|
1627 | mProcessBar->activate(); |
---|
1628 | } |
---|
1629 | |
---|
1630 | //--------------------------------------------------------------------------- |
---|
1631 | // Hide the Simplify Leaves Collapse. |
---|
1632 | //--------------------------------------------------------------------------- |
---|
1633 | void GeoMeshViewUI::hideLeavesCollapse() |
---|
1634 | { |
---|
1635 | mMetricLabel->hide(); |
---|
1636 | mMetricLabel->deactivate(); |
---|
1637 | |
---|
1638 | mGeometryBased->hide(); |
---|
1639 | mGeometryBased->deactivate(); |
---|
1640 | |
---|
1641 | mViewPointDriven->hide(); |
---|
1642 | mViewPointDriven->deactivate(); |
---|
1643 | |
---|
1644 | /* |
---|
1645 | mTypeLabel->hide(); |
---|
1646 | mTypeLabel->deactivate(); |
---|
1647 | |
---|
1648 | mChangeTexture->hide(); |
---|
1649 | mChangeTexture->deactivate(); |
---|
1650 | */ |
---|
1651 | |
---|
1652 | mMeshReductionLabel->hide(); |
---|
1653 | mMeshReductionLabel->deactivate(); |
---|
1654 | |
---|
1655 | mPercent->hide(); |
---|
1656 | mPercent->deactivate(); |
---|
1657 | |
---|
1658 | mVerticesNumber->hide(); |
---|
1659 | mVerticesNumber->deactivate(); |
---|
1660 | |
---|
1661 | mMeshReduction->hide(); |
---|
1662 | mMeshReduction->deactivate(); |
---|
1663 | |
---|
1664 | mButtonProcess->hide(); |
---|
1665 | mButtonProcess->deactivate(); |
---|
1666 | |
---|
1667 | mProcessBar->hide(); |
---|
1668 | mProcessBar->deactivate(); |
---|
1669 | } |
---|
1670 | |
---|
1671 | //--------------------------------------------------------------------------- |
---|
1672 | // Show the LodStrips Panel. |
---|
1673 | //--------------------------------------------------------------------------- |
---|
1674 | void GeoMeshViewUI::showOpenMeshSimplification() |
---|
1675 | { |
---|
1676 | mButtonProcess->set_visible(); |
---|
1677 | mButtonProcess->activate(); |
---|
1678 | |
---|
1679 | mProcessBar->set_visible(); |
---|
1680 | mProcessBar->activate(); |
---|
1681 | |
---|
1682 | mButtonBuild->set_visible(); |
---|
1683 | mButtonBuild->activate(); |
---|
1684 | |
---|
1685 | mBuildBar->set_visible(); |
---|
1686 | mBuildBar->activate(); |
---|
1687 | } |
---|
1688 | |
---|
1689 | //--------------------------------------------------------------------------- |
---|
1690 | // Hide the LodStrips Panel. |
---|
1691 | //--------------------------------------------------------------------------- |
---|
1692 | void GeoMeshViewUI::hideOpenMeshSimplification() |
---|
1693 | { |
---|
1694 | mButtonProcess->hide(); |
---|
1695 | mButtonProcess->deactivate(); |
---|
1696 | |
---|
1697 | mProcessBar->hide(); |
---|
1698 | mProcessBar->deactivate(); |
---|
1699 | |
---|
1700 | mButtonBuild->hide(); |
---|
1701 | mButtonBuild->deactivate(); |
---|
1702 | |
---|
1703 | mBuildBar->hide(); |
---|
1704 | mBuildBar->deactivate(); |
---|
1705 | } |
---|
1706 | |
---|
1707 | //--------------------------------------------------------------------------- |
---|
1708 | // Shows the auto generate LodStrips panel. |
---|
1709 | //--------------------------------------------------------------------------- |
---|
1710 | void GeoMeshViewUI::showAutoGenerateLodStrips() |
---|
1711 | { |
---|
1712 | // Shows the simplify panel. |
---|
1713 | showEdgeCollapse(); |
---|
1714 | |
---|
1715 | mButtonBuild->set_visible(); |
---|
1716 | //mButtonBuild->activate(); |
---|
1717 | |
---|
1718 | mBuildBar->set_visible(); |
---|
1719 | //mBuildBar->activate(); |
---|
1720 | } |
---|
1721 | |
---|
1722 | //--------------------------------------------------------------------------- |
---|
1723 | // Shows the auto generate LodStrips panel. |
---|
1724 | //--------------------------------------------------------------------------- |
---|
1725 | void GeoMeshViewUI::showAutoGenerateLodTrees() |
---|
1726 | { |
---|
1727 | // Shows the simplify panel. |
---|
1728 | showEdgeCollapse(); |
---|
1729 | |
---|
1730 | mButtonBuild->set_visible(); |
---|
1731 | //mButtonBuild->activate(); |
---|
1732 | |
---|
1733 | mBuildBar->set_visible(); |
---|
1734 | //mBuildBar->activate(); |
---|
1735 | } |
---|
1736 | |
---|
1737 | //--------------------------------------------------------------------------- |
---|
1738 | // Show the LodStrips visulization panel. |
---|
1739 | //--------------------------------------------------------------------------- |
---|
1740 | void GeoMeshViewUI::showLodStripSlider() |
---|
1741 | { |
---|
1742 | mLodStripSlider->set_visible(); |
---|
1743 | mLodStripSlider->activate(); |
---|
1744 | } |
---|
1745 | |
---|
1746 | //--------------------------------------------------------------------------- |
---|
1747 | // Hide the LodStrips visualization panel. |
---|
1748 | //--------------------------------------------------------------------------- |
---|
1749 | void GeoMeshViewUI::hideLodStripSlider() |
---|
1750 | { |
---|
1751 | mLodStripSlider->hide(); |
---|
1752 | mLodStripSlider->deactivate(); |
---|
1753 | } |
---|
1754 | |
---|
1755 | //--------------------------------------------------------------------------- |
---|
1756 | // Show the LodTree visulization panel. |
---|
1757 | //--------------------------------------------------------------------------- |
---|
1758 | void GeoMeshViewUI::showLodTreeSlider() |
---|
1759 | { |
---|
1760 | mLodTreeSlider->set_visible(); |
---|
1761 | mLodTreeSlider->activate(); |
---|
1762 | } |
---|
1763 | |
---|
1764 | //--------------------------------------------------------------------------- |
---|
1765 | // Hide the LodTree visualization panel. |
---|
1766 | //--------------------------------------------------------------------------- |
---|
1767 | void GeoMeshViewUI::hideLodTreeSlider() |
---|
1768 | { |
---|
1769 | mLodTreeSlider->hide(); |
---|
1770 | mLodTreeSlider->deactivate(); |
---|
1771 | } |
---|
1772 | |
---|
1773 | //--------------------------------------------------------------------------- |
---|
1774 | // Show the LodTrees Panel. |
---|
1775 | //--------------------------------------------------------------------------- |
---|
1776 | void GeoMeshViewUI::showOpenLeavesSimplification() |
---|
1777 | { |
---|
1778 | mButtonBuild->set_visible(); |
---|
1779 | mButtonBuild->activate(); |
---|
1780 | |
---|
1781 | mBuildBar->set_visible(); |
---|
1782 | mBuildBar->activate(); |
---|
1783 | } |
---|
1784 | |
---|
1785 | //--------------------------------------------------------------------------- |
---|
1786 | // Hide the LodTrees Panel. |
---|
1787 | //--------------------------------------------------------------------------- |
---|
1788 | void GeoMeshViewUI::hideOpenLeavesSimplification() |
---|
1789 | { |
---|
1790 | mButtonBuild->hide(); |
---|
1791 | mButtonBuild->deactivate(); |
---|
1792 | |
---|
1793 | mBuildBar->hide(); |
---|
1794 | mBuildBar->deactivate(); |
---|
1795 | } |
---|
1796 | |
---|
1797 | //--------------------------------------------------------------------------- |
---|
1798 | // Show the mesh info browser. |
---|
1799 | //--------------------------------------------------------------------------- |
---|
1800 | void GeoMeshViewUI::showMeshInfo() |
---|
1801 | { |
---|
1802 | char type[10]; |
---|
1803 | |
---|
1804 | if (mGeoMesh) |
---|
1805 | { |
---|
1806 | // Remove previous mesh information |
---|
1807 | this->mMeshInfo->remove_all(); |
---|
1808 | ogeometry = new fltk::ItemGroup("Geometry"); |
---|
1809 | ogeometry->begin(); |
---|
1810 | |
---|
1811 | fltk::ItemGroup **oprueba; |
---|
1812 | oprueba=new fltk::ItemGroup*[mGeoMesh->mSubMeshCount]; |
---|
1813 | for(int i=0; i<mGeoMesh->mSubMeshCount;i++) |
---|
1814 | { |
---|
1815 | char *cadena=new char[256]; |
---|
1816 | |
---|
1817 | if (geoMeshView->getLeavesSubMesh() >= 0) |
---|
1818 | { |
---|
1819 | if (geoMeshView->getLeavesSubMesh() == i) |
---|
1820 | { |
---|
1821 | strcpy(type,"(Leaves)"); |
---|
1822 | } |
---|
1823 | else |
---|
1824 | { |
---|
1825 | strcpy(type,"(Trunc)"); |
---|
1826 | } |
---|
1827 | } |
---|
1828 | else |
---|
1829 | { |
---|
1830 | strcpy(type,""); |
---|
1831 | } |
---|
1832 | |
---|
1833 | // Submesh identifier. |
---|
1834 | sprintf(cadena,"SubMesh %d %s",i,type); |
---|
1835 | |
---|
1836 | oprueba[i] = new fltk::ItemGroup(cadena); |
---|
1837 | oprueba[i]->begin(); |
---|
1838 | fltk::Item *sharedGeometry; |
---|
1839 | if (mGeoMesh->mSubMesh[i].mSharedVertexBuffer) |
---|
1840 | { |
---|
1841 | sharedGeometry = new fltk::Item("Shared Geometry: Yes"); |
---|
1842 | } |
---|
1843 | else |
---|
1844 | { |
---|
1845 | sharedGeometry = new fltk::Item("Shared Geometry: No"); |
---|
1846 | } |
---|
1847 | |
---|
1848 | // Adds material name. |
---|
1849 | char *cadena2=new char[100]; |
---|
1850 | sprintf(cadena2, "Material: %s",mGeoMesh->mSubMesh[i].mMaterialName); |
---|
1851 | |
---|
1852 | fltk::Item *geomaterial = new fltk::Item(cadena2); |
---|
1853 | |
---|
1854 | char *cadena3=new char[100]; |
---|
1855 | |
---|
1856 | sprintf(cadena3, "Number of indexes: %d",mGeoMesh->mSubMesh[i].mIndexCount); |
---|
1857 | fltk::Item *numberIndex = new fltk::Item(cadena3); |
---|
1858 | if (mGeoMesh->mSubMesh[i].mType==Geometry::GEO_TRIANGLE_LIST) |
---|
1859 | { |
---|
1860 | fltk::Item *type = new fltk::Item("Triangle List"); |
---|
1861 | } |
---|
1862 | else |
---|
1863 | { |
---|
1864 | fltk::Item *type = new fltk::Item("Triangle Strips"); |
---|
1865 | } |
---|
1866 | |
---|
1867 | char *cadenavertex=new char[30]; |
---|
1868 | sprintf(cadenavertex, "Number of vertices: %d",mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexCount); |
---|
1869 | fltk::Item *numberVertex = new fltk::Item(cadenavertex); |
---|
1870 | |
---|
1871 | if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_NORMAL) |
---|
1872 | { |
---|
1873 | fltk::Item *normals = new fltk::Item("Normals: Yes"); |
---|
1874 | } |
---|
1875 | else |
---|
1876 | { |
---|
1877 | fltk::Item *normals = new fltk::Item("Normals: No"); |
---|
1878 | } |
---|
1879 | |
---|
1880 | if (mGeoMesh->mSubMesh[i].mVertexBuffer->mVertexInfo & Geometry::VERTEX_TEXCOORDS) |
---|
1881 | { |
---|
1882 | fltk::Item *textures = new fltk::Item("Textures: Yes"); |
---|
1883 | } |
---|
1884 | else |
---|
1885 | { |
---|
1886 | fltk::Item *textures = new fltk::Item("Textures: No"); |
---|
1887 | } |
---|
1888 | |
---|
1889 | |
---|
1890 | oprueba[i]->end(); |
---|
1891 | } |
---|
1892 | ogeometry->end(); |
---|
1893 | this->mMeshInfo->add(ogeometry); |
---|
1894 | } |
---|
1895 | |
---|
1896 | // Hide the right panel. |
---|
1897 | hideRightPanel(); |
---|
1898 | |
---|
1899 | mMeshInfo->set_visible(); |
---|
1900 | mMeshInfo->activate(); |
---|
1901 | } |
---|
1902 | |
---|
1903 | //--------------------------------------------------------------------------- |
---|
1904 | // Hide the mesh info browser. |
---|
1905 | //--------------------------------------------------------------------------- |
---|
1906 | void GeoMeshViewUI::hideMeshInfo() |
---|
1907 | { |
---|
1908 | mMeshInfo->hide(); |
---|
1909 | mMeshInfo->deactivate(); |
---|
1910 | } |
---|
1911 | |
---|
1912 | //--------------------------------------------------------------------------- |
---|
1913 | // Hide the right panel. |
---|
1914 | //--------------------------------------------------------------------------- |
---|
1915 | void GeoMeshViewUI::hideRightPanel() |
---|
1916 | { |
---|
1917 | hideStripify(); |
---|
1918 | hideEdgeCollapse(); |
---|
1919 | hideLeavesCollapse(); |
---|
1920 | hideOpenMeshSimplification(); |
---|
1921 | hideOpenLeavesSimplification(); |
---|
1922 | hideLodStripSlider(); |
---|
1923 | hideLodTreeSlider(); |
---|
1924 | hideMeshInfo(); |
---|
1925 | } |
---|
1926 | |
---|
1927 | //--------------------------------------------------------------------------- |
---|
1928 | // Get the number of vertices. |
---|
1929 | //--------------------------------------------------------------------------- |
---|
1930 | size_t GeoMeshViewUI::getVertexCount(Mesh *geoMesh) |
---|
1931 | { |
---|
1932 | size_t vertex_count; |
---|
1933 | SubMesh *geoSubMesh; |
---|
1934 | |
---|
1935 | vertex_count = geoMesh->mVertexBuffer->mVertexCount; |
---|
1936 | |
---|
1937 | // For each submesh. |
---|
1938 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
1939 | { |
---|
1940 | // Gets the actual submesh. |
---|
1941 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
1942 | |
---|
1943 | // If the mesh does not have shared vertex. |
---|
1944 | if (!geoSubMesh->mSharedVertexBuffer) |
---|
1945 | { |
---|
1946 | // Adds the vertex of the submesh to the total count. |
---|
1947 | vertex_count += geoSubMesh->mVertexBuffer->mVertexCount; |
---|
1948 | } |
---|
1949 | } |
---|
1950 | |
---|
1951 | return vertex_count; |
---|
1952 | } |
---|
1953 | |
---|
1954 | //--------------------------------------------------------------------------- |
---|
1955 | // Get the number of triangles. |
---|
1956 | //--------------------------------------------------------------------------- |
---|
1957 | size_t GeoMeshViewUI::getTriangleCount(Geometry::Mesh *geoMesh) |
---|
1958 | { |
---|
1959 | size_t triangle_count; |
---|
1960 | SubMesh *geoSubMesh; |
---|
1961 | |
---|
1962 | // Initialize the triangle count. |
---|
1963 | triangle_count = 0; |
---|
1964 | |
---|
1965 | // If the application is in visualize lodstrips mode. |
---|
1966 | if (mApplicationState == VISUALIZE_LODSTRIPS) |
---|
1967 | { |
---|
1968 | triangle_count = geoMeshView->getLodStripsTriangleCount(); |
---|
1969 | } |
---|
1970 | else |
---|
1971 | { |
---|
1972 | // For each submesh. |
---|
1973 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
1974 | { |
---|
1975 | // Gets the actual submesh. |
---|
1976 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
1977 | |
---|
1978 | switch (geoSubMesh->mType) |
---|
1979 | { |
---|
1980 | case GEO_TRIANGLE_LIST: |
---|
1981 | triangle_count += geoSubMesh->mIndexCount / 3; |
---|
1982 | break; |
---|
1983 | case GEO_TRIANGLE_STRIPS: |
---|
1984 | triangle_count += geoSubMesh->mIndexCount - 2; |
---|
1985 | break; |
---|
1986 | } |
---|
1987 | } |
---|
1988 | } |
---|
1989 | |
---|
1990 | return triangle_count; |
---|
1991 | } |
---|
1992 | |
---|
1993 | //--------------------------------------------------------------------------- |
---|
1994 | // Get the number of strips. |
---|
1995 | //--------------------------------------------------------------------------- |
---|
1996 | size_t GeoMeshViewUI::getStripCount(Geometry::Mesh *geoMesh) |
---|
1997 | { |
---|
1998 | size_t strip_count; |
---|
1999 | SubMesh *geoSubMesh; |
---|
2000 | |
---|
2001 | // Initialize the triangle count. |
---|
2002 | strip_count = 0; |
---|
2003 | |
---|
2004 | // For each submesh. |
---|
2005 | for (int submesh = 0; submesh < geoMesh->mSubMeshCount; submesh++) |
---|
2006 | { |
---|
2007 | // Gets the actual submesh. |
---|
2008 | geoSubMesh = &geoMesh->mSubMesh[submesh]; |
---|
2009 | |
---|
2010 | if (geoSubMesh->mType == GEO_TRIANGLE_STRIPS) |
---|
2011 | { |
---|
2012 | strip_count += geoSubMesh->mStripCount; |
---|
2013 | } |
---|
2014 | } |
---|
2015 | |
---|
2016 | return strip_count; |
---|
2017 | } |
---|
2018 | |
---|
2019 | //--------------------------------------------------------------------------- |
---|
2020 | // It paints the submesh selected by the mMeshInfo tree. |
---|
2021 | // Trate the mMeshInfo event. |
---|
2022 | //--------------------------------------------------------------------------- |
---|
2023 | int GeoMeshViewUI::paintMesh(void) |
---|
2024 | { |
---|
2025 | char selectedTag[100]; |
---|
2026 | char *pch; |
---|
2027 | char *p; |
---|
2028 | int meshNumber; |
---|
2029 | |
---|
2030 | // Initializa mesh to not selected. |
---|
2031 | meshNumber = -1; |
---|
2032 | |
---|
2033 | // Shows the selected object label. |
---|
2034 | strcpy(selectedTag,mMeshInfo->goto_focus()->label()); |
---|
2035 | |
---|
2036 | p=strstr(selectedTag,"SubMesh "); |
---|
2037 | |
---|
2038 | // If the item begins with string "SubMesh". |
---|
2039 | if (p!=NULL) |
---|
2040 | { |
---|
2041 | pch = strtok (selectedTag," "); |
---|
2042 | pch = strtok (NULL, " "); |
---|
2043 | sscanf(pch,"%d",&meshNumber); |
---|
2044 | } |
---|
2045 | |
---|
2046 | geoMeshView->setSubMeshSelected(meshNumber); |
---|
2047 | geoMeshView->redraw(); |
---|
2048 | |
---|
2049 | return meshNumber; |
---|
2050 | } |
---|
2051 | |
---|
2052 | //--------------------------------------------------------------------------- |
---|
2053 | // Simplify the mesh object. |
---|
2054 | //--------------------------------------------------------------------------- |
---|
2055 | bool GeoMeshViewUI::simplifyEdgeCollapse() |
---|
2056 | { |
---|
2057 | Real percent; |
---|
2058 | |
---|
2059 | // If input field empty. |
---|
2060 | if (mMeshReduction->fvalue() <= 0.0) |
---|
2061 | { |
---|
2062 | return false; |
---|
2063 | } |
---|
2064 | |
---|
2065 | geoMeshView->saveContext(); |
---|
2066 | |
---|
2067 | // Debug. |
---|
2068 | cout << "Mesh Reduction: " |
---|
2069 | << mMeshReduction->fvalue() |
---|
2070 | << endl; |
---|
2071 | |
---|
2072 | // Gets simplify option. |
---|
2073 | if (mGeometryBased->value()) |
---|
2074 | { |
---|
2075 | simplificationState = MESHSIMP; |
---|
2076 | mMeshSimplifier = new GeometryBasedSimplifier(mGeoMesh, |
---|
2077 | progress_function); |
---|
2078 | } |
---|
2079 | else |
---|
2080 | { |
---|
2081 | simplificationState = VIEWPOINTDRIVEN; |
---|
2082 | mMeshSimplifier = new ViewPointDrivenSimplifier(mGeoMesh, |
---|
2083 | progress_function); |
---|
2084 | } |
---|
2085 | |
---|
2086 | mMeshSimplifier->setMeshLeaves(idMeshLeaves); |
---|
2087 | |
---|
2088 | if (mPercent->value()) |
---|
2089 | { |
---|
2090 | // Simplificación por porcentaje |
---|
2091 | if (mMeshReduction->fvalue() <= 100.0 && |
---|
2092 | mMeshReduction->fvalue() > 0.0) |
---|
2093 | { |
---|
2094 | percent = mMeshReduction->fvalue(); |
---|
2095 | percent = percent / 100.0; |
---|
2096 | |
---|
2097 | // Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. |
---|
2098 | mMeshSimplifier->Simplify(percent); |
---|
2099 | |
---|
2100 | // Deletes the previous mesh. |
---|
2101 | delete mUndoMesh; |
---|
2102 | |
---|
2103 | mUndoMesh = new Mesh(); |
---|
2104 | |
---|
2105 | // Sets the undo mesh. |
---|
2106 | *mUndoMesh = *mGeoMesh; |
---|
2107 | |
---|
2108 | delete mGeoMesh; |
---|
2109 | |
---|
2110 | mGeoMesh = mMeshSimplifier->GetMesh(); |
---|
2111 | |
---|
2112 | // Visualize mesh. |
---|
2113 | geoMeshView->setMesh(mGeoMesh); |
---|
2114 | } |
---|
2115 | else |
---|
2116 | { |
---|
2117 | fltk::alert("Wrong value for simplification.\n" |
---|
2118 | "Valid values [0..100]"); |
---|
2119 | |
---|
2120 | return false; |
---|
2121 | } |
---|
2122 | } |
---|
2123 | else |
---|
2124 | { |
---|
2125 | // Simplificar hasta un número de vértices. |
---|
2126 | uint32 v = (uint32)mMeshReduction->fvalue(); |
---|
2127 | |
---|
2128 | // Simplifica el geomesh -> Parámetro es un factor LOD [0,1]. |
---|
2129 | mMeshSimplifier->Simplify(v); |
---|
2130 | |
---|
2131 | // Deletes the previous mesh. |
---|
2132 | delete mUndoMesh; |
---|
2133 | |
---|
2134 | mUndoMesh = new Mesh(); |
---|
2135 | |
---|
2136 | // Sets the undo mesh. |
---|
2137 | *mUndoMesh = *mGeoMesh; |
---|
2138 | |
---|
2139 | delete mGeoMesh; |
---|
2140 | |
---|
2141 | mGeoMesh = mMeshSimplifier->GetMesh(); |
---|
2142 | |
---|
2143 | // Visualize the mesh. |
---|
2144 | geoMeshView->setMesh(mGeoMesh); |
---|
2145 | } |
---|
2146 | |
---|
2147 | return true; |
---|
2148 | } |
---|
2149 | |
---|
2150 | //--------------------------------------------------------------------------- |
---|
2151 | // Simplify the mesh object. |
---|
2152 | //--------------------------------------------------------------------------- |
---|
2153 | void GeoMeshViewUI::simplifyLeavesCollapse() |
---|
2154 | { |
---|
2155 | bool error; |
---|
2156 | uint32 vi; |
---|
2157 | |
---|
2158 | // Initialize error flag. |
---|
2159 | error = false; |
---|
2160 | |
---|
2161 | // Check submeshes for triangles strips. |
---|
2162 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
2163 | { |
---|
2164 | // If current submesh is in triangle strips. |
---|
2165 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
2166 | { |
---|
2167 | error = true; |
---|
2168 | } |
---|
2169 | } |
---|
2170 | |
---|
2171 | // if the mesh is stripified. |
---|
2172 | if (error) |
---|
2173 | { |
---|
2174 | fltk::alert("Can't simplify a tree in triagle strips."); |
---|
2175 | } |
---|
2176 | // if the mesh is in triangle list. |
---|
2177 | else |
---|
2178 | { |
---|
2179 | simplificationState = HOJAS; |
---|
2180 | |
---|
2181 | mTreeSimplifier = new TreeSimplifier(mGeoMesh, progress_function); |
---|
2182 | vi = (uint32)mMeshReduction->fvalue(); |
---|
2183 | |
---|
2184 | // Simplify |
---|
2185 | if(idMeshLeaves != (unsigned short)-1) |
---|
2186 | { |
---|
2187 | // Simplify |
---|
2188 | mTreeSimplifier->Simplify(vi, idMeshLeaves); |
---|
2189 | |
---|
2190 | // Deletes the previous mesh. |
---|
2191 | delete mUndoMesh; |
---|
2192 | |
---|
2193 | mUndoMesh = new Mesh(); |
---|
2194 | |
---|
2195 | // Sets the undo mesh. |
---|
2196 | *mUndoMesh = *mGeoMesh; |
---|
2197 | |
---|
2198 | delete mGeoMesh; |
---|
2199 | |
---|
2200 | mGeoMesh = mTreeSimplifier->GetMesh(); |
---|
2201 | |
---|
2202 | geoMeshView->setMesh(mGeoMesh); |
---|
2203 | } |
---|
2204 | else |
---|
2205 | { |
---|
2206 | fltk::alert("You must select the mesh that contains the leaves."); |
---|
2207 | } |
---|
2208 | } |
---|
2209 | } |
---|
2210 | |
---|
2211 | //--------------------------------------------------------------------------- |
---|
2212 | // Create a simplification sequence of the simplification method. |
---|
2213 | //--------------------------------------------------------------------------- |
---|
2214 | void GeoMeshViewUI::createSimplificationSequence() |
---|
2215 | { |
---|
2216 | MeshSimplificationSequence *secsimpl; |
---|
2217 | |
---|
2218 | secsimpl = mMeshSimplifier->GetSimplificationSequence(); |
---|
2219 | |
---|
2220 | secsimpl->putMeshName(nombremesh); // Nombre del mesh para guardar la secuencia de simplificación |
---|
2221 | secsimpl->Save(Geometry::Serializer("SimplifSequence.txt",Serializer::WRITE)); |
---|
2222 | |
---|
2223 | //delete secsimpl; |
---|
2224 | } |
---|
2225 | |
---|
2226 | //--------------------------------------------------------------------------- |
---|
2227 | // Create a simplification sequence of the leaves. |
---|
2228 | //--------------------------------------------------------------------------- |
---|
2229 | void GeoMeshViewUI::createLeavesSequence(const std::string &filename) |
---|
2230 | { |
---|
2231 | TreeSimplificationSequence *tree_sequencer; |
---|
2232 | |
---|
2233 | tree_sequencer = mTreeSimplifier->GetSimplificationSequence(); |
---|
2234 | |
---|
2235 | tree_sequencer->putMeshName(nombremesh); |
---|
2236 | tree_sequencer->Save(Serializer(filename,Serializer::WRITE)); |
---|
2237 | |
---|
2238 | delete tree_sequencer; |
---|
2239 | } |
---|
2240 | |
---|
2241 | //--------------------------------------------------------------------------- |
---|
2242 | // Stripify the mesh object. |
---|
2243 | //--------------------------------------------------------------------------- |
---|
2244 | void GeoMeshViewUI::stripify() |
---|
2245 | { |
---|
2246 | bool error; |
---|
2247 | char char_value[10]; |
---|
2248 | CustomStripifier *geoStripifier; |
---|
2249 | |
---|
2250 | // Initialize error flag. |
---|
2251 | error = false; |
---|
2252 | |
---|
2253 | // Check submeshes for triangles strips. |
---|
2254 | for (int i = 0; i < mGeoMesh->mSubMeshCount; i++) |
---|
2255 | { |
---|
2256 | // If current submesh is in triangle strips. |
---|
2257 | if (mGeoMesh->mSubMesh[i].mType == GEO_TRIANGLE_STRIPS) |
---|
2258 | { |
---|
2259 | error = true; |
---|
2260 | } |
---|
2261 | } |
---|
2262 | |
---|
2263 | // if the mesh is stripified. |
---|
2264 | if (error) |
---|
2265 | { |
---|
2266 | fltk::alert("The mesh is already in strips."); |
---|
2267 | } |
---|
2268 | // if the mesh is in triangle list. |
---|
2269 | else |
---|
2270 | { |
---|
2271 | //Stripify. |
---|
2272 | geoStripifier = new CustomStripifier(mGeoMesh); |
---|
2273 | |
---|
2274 | // Set the progress bar function. |
---|
2275 | geoStripifier->SetProgressFunc(progress_function); |
---|
2276 | |
---|
2277 | // Sets the leaves submesh if exists. |
---|
2278 | geoStripifier->SetSubMeshLeaves(idMeshLeaves); |
---|
2279 | |
---|
2280 | if (geoStripifier->Stripify()) |
---|
2281 | { |
---|
2282 | // Deletes the mesh object. |
---|
2283 | delete mUndoMesh; |
---|
2284 | |
---|
2285 | mUndoMesh = new Mesh(); |
---|
2286 | |
---|
2287 | *mUndoMesh = *mGeoMesh; |
---|
2288 | |
---|
2289 | delete mGeoMesh; |
---|
2290 | |
---|
2291 | // Gets the mesh stripified. |
---|
2292 | mGeoMesh = geoStripifier->GetMesh(); |
---|
2293 | |
---|
2294 | // Visualize the mesh stripified. |
---|
2295 | geoMeshView->setMesh(mGeoMesh); |
---|
2296 | |
---|
2297 | // Store the color of the strips. |
---|
2298 | geoMeshView->setStripColors(); |
---|
2299 | } |
---|
2300 | else |
---|
2301 | { |
---|
2302 | // Error message. |
---|
2303 | fltk::alert("Impossible to stripify. The mesh is not manifold"); |
---|
2304 | } |
---|
2305 | |
---|
2306 | // Deletes the stripifier object. |
---|
2307 | delete geoStripifier; |
---|
2308 | } |
---|
2309 | } |
---|
2310 | |
---|
2311 | //--------------------------------------------------------------------------- |
---|
2312 | // Method that undo then mesh changes. |
---|
2313 | //--------------------------------------------------------------------------- |
---|
2314 | void GeoMeshViewUI::undo() |
---|
2315 | { |
---|
2316 | // if the undo mesh is not initialized. |
---|
2317 | if (mUndoMesh != NULL) |
---|
2318 | { |
---|
2319 | // Deletes the actual mesh. |
---|
2320 | delete mGeoMesh; |
---|
2321 | |
---|
2322 | mGeoMesh = new Mesh(); |
---|
2323 | |
---|
2324 | // Restore the previous mesh. |
---|
2325 | *mGeoMesh = *mUndoMesh; |
---|
2326 | |
---|
2327 | // Visualize the mesh. |
---|
2328 | geoMeshView->setMesh(mGeoMesh); |
---|
2329 | |
---|
2330 | // Refresh geometry attributes. |
---|
2331 | refreshApplicationBar(); |
---|
2332 | |
---|
2333 | // Repaint the window. |
---|
2334 | mMainWindow->redraw(); |
---|
2335 | } |
---|
2336 | } |
---|
2337 | |
---|
2338 | //--------------------------------------------------------------------------- |
---|
2339 | // Refresh number of vertices, triangles, strips, ... |
---|
2340 | //--------------------------------------------------------------------------- |
---|
2341 | void GeoMeshViewUI::refreshApplicationBar() |
---|
2342 | { |
---|
2343 | static char vertices_value[50]; |
---|
2344 | static char triangles_value[50]; |
---|
2345 | static char strips_value[50]; |
---|
2346 | |
---|
2347 | // Translate the vertex count to a char value. |
---|
2348 | sprintf(vertices_value,"Vertices %d",getVertexCount(mGeoMesh)); |
---|
2349 | |
---|
2350 | mVertices->label(vertices_value); |
---|
2351 | |
---|
2352 | // Translate the triangle count to a char value. |
---|
2353 | sprintf(triangles_value,"Triangles %d",getTriangleCount(mGeoMesh)); |
---|
2354 | |
---|
2355 | mTriangles->label(triangles_value); |
---|
2356 | |
---|
2357 | // Translate the triangle count to a char value. |
---|
2358 | sprintf(strips_value,"Strips %d",getStripCount(mGeoMesh)); |
---|
2359 | |
---|
2360 | mStrips->label(strips_value); |
---|
2361 | } |
---|
2362 | |
---|
2363 | // Method that updates the porgress bar. |
---|
2364 | float GeoMeshViewUI::updateProgressBar(float v) |
---|
2365 | { |
---|
2366 | fltk::ProgressBar *progressBar; |
---|
2367 | |
---|
2368 | // Choose progress bar to update. |
---|
2369 | switch(progressBarType) |
---|
2370 | { |
---|
2371 | case PROCESS: |
---|
2372 | progressBar = mProcessBar; |
---|
2373 | break; |
---|
2374 | case BUILD: |
---|
2375 | progressBar = mBuildBar; |
---|
2376 | break; |
---|
2377 | } |
---|
2378 | |
---|
2379 | // Update progress bar. |
---|
2380 | progressBar->step(v); |
---|
2381 | progressBar->step(); |
---|
2382 | mMainWindow->flush(); |
---|
2383 | //mMainWindow->redraw(); |
---|
2384 | |
---|
2385 | return 0; |
---|
2386 | } |
---|
2387 | |
---|
2388 | //--------------------------------------------------------------------------- |
---|
2389 | // Initialize the lodstripslibrary for visualization. |
---|
2390 | //--------------------------------------------------------------------------- |
---|
2391 | void GeoMeshViewUI::setLodStripsLibrary(std::string lodfile, Mesh *geomesh) |
---|
2392 | { |
---|
2393 | // If there is no lod strips object. |
---|
2394 | if (lodStripsLib) |
---|
2395 | { |
---|
2396 | delete lodStripsLib; |
---|
2397 | } |
---|
2398 | |
---|
2399 | // New lod strips object. |
---|
2400 | lodStripsLib = new LodStripsLibrary(lodfile, geomesh); |
---|
2401 | |
---|
2402 | // Sets the slider range. |
---|
2403 | // mLodStripSlider->range(lodStripsLib->MinLod(),lodStripsLib->MaxLod()); |
---|
2404 | mLodStripSlider->range(0.0f,1.0f); |
---|
2405 | |
---|
2406 | // Pass to geomeshview the lod strips object. |
---|
2407 | geoMeshView->setLodStripsLibrary(lodStripsLib); |
---|
2408 | |
---|
2409 | // Puts the slider in the max position. |
---|
2410 | //mLodStripSlider->value(lodStripsLib->MinLod()); |
---|
2411 | } |
---|
2412 | |
---|
2413 | //--------------------------------------------------------------------------- |
---|
2414 | // Initialize the lodTreelibrary for visualization. |
---|
2415 | //--------------------------------------------------------------------------- |
---|
2416 | //void GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, Mesh *geomesh) |
---|
2417 | void GeoMeshViewUI::setLodTreesLibrary(std::string lodfile, std::string leafseqfile, Mesh *geomesh, uint32 ileafSubMesh) |
---|
2418 | |
---|
2419 | { |
---|
2420 | // If there is no lod strips object. |
---|
2421 | if (lodTreeLib) |
---|
2422 | { |
---|
2423 | delete lodTreeLib; |
---|
2424 | } |
---|
2425 | |
---|
2426 | // New lod strips object. |
---|
2427 | /* lodTreeLib = new Geometry::LodTreeLibrary(lodfile, geomesh,"\\\\quake\\home\\\Modelos\\betula_populifolia\\vertices.obj", |
---|
2428 | "\\\\quake\\home\\\Modelos\\betula_populifolia\\hojas.obj", |
---|
2429 | "\\\\quake\\home\\\Modelos\\betula_populifolia\\simplifica.obj");*/ |
---|
2430 | |
---|
2431 | lodTreeLib = new Geometry::LodTreeLibrary(lodfile,leafseqfile,geomesh,ileafSubMesh); |
---|
2432 | |
---|
2433 | // Sets the slider range. |
---|
2434 | // mLodStripSlider->range(lodTreeLib->MaxTrunkLod(), lodTreeLib->MinTrunkLod()); |
---|
2435 | // mLodTreeSlider->range(lodTreeLib->MaxFoliageLod(), lodTreeLib->MinFoliageLod()); |
---|
2436 | mLodStripSlider->range(0.0f,1.0f); |
---|
2437 | mLodTreeSlider->range(0.0f,1.0f); |
---|
2438 | |
---|
2439 | // Pass to geomeshview the lod strips object. |
---|
2440 | geoMeshView->setLodTreesLibrary(lodTreeLib); |
---|
2441 | |
---|
2442 | // Puts the slider in the max position. |
---|
2443 | mLodStripSlider->value(1.0f); |
---|
2444 | mLodTreeSlider->value(1.0f); |
---|
2445 | } |
---|
2446 | |
---|
2447 | //--------------------------------------------------------------------------- |
---|
2448 | // Open a mesh file. |
---|
2449 | //--------------------------------------------------------------------------- |
---|
2450 | void GeoMeshViewUI::openMeshFile(void) |
---|
2451 | { |
---|
2452 | Mesh *mesh_loaded; |
---|
2453 | fltk::FileChooser *fcho; |
---|
2454 | static char char_value[10]; |
---|
2455 | static char title[256]; |
---|
2456 | |
---|
2457 | fcho = new fltk::FileChooser("", "*.{mesh,obj}", fltk::FileChooser::CREATE, "Open a mesh"); |
---|
2458 | |
---|
2459 | fcho->exec(); |
---|
2460 | |
---|
2461 | // File name. |
---|
2462 | mFileName = (char *)fcho->value(); |
---|
2463 | |
---|
2464 | if (mFileName) |
---|
2465 | { |
---|
2466 | // Loads a new mesh. |
---|
2467 | mesh_loaded = geoMeshLoader->load(mFileName); |
---|
2468 | |
---|
2469 | // If no error happens. |
---|
2470 | if (mesh_loaded) |
---|
2471 | { |
---|
2472 | // Identify the mesh that stores the leaves |
---|
2473 | idMeshLeaves = -1; |
---|
2474 | |
---|
2475 | // Delete the current mesh. |
---|
2476 | delete mGeoMesh; |
---|
2477 | delete mUndoMesh; |
---|
2478 | |
---|
2479 | // Assigns mesh loaded. |
---|
2480 | mGeoMesh = mesh_loaded; |
---|
2481 | |
---|
2482 | // Set Window Title. |
---|
2483 | strcpy(title,filename_name(mFileName)); |
---|
2484 | mMainWindow->label(strcat(title," - GeoTool")); |
---|
2485 | |
---|
2486 | // Stores the name of the mesh. |
---|
2487 | nombremesh = new char[255]; |
---|
2488 | strcpy(nombremesh,mFileName); |
---|
2489 | |
---|
2490 | // Reset the undo mesh. |
---|
2491 | mUndoMesh = new Mesh(); |
---|
2492 | *mUndoMesh = *mGeoMesh; |
---|
2493 | |
---|
2494 | // Translate the MB count to a char value. |
---|
2495 | sprintf(char_value, |
---|
2496 | "MB %.3f", |
---|
2497 | (float)geoMeshLoader->getFileSize()/1024/1024); |
---|
2498 | |
---|
2499 | mMB->label(char_value); |
---|
2500 | |
---|
2501 | // Visualize mesh. |
---|
2502 | geoMeshView->setMesh(mGeoMesh); |
---|
2503 | |
---|
2504 | // Set textures. |
---|
2505 | geoMeshView->resetTextures(); |
---|
2506 | setTextures(); |
---|
2507 | |
---|
2508 | // Hide right panel. |
---|
2509 | hideRightPanel(); |
---|
2510 | |
---|
2511 | // Quit culling. |
---|
2512 | menuRenderCW->clear_value(); |
---|
2513 | menuRenderCCW->clear_value(); |
---|
2514 | geoMeshView->deactiveCW(); |
---|
2515 | geoMeshView->deactiveCCW(); |
---|
2516 | |
---|
2517 | // Deactive solid mode and wire. |
---|
2518 | menuRenderSolid->clear_value(); |
---|
2519 | menuRenderWire->clear_value(); |
---|
2520 | geoMeshView->deactiveSolid(); |
---|
2521 | geoMeshView->deactiveWire(); |
---|
2522 | |
---|
2523 | // Fit model in midle. |
---|
2524 | geoMeshView->fit(); |
---|
2525 | |
---|
2526 | // Lighting smooth. |
---|
2527 | menuRenderFlat->clear_value(); |
---|
2528 | menuRenderSmooth->set_value(); |
---|
2529 | geoMeshView->smooth(); |
---|
2530 | |
---|
2531 | // Show title. |
---|
2532 | mProcessTitle->label("Mesh Info"); |
---|
2533 | |
---|
2534 | // Shows the mesh info. |
---|
2535 | showMeshInfo(); |
---|
2536 | |
---|
2537 | // if the mesh is stripified. |
---|
2538 | geoMeshView->setStripColors(); |
---|
2539 | |
---|
2540 | // Refresh geometry attributes. |
---|
2541 | refreshApplicationBar(); |
---|
2542 | |
---|
2543 | // Restore simplification state. |
---|
2544 | simplificationState = NO_SIMPLIFICATION; |
---|
2545 | } |
---|
2546 | } |
---|
2547 | // Free memory. |
---|
2548 | delete fcho; |
---|
2549 | } |
---|
2550 | |
---|
2551 | // Set textures to mesh model. |
---|
2552 | void GeoMeshViewUI::setTextures() |
---|
2553 | { |
---|
2554 | GeoMaterialLoader *loader; |
---|
2555 | string filename; |
---|
2556 | string material; |
---|
2557 | |
---|
2558 | loader = new GeoMaterialLoader(); |
---|
2559 | |
---|
2560 | // For each submesh. |
---|
2561 | for (int submesh = 0; submesh < mGeoMesh->mSubMeshCount; submesh++) |
---|
2562 | { |
---|
2563 | material = string(mGeoMesh->mSubMesh[submesh].mMaterialName); |
---|
2564 | |
---|
2565 | if (loader->existsMaterial(material)) |
---|
2566 | { |
---|
2567 | // Debug. |
---|
2568 | cout << "Material " |
---|
2569 | << material |
---|
2570 | << " found." |
---|
2571 | << endl; |
---|
2572 | |
---|
2573 | filename = loader->getTextureFileName(material); |
---|
2574 | |
---|
2575 | // Debug. |
---|
2576 | cout << "File: " |
---|
2577 | << filename.c_str() |
---|
2578 | << endl; |
---|
2579 | |
---|
2580 | geoMeshView->LoadTextureSubMesh(submesh, filename.c_str()); |
---|
2581 | } |
---|
2582 | } |
---|
2583 | } |
---|
2584 | |
---|
2585 | //--------------------------------------------------------------------------- |
---|
2586 | // If file exists. |
---|
2587 | //--------------------------------------------------------------------------- |
---|
2588 | bool GeoMeshViewUI::fileExists(const char *fileNameMesh) |
---|
2589 | { |
---|
2590 | FILE *pFile; |
---|
2591 | |
---|
2592 | // Open the mesh file. |
---|
2593 | pFile = fopen(fileNameMesh, "r"); |
---|
2594 | |
---|
2595 | if (pFile) |
---|
2596 | { |
---|
2597 | return true; |
---|
2598 | } |
---|
2599 | else |
---|
2600 | { |
---|
2601 | return false; |
---|
2602 | } |
---|
2603 | } |
---|
2604 | |
---|
2605 | /******************/ |
---|
2606 | /* Constructor */ |
---|
2607 | /******************/ |
---|
2608 | GeoMeshViewUI::GeoMeshViewUI(TIPOFUNC fun) |
---|
2609 | { |
---|
2610 | progress_function = fun; |
---|
2611 | fltk::gifImage *logo; |
---|
2612 | |
---|
2613 | // Initialize the file name. |
---|
2614 | mFileName = NULL; |
---|
2615 | |
---|
2616 | // Initialize the 3D object. |
---|
2617 | mGeoMesh = NULL; |
---|
2618 | mUndoMesh = NULL; |
---|
2619 | |
---|
2620 | // Initialize the lod strip object. |
---|
2621 | lodStripsLib = NULL; |
---|
2622 | lodTreeLib = NULL; |
---|
2623 | |
---|
2624 | // Identify the mesh that stores the leaves |
---|
2625 | idMeshLeaves = -1; |
---|
2626 | |
---|
2627 | // Initialize the loader of meshes. |
---|
2628 | geoMeshLoader = new GeoMeshLoader(); |
---|
2629 | |
---|
2630 | // Initialize the menus application state. |
---|
2631 | mApplicationState = NONE; |
---|
2632 | |
---|
2633 | SubMeshNames=NULL; |
---|
2634 | |
---|
2635 | { |
---|
2636 | fltk::Window* o = new fltk::Window(800, 600,"GeoTool"); |
---|
2637 | |
---|
2638 | mMainWindow = o; |
---|
2639 | |
---|
2640 | // Program Icon for Win32. |
---|
2641 | mMainWindow->icon((char *)LoadIcon( GetModuleHandle(0), |
---|
2642 | MAKEINTRESOURCE(GEOICON))); |
---|
2643 | |
---|
2644 | // Double buffer. |
---|
2645 | mMainWindow->set_double_buffer(); |
---|
2646 | |
---|
2647 | o->user_data((void*)(this)); |
---|
2648 | o->begin(); |
---|
2649 | |
---|
2650 | { |
---|
2651 | fltk::Group* o = new fltk::Group(0, 27, 806, 559); |
---|
2652 | o->begin(); |
---|
2653 | |
---|
2654 | { |
---|
2655 | fltk::Group* o; |
---|
2656 | o = MainView = new fltk::Group(0, 0, 570, 530); |
---|
2657 | o->begin(); |
---|
2658 | |
---|
2659 | { |
---|
2660 | fltk::InvisibleBox* o; |
---|
2661 | o = cframe = new fltk::InvisibleBox(0, 0, 570, 530); |
---|
2662 | o->box(fltk::FLAT_BOX); |
---|
2663 | o->color((fltk::Color)0xffffff00); |
---|
2664 | //fltk::Group::current()->resizable(o); |
---|
2665 | } |
---|
2666 | |
---|
2667 | { |
---|
2668 | GeoMeshView* o; |
---|
2669 | o = geoMeshView = new GeoMeshView( 0,0,570,530,0,this); |
---|
2670 | } |
---|
2671 | |
---|
2672 | o->end(); |
---|
2673 | |
---|
2674 | fltk::Group::current()->resizable(o); |
---|
2675 | |
---|
2676 | } |
---|
2677 | |
---|
2678 | { |
---|
2679 | fltk::Group* o; |
---|
2680 | o = MainView = new fltk::Group(570, 0, 230, 530); |
---|
2681 | o->begin(); |
---|
2682 | |
---|
2683 | { |
---|
2684 | fltk::Button* o; |
---|
2685 | //o = mButtonProcess = new fltk::Button(665, 410, 73, 25, "Process"); |
---|
2686 | o = mButtonProcess = new fltk::Button(75, 410, 73, 25, "Process"); |
---|
2687 | o->callback((fltk::Callback*)cb_mButtonProcess); |
---|
2688 | o->hide(); |
---|
2689 | o->deactivate(); |
---|
2690 | } |
---|
2691 | |
---|
2692 | { |
---|
2693 | fltk::ProgressBar* o; |
---|
2694 | //o = mProcessBar = new fltk::ProgressBar(616, 435, 175, 18); |
---|
2695 | o = mProcessBar = new fltk::ProgressBar(16, 435, 195, 18); |
---|
2696 | o->hide(); |
---|
2697 | o->deactivate(); |
---|
2698 | } |
---|
2699 | |
---|
2700 | { |
---|
2701 | fltk::Button* o; |
---|
2702 | o = mButtonSort = new fltk::Button(75, 375, 73, 25, "Sort"); |
---|
2703 | o->callback((fltk::Callback*)cb_mButtonSort); |
---|
2704 | o->hide(); |
---|
2705 | o->deactivate(); |
---|
2706 | } |
---|
2707 | |
---|
2708 | { |
---|
2709 | fltk::ProgressBar* o; |
---|
2710 | o = mSortBar = new fltk::ProgressBar(16, 390, 195, 18); |
---|
2711 | o->hide(); |
---|
2712 | o->deactivate(); |
---|
2713 | } |
---|
2714 | |
---|
2715 | { |
---|
2716 | fltk::Button* o; |
---|
2717 | o = mButtonBuild = new fltk::Button(75, 455, 73, 25, "Build"); |
---|
2718 | o->callback((fltk::Callback*)cb_mButtonBuild); |
---|
2719 | o->hide(); |
---|
2720 | o->deactivate(); |
---|
2721 | } |
---|
2722 | |
---|
2723 | { |
---|
2724 | fltk::ProgressBar* o; |
---|
2725 | o = mBuildBar = new fltk::ProgressBar(16, 480, 195, 18); |
---|
2726 | o->hide(); |
---|
2727 | o->deactivate(); |
---|
2728 | } |
---|
2729 | |
---|
2730 | { |
---|
2731 | fltk::Slider* o; |
---|
2732 | o = mLodStripSlider = new fltk::Slider(16, 50, 30, 450); |
---|
2733 | o->type(fltk::Slider::TICK_BELOW); |
---|
2734 | o->set_vertical(); |
---|
2735 | o->callback((fltk::Callback*)cb_mLodStripSlider); |
---|
2736 | o->hide(); |
---|
2737 | o->deactivate(); |
---|
2738 | } |
---|
2739 | { |
---|
2740 | fltk::Slider* o; |
---|
2741 | o = mLodTreeSlider = new fltk::Slider(46, 50, 30, 450); |
---|
2742 | o->type(fltk::Slider::TICK_BELOW); |
---|
2743 | o->set_vertical(); |
---|
2744 | o->callback((fltk::Callback*)cb_mLodTreeSlider); |
---|
2745 | o->hide(); |
---|
2746 | o->deactivate(); |
---|
2747 | } |
---|
2748 | |
---|
2749 | { |
---|
2750 | mMetricLabel = new fltk::Output(26, 28, 5, 25, "Metric"); |
---|
2751 | fltk::Output* o = mMetricLabel; |
---|
2752 | o->set_vertical(); |
---|
2753 | o->box(fltk::NO_BOX); |
---|
2754 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2755 | o->color((fltk::Color)0xe0dfe300); |
---|
2756 | o->align(fltk::ALIGN_RIGHT); |
---|
2757 | } |
---|
2758 | |
---|
2759 | { |
---|
2760 | fltk::Group* o; |
---|
2761 | o = MainView = new fltk::Group(30, 40, 30, 60); |
---|
2762 | o->begin(); |
---|
2763 | { |
---|
2764 | mGeometryBased = new fltk::RadioButton(0, 8, 25, 25, "Geometry based"); |
---|
2765 | mViewPointDriven = new fltk::RadioButton(0, 23, 25, 25, "Viewpoint driven"); |
---|
2766 | } |
---|
2767 | o->end(); |
---|
2768 | } |
---|
2769 | |
---|
2770 | //mChangeVertices = new fltk::CheckButton(30, 104, 25, 25, "Change vertices"); |
---|
2771 | |
---|
2772 | { |
---|
2773 | mProcessTitle = new fltk::Widget(0, 0, 230, 25, ""); |
---|
2774 | fltk::Widget* o = mProcessTitle; |
---|
2775 | o->set_vertical(); |
---|
2776 | o->box(fltk::NO_BOX); |
---|
2777 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2778 | o->labelsize(15.0); |
---|
2779 | o->color((fltk::Color)0xe0dfe300); |
---|
2780 | o->align(fltk::ALIGN_CENTER); |
---|
2781 | } |
---|
2782 | |
---|
2783 | /* |
---|
2784 | { |
---|
2785 | mTypeLabel = new fltk::Output(26, 82, 5, 25, "Type"); |
---|
2786 | fltk::Output* o = mTypeLabel; |
---|
2787 | o->set_vertical(); |
---|
2788 | o->box(fltk::NO_BOX); |
---|
2789 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2790 | o->color((fltk::Color)0xe0dfe300); |
---|
2791 | o->align(fltk::ALIGN_RIGHT); |
---|
2792 | } |
---|
2793 | */ |
---|
2794 | |
---|
2795 | { |
---|
2796 | mMeshReductionLabel = new fltk::Output(26, 124, 5, 25, "Mesh Reduction"); |
---|
2797 | fltk::Output* o = mMeshReductionLabel; |
---|
2798 | o->set_vertical(); |
---|
2799 | o->box(fltk::NO_BOX); |
---|
2800 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
2801 | o->color((fltk::Color)0xe0dfe300); |
---|
2802 | o->align(fltk::ALIGN_RIGHT); |
---|
2803 | } |
---|
2804 | |
---|
2805 | //mChangeTexture = new fltk::CheckButton(30, 104, 25, 25, "Change texture"); |
---|
2806 | |
---|
2807 | { |
---|
2808 | fltk::Group* o; |
---|
2809 | o = MainView = new fltk::Group(30, 140, 30, 60); |
---|
2810 | o->begin(); |
---|
2811 | |
---|
2812 | { |
---|
2813 | mPercent = new fltk::RadioButton(0, 5, 25, 25, "%"); |
---|
2814 | mVerticesNumber = new fltk::RadioButton(0, 20, 25, 25, "Vertices number"); |
---|
2815 | } |
---|
2816 | o->end(); |
---|
2817 | } |
---|
2818 | |
---|
2819 | { |
---|
2820 | mMeshReduction = new fltk::FloatInput(75, 181, 75, 21, "Value:"); |
---|
2821 | fltk::FloatInput* o = mMeshReduction; |
---|
2822 | o->type(1); |
---|
2823 | } |
---|
2824 | |
---|
2825 | { |
---|
2826 | fltk::Group* o; |
---|
2827 | o = MainView = new fltk::Group(30, 100, 30, 60); |
---|
2828 | o->begin(); |
---|
2829 | |
---|
2830 | { |
---|
2831 | mOneCacheStrip = new fltk::RadioButton(0, 4, 25, 25, "One cache strip"); |
---|
2832 | mQualityStrips = new fltk::RadioButton(0, 23, 25, 25, "Quality strips"); |
---|
2833 | } |
---|
2834 | o->end(); |
---|
2835 | } |
---|
2836 | |
---|
2837 | { |
---|
2838 | fltk::Browser* o = mMeshInfo = new fltk::Browser(0, 20, 230, 380); |
---|
2839 | o->set_vertical(); |
---|
2840 | o->callback((fltk::Callback*)cb_mMeshInfo); |
---|
2841 | } |
---|
2842 | o->end(); |
---|
2843 | } |
---|
2844 | |
---|
2845 | o->end(); |
---|
2846 | |
---|
2847 | fltk::Group::current()->resizable(o); |
---|
2848 | } |
---|
2849 | |
---|
2850 | { |
---|
2851 | fltk::MenuBar* o = menuBar = new fltk::MenuBar(1, 2, 801, 21); |
---|
2852 | o->begin(); |
---|
2853 | |
---|
2854 | // Menu File. |
---|
2855 | { |
---|
2856 | fltk::ItemGroup* o = menuFile = new fltk::ItemGroup("File"); |
---|
2857 | o->begin(); |
---|
2858 | |
---|
2859 | { |
---|
2860 | fltk::Item* o = menuFileOpen = new fltk::Item("Open"); |
---|
2861 | o->callback((fltk::Callback*)cb_menuFileOpen); |
---|
2862 | } |
---|
2863 | |
---|
2864 | { |
---|
2865 | fltk::Item* o = menuFileSave = new fltk::Item("Save"); |
---|
2866 | o->callback((fltk::Callback*)cb_menuFileSave); |
---|
2867 | } |
---|
2868 | |
---|
2869 | { |
---|
2870 | fltk::Item* o = menuFileSaveAs = new fltk::Item("Save As"); |
---|
2871 | o->callback((fltk::Callback*)cb_menuFileSaveAs); |
---|
2872 | } |
---|
2873 | |
---|
2874 | { |
---|
2875 | fltk::Item* o = menuMeshExportOBJ = new fltk::Item("Export to OBJ"); |
---|
2876 | o->callback((fltk::Callback*)cb_menuMeshExportOBJ); |
---|
2877 | } |
---|
2878 | |
---|
2879 | //{ |
---|
2880 | // fltk::Item* o = menuFileTransformSharedVertex = new fltk::Item("Transform to Shared Vertex"); |
---|
2881 | // o->callback((fltk::Callback*)cb_menuFileTransformSharedVertex); |
---|
2882 | //} |
---|
2883 | |
---|
2884 | { |
---|
2885 | menuLoadTextures = new fltk::ItemGroup("Load Textures"); |
---|
2886 | o->add(menuLoadTextures); |
---|
2887 | } |
---|
2888 | |
---|
2889 | { |
---|
2890 | fltk::Item* o = menuFileQuit = new fltk::Item("Quit"); |
---|
2891 | o->callback((fltk::Callback*)cb_menuFileQuit); |
---|
2892 | } |
---|
2893 | |
---|
2894 | o->end(); |
---|
2895 | } |
---|
2896 | |
---|
2897 | // Menu Edit. |
---|
2898 | { |
---|
2899 | fltk::ItemGroup* o = menuEdit = new fltk::ItemGroup("Edit"); |
---|
2900 | o->begin(); |
---|
2901 | |
---|
2902 | { |
---|
2903 | fltk::Item* o = menuEditUndo = new fltk::Item("Undo"); |
---|
2904 | o->callback((fltk::Callback*)cb_menuEditUndo); |
---|
2905 | } |
---|
2906 | |
---|
2907 | { |
---|
2908 | fltk::Item* o = menuEditFit = new fltk::Item("Fit"); |
---|
2909 | o->callback((fltk::Callback*)cb_menuEditFit); |
---|
2910 | |
---|
2911 | } |
---|
2912 | |
---|
2913 | { |
---|
2914 | fltk::Item* o = menuEditRotate = new fltk::Item("Rotate"); |
---|
2915 | o->type(fltk::Item::RADIO); |
---|
2916 | o->set_value(); |
---|
2917 | o->callback((fltk::Callback*)cb_menuEditRotate); |
---|
2918 | } |
---|
2919 | |
---|
2920 | { |
---|
2921 | fltk::Item* o = menuEditPan = new fltk::Item("Pan"); |
---|
2922 | o->type(fltk::Item::RADIO); |
---|
2923 | o->callback((fltk::Callback*)cb_menuEditPan); |
---|
2924 | } |
---|
2925 | |
---|
2926 | //{ |
---|
2927 | // fltk::Item* o = menuEditZoom = new fltk::Item("Zoom"); |
---|
2928 | // o->callback((fltk::Callback*)cb_menuEditZoom); |
---|
2929 | //} |
---|
2930 | |
---|
2931 | new fltk::Divider(); |
---|
2932 | |
---|
2933 | { |
---|
2934 | fltk::Item* o = menuMeshInfo = new fltk::Item("Mesh info"); |
---|
2935 | o->callback((fltk::Callback*)cb_menuMeshInfo); |
---|
2936 | } |
---|
2937 | |
---|
2938 | { |
---|
2939 | fltk::Item* o; |
---|
2940 | o = menuSelectLeaves = new fltk::Item("Select leaves"); |
---|
2941 | o->callback((fltk::Callback*)cb_menuSelectLeaves); |
---|
2942 | } |
---|
2943 | |
---|
2944 | o->end(); |
---|
2945 | } |
---|
2946 | |
---|
2947 | // Menu Render. |
---|
2948 | { |
---|
2949 | fltk::ItemGroup* o = menuRender = new fltk::ItemGroup("Render"); |
---|
2950 | o->begin(); |
---|
2951 | |
---|
2952 | { |
---|
2953 | fltk::Item* o = menuRenderWire = new fltk::Item("Wire"); |
---|
2954 | o->type(fltk::Item::RADIO); |
---|
2955 | o->callback((fltk::Callback*)cb_menuRenderWire); |
---|
2956 | } |
---|
2957 | |
---|
2958 | { |
---|
2959 | fltk::Item* o = menuRenderSolid = new fltk::Item("Solid"); |
---|
2960 | o->type(fltk::Item::RADIO); |
---|
2961 | o->callback((fltk::Callback*)cb_menuRenderSolid); |
---|
2962 | } |
---|
2963 | |
---|
2964 | //new fltk::Divider(); |
---|
2965 | |
---|
2966 | { |
---|
2967 | fltk::Item* o = menuRenderCW = new fltk::Item("CW"); |
---|
2968 | o->type(fltk::Item::RADIO); |
---|
2969 | o->callback((fltk::Callback*)cb_menuRenderCW); |
---|
2970 | |
---|
2971 | //o->hide(); |
---|
2972 | } |
---|
2973 | |
---|
2974 | { |
---|
2975 | fltk::Item* o = menuRenderCCW = new fltk::Item("CCW"); |
---|
2976 | o->type(fltk::Item::RADIO); |
---|
2977 | o->set_value(); |
---|
2978 | o->callback((fltk::Callback*)cb_menuRenderCCW); |
---|
2979 | |
---|
2980 | //o->hide(); |
---|
2981 | } |
---|
2982 | |
---|
2983 | new fltk::Divider(); |
---|
2984 | |
---|
2985 | { |
---|
2986 | fltk::Item* o = menuRenderFlat = new fltk::Item("Flat"); |
---|
2987 | o->type(fltk::Item::RADIO); |
---|
2988 | o->clear_value(); |
---|
2989 | o->callback((fltk::Callback*)cb_menuRenderFlat); |
---|
2990 | } |
---|
2991 | |
---|
2992 | { |
---|
2993 | fltk::Item* o = menuRenderSmooth = new fltk::Item("Smooth"); |
---|
2994 | o->type(fltk::Item::RADIO); |
---|
2995 | o->set_value(); |
---|
2996 | o->callback((fltk::Callback*)cb_menuRenderSmooth); |
---|
2997 | } |
---|
2998 | |
---|
2999 | new fltk::Divider(); |
---|
3000 | |
---|
3001 | { |
---|
3002 | fltk::Item* o = menuRenderTextures = new fltk::Item("Texture mapping"); |
---|
3003 | o->type(fltk::Item::RADIO); |
---|
3004 | o->set_value(); |
---|
3005 | o->callback((fltk::Callback*)cb_menuRenderTextures); |
---|
3006 | } |
---|
3007 | |
---|
3008 | o->end(); |
---|
3009 | } |
---|
3010 | |
---|
3011 | // Menu Stripify. |
---|
3012 | { |
---|
3013 | fltk::Item* o = menuStripify = new fltk::Item("Stripify"); |
---|
3014 | o->callback((fltk::Callback*)cb_menuStripify); |
---|
3015 | } |
---|
3016 | |
---|
3017 | // Menu Simplify. |
---|
3018 | { |
---|
3019 | fltk::ItemGroup* o = menuSimplify = new fltk::ItemGroup("Simplify"); |
---|
3020 | o->callback((fltk::Callback*)cb_menuSimplify); |
---|
3021 | o->begin(); |
---|
3022 | |
---|
3023 | { |
---|
3024 | fltk::Item* o; |
---|
3025 | o = menuSimplifyEdgeCollapse = new fltk::Item("Mesh Simplification"); |
---|
3026 | o->callback((fltk::Callback*)cb_menuSimplifyEdgeCollapse); |
---|
3027 | } |
---|
3028 | |
---|
3029 | { |
---|
3030 | fltk::Item* o; |
---|
3031 | o = menuSimplifyLeavesCollapse = new fltk::Item("Leaves Simplification"); |
---|
3032 | o->callback((fltk::Callback*)cb_menuSimplifyLeavesCollapse); |
---|
3033 | } |
---|
3034 | |
---|
3035 | o->end(); |
---|
3036 | } |
---|
3037 | |
---|
3038 | // Menu LodStrips. |
---|
3039 | { |
---|
3040 | fltk::ItemGroup* o; |
---|
3041 | o = menuLodStrips = new fltk::ItemGroup("LodStrips"); |
---|
3042 | o->begin(); |
---|
3043 | |
---|
3044 | { |
---|
3045 | fltk::Item* o; |
---|
3046 | o = menuLodStripsGenerate = new fltk::Item("Generate"); |
---|
3047 | o->callback((fltk::Callback*)cb_menuLodStripsGenerate); |
---|
3048 | } |
---|
3049 | |
---|
3050 | { |
---|
3051 | fltk::Item* o; |
---|
3052 | o = menuLodStripsVisualize = new fltk::Item("Visualize"); |
---|
3053 | o->callback((fltk::Callback*)cb_menuLodStripsVisualize); |
---|
3054 | } |
---|
3055 | |
---|
3056 | o->end(); |
---|
3057 | } |
---|
3058 | |
---|
3059 | // Menu LodTrees. |
---|
3060 | |
---|
3061 | { |
---|
3062 | fltk::ItemGroup* o; |
---|
3063 | o = menuLodTrees = new fltk::ItemGroup("LodTrees"); |
---|
3064 | o->begin(); |
---|
3065 | |
---|
3066 | { |
---|
3067 | fltk::Item* o; |
---|
3068 | o = menuLodTreesGenerate = new fltk::Item("Generate"); |
---|
3069 | o->callback((fltk::Callback*)cb_menuLodTreesGenerate); |
---|
3070 | } |
---|
3071 | { |
---|
3072 | fltk::Item* o; |
---|
3073 | o = menuLodTreesVisualize = new fltk::Item("Visualize"); |
---|
3074 | o->callback((fltk::Callback*)cb_menuLodTreesVisualize); |
---|
3075 | } |
---|
3076 | |
---|
3077 | o->end(); |
---|
3078 | } |
---|
3079 | |
---|
3080 | |
---|
3081 | { |
---|
3082 | fltk::ItemGroup* o = new fltk::ItemGroup("?"); |
---|
3083 | o->begin(); |
---|
3084 | |
---|
3085 | { |
---|
3086 | fltk::Item* o = menuHelpAbout = new fltk::Item("About"); |
---|
3087 | o->callback((fltk::Callback*)cb_menuHelpAbout); |
---|
3088 | } |
---|
3089 | |
---|
3090 | o->end(); |
---|
3091 | } |
---|
3092 | |
---|
3093 | /* { |
---|
3094 | fltk::SharedImage *gifLogo = logo->get("media\\logos\\logo.gif"); |
---|
3095 | |
---|
3096 | //o->callback((fltk::Callback*)cb_mLogo); |
---|
3097 | |
---|
3098 | mLogo = new fltk::InvisibleBox(406, 1, 43, 13); |
---|
3099 | mLogo->image(gifLogo); |
---|
3100 | }*/ |
---|
3101 | |
---|
3102 | o->end(); |
---|
3103 | } |
---|
3104 | |
---|
3105 | { |
---|
3106 | fltk::Group* o; |
---|
3107 | o = ApplicationBar = new fltk::Group(0, 570, 807, 28); |
---|
3108 | o->box(fltk::BORDER_BOX); |
---|
3109 | o->begin(); |
---|
3110 | |
---|
3111 | { |
---|
3112 | fltk::Widget* o; |
---|
3113 | o = mFPS = new fltk::Widget(10, 4, 30, 15, "FPS "); |
---|
3114 | o->box(fltk::NO_BOX); |
---|
3115 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3116 | o->color((fltk::Color)0xe0dfe300); |
---|
3117 | } |
---|
3118 | |
---|
3119 | { |
---|
3120 | fltk::Widget* o; |
---|
3121 | o = mVertices = new fltk::Widget(154, 4, 40, 15, "Vertices"); |
---|
3122 | o->box(fltk::NO_BOX); |
---|
3123 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3124 | o->color((fltk::Color)0xe0dfe300); |
---|
3125 | } |
---|
3126 | |
---|
3127 | { |
---|
3128 | fltk::Widget* o; |
---|
3129 | o = mTriangles = new fltk::Widget(254, 3, 40, 15, "Triangles"); |
---|
3130 | o->box(fltk::NO_BOX); |
---|
3131 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3132 | o->color((fltk::Color)0xe0dfe300); |
---|
3133 | |
---|
3134 | // Hide triangle count. |
---|
3135 | o->hide(); |
---|
3136 | } |
---|
3137 | |
---|
3138 | { |
---|
3139 | fltk::Widget* o; |
---|
3140 | o = mStrips = new fltk::Widget(354, 3, 30, 15, "Strips"); |
---|
3141 | o->box(fltk::NO_BOX); |
---|
3142 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3143 | o->color((fltk::Color)0xe0dfe300); |
---|
3144 | } |
---|
3145 | |
---|
3146 | //{ |
---|
3147 | // fltk::Widget* o; |
---|
3148 | // o = mQuads = new fltk::Widget(454, 4, 40, 15, "Quads"); |
---|
3149 | // o->box(fltk::NO_BOX); |
---|
3150 | // o->labelfont(fltk::HELVETICA_BOLD); |
---|
3151 | // o->color((fltk::Color)0xe0dfe300); |
---|
3152 | //} |
---|
3153 | |
---|
3154 | { |
---|
3155 | fltk::Widget* o; |
---|
3156 | o = mMB = new fltk::Widget(740, 3, 30, 15, "MB"); |
---|
3157 | o->box(fltk::NO_BOX); |
---|
3158 | o->labelfont(fltk::HELVETICA_BOLD); |
---|
3159 | o->color((fltk::Color)0xe0dfe300); |
---|
3160 | } |
---|
3161 | o->end(); |
---|
3162 | } |
---|
3163 | |
---|
3164 | |
---|
3165 | o->end(); |
---|
3166 | } |
---|
3167 | |
---|
3168 | fltk::focus(geoMeshView); |
---|
3169 | |
---|
3170 | |
---|
3171 | /*Hide Right Panel*/ |
---|
3172 | hideRightPanel(); |
---|
3173 | |
---|
3174 | mMainWindow->show(); |
---|
3175 | } |
---|
3176 | |
---|
3177 | /****************/ |
---|
3178 | /* Destroyer */ |
---|
3179 | /****************/ |
---|
3180 | GeoMeshViewUI::~GeoMeshViewUI() |
---|
3181 | { |
---|
3182 | delete geoMeshLoader; |
---|
3183 | mMainWindow->destroy(); |
---|
3184 | } |
---|
3185 | |
---|
3186 | // Shows the main window. |
---|
3187 | void GeoMeshViewUI::show() |
---|
3188 | { |
---|
3189 | } |
---|
3190 | |
---|
3191 | |
---|
3192 | void GeoMeshViewUI::BuildLoadTextureSubMeshMenu(void) |
---|
3193 | { |
---|
3194 | if (SubMeshNames) |
---|
3195 | { |
---|
3196 | menuLoadTextures->clear(); |
---|
3197 | for (int i=0; i<numSubMeshNames; i++) |
---|
3198 | { |
---|
3199 | delete[] SubMeshNames[i]; |
---|
3200 | } |
---|
3201 | delete[] SubMeshNames; |
---|
3202 | } |
---|
3203 | |
---|
3204 | menuFileLoadTexture = new fltk::Item("Entire model"); |
---|
3205 | menuFileLoadTexture->callback((fltk::Callback*)cb_menuFileLoadTexture); |
---|
3206 | menuLoadTextures->add(menuFileLoadTexture); |
---|
3207 | |
---|
3208 | numSubMeshNames=geoMeshView->getSubMeshCount(); |
---|
3209 | SubMeshNames=new char*[numSubMeshNames]; |
---|
3210 | |
---|
3211 | for (int i=0; i<numSubMeshNames; i++) |
---|
3212 | { |
---|
3213 | SubMeshNames[i]=new char[10]; |
---|
3214 | |
---|
3215 | sprintf(SubMeshNames[i],"submesh %d",i); |
---|
3216 | fltk::Item *item = new fltk::Item(SubMeshNames[i]); |
---|
3217 | item->callback((fltk::Callback*)cb_menuFileLoadTextureSubMesh); |
---|
3218 | menuLoadTextures->add(item); |
---|
3219 | } |
---|
3220 | } |
---|