1 /* $Id$Revision: */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include "polytess.h"
15 #include "xdot.h"
16 tessPoly TP;
17 #if 0
18 GLdouble star[5][3] = { 0.6f,  -0.1f, 0.0f,
19                         1.35f, 1.4f, 0.0f,
20                         2.1f,  -0.1f, 0.0f,
21                         0.6f, 0.9f, 0.0f,
22                         2.1f, 0.9f, 0.0f,};
23 
24 
25 //second polygon: a quad-4 vertices; first contour
26 
27 GLdouble s1[3][3] = { 0.0f, 0.0f, 0.0f,
28                         1.0f, 0.0f, 0.0f,
29                         1.0f, 0.0f, 0.0f,};
30 GLdouble s2[4][3] = {	0.0f, 1.0f, 0.0f,
31 			0.3f, 0.3f, 0.0f,
32 			0.7f, 0.3f, 0.0f,
33 			0.5f, 0.7f, 0.0f,};
34 
35 
36 
37 
38 
39 
40 GLdouble quad2[9][3] = { 0.0f, 0.0f, 0.0f,
41                         1.0f, 0.0f, 0.0f,
42                         1.0f, 1.0f, 0.0f,
43                         0.0f, 1.0f, 0.0f,
44 			0.0f, 0.0f, 0.0f,
45 			0.3f, 0.3f, 0.0f,
46                        0.7f, 0.3f, 0.0f,
47                        0.5f, 0.7f, 0.0f,
48 			0.3f, 0.3f, 0.0f};
49 
50 
51 
52 GLdouble quad[5][3] = { 0.0f, 0.0f, 0.0f,
53                         1.0f, 0.0f, 0.0f,
54                         1.0f, 1.0f, 0.0f,
55                         0.0f, 1.0f, 0.0f,
56 			0.0f, 0.0f, 0.0f};
57 
58 //second polygon: a triangle-3 vertices; second contour
59 GLdouble tri[3][3] = { 0.3f, 0.3f, 0.0f,
60                        0.7f, 0.3f, 0.0f,
61                        0.5f, 0.7f, 0.0f};
62 
63 GLdouble complex[25][3] = { 0.0f, 0.0f, 0.0f,
64                         2.0f, 1.0f, 0.0f,
65                         2.0f, 2.0f, 0.0f,
66                         1.0f, 3.0f, 0.0f,
67 			3.0f, 3.0f, 0.0f,
68 			3.0f, 5.0f, 0.0f,
69                        0.0f, 5.0f, 0.0f,
70                        1.0f, 6.0f, 0.0f,
71 			0.0f, 7.0f, 0.0f,
72 			3.0f, 7.0f, 0.0f,
73 			5.0f, 5.0f, 0.0f,
74 			6.0f, 7.0f, 0.0f,
75 			7.0f, 7.0f, 0.0f,
76 			6.0f, 4.0f, 0.0f,
77 			5.0f, 4.0f, 0.0f,
78 			5.0f, 3.0f, 0.0f,
79 			4.0f, 3.0f, 0.0f,
80 			4.0f, 2.0f, 0.0f,
81 			7.0f, 2.0f, 0.0f,
82 			4.0f, 0.0f, 0.0f,
83 			0.0f, 0.0f, 0.0f,
84 			2.5f, 0.5f, 0.0f,
85 			3.5f, 1.0f, 0.0f,
86 			3.5f, 0.5f, 0.0f,
87 			2.5f, 0.5f, 0.0f};
88 
89 
90 
91 #endif
92 #ifndef _WIN32
93 #define CALLBACK
94 #endif
combineCallback(GLdouble coords[3],GLdouble * vertex_data[4],GLfloat weight[4],GLdouble ** dataOut)95 static void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4],GLfloat weight[4], GLdouble **dataOut)
96 {
97     GLdouble *vertex;
98     int i;
99     vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
100     vertex[0] = coords[0];
101     vertex[1] = coords[1];
102     vertex[2] = coords[2];
103     for (i = 3; i < 6; i++)
104     {
105 /*	vertex[i] = weight[0] * vertex_data[0][i] +
106 		    weight[1] * vertex_data[1][i] +
107 		    weight[2] * vertex_data[2][i] +
108 		    weight[3] * vertex_data[3][i];*/
109 	vertex[i] = 0;
110 
111     }
112     *dataOut = vertex;
113 }
114 
vertexCallback(GLvoid * vertex)115 static void CALLBACK vertexCallback(GLvoid *vertex)
116 {
117     GLdouble *ptr;
118     ptr = (GLdouble *) vertex;
119     glVertex3dv((GLdouble *) ptr);
120 
121 }
122 
Init()123 static GLUtesselator* Init()
124 {
125     // Create a new tessellation object
126     GLUtesselator* tobj = gluNewTess();
127     // Set callback functions
128     gluTessCallback(tobj, GLU_TESS_VERTEX, &vertexCallback);
129     gluTessCallback(tobj, GLU_TESS_BEGIN, &glBegin);
130     gluTessCallback(tobj, GLU_TESS_END, &glEnd);
131     gluTessCallback(tobj, GLU_TESS_COMBINE,&combineCallback);
132     return tobj;
133 }
134 
135 
136 
Set_Winding_Rule(GLUtesselator * tobj,GLenum winding_rule)137 static int Set_Winding_Rule(GLUtesselator *tobj,GLenum winding_rule)
138 {
139 
140 // Set the winding rule
141     gluTessProperty(tobj, GLU_TESS_WINDING_RULE, winding_rule);
142     return 1 ;
143 }
144 
Render_Contour2(GLUtesselator * tobj,sdot_op * p)145 static int Render_Contour2(GLUtesselator *tobj,sdot_op* p)
146 {
147     GLdouble** d;
148     int x=0;
149     /* int y=0; */
150 
151     d=(GLdouble**) malloc(sizeof(GLdouble)* p->op.u.polygon.cnt);
152     for (x=0;x < p->op.u.polygon.cnt; x++)
153     {
154 	/* GLdouble temp; */
155 	d[x]=(GLdouble*)(malloc(sizeof(GLdouble)*3));
156 	d[x][0]=p->op.u.polygon.pts[x].x;
157 	d[x][1]=p->op.u.polygon.pts[x].y;
158 	d[x][2]=p->op.u.polygon.pts[x].z+view->Topview->global_z;
159     }
160     for (x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
161     {
162 	gluTessVertex(tobj, d[x],d[x]); //store the vertex
163     }
164 
165 
166 /*    for (x = 0; x < p->op.u.polygon.cnt; x++) //loop through the vertices
167     {
168 	d[0]=p->op.u.polygon.pts[x].x;
169 	d[1]=p->op.u.polygon.pts[x].y;
170 	d[2]=p->op.u.polygon.pts[x].z;
171 //	gluTessVertex(tobj, obj_data[x], obj_data[x]); //store the vertex
172 	gluTessVertex(tobj, d,d); //store the vertex
173     }*/
174     return(1);
175 
176 }
177 
178 #if UNUSED
Render_Contour(GLUtesselator * tobj,GLdouble obj_data[][3],int cnt)179 static int Render_Contour(GLUtesselator *tobj, GLdouble obj_data[][3],int cnt)
180 {
181 //    GLdouble d[1][3];
182     static GLdouble** d;
183     int x=0;
184     /* int y=0; */
185     if (!d) {
186 	d = N_NEW(cnt,GLdouble*);
187 	for (x=0;x < cnt; x++)
188 	{
189 	    /* GLdouble temp; */
190 	    d[x] = N_NEW3,GLdouble);
191 	    d[x][0]=obj_data[x][0];
192 	    d[x][1]=obj_data[x][1];
193 	    d[x][2]=obj_data[x][2];
194         }
195     }
196 
197 
198 
199 
200     for (x = 0; x < cnt; x++) //loop through the vertices
201     {
202 /*	d[0][0]=obj_data[x][0];
203 	d[0][1]=obj_data[x][1];
204 	d[0][2]=obj_data[x][2];*/
205 
206 
207 
208 /*void APIENTRY  gluTessVertex(
209     GLUtesselator       *tess,
210     GLdouble            coords[3],
211     void                *data );*/
212 
213 	gluTessVertex(tobj, d[x], d[x]); //store the vertex
214 //	gluTessVertex(tobj, obj_data[x], obj_data[x]); //store the vertex
215 //	gluTessVertex(tobj, d[0],d[0]); //store the vertex
216 //	gluTessVertex(tobj, g,g); //store the vertex
217 
218     }
219 
220     return(1);
221 
222 }
223 #endif
224 
225 
226 
227 
228 
229 
Begin_Polygon(GLUtesselator * tobj)230 static int Begin_Polygon(GLUtesselator *tobj)
231 {
232     gluTessBeginPolygon(tobj, NULL);
233     return(1);
234 }
End_Polygon(GLUtesselator * tobj)235 static int End_Polygon(GLUtesselator *tobj)
236 {
237     gluTessEndPolygon(tobj);
238     return(1);
239 
240 }
Begin_Contour(GLUtesselator * tobj)241 static int Begin_Contour(GLUtesselator *tobj)
242 {
243     gluTessBeginContour(tobj);
244     return(1);
245 
246 }
End_Contour(GLUtesselator * tobj)247 static int End_Contour(GLUtesselator *tobj)
248 {
249     gluTessEndContour(tobj);
250     return(1);
251 
252 }
253 
254 #if 0
255 static int freeTes(GLUtesselator *tobj)
256 {
257     gluDeleteTess(tobj);
258     return(1);
259 
260 }
261 #endif
262 
drawTessPolygon(sdot_op * p)263 int drawTessPolygon(sdot_op* p)
264 {
265     if (!TP.tobj)
266     {
267 	TP.tobj=Init();
268 	TP.windingRule=GLU_TESS_WINDING_ODD;
269     }
270     Set_Winding_Rule(TP.tobj,TP.windingRule);
271     Begin_Polygon(TP.tobj);
272     Begin_Contour(TP.tobj);
273     Render_Contour2(TP.tobj,p);
274 //    Render_Contour(TP.tobj,complex,25);
275     End_Contour(TP.tobj);
276     End_Polygon(TP.tobj);
277     return 1;
278 }
279 
280