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

Classes

class  add_prm
 

Public Types

typedef std::vector< tess_prim * > prims_t
 

Public Member Functions

 tessellate (std::ostream &a_out)
 
virtual ~tessellate ()
 
 tessellate (const tessellate &a_from)
 
tessellateoperator= (const tessellate &a_from)
 
void do_it (size_t a_npt, const double *a_contour, prims_t &a_prims)
 
void clear ()
 

Protected Types

typedef _GLUfuncptr Func
 
typedef float _vec3f[3]
 

Protected Member Functions

double * add_combine_vec3d (double a_x, double a_y, double a_z)
 
void _clear ()
 

Static Protected Member Functions

static void GLUAPIENTRY begin_cbk (GLUenum a_which, void *a_this)
 
static void GLUAPIENTRY vertex_cbk (void *a_vertex, void *a_this)
 
static void GLUAPIENTRY end_cbk (void *a_this)
 
static void GLUAPIENTRY combine_cbk (double a_coords[3], void *[4], float[4], void **a_data_out, void *a_this)
 
static void GLUAPIENTRY error_cbk (GLUenum, void *)
 

Protected Attributes

std::ostream & m_out
 
GLUtesselatorm_tobj
 
std::vector< float > * m_coords
 
std::vector< double * > m_combine_trids
 
size_t m_combine_trids_num
 
prims_tm_prims
 

Detailed Description

Definition at line 92 of file tessellate.

Member Typedef Documentation

◆ _vec3f

typedef float tools::sg::tessellate::_vec3f[3]
protected

Definition at line 185 of file tessellate.

◆ Func

Definition at line 160 of file tessellate.

◆ prims_t

Definition at line 142 of file tessellate.

Constructor & Destructor Documentation

◆ tessellate() [1/2]

tools::sg::tessellate::tessellate ( std::ostream &  a_out)
inline

Definition at line 97 of file tessellate.

97  :m_out(a_out),m_tobj(0) {
98 #ifdef TOOLS_MEM
99  mem::increment(s_class().c_str());
100 #endif
101  m_tobj = gluNewTess();
107  //set winding rule to positive => no holes
109  //m_out << "tools::sg::tessellate::tessellate :"
110  // << " GL_TRIANGLE_STRIP " << GL_TRIANGLE_STRIP
111  // << " GL_TRIANGLE_FAN " << GL_TRIANGLE_FAN
112  // << " GL_TRIANGLES " << GL_TRIANGLES
113  // << std::endl;
114  }

◆ ~tessellate()

virtual tools::sg::tessellate::~tessellate ( )
inlinevirtual

Definition at line 115 of file tessellate.

115  {
117  _clear();
118 #ifdef TOOLS_MEM
119  mem::decrement(s_class().c_str());
120 #endif
121  }

◆ tessellate() [2/2]

tools::sg::tessellate::tessellate ( const tessellate a_from)
inline

Definition at line 123 of file tessellate.

Member Function Documentation

◆ _clear()

void tools::sg::tessellate::_clear ( )
inlineprotected

Definition at line 285 of file tessellate.

285  {
286  tools_vforit(double*,m_combine_trids,it) delete [] *it;
287  m_combine_trids.clear();
289  }

◆ add_combine_vec3d()

double* tools::sg::tessellate::add_combine_vec3d ( double  a_x,
double  a_y,
double  a_z 
)
inlineprotected

Definition at line 268 of file tessellate.

268  {
269  double* v = 0;
271  v = new double[3];
272  m_combine_trids.push_back(v);
273  } else {
275  }
277 
278  v[0] = a_x;
279  v[1] = a_y;
280  v[2] = a_z;
281 
282  return v;
283  }

◆ begin_cbk()

static void GLUAPIENTRY tools::sg::tessellate::begin_cbk ( GLUenum  a_which,
void *  a_this 
)
inlinestaticprotected

Definition at line 162 of file tessellate.

162  {
163  tessellate& self = *((tessellate*)a_this);
164 
165  self.m_prims->push_back(new tess_prim());
166  tess_prim& prim = *(self.m_prims->back());
167  prim.m_mode = a_which;
168  prim.m_coords.reserve(12); //4 points.
169  prim.m_norms.reserve(12);
170 
171  self.m_coords = &prim.m_coords;
172 
173  //::printf("tools::sg::tessellate::begin_cbk : %d : STRIP %d FAN %d TRIS %d\n",
174  // a_which,GL_TRIANGLE_STRIP,GL_TRIANGLE_FAN,GL_TRIANGLES);
175  }

◆ clear()

void tools::sg::tessellate::clear ( )
inline

Definition at line 157 of file tessellate.

157 {_clear();}

◆ combine_cbk()

