source: GTP/trunk/Lib/Geom/shared/GeoTool/src/GeoMeshViewUI.cpp @ 1098

Revision 1098, 75.0 KB checked in by gumbau, 18 years ago (diff)

Actualize LodStrips? Faces and scale bug fixed

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