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