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

Revision 1017, 75.9 KB checked in by gumbau, 18 years ago (diff)

LodStripsConstructor? optimized and fixed bug building a lodtree

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