SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GUIPolygon.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // The GUI-version of a polygon
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
13 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <string>
34 #include "GUIPolygon.h"
39 #include <utils/gui/div/GLHelper.h>
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 #ifdef WIN32
47 #include <windows.h>
48 #endif
49 
50 #include <GL/gl.h>
51 #include <GL/glu.h>
52 
53 
54 // ===========================================================================
55 // method definitions
56 // ===========================================================================
58  const std::string name, const std::string type,
59  const RGBColor& color,
60  const PositionVector& Pos,
61  bool fill)
62  : Polygon(name, type, color, Pos, fill),
63  GUIGlObject_AbstractAdd("poly", GLO_SHAPE, name), myLayer(layer) {}
64 
65 
67 
68 
69 
72  GUISUMOAbstractView& parent) {
73  GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this);
74  buildPopupHeader(ret, app, false);
75  FXString t(myType.c_str());
76  new FXMenuCommand(ret, "(" + t + ")", 0, 0, 0);
77  new FXMenuSeparator(ret);
81  buildPositionCopyEntry(ret, false);
82  return ret;
83 }
84 
85 
89  return 0;
90 }
91 
92 
95  Boundary b;
97  b.grow(10);
98  return b;
99 }
100 
101 
102 void APIENTRY beginCallback(GLenum which) {
103  glBegin(which);
104 }
105 
106 void APIENTRY errorCallback(GLenum errorCode) {
107  const GLubyte* estring;
108 
109  estring = gluErrorString(errorCode);
110  fprintf(stderr, "Tessellation Error: %s\n", estring);
111  exit(0);
112 }
113 
114 void APIENTRY endCallback(void) {
115  glEnd();
116 }
117 
118 void APIENTRY vertexCallback(GLvoid* vertex) {
119  const GLdouble* pointer;
120 
121  pointer = (GLdouble*) vertex;
122  glVertex3dv((GLdouble*) vertex);
123 }
124 
125 void APIENTRY combineCallback(GLdouble coords[3],
126  GLdouble* vertex_data[4],
127  GLfloat weight[4], GLdouble** dataOut) {
128  UNUSED_PARAMETER(weight);
129  UNUSED_PARAMETER(*vertex_data);
130  GLdouble* vertex;
131 
132  vertex = (GLdouble*) malloc(7 * sizeof(GLdouble));
133 
134  vertex[0] = coords[0];
135  vertex[1] = coords[1];
136  vertex[2] = coords[2];
137  *dataOut = vertex;
138 }
139 
140 double glvert[6];
141 void
143  UNUSED_PARAMETER(s);
144  if (fill()) {
145  if (myShape.size() < 3) {
146  return;
147  }
148  } else {
149  if (myShape.size() < 2) {
150  return;
151  }
152  }
153  glPushName(getGlID());
154  glPushMatrix();
155  glTranslated(0, 0, getLayer());
156  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
158  if (fill()) {
159  double* points = new double[myShape.size() * 3];
160  GLUtesselator* tobj = gluNewTess();
161  gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv);
162  gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &beginCallback);
163  gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &endCallback);
164  //gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (APIENTRY*) ()) &errorCallback);
165  gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &combineCallback);
166  gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
167  gluTessBeginPolygon(tobj, NULL);
168  gluTessBeginContour(tobj);
169  for (size_t i = 0; i != myShape.size(); ++i) {
170  points[3 * i] = myShape[(int) i].x();
171  points[3 * i + 1] = myShape[(int) i].y();
172  points[3 * i + 2] = 0;
173  glvert[0] = myShape[(int) i].x();
174  glvert[1] = myShape[(int) i].y();
175  glvert[2] = 0;
176  glvert[3] = 1;
177  glvert[4] = 1;
178  glvert[5] = 1;
179  gluTessVertex(tobj, points + 3 * i, points + 3 * i) ;
180  }
181  gluTessEndContour(tobj);
182 
183  gluTessEndPolygon(tobj);
184  gluDeleteTess(tobj);
185  delete[] points;
186  } else {
189  }
190  glPopName();
191  glPopMatrix();
192 }
193 
194 
195 
196 int
198  return myLayer;
199 }
200 
201 
202 
203 /****************************************************************************/
204