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

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