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