g4tools  5.4.0
Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
tools::tess_contour Class Reference
Collaboration diagram for tools::tess_contour:
Collaboration graph
[legend]

Public Member Functions

 tess_contour (std::ostream &a_out, std::vector< tess_triangle > &a_triangles)
 
virtual ~tess_contour ()
 
void getFilledArea (const std::vector< std::vector< vec3f > > aContour)
 

Protected Types

typedef GLUvoid(* Func) ()
 

Protected Member Functions

 tess_contour (const tess_contour &a_from)
 
tess_contouroperator= (const tess_contour &)
 
void resetVertex ()
 
void setBeginType (gl::mode_t aType)
 
void setError (bool aError)
 
std::vector< double * > & combineTmps ()
 
void addVertex (const double *vertex)
 

Static Protected Member Functions

static void beginCallback (GLUenum aWhich, GLUvoid *aThis)
 
static void errorCallback (GLUenum aErrorCode, GLUvoid *aThis)
 
static void endCallback (void *)
 
static void vertexCallback (GLUvoid *vertex, GLUvoid *aThis)
 
static void combineCallback (GLUdouble coords[3], void *[4], GLUfloat[4], void **dataOut, void *aThis)
 

Protected Attributes

std::ostream & m_out
 
std::vector< tess_triangle > & m_triangles
 
tess_triangle m_tmp
 
unsigned int m_vertex_number
 
gl::mode_t m_begin_type
 
bool m_error
 
std::vector< double * > m_combine_tmps
 

Detailed Description

Definition at line 19 of file tess_contour.

Member Typedef Documentation

◆ Func

typedef GLUvoid(* tools::tess_contour::Func) ()
protected

Definition at line 177 of file tess_contour.

Constructor & Destructor Documentation

◆ tess_contour() [1/2]

tools::tess_contour::tess_contour ( std::ostream &  a_out,
std::vector< tess_triangle > &  a_triangles 
)
inline

Definition at line 21 of file tess_contour.

22  :m_out(a_out)
23  ,m_triangles(a_triangles)

◆ ~tess_contour()

virtual tools::tess_contour::~tess_contour ( )
inlinevirtual

Definition at line 25 of file tess_contour.

25 {}

◆ tess_contour() [2/2]

tools::tess_contour::tess_contour ( const tess_contour a_from)
inlineprotected

Definition at line 27 of file tess_contour.

27 :m_out(a_from.m_out),m_triangles(a_from.m_triangles){}

Member Function Documentation

◆ addVertex()

void tools::tess_contour::addVertex ( const double *  vertex)
inlineprotected

Definition at line 93 of file tess_contour.

93  {
94  // GLU_TRIANGLE_STRIP
95  // Draws a connected group of triangles. One triangle is defined for each
96  // vertex presented after the first two vertices. For odd n, vertices n,
97  // n+1, and n+2 define triangle n. For even n, vertices n+1, n, and n+2
98  // define triangle n. N-2 triangles are drawn.
100  m_tmp.pointC[0] = vertex[0];
101  m_tmp.pointC[1] = vertex[1];
102  m_tmp.pointC[2] = vertex[2];
103 
104  if(m_vertex_number>=2) m_triangles.push_back(m_tmp);
105 
106  int rest = m_vertex_number % 2;
107  if(rest==1) {
108  m_tmp.pointA[0] = vertex[0];
109  m_tmp.pointA[1] = vertex[1];
110  m_tmp.pointA[2] = vertex[2];
111  } else {
112  m_tmp.pointB[0] = vertex[0];
113  m_tmp.pointB[1] = vertex[1];
114  m_tmp.pointB[2] = vertex[2];
115  }
116  m_vertex_number++;
117  }
118 
119  // GLU_TRIANGLE_FAN
120  // Draws a connected group of triangles. One triangle is defined for each
121  // vertex presented after the first two vertices. Vertices 1, n+1,
122  // and n+2 define triangle n. N-2 triangles are drawn.
123  else if (m_begin_type == gl::triangle_fan()) {
124  if (m_vertex_number == 0) {
125  m_tmp.pointA[0] = vertex[0];
126  m_tmp.pointA[1] = vertex[1];
127  m_tmp.pointA[2] = vertex[2];
128  } else {
129  m_tmp.pointC[0] = vertex[0];
130  m_tmp.pointC[1] = vertex[1];
131  m_tmp.pointC[2] = vertex[2];
132 
133  if (m_vertex_number >=2 ) {
134  m_triangles.push_back(m_tmp);
135  }
136  m_tmp.pointB[0] = vertex[0];
137  m_tmp.pointB[1] = vertex[1];
138  m_tmp.pointB[2] = vertex[2];
139  }
140  m_vertex_number++;
141  }
142 
143  // GLU_TRIANGLES
144  // Treats each triplet of vertices as an independent triangle.
145  // Vertices 3n-2, 3n-1, and 3n define triangle n. N/3 triangles are drawn.
146  else if (m_begin_type == gl::triangles()) {
147 
148  int rest = m_vertex_number % 3;
149 
150  if(rest==2) {
151  m_tmp.pointC[0] = vertex[0];
152  m_tmp.pointC[1] = vertex[1];
153  m_tmp.pointC[2] = vertex[2];
154 
155  m_triangles.push_back(m_tmp);
156 
157  } else if(rest==1) {
158  m_tmp.pointB[0] = vertex[0];
159  m_tmp.pointB[1] = vertex[1];
160  m_tmp.pointB[2] = vertex[2];
161 
162  } else if(rest==0) {
163  m_tmp.pointA[0] = vertex[0];
164  m_tmp.pointA[1] = vertex[1];
165  m_tmp.pointA[2] = vertex[2];
166  }
167  m_vertex_number++;
168 
169  } else {
170  // do nothing and should never happend
171  }
172  }