static void GLUAPIENTRY tools::sg::tessellate::combine_cbk ( double  a_coords[3],
void *  [4],
float  [4],
void **  a_data_out,
void *  a_this 
)
inlinestaticprotected

Definition at line 250 of file tessellate.

254  {
255  tessellate& self = *((tessellate*)a_this);
256  double* v = self.add_combine_vec3d(a_coords[0],a_coords[1],a_coords[2]);
257  //if(!v) ???
258  *a_data_out = v;
259  }

◆ do_it()

void tools::sg::tessellate::do_it ( size_t  a_npt,
const double *  a_contour,
prims_t a_prims 
)
inline

Definition at line 143 of file tessellate.

143  {
146  double* pos = (double*)a_contour;
147  for(size_t i=0;i<a_npt;i++,pos+=3) {
148  ::gluTessVertex(m_tobj,pos,pos);
149  }
151  a_prims.clear();
152  m_prims = &a_prims;
154  ::gluTessEndPolygon(m_tobj); //trigger callbacks and fill a_prims.
155  }

◆ end_cbk()

static void GLUAPIENTRY tools::sg::tessellate::end_cbk ( void *  a_this)
inlinestaticprotected

Definition at line 187 of file tessellate.

187  {
188  tessellate& self = *((tessellate*)a_this);
189 
190  tess_prim& prim = *(self.m_prims->back());
191 
192  //self.m_out << "tools::sg::tessellate::end_cbk : "
193  // << prim.m_coords.size()/3 << std::endl;
194 
195  add_prm aprm(self.m_out,prim.m_norms);
196 
197  float* data = vec_data<float>(prim.m_coords);
198 
199  bool ok = true;
200  if(prim.m_mode==gl::triangles()) {
201  if(!aprm.add_triangles(prim.m_coords.size(),data,false)) {
202  self.m_out << "tools::sg::tessellate::end_cbk : "
203  << " add_triangles failed."
204  << std::endl;
205  ok = false;
206  }
207  } else if(prim.m_mode==gl::triangle_strip()) {
208  if(!aprm.add_triangle_strip(prim.m_coords.size(),data,false)){
209  self.m_out << "tools::sg::tessellate::end_cbk : "
210  << " add_triangle_strip failed."
211  << std::endl;
212  ok = false;
213  }
214 
215  } else if(prim.m_mode==gl::triangle_fan()) {
216  if(!aprm.add_triangle_fan(prim.m_coords.size(),data,false)) {
217  self.m_out << "tools::sg::tessellate::end_cbk : "
218  << " add_triangle_fan failed."
219  << std::endl;
220  ok = false;
221  }
222  } else {
223  self.m_out << "tools::sg::tessellate::end_cbk : "
224  << " mode " << prim.m_mode << " not yet treated."
225  << std::endl;
226  ok = false;
227  }
228  if(!ok) {
229  size_t num = prim.m_coords.size();
230  self.m_out << "tools::sg::tessellate::end_cbk :"
231  << " primitive anomaly."
232  << " num points " << num
233  << " mode " << prim.m_mode
234  << " (TRIANGLES=4, STRIP=5, FAN=6)."
235  << std::endl;
236  float* pos = vec_data<float>(prim.m_coords);
237  for(size_t ipt=0;ipt<num;ipt++) {
238  self.m_out << " " << ipt << " :"
239  << " " << *(pos+0)
240  << " " << *(pos+1)
241  << " " << *(pos+2)
242  << std::endl;
243  pos += 3;
244  }
245  prim.m_coords.clear();
246  prim.m_norms.clear();
247  }
248  }

◆ error_cbk()

static void GLUAPIENTRY tools::sg::tessellate::error_cbk ( GLUenum  ,
void *   
)
inlinestaticprotected

Definition at line 261 of file tessellate.

261  {
262  //const GLubyte* estring = gluErrorString(aErrorCode);
263  //::fprintf(stderr, "Tessellation Error: %s\n", estring);
264  //SbTessContour* This = (SbTessContour*)aThis;
265  //This->setError(true);
266  }

◆ operator=()

tessellate& tools::sg::tessellate::operator= ( const tessellate a_from)
inline

Definition at line 136 of file tessellate.

136  {
137  if(&a_from==this) return *this;
138  _clear();
139  return *this;
140  }

◆ vertex_cbk()

static void GLUAPIENTRY tools::sg::tessellate::vertex_cbk ( void *  a_vertex,
void *  a_this 
)
inlinestaticprotected

Definition at line 177 of file tessellate.

177  {
178  tessellate& self = *((tessellate*)a_this);
179  double* vertex = (double*)a_vertex;
180  self.m_coords->push_back(float(vertex[0]));
181  self.m_coords->push_back(float(vertex[1]));
182  self.m_coords->push_back(float(vertex[2]));
183  }

Member Data Documentation

◆ m_combine_trids

std::vector<double*> tools::sg::tessellate::m_combine_trids
protected

Definition at line 492 of file tessellate.

◆ m_combine_trids_num

size_t tools::sg::tessellate::m_combine_trids_num
protected

Definition at line 493 of file tessellate.

◆ m_coords

std::vector<float>* tools::sg::tessellate::m_coords
protected

Definition at line 491 of file tessellate.

◆ m_out

std::ostream& tools::sg::tessellate::m_out
protected

Definition at line 489 of file tessellate.

◆ m_prims

prims_t* tools::sg::tessellate::m_prims
protected

Definition at line 494 of file tessellate.

◆ m_tobj

GLUtesselator* tools::sg::tessellate::m_tobj
protected

Definition at line 490 of file tessellate.


The documentation for this class was generated from the following file:
tools::sg::tessellate::m_prims
prims_t * m_prims
Definition: tessellate:494
GLU_TESS_WINDING_POSITIVE
#define GLU_TESS_WINDING_POSITIVE
Definition: _glu:39
tools::sg::tessellate::Func
_GLUfuncptr Func
Definition: tessellate:160
tools::gl::triangles
mode_t triangles()
Definition: glprims:20
gluTessCallback
GLUAPI void GLUAPIENTRY gluTessCallback(GLUtesselator *tess, GLUenum which, _GLUfuncptr CallBackFunc)
Definition: glutess:269
GLU_TESS_COMBINE_DATA
#define GLU_TESS_COMBINE_DATA
Definition: _glu:31
tools::sg::tessellate::m_combine_trids_num
size_t m_combine_trids_num
Definition: tessellate:493
tools::gl::triangle_fan
mode_t triangle_fan()
Definition: glprims:22
gluTessBeginPolygon
GLUAPI void GLUAPIENTRY gluTessBeginPolygon(GLUtesselator *tess, GLUvoid *data)
Definition: glutess:455
tools::sg::tessellate::m_tobj
GLUtesselator * m_tobj
Definition: tessellate:490
tools::sg::tessellate::combine_cbk
static void GLUAPIENTRY combine_cbk(double a_coords[3], void *[4], float[4], void **a_data_out, void *a_this)
Definition: tessellate:250
tools::sg::tessellate::error_cbk
static void GLUAPIENTRY error_cbk(GLUenum, void *)
Definition: tessellate:261
tools::sg::tessellate::m_out
std::ostream & m_out
Definition: tessellate:489
gluTessBeginContour
GLUAPI void GLUAPIENTRY gluTessBeginContour(GLUtesselator *tess)
Definition: glutess:469
GLU_TESS_ERROR_DATA
#define GLU_TESS_ERROR_DATA
Definition: _glu:30
tools::gl::triangle_strip
mode_t triangle_strip()
Definition: glprims:21
tools::sg::tessellate::begin_cbk
static void GLUAPIENTRY begin_cbk(GLUenum a_which, void *a_this)
Definition: tessellate:162
gluTessVertex
#define gluTessVertex
Definition: rename:13
tools_vforit
#define tools_vforit(a__T, a__v, a__it)
Definition: forit:13
tools::sg::tessellate::m_combine_trids
std::vector< double * > m_combine_trids
Definition: tessellate:492
GLU_TESS_END_DATA
#define GLU_TESS_END_DATA
Definition: _glu:29
gluTessEndContour
GLUAPI void GLUAPIENTRY gluTessEndContour(GLUtesselator *tess)
Definition: glutess:486
GLU_TESS_BEGIN_DATA
#define GLU_TESS_BEGIN_DATA
Definition: _glu:27
gluDeleteTess
GLUAPI void GLUAPIENTRY gluDeleteTess(GLUtesselator *tess)
Definition: glutess:160
gluTessEndPolygon
GLUAPI void GLUAPIENTRY gluTessEndPolygon(GLUtesselator *tess)
Definition: glutess:493
tools::sg::tessellate::tessellate
tessellate(std::ostream &a_out)
Definition: tessellate:97
tools::sg::tessellate::vertex_cbk
static void GLUAPIENTRY vertex_cbk(void *a_vertex, void *a_this)
Definition: tessellate:177
tools::sg::tessellate::_clear
void _clear()
Definition: tessellate:285
tools::sg::tessellate::end_cbk
static void GLUAPIENTRY end_cbk(void *a_this)
Definition: tessellate:187
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_VERTEX_DATA
#define GLU_TESS_VERTEX_DATA
Definition: _glu:28
GLU_TESS_WINDING_RULE
#define GLU_TESS_WINDING_RULE
Definition: _glu:34
GLUenum
unsigned int GLUenum
Definition: _glu:14