# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

# D:/VL/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vlGraphics/Tessellator.hpp

Go to the documentation of this file.

    00001 /**************************************************************************************/
    00002 /*                                                                                    */
    00003 /*  Visualization Library                                                             */
    00004 /*  http://www.visualizationlibrary.org                                               */
    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     VL_INSTRUMENT_CLASS(vl::Tessellator, Object)
    00053
    00054     typedef void (CALLBACK *callback_type)(void);
    00055   public:
    00056
    00058     Tessellator();
    00059
    00061     ~Tessellator();
    00062
    00064     const std::vector<dvec3>& contourVerts() const { return mContourVerts; }
    00065
    00067     std::vector<dvec3>& contourVerts() { return mContourVerts; }
    00068
    00070     const std::vector<int>& contours() const { return mContours; }
    00071
    00073     std::vector<int>& contours() { return mContours; }
    00074
    00076     const std::vector<fvec3>& tessellatedTris() const { return mTessellatedTris; }
    00077
    00079     std::vector<fvec3>& tessellatedTris() { return mTessellatedTris; }
    00080
    00082     void setTessNormal(const fvec3& normal) { mTessNormal = normal; }
    00083
    00085     const fvec3& tessNormal() const { return mTessNormal; }
    00086
    00088     void setBoundaryOnly(bool on) { mBoundaryOnly = on; }
    00089
    00091     bool boundaryOnly() const { return mBoundaryOnly; }
    00092
    00094     double tolerance() const { return mTolerance; }
    00095
    00097     void setTolerance(double tolerance) { mTolerance = tolerance; }
    00098
    00100     ETessellationWinding windingRule() const { return mWindingRule; }
    00101
    00103     void setWindingRule(ETessellationWinding rule) { mWindingRule = rule; }
    00104
    00105     /*
    00106      * Tessellates the specified polygon.
    00107      * If \p append_tessellated_tris equals \p true then the previously tessellated triangles are kept and the newly
    00108      * generated triangles are appended to them. This is useful when one has to tessellate several triangles and
    00109      * the result should be accumulated in a single triangle set.
    00110      *
    00111      * After the function is called the contours() and contourVerts() are cleared.
    00112      */
    00113     bool tessellate(bool append_tessellated_tris=false);
    00114
    00116     ref<Geometry> tessellateGeometry(bool append_tessellated_tris=false);
    00117
    00118     void setTessellateIntoSinglePolygon(bool on) { mTessellateIntoSinglePolygon = on; }
    00119
    00120     bool tessellateIntoSinglePolygon() const { return mTessellateIntoSinglePolygon; }
    00121
    00122   protected:
    00123     static void CALLBACK tessBeginData( GLenum type, Tessellator* tessellator );
    00124     static void CALLBACK tessVertexData( dvec3* vec, Tessellator* tessellator );
    00125     static void CALLBACK tessCombineData( GLdouble coords[3], dvec3 *d[4], GLfloat w[4], dvec3 **dataOut, Tessellator* tessellator );
    00126     static void CALLBACK tessEnd(void);
    00127     static void CALLBACK tessError( GLenum errno );
    00128     void freeCombinedVertices();
    00129
    00130   protected:
    00131     // input
    00132     std::vector<int> mContours;
    00133     std::vector<dvec3> mContourVerts;
    00134     // output
    00135     std::vector<fvec3> mTessellatedTris;
    00136     // intermediate data
    00137     std::vector< std::vector<fvec3> > mFans;
    00138     std::vector< std::vector<fvec3> > mTriStrips;
    00139     std::vector< std::vector<fvec3> > mLineLoops;
    00140     std::vector< dvec3* > mCombinedVertices;
    00141     GLenum mPrimitiveType;
    00142     // see gluTessNorml()
    00143     fvec3 mTessNormal;
    00144     // see GLU_TESS_BOUNDARY_ONLY
    00145     bool mBoundaryOnly;
    00146     // see GLU_TESS_TOLERANCE
    00147     double mTolerance;
    00148     // see GLU_TESS_WINDING_RULE
    00149     ETessellationWinding mWindingRule;
    00150     // tessellate into a single polygon
    00151     bool mTessellateIntoSinglePolygon;
    00152   };
    00153
    00154 }
    00155
    00156 #endif

Visualization Library v2011.09.1162 Reference Documentation
Copyright 2005-2011 Michele Bosi. All rights reserved.
Updated on Thu Jan 26 2012 00:43:44.
Permission is granted to use this page to write and publish articles regarding Visualization Library.