◆ beginCallback()

static void tools::tess_contour::beginCallback ( GLUenum  aWhich,
GLUvoid aThis 
)
inlinestaticprotected

Definition at line 184 of file tess_contour.

184  {
185  tess_contour* This = (tess_contour*)aThis;
186  This->setBeginType(aWhich);
187  This->resetVertex();
188  }

◆ combineCallback()

static void tools::tess_contour::combineCallback ( GLUdouble  coords[3],
void *  [4],
GLUfloat  [4],
void **  dataOut,
void *  aThis 
)
inlinestaticprotected

Definition at line 219 of file tess_contour.

223  {
224  tess_contour* This = (tess_contour*)aThis;
225  double* vertex = new double[3];
226  vertex[0] = coords[0];
227  vertex[1] = coords[1];
228  vertex[2] = coords[2];
229  This->combineTmps().push_back(vertex);
230  *dataOut = vertex;
231  }

◆ combineTmps()

std::vector<double*>& tools::tess_contour::combineTmps ( )
inlineprotected

Definition at line 91 of file tess_contour.

91 {return m_combine_tmps;}

◆ endCallback()

static void tools::tess_contour::endCallback ( void *  )
inlinestaticprotected

Definition at line 204 of file tess_contour.

204 {}

◆ errorCallback()

static void tools::tess_contour::errorCallback ( GLUenum  aErrorCode,
GLUvoid aThis 
)
inlinestaticprotected

Definition at line 194 of file tess_contour.

194  {
195  tess_contour* This = (tess_contour*)aThis;
196  This->m_out << "tools::tess_contour::errorCallback : " << aErrorCode << std::endl;
197  This->setError(true);
198  }

◆ getFilledArea()

void tools::tess_contour::getFilledArea ( const std::vector< std::vector< vec3f > >  aContour)
inline

Definition at line 30 of file tess_contour.

