Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveGluTess.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007, 2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifdef ROOT_BUILTIN_GLU
13#include "GL/glu.h"
14#elif defined(__APPLE__) && defined(__MACH__) // fallback solution for APPLE system GLU
15#include <OpenGL/glu.h>
16#ifndef _GLUfuncptr
17typedef void (* _GLUfuncptr)(void);
18#endif
19#elif defined(WIN32)
20#include <windows.h>
21#include <GL/glu.h>
22#ifndef GLAPIENTRY
23#define GLAPIENTRY __stdcall
24#endif
25#ifndef _GLUfuncptr
26typedef void (GLAPIENTRY * _GLUfuncptr)(void);
27#endif
28#else // Linux system GLU
29#include <GL/glu.h>
30#endif
31
32#include <ROOT/REveGluTess.hxx>
33
34#include <cmath>
35#include <cstdlib>
36#include <stdexcept>
37
38namespace ROOT {
39namespace Experimental {
40namespace EveGlu {
41
42//////////////////////////////////////////////////////////////////////////////////////
43/// TestTriangleHandler is just helper class to get access to protected members of TriangleCollector
44/// Hide static declarations, let use "native" GL types
45//////////////////////////////////////////////////////////////////////////////////////
46
48public:
50 static void tess_vertex(Int_t *vi, TriangleCollector *tc);
51 static void
52 tess_combine(GLdouble coords[3], void *vertex_data[4], GLfloat weight[4], void **outData, TriangleCollector *tc);
53 static void tess_end(TriangleCollector *tc);
54};
55
56
57//////////////////////////////////////////////////////////////////////////////////////
58/// tess_begin
59
61{
62 tc->fNVertices = 0;
63 tc->fV0 = tc->fV1 = -1;
64 tc->fType = type;
65}
66
67//////////////////////////////////////////////////////////////////////////////////////
68/// tess_vertex
69
71{
72 tc->process_vertex(*vi);
73}
74
75//////////////////////////////////////////////////////////////////////////////////////
76/// tess_combine
77
78void TestTriangleHandler::tess_combine(GLdouble /*coords*/[3], void * /*vertex_data*/[4],
79 GLfloat /*weight*/[4], void ** /*outData*/,
80 TriangleCollector * /*tc*/)
81{
82 throw std::runtime_error("GLU::TriangleCollector tesselator requested vertex combining -- not supported yet.");
83}
84
85//////////////////////////////////////////////////////////////////////////////////////
86/// tess_end
87
92
93
94//==============================================================================
95// TriangleCollector
96//==============================================================================
97
98//////////////////////////////////////////////////////////////////////////////////////
99/// constructor
100
112
113//////////////////////////////////////////////////////////////////////////////////////
114/// destructor
115
120
121//////////////////////////////////////////////////////////////////////////////////////
122/// add triangle
123
125{
126 fPolyDesc.emplace_back(3);
127 fPolyDesc.emplace_back(v0);
128 fPolyDesc.emplace_back(v1);
129 fPolyDesc.emplace_back(v2);
130 ++fNTriangles;
131}
132
133//////////////////////////////////////////////////////////////////////////////////////
134/// process_vertex
135
137{
138 ++fNVertices;
139
140 if (fV0 == -1) {
141 fV0 = vi;
142 return;
143 }
144 if (fV1 == -1) {
145 fV1 = vi;
146 return;
147 }
148
149 switch (fType)
150 {
151 case GL_TRIANGLES:
152 {
153 add_triangle(fV0, fV1, vi);
154 fV0 = fV1 = -1;
155 break;
156 }
158 {
159 if (fNVertices % 2 == 0)
160 add_triangle(fV1, fV0, vi);
161 else
162 add_triangle(fV0, fV1, vi);
163 fV0 = fV1;
164 fV1 = vi;
165 break;
166 }
167 case GL_TRIANGLE_FAN:
168 {
169 add_triangle(fV0, fV1, vi);
170 fV1 = vi;
171 break;
172 }
173 default:
174 {
175 throw std::runtime_error("GLU::TriangleCollector unexpected type in tess_vertex callback.");
176 }
177 }
178}
179
180//////////////////////////////////////////////////////////////////////////////////////
181/// ProcessData
182
184 const std::vector<UInt_t> & polys,
185 const Int_t n_polys)
186{
187 if (verts.empty() || polys.empty())
188 return;
189
190 const Double_t *pnts = &verts[0];
191 const UInt_t *pols = &polys[0];
192
193 for (Int_t i = 0, j = 0; i < n_polys; ++i)
194 {
195 Int_t n_points = pols[j++];
196
197 gluTessBeginPolygon(fTess, this);
198 gluTessBeginContour(fTess);
199
200 for (Int_t k = 0; k < n_points; ++k, ++j)
201 {
202 gluTessVertex(fTess, (Double_t*) pnts + pols[j] * 3, (GLvoid*) &pols[j]);
203 }
204
205 gluTessEndContour(fTess);
206
207 static int except_cnt = 0;
208
209 try {
210 gluTessEndPolygon(fTess);
211 } catch(...) {
212 if (except_cnt++ < 100) printf("Catch exception gluTessEndPolygon!\n");
213 }
214 }
215}
216
217} // namespace EveGlu
218} // namespace Experimental
219} // namespace ROOT
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
TestTriangleHandler is just helper class to get access to protected members of TriangleCollector Hide...
static void tess_combine(GLdouble coords[3], void *vertex_data[4], GLfloat weight[4], void **outData, TriangleCollector *tc)
tess_combine
static void tess_begin(GLenum type, TriangleCollector *tc)
tess_begin
static void tess_vertex(Int_t *vi, TriangleCollector *tc)
tess_vertex
static void tess_end(TriangleCollector *tc)
tess_end
void process_vertex(UInt_t vi)
process_vertex
void add_triangle(UInt_t v0, UInt_t v1, UInt_t v2)
add triangle
void ProcessData(const std::vector< Double_t > &verts, const std::vector< UInt_t > &polys, const Int_t n_polys)
ProcessData.