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

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