30  {
31  m_triangles.clear();
32  m_combine_tmps.clear();
33  m_error = false;
34 
35  GLUtesselator* tobj = gluNewTess();
36 
37  // g++-8.1.0 : the five below lines induce warnings : cast between incompatible function types.
38  //::gluTessCallback(tobj,(GLUenum)GLU_TESS_VERTEX_DATA, (Func)vertexCallback);
39  //::gluTessCallback(tobj,(GLUenum)GLU_TESS_BEGIN_DATA, (Func)beginCallback);
40  //::gluTessCallback(tobj,(GLUenum)GLU_TESS_END_DATA, (Func)endCallback);
41  //::gluTessCallback(tobj,(GLUenum)GLU_TESS_ERROR_DATA, (Func)errorCallback);
42  //::gluTessCallback(tobj,(GLUenum)GLU_TESS_COMBINE_DATA,(Func)combineCallback);
43 
44  // NOTE : the gluTessCallback_<> are inlib/glutess specific.
50 
52 
53  for(unsigned int a=0;a<aContour.size();a++) {
54  //if(aContour[a][0]!=aContour[a][aContour[a].size()-1]) continue;
55  if(aContour[a].size()<=1) continue; //should not happen.
56  size_t vecSize = aContour[a].size()-1;
57 
58  typedef GLUdouble point[3];
59  point* tab = new point[vecSize];
60 
61  ::gluTessBeginPolygon(tobj, this);
62 
64  for(size_t b=0;b<vecSize;b++) {
65  tab[b][0] = aContour[a][b][0];
66  tab[b][1] = aContour[a][b][1];
67  tab[b][2] = aContour[a][b][2];
68  ::gluTessVertex(tobj, tab[b],tab[b]);
69  }
70  ::gluTessEndContour(tobj);
71 
72  ::gluTessEndPolygon(tobj);
73 
74  delete [] tab;
75  }
76 
77  ::gluDeleteTess(tobj);
78 
79  for(unsigned int index=0;index<m_combine_tmps.size();index++) {
80  delete [] m_combine_tmps[index];
81  }
82  m_combine_tmps.clear();
83 
84  if(m_error) m_triangles.clear();
85  }

◆ operator=()

tess_contour& tools::tess_contour::operator= ( const tess_contour )
inlineprotected

Definition at line 28 of file tess_contour.

28 {return *this;}

◆ resetVertex()

void tools::tess_contour::resetVertex ( )
inlineprotected

Definition at line 88 of file tess_contour.

88 {m_vertex_number = 0;}

◆ setBeginType()

void tools::tess_contour::setBeginType ( gl::mode_t  aType)
inlineprotected

Definition at line 89 of file tess_contour.

89 {m_begin_type = aType;}

◆ setError()

void tools::tess_contour::setError ( bool  aError)
inlineprotected

Definition at line 90 of file tess_contour.

90 {m_error = aError;}

◆ vertexCallback()

static void tools::tess_contour::vertexCallback ( GLUvoid vertex,
GLUvoid aThis 
)
inlinestaticprotected

Definition at line 210 of file tess_contour.

210  {
211  tess_contour* This = (tess_contour*)aThis;
212  This->addVertex((double*)vertex);
213  }

Member Data Documentation

◆ m_begin_type

gl::mode_t tools::tess_contour::m_begin_type
protected

Definition at line 238 of file tess_contour.

◆ m_combine_tmps

std::vector<double*> tools::tess_contour::m_combine_tmps
protected

Definition at line 240 of file tess_contour.

◆ m_error

bool tools::tess_contour::m_error
protected

Definition at line 239 of file tess_contour.

◆ m_out

std::ostream& tools::tess_contour::m_out
protected

Definition at line 234 of file tess_contour.

◆ m_tmp

tess_triangle tools::tess_contour::m_tmp
protected

Definition at line 236 of file tess_contour.

◆ m_triangles

std::vector<tess_triangle>& tools::tess_contour::m_triangles
protected

Definition at line 235 of file tess_contour.

◆ m_vertex_number

unsigned int tools::tess_contour::m_vertex_number
protected

Definition at line 237 of file tess_contour.


The documentation for this class was generated from the following file:
tools::tess_contour::combineCallback
static void combineCallback(GLUdouble coords[3], void *[4], GLUfloat[4], void **dataOut, void *aThis)
Definition: tess_contour:219
tools::tess_contour::m_out
std::ostream & m_out
Definition: tess_contour:234
gluTessCallback_GLU_TESS_VERTEX_DATA
void GLUAPIENTRY gluTessCallback_GLU_TESS_VERTEX_DATA(GLUtesselator *tess, void(GLUAPIENTRY *a_fn)(void *, void *))
Definition: glutess:246
gluTessCallback_GLU_TESS_COMBINE_DATA
void GLUAPIENTRY gluTessCallback_GLU_TESS_COMBINE_DATA(GLUtesselator *tess, void(GLUAPIENTRY *a_fn)(GLUdouble[3], void *[4], GLUfloat[4], void **, void *))
Definition: glutess:262
tools::tess_contour::m_tmp
tess_triangle m_tmp
Definition: tess_contour:236
tools::tess_contour::errorCallback
static void errorCallback(GLUenum aErrorCode, GLUvoid *aThis)
Definition: tess_contour:194
tools::gl::triangles
mode_t triangles()
Definition: glprims:20
tools::tess_contour::beginCallback
static void beginCallback(GLUenum aWhich, GLUvoid *aThis)
Definition: tess_contour:184
tools::gl::triangle_fan
mode_t triangle_fan()
Definition: glprims:22
tools::tess_triangle::pointA
double pointA[3]
Definition: tess_contour:14
gluTessBeginPolygon
GLUAPI void GLUAPIENTRY gluTessBeginPolygon(GLUtesselator *tess, GLUvoid *data)
Definition: glutess:455
GLUdouble
double GLUdouble
Definition: _glu:16
gluTessCallback_GLU_TESS_ERROR_DATA
void GLUAPIENTRY gluTessCallback_GLU_TESS_ERROR_DATA(GLUtesselator *tess, void(GLUAPIENTRY *a_fn)(GLUenum, void *))
Definition: glutess:258
tools::tess_contour::m_begin_type
gl::mode_t m_begin_type
Definition: tess_contour:238
tools::tess_contour::m_triangles
std::vector< tess_triangle > & m_triangles
Definition: tess_contour:235
tools::tess_contour::vertexCallback
static void vertexCallback(GLUvoid *vertex, GLUvoid *aThis)
Definition: tess_contour:210
gluTessBeginContour
GLUAPI void GLUAPIENTRY gluTessBeginContour(GLUtesselator *tess)
Definition: glutess:469
tools::gl::triangle_strip
mode_t triangle_strip()
Definition: glprims:21
tools::tess_triangle::pointB
double pointB[3]
Definition: tess_contour:15
GLU_TESS_WINDING_ODD
#define GLU_TESS_WINDING_ODD
Definition: _glu:38
tools::file::size
bool size(const std::string &a_file, long &a_size)
Definition: fsize:13
GLUtesselator
Definition: _tess:27
tools::tess_contour::endCallback
static void endCallback(void *)
Definition: tess_contour:204
tools::tess_contour::m_vertex_number
unsigned int m_vertex_number
Definition: tess_contour:237
gluTessVertex
#define gluTessVertex
Definition: rename:13
tools::tess_contour::m_combine_tmps
std::vector< double * > m_combine_tmps
Definition: tess_contour:240
tools::tess_triangle::pointC
double pointC[3]
Definition: tess_contour:16
gluTessEndContour
GLUAPI void GLUAPIENTRY gluTessEndContour(GLUtesselator *tess)
Definition: glutess:486
tools::tess_contour::m_error
bool m_error
Definition: tess_contour:239
gluDeleteTess
GLUAPI void GLUAPIENTRY gluDeleteTess(GLUtesselator *tess)
Definition: glutess:160
tools::tess_contour::tess_contour
tess_contour(std::ostream &a_out, std::vector< tess_triangle > &a_triangles)
Definition: tess_contour:21
gluTessEndPolygon
GLUAPI void GLUAPIENTRY gluTessEndPolygon(GLUtesselator *tess)
Definition: glutess:493
gluTessCallback_GLU_TESS_BEGIN_DATA
void GLUAPIENTRY gluTessCallback_GLU_TESS_BEGIN_DATA(GLUtesselator *tess, void(GLUAPIENTRY *a_fn)(GLUenum, void *))
Definition: glutess:250
gluNewTess
GLUAPI GLUtesselator *GLUAPIENTRY gluNewTess(void)
Definition: glutess:59
gluTessProperty
GLUAPI void GLUAPIENTRY gluTessProperty(GLUtesselator *tess, GLUenum which, GLUdouble data)
Definition: glutess:168
GLU_TESS_WINDING_RULE
#define GLU_TESS_WINDING_RULE
Definition: _glu:34
GLUenum
unsigned int GLUenum
Definition: _glu:14
gluTessCallback_GLU_TESS_END_DATA
void GLUAPIENTRY gluTessCallback_GLU_TESS_END_DATA(GLUtesselator *tess, void(GLUAPIENTRY *a_fn)(void *))
Definition: glutess:254