Visualization Library 2.1.0

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

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
Tessellator.hpp
Go to the documentation of this file.
1 /**************************************************************************************/
2 /* */
3 /* Visualization Library */
4 /* http://visualizationlibrary.org */
5 /* */
6 /* Copyright (c) 2005-2020, Michele Bosi */
7 /* All rights reserved. */
8 /* */
9 /* Redistribution and use in source and binary forms, with or without modification, */
10 /* are permitted provided that the following conditions are met: */
11 /* */
12 /* - Redistributions of source code must retain the above copyright notice, this */
13 /* list of conditions and the following disclaimer. */
14 /* */
15 /* - Redistributions in binary form must reproduce the above copyright notice, this */
16 /* list of conditions and the following disclaimer in the documentation and/or */
17 /* other materials provided with the distribution. */
18 /* */
19 /* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND */
20 /* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED */
21 /* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
22 /* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR */
23 /* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
24 /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; */
25 /* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON */
26 /* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
27 /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
28 /* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
29 /* */
30 /**************************************************************************************/
31 
32 #ifndef Tessellator_INCLUDE_ONCE
33 #define Tessellator_INCLUDE_ONCE
34 
35 #include <vlGraphics/OpenGL.hpp>
36 #include <vlGraphics/Geometry.hpp>
37 #include <vlCore/Vector3.hpp>
38 #include <vector>
39 
40 #ifndef CALLBACK
41 #define CALLBACK
42 #endif
43 
44 namespace vl
45 {
51  {
53 
54  typedef void (CALLBACK *callback_type)(void);
55  public:
56 
58  Tessellator();
59 
61  ~Tessellator();
62 
64  const std::vector<dvec3>& contourVerts() const { return mContourVerts; }
65 
67  std::vector<dvec3>& contourVerts() { return mContourVerts; }
68 
70  const std::vector<int>& contours() const { return mContours; }
71 
73  std::vector<int>& contours() { return mContours; }
74 
76  const std::vector<fvec3>& tessellatedTris() const { return mTessellatedTris; }
77 
79  std::vector<fvec3>& tessellatedTris() { return mTessellatedTris; }
80 
82  void setTessNormal(const fvec3& normal) { mTessNormal = normal; }
83 
85  const fvec3& tessNormal() const { return mTessNormal; }
86 
88  void setBoundaryOnly(bool on) { mBoundaryOnly = on; }
89 
91  bool boundaryOnly() const { return mBoundaryOnly; }
92 
94  double tolerance() const { return mTolerance; }
95 
97  void setTolerance(double tolerance) { mTolerance = tolerance; }
98 
100  ETessellationWinding windingRule() const { return mWindingRule; }
101 
103  void setWindingRule(ETessellationWinding rule) { mWindingRule = rule; }
104 
105  /*
106  * Tessellates the specified polygon.
107  * If \p append_tessellated_tris equals \p true then the previously tessellated triangles are kept and the newly
108  * generated triangles are appended to them. This is useful when one has to tessellate several triangles and
109  * the result should be accumulated in a single triangle set.
110  *
111  * After the function is called the contours() and contourVerts() are cleared.
112  */
113  bool tessellate(bool append_tessellated_tris=false);
114 
116  ref<Geometry> tessellateGeometry(bool append_tessellated_tris=false);
117 
118  void setTessellateIntoSinglePolygon(bool on) { mTessellateIntoSinglePolygon = on; }
119 
120  bool tessellateIntoSinglePolygon() const { return mTessellateIntoSinglePolygon; }
121 
122  protected:
123  static void CALLBACK tessBeginData( GLenum type, Tessellator* tessellator );
124  static void CALLBACK tessVertexData( dvec3* vec, Tessellator* tessellator );
125  static void CALLBACK tessCombineData( GLdouble coords[3], dvec3 *d[4], GLfloat w[4], dvec3 **dataOut, Tessellator* tessellator );
126  static void CALLBACK tessEnd(void);
127  static void CALLBACK tessError( GLenum errno );
128  void freeCombinedVertices();
129 
130  protected:
131  // input
132  std::vector<int> mContours;
133  std::vector<dvec3> mContourVerts;
134  // output
135  std::vector<fvec3> mTessellatedTris;
136  // intermediate data
137  std::vector< std::vector<fvec3> > mFans;
138  std::vector< std::vector<fvec3> > mTriStrips;
139  std::vector< std::vector<fvec3> > mLineLoops;
140  std::vector< dvec3* > mCombinedVertices;
142  // see gluTessNorml()
144  // see GLU_TESS_BOUNDARY_ONLY
146  // see GLU_TESS_TOLERANCE
147  double mTolerance;
148  // see GLU_TESS_WINDING_RULE
150  // tessellate into a single polygon
152  };
153 
154 }
155 
156 #endif
const std::vector< fvec3 > & tessellatedTris() const
A set of triangles representing the tessellated polygon.
Definition: Tessellator.hpp:76
std::vector< fvec3 > & tessellatedTris()
A set of triangles representing the tessellated polygon.
Definition: Tessellator.hpp:79
Tessellates a complex polygon defined by a set of outlines into a set of triangles that can be render...
Definition: Tessellator.hpp:50
bool boundaryOnly() const
See gluTessProperty documentation (GLU_TESS_BOUNDARY_ONLY)
Definition: Tessellator.hpp:91
std::vector< fvec3 > mTessellatedTris
std::vector< dvec3 > & contourVerts()
The contours that specify the complex polygon to be tessellated.
Definition: Tessellator.hpp:67
void setTessNormal(const fvec3 &normal)
See gluTessNormal documentation.
Definition: Tessellator.hpp:82
std::vector< std::vector< fvec3 > > mFans
const fvec3 & tessNormal() const
See gluTessNormal documentation.
Definition: Tessellator.hpp:85
bool mTessellateIntoSinglePolygon
std::vector< std::vector< fvec3 > > mTriStrips
#define VL_INSTRUMENT_CLASS(ClassName, BaseClass)
Definition: TypeInfo.hpp:122
double tolerance() const
See gluTessProperty documentation (GLU_TESS_TOLERANCE)
Definition: Tessellator.hpp:94
std::vector< std::vector< fvec3 > > mLineLoops
Visualization Library main namespace.
const std::vector< dvec3 > & contourVerts() const
The contours that specify the complex polygon to be tessellated.
Definition: Tessellator.hpp:64
The base class for all the reference counted objects.
Definition: Object.hpp:158
std::vector< int > mContours
const std::vector< int > & contours() const
The contours that specify the complex polygon to be tessellated.
Definition: Tessellator.hpp:70
bool tessellateIntoSinglePolygon() const
#define CALLBACK
Definition: Tessellator.hpp:41
ETessellationWinding windingRule() const
See gluTessProperty documentation (GLU_TESS_WINDING_RULE)
void setWindingRule(ETessellationWinding rule)
See gluTessProperty documentation (GLU_TESS_WINDING_RULE)
std::vector< dvec3 *> mCombinedVertices
void setBoundaryOnly(bool on)
See gluTessProperty documentation (GLU_TESS_BOUNDARY_ONLY)
Definition: Tessellator.hpp:88
The ref<> class is used to reference-count an Object.
Definition: Object.hpp:55
std::vector< dvec3 > mContourVerts
ETessellationWinding
void setTolerance(double tolerance)
See gluTessProperty documentation (GLU_TESS_TOLERANCE)
Definition: Tessellator.hpp:97
void setTessellateIntoSinglePolygon(bool on)
std::vector< int > & contours()
The contours that specify the complex polygon to be tessellated.
Definition: Tessellator.hpp:73
ETessellationWinding mWindingRule