source: GTP/trunk/Lib/Geom/shared/GeoTool/include/GeoMeshView.h @ 2090

Revision 2090, 7.1 KB checked in by gumbau, 17 years ago (diff)
Line 
1// generated by Fast Light User Interface Designer (fluid) version 2.0100
2#ifndef GeoMeshView_h
3#define GeoMeshView_h
4#include "GL/glew.h"
5#ifdef _WIN32
6#include "GL/wglew.h"
7#endif
8
9#include        <fltk/events.h>
10#include        <stdlib.h>
11#include        <time.h>
12#include        <iostream>
13#include        <glut.h>
14#include        <fltk/GlWindow.h>
15#include        <GeoVertexBuffer.h>
16#include        <GeoMesh.h>
17#include        <GeoMeshSaver.h>
18#include        <GeoMeshViewUI.h>
19
20namespace Geometry{ class LodTreeLibrary; }
21
22using   namespace       Geometry;
23using   namespace       std;
24
25class GeoMeshView : public fltk::GlWindow
26{
27        friend  class   GeoMeshViewUI;
28
29        public:
30
31        // this value determines the scaling factor used to draw the cube.
32        double  size;
33        double  mScaleFactor;
34        bool            mWire;
35        bool            mSolid;
36        bool            mLighting;
37        bool            mCW;
38        bool            mCCW;
39        bool            mPan;
40        bool            mRotate;
41        bool            mLodStrip;
42        bool            mLodTree;
43
44        GeoMeshView(int                                         x,
45                                                        int                                             y,
46                                                        int                                             w,
47                                                        int                                             h,
48                                                        const   char            *l                                                      =       0,
49                                                        GeoMeshViewUI   *geoMeshViewUI  =       0);
50
51        /*      This function is callalled by the zoom slider
52         *     
53         */
54        void scale(double factor){size  =       factor;};
55
56        /* Set the rotation about the vertical (y ) axis.
57         *
58         * This function is called by the horizontal roller in GeoMeshViewUI
59         * and the initialize button in GeoMeshViewUI.
60         */
61        void v_angle(float angle){vAng  =       angle;};
62       
63        // Return the rotation about the vertical (y ) axis.
64        float v_angle(){return vAng;};
65       
66        /* Set the rotation about the horizontal (x ) axis.
67         *
68         * This function is called by the vertical roller in GeoMeshViewUI
69         and the
70         * initialize button in GeoMeshViewUI.
71         */
72        void h_angle(float angle){hAng  =       angle;};
73       
74        // the rotation about the horizontal (x ) axis.
75        float h_angle(){return hAng;};
76       
77        /* Sets the x shift of the cube view camera.
78         *
79         * This function is called by the slider in GeoMeshViewUI and the
80         * initialize button in GeoMeshViewUI.
81         */
82        void panx(float x){xshift       =       x;};
83       
84        /* Sets the y shift of the cube view camera.
85         *
86         * This function is called by the slider in GeoMeshViewUI and the
87         * initialize button in GeoMeshViewUI.
88         */
89        void pany(float y){yshift       =       y;};
90
91        //      Wire model.
92        void    activeWire(){mWire      =       true;};
93        void    deactiveWire(){mWire    =       false;};
94
95        //      Solid model.
96        void    activeSolid(){mSolid    =       true;};
97        void    deactiveSolid(){mSolid  =       false;};
98
99        //      Lighting.
100        void    activeLighting(){mLighting      =       true;};
101        void    deactiveLighting(){mLighting    =       false;};
102
103        //      Clockwise mode.
104        void    activeCW(){mCW  =       true;};
105        void    deactiveCW(){mCW        =       false;};
106
107        //      Counter Clockwise mode.
108        void    activeCCW(){mCCW        =       true;}
109        void    deactiveCCW(){mCCW      =       false;}
110
111        //      Pan mode.
112        void    activePan(){mPan        =       true;}
113        void    deactivePan(){mPan      =       false;}
114
115        //      Rotate mode.
116        void    activeRotate(){mRotate  =       true;}
117        void    deactiveRotate(){mRotate        =       false;}
118
119        //      LodStrip mode.
120        void    activeLodStrip(){mLodStrip      =       true;}
121        void    deactiveLodStrip(){mLodStrip    =       false;}
122
123        //      LodTree mode.
124        void    activeLodTree(){mLodTree        =       true;}
125        void    deactiveLodTree(){mLodTree      =       false;}
126
127        //      Ilumination modes.
128        void    flat(){glShadeModel(GL_FLAT);};
129        void    smooth(){glShadeModel(GL_SMOOTH);};
130
131        //      Change Open GL context.
132#ifdef _WIN32
133        HDC hOldDC;
134        HGLRC hOldRC;
135#endif
136        void    saveContext()
137        {
138#ifdef _WIN32
139                hOldDC = wglGetCurrentDC();
140                hOldRC = wglGetCurrentContext();
141#endif
142        }
143
144        void    restoreContext()
145        {
146#ifdef _WIN32
147                wglMakeCurrent( hOldDC, hOldRC );
148#endif
149        }
150
151        //      Fits the object in the window view.
152        void    fit()
153        {
154                vAng            = 0.0;
155                hAng            =       0.0;
156                size            =       0.0;
157                xshift  =       0.0;
158                yshift  =       0.0;
159        };
160
161        /* Sets the Mesh to display.
162        */
163        void    setMesh(Geometry::Mesh  *geomesh);
164
165        /* The widget class draw() override.
166         * The draw() function initialize Gl for another round of
167         * drawing then calls specialized functions for drawing each
168         * of the entities displayed in the cube view.
169         */
170        void draw();
171
172        //      Gets the bounding box.
173        //Geometry::GeometryBounds      getBoundingBox();
174
175        //      Store one random color to each strip.
176        void    setStripColors();
177
178        //      Get the number of frames per second.
179        size_t  getFPS();
180
181        //      Sets the submesh selected.
182        void    setSubMeshSelected(int submeshIndex);
183
184        //      Sets the leaves submesh index.
185        void    setLeavesSubMesh(int submeshIndex);
186
187        //      Gets the leaves submesh index.
188        int     getLeavesSubMesh();
189
190        //      Gets the triangle count of the current lod.
191        size_t  getLodStripsTriangleCount();
192       
193        //      Sets the lodstripslibrary object.
194        void    setLodStripsLibrary(Geometry::LodStripsLibrary *lodstrips);
195
196        //      Sets the lodtreeslibrary object.
197        void    setLodTreesLibrary(Geometry::LodTreeLibrary *lodtrees);
198
199        //      Change de Level of detail of the object.
200        void    GoToLod_LodStrip(float lod);
201        void    GoToLod_LodTree(float lod);
202       
203        // load a image file as a texture
204        void    LoadTexture(const char *);
205        void    LoadTextureSubMesh(int isubmesh, const char *);
206        void    addTexFile(const char *);
207        void    changeTexFile(int isubmesh, const char *);
208
209        int getSubMeshCount(void) const { return mSubMeshCount; }
210        void resetTextures(void);
211        int findLeavesSubMesh(void);
212
213        private:
214        /* Draw the cube boundaries
215         * Draw the faces of the cube using the boxv[] vertices, using
216         * GL_LINE_LOOP for the faces. The color is #defined by
217         * CUBECOLOR.
218         */
219
220        //      GeoMeshViewUI.
221        GeoMeshViewUI   *mGeoMeshViewUI;
222
223        //      LodStrips library object.
224        Geometry::LodStripsLibrary      *lodStripsLib;
225        //      LodTree library object.
226        Geometry::LodTreeLibrary        *lodTreeLib;
227       
228        //      Flag tha activate / deactivate the color strips.
229        bool    colorStripsFlag;
230
231        // Stores the index of the mesh to paint of red color.
232        int             mSubMeshSelected;
233
234        //      Frames per second.
235        size_t  mFPS;
236
237        //      StartTime for FPS.
238        clock_t mStartTime;
239
240        float           xMed;
241        float           yMed;
242        float           zMed;
243
244        int                     leavesSubMesh;
245       
246        //      Submesh count.
247        int                     mSubMeshCount;
248
249        //      Mesh to show.
250        Geometry::Mesh  *geoMesh;
251
252        // Current texture handle (OpenGL handle: 0=no texture)
253        GLuint current_texture;
254        GLuint *current_texture_submesh;
255        bool use_texture_mapping; // this flag enables texture mapping when a texture is loaded
256        bool SetTextureRenderingState(int submesh); // returns true if textures must be used
257
258        virtual int     handle(int event);
259
260        //      Paint the mesh object.
261        void    drawGeoMesh(bool paintWire);
262        void    drawTriangleList(int submesh, bool selectedMesh, bool paintWire);
263        void    drawTriangleStrip(int submesh);
264        void    drawLodStrip();
265        void    drawLodTree();
266        void    enableColorStrips();
267        void    disableColorStrips();
268        void    enableTextureMapping(){ use_texture_mapping=true; }
269        void    disableTextureMapping(){ use_texture_mapping=false; }
270        bool    isTextureMappingEnabled(){ return use_texture_mapping; }
271        bool    getColorStrips();
272
273        //      Calculate the number of frames per second.
274        void    calcFPS();
275
276        //      Copy the mesh vertices to the vertex array.
277        void    refreshVertices(Geometry::Mesh  *geomesh);
278
279        float   vAng;
280        float   hAng;
281        float   xshift;
282        float   yshift;
283        int                     mMouseX;
284        int                     mMouseY;
285        int                     mSizeY;
286        GLfloat **mPosArray;
287        GLfloat **mNorArray;
288        GLfloat **mTexCoordArray;
289        GLfloat *mSharedPosArray;
290        GLfloat *mSharedNorArray;
291        GLfloat *mSharedTexCoordArray;
292        GLuint  **mIndexArray;
293
294        struct  ColorElement
295        {
296                float   r;
297                float   g;
298                float   b;
299        };
300
301        ColorElement    **mStripColors;
302        int                                             mStripColorsCount;
303       
304        //      Idetifier of Visualization List.
305        GLuint  mIdVisualList;
306
307        //      List of texture files of the mesh.
308        vector<string>  mMeshTexFiles;
309};
310
311#endif
312
Note: See TracBrowser for help on using the repository browser.