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

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