59 fVertices(buffer.fPnts, buffer.fPnts + 3 * buffer.NbPnts()),
73 descSize += pols[j] + 1;
79 for (
UInt_t numPol = 0, currInd = 0, j = 1; numPol <
fNbPols; ++numPol)
81 Int_t segmentInd = pols[j] + j;
82 Int_t segmentCol = pols[j];
85 Int_t s2 = pols[segmentInd];
89 Int_t numPnts[3] = {0};
91 if (segEnds[0] == segEnds[2]) {
92 numPnts[0] = segEnds[1], numPnts[1] = segEnds[0], numPnts[2] = segEnds[3];
93 }
else if (segEnds[0] == segEnds[3]) {
94 numPnts[0] = segEnds[1], numPnts[1] = segEnds[0], numPnts[2] = segEnds[2];
95 }
else if (segEnds[1] == segEnds[2]) {
96 numPnts[0] = segEnds[0], numPnts[1] = segEnds[1], numPnts[2] = segEnds[3];
98 numPnts[0] = segEnds[0], numPnts[1] = segEnds[1], numPnts[2] = segEnds[2];
102 Int_t sizeInd = currInd++;
106 Int_t lastAdded = numPnts[2];
109 for (; segmentInd != end; segmentInd--) {
110 segEnds[0] =
segs[pols[segmentInd] * 3 + 1];
111 segEnds[1] =
segs[pols[segmentInd] * 3 + 2];
112 if (segEnds[0] == lastAdded) {
114 lastAdded = segEnds[1];
117 lastAdded = segEnds[0];
137 UInt_t nv = mesh->NumberOfVertices();
141 for (i = 0; i < nv; ++i) {
146 fNbPols = mesh->NumberOfPolys();
150 for (i = 0; i <
fNbPols; ++i) descSize += mesh->SizeOfPoly(i) + 1;
154 for (
UInt_t polyIndex = 0; polyIndex <
fNbPols; ++polyIndex) {
155 UInt_t polySize = mesh->SizeOfPoly(polyIndex);
159 for(i = 0; i < polySize; ++i)
fPolyDesc.push_back(mesh->GetVertexIndex(polyIndex, i));
177 class TriangleCollector
195 void process_vertex(
Int_t vi)
212 add_triangle(fV0, fV1, vi);
216 case GL_TRIANGLE_STRIP:
218 if (fNVertices % 2 == 0)
219 add_triangle(fV1, fV0, vi);
221 add_triangle(fV0, fV1, vi);
226 case GL_TRIANGLE_FAN:
228 add_triangle(fV0, fV1, vi);
234 throw std::runtime_error(
"TGLFaceSet::EnforceTriangles unexpected type in tess_vertex callback.");
240 TriangleCollector(GLUtesselator* ts) :
241 fNTriangles(0), fNVertices(0), fV0(-1), fV1(-1), fType(GL_NONE)
243 gluTessCallback(ts, (GLenum)GLU_TESS_BEGIN_DATA, (tessfuncptr_t)((
void*)tess_begin));
244 gluTessCallback(ts, (GLenum)GLU_TESS_VERTEX_DATA, (tessfuncptr_t)((
void*)tess_vertex));
245 gluTessCallback(ts, (GLenum)GLU_TESS_COMBINE_DATA, (tessfuncptr_t)((
void*)tess_combine));
246 gluTessCallback(ts, (GLenum)GLU_TESS_END_DATA, (tessfuncptr_t)((
void*)tess_end));
249 Int_t GetNTrianlges() {
return fNTriangles; }
250 std::vector<Int_t>& RefPolyDesc() {
return fPolyDesc; }
252 static void tess_begin(GLenum type, TriangleCollector* tc)
255 tc->fV0 = tc->fV1 = -1;
259 static void tess_vertex(
Int_t* vi, TriangleCollector* tc)
261 tc->process_vertex(*vi);
264 static void tess_combine(GLdouble [3],
void* [4],
265 GLfloat [4],
void** ,
268 throw std::runtime_error(
"TGLFaceSet::EnforceTriangles tesselator requested vertex combining -- not supported yet.");
271 static void tess_end(TriangleCollector* tc)
277 GLUtesselator *tess = gluNewTess();
278 if (!tess)
throw std::bad_alloc();
280 TriangleCollector tc(tess);
288 Int_t npoints = pols[j++];
290 gluTessBeginPolygon(tess, &tc);
291 gluTessBeginContour(tess);
293 for (
Int_t k = 0; k < npoints; ++k, ++j)
295 gluTessVertex(tess, (
Double_t*) pnts + pols[j] * 3, (GLvoid*) &pols[j]);
298 gluTessEndContour(tess);
299 gluTessEndPolygon(tess);
314 Info(
"TGLFaceSet::DirectDraw",
"this %zd (class %s) LOD %d", (
size_t)
this,
IsA()->GetName(), rnrCtx.
ShapeLOD());
325 Int_t npoints = pols[j++];
327 if (tessObj && npoints > 4) {
328 gluBeginPolygon(tessObj);
329 gluNextContour(tessObj, (GLenum)GLU_UNKNOWN);
330 glNormal3dv(normals + i * 3);
332 for (
Int_t k = 0; k < npoints; ++k, ++j) {
333 gluTessVertex(tessObj, (
Double_t *)pnts + pols[j] * 3, (
Double_t *)pnts + pols[j] * 3);
335 gluEndPolygon(tessObj);
338 glNormal3dv(normals + i * 3);
340 for (
Int_t k = 0; k < npoints; ++k, ++j) {
341 glVertex3dv(pnts + pols[j] * 3);
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
T * Normal2Plane(const T v1[3], const T v2[3], const T v3[3], T normal[3])
Calculates a normal vector of a plane.