Visualization LibraryA lightweight C++ OpenGL middleware for 2D/3D graphics |
[Home] [Tutorials] [All Classes] [Grouped Classes] |
00001 /**************************************************************************************/ 00002 /* */ 00003 /* Visualization Library */ 00004 /* http://www.visualizationlibrary.com */ 00005 /* */ 00006 /* Copyright (c) 2005-2010, Michele Bosi */ 00007 /* All rights reserved. */ 00008 /* */ 00009 /* Redistribution and use in source and binary forms, with or without modification, */ 00010 /* are permitted provided that the following conditions are met: */ 00011 /* */ 00012 /* - Redistributions of source code must retain the above copyright notice, this */ 00013 /* list of conditions and the following disclaimer. */ 00014 /* */ 00015 /* - Redistributions in binary form must reproduce the above copyright notice, this */ 00016 /* list of conditions and the following disclaimer in the documentation and/or */ 00017 /* other materials provided with the distribution. */ 00018 /* */ 00019 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */ 00020 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */ 00021 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */ 00022 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */ 00023 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */ 00024 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */ 00025 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */ 00026 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */ 00027 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */ 00028 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ 00029 /* */ 00030 /**************************************************************************************/ 00031 00032 #ifndef Tessellator_INCLUDE_ONCE 00033 #define Tessellator_INCLUDE_ONCE 00034 00035 #include <vlGraphics/OpenGL.hpp> 00036 #include <vlGraphics/Geometry.hpp> 00037 #include <vlCore/Vector3.hpp> 00038 #include <vector> 00039 00040 #ifndef CALLBACK 00041 #define CALLBACK 00042 #endif 00043 00044 namespace vl 00045 { 00050 class VLGRAPHICS_EXPORT Tessellator: public Object 00051 { 00052 typedef void (CALLBACK *callback_type)(void); 00053 public: 00054 virtual const char* className() { return "vl::Tessellator"; } 00055 00057 Tessellator(); 00058 00060 ~Tessellator(); 00061 00063 const std::vector<dvec3>& contourVerts() const { return mContourVerts; } 00064 00066 std::vector<dvec3>& contourVerts() { return mContourVerts; } 00067 00069 const std::vector<int>& contours() const { return mContours; } 00070 00072 std::vector<int>& contours() { return mContours; } 00073 00075 const std::vector<fvec3>& tessellatedTris() const { return mTessellatedTris; } 00076 00078 std::vector<fvec3>& tessellatedTris() { return mTessellatedTris; } 00079 00081 void setTessNormal(const fvec3& normal) { mTessNormal = normal; } 00082 00084 const fvec3& tessNormal() const { return mTessNormal; } 00085 00087 void setBoundaryOnly(bool on) { mBoundaryOnly = on; } 00088 00090 bool boundaryOnly() const { return mBoundaryOnly; } 00091 00093 double tolerance() const { return mTolerance; } 00094 00096 void setTolerance(double tolerance) { mTolerance = tolerance; } 00097 00099 ETessellationWinding windingRule() const { return mWindingRule; } 00100 00102 void setWindingRule(ETessellationWinding rule) { mWindingRule = rule; } 00103 00104 /* 00105 * Tessellates the specified polygon. 00106 * If \p append_tessellated_tris equals \p true then the previously tessellated triangles are kept and the newly 00107 * generated triangles are appended to them. This is useful when one has to tessellate several triangles and 00108 * the result should be accumulated in a single triangle set. 00109 * 00110 * After the function is called the contours() and contourVerts() are cleared. 00111 */ 00112 bool tessellate(bool append_tessellated_tris=false); 00113 00115 ref<Geometry> tessellateGeometry(bool append_tessellated_tris=false); 00116 00117 void setTessellateIntoSinglePolygon(bool on) { mTessellateIntoSinglePolygon = on; } 00118 00119 bool tessellateIntoSinglePolygon() const { return mTessellateIntoSinglePolygon; } 00120 00121 protected: 00122 static void CALLBACK tessBeginData( GLenum type, Tessellator* tessellator ); 00123 static void CALLBACK tessVertexData( dvec3* vec, Tessellator* tessellator ); 00124 static void CALLBACK tessCombineData( GLdouble coords[3], dvec3 *d[4], GLfloat w[4], dvec3 **dataOut, Tessellator* tessellator ); 00125 static void CALLBACK tessEnd(void); 00126 static void CALLBACK tessError( GLenum errno ); 00127 void freeCombinedVertices(); 00128 00129 protected: 00130 // input 00131 std::vector<int> mContours; 00132 std::vector<dvec3> mContourVerts; 00133 // output 00134 std::vector<fvec3> mTessellatedTris; 00135 // intermediate data 00136 std::vector< std::vector<fvec3> > mFans; 00137 std::vector< std::vector<fvec3> > mTriStrips; 00138 std::vector< std::vector<fvec3> > mLineLoops; 00139 std::vector< dvec3* > mCombinedVertices; 00140 GLenum mPrimitiveType; 00141 // see gluTessNorml() 00142 fvec3 mTessNormal; 00143 // see GLU_TESS_BOUNDARY_ONLY 00144 bool mBoundaryOnly; 00145 // see GLU_TESS_TOLERANCE 00146 double mTolerance; 00147 // see GLU_TESS_WINDING_RULE 00148 ETessellationWinding mWindingRule; 00149 // tessellate into a single polygon 00150 bool mTessellateIntoSinglePolygon; 00151 }; 00152 00153 } 00154 00155 #endif