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

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