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

Revision 1078, 75.8 KB checked in by gumbau, 18 years ago (diff)

Extended Mesh implementation

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