SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00010 // The GUI-version of a polygon 00011 /****************************************************************************/ 00012 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00013 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00014 /****************************************************************************/ 00015 // 00016 // This file is part of SUMO. 00017 // SUMO is free software: you can redistribute it and/or modify 00018 // it under the terms of the GNU General Public License as published by 00019 // the Free Software Foundation, either version 3 of the License, or 00020 // (at your option) any later version. 00021 // 00022 /****************************************************************************/ 00023 00024 // =========================================================================== 00025 // included modules 00026 // =========================================================================== 00027 #ifdef _MSC_VER 00028 #include <windows_config.h> 00029 #else 00030 #include <config.h> 00031 #endif 00032 00033 #include <string> 00034 #include "GUIPolygon.h" 00035 #include <utils/gui/globjects/GUIGlObject.h> 00036 #include <utils/gui/div/GUIParameterTableWindow.h> 00037 #include <utils/gui/globjects/GUIGLObjectPopupMenu.h> 00038 #include <utils/gui/settings/GUIVisualizationSettings.h> 00039 #include <utils/gui/div/GLHelper.h> 00040 #include <foreign/polyfonts/polyfonts.h> 00041 00042 #ifdef CHECK_MEMORY_LEAKS 00043 #include <foreign/nvwa/debug_new.h> 00044 #endif // CHECK_MEMORY_LEAKS 00045 00046 #ifdef WIN32 00047 #include <windows.h> 00048 #endif 00049 00050 #include <GL/gl.h> 00051 #include <GL/glu.h> 00052 00053 00054 // =========================================================================== 00055 // method definitions 00056 // =========================================================================== 00057 GUIPolygon::GUIPolygon(int layer, 00058 const std::string name, const std::string type, 00059 const RGBColor& color, 00060 const PositionVector& Pos, 00061 bool fill) 00062 : Polygon(name, type, color, Pos, fill), 00063 GUIGlObject_AbstractAdd("poly", GLO_SHAPE, name), myLayer(layer) {} 00064 00065 00066 GUIPolygon::~GUIPolygon() {} 00067 00068 00069 00070 GUIGLObjectPopupMenu* 00071 GUIPolygon::getPopUpMenu(GUIMainWindow& app, 00072 GUISUMOAbstractView& parent) { 00073 GUIGLObjectPopupMenu* ret = new GUIGLObjectPopupMenu(app, parent, *this); 00074 buildPopupHeader(ret, app, false); 00075 FXString t(myType.c_str()); 00076 new FXMenuCommand(ret, "(" + t + ")", 0, 0, 0); 00077 new FXMenuSeparator(ret); 00078 buildCenterPopupEntry(ret); 00079 buildNameCopyPopupEntry(ret); 00080 buildSelectionPopupEntry(ret); 00081 buildPositionCopyEntry(ret, false); 00082 return ret; 00083 } 00084 00085 00086 GUIParameterTableWindow* 00087 GUIPolygon::getParameterWindow(GUIMainWindow&, 00088 GUISUMOAbstractView&) { 00089 return 0; 00090 } 00091 00092 00093 Boundary 00094 GUIPolygon::getCenteringBoundary() const { 00095 Boundary b; 00096 b.add(myShape.getBoxBoundary()); 00097 b.grow(10); 00098 return b; 00099 } 00100 00101 00102 void APIENTRY beginCallback(GLenum which) { 00103 glBegin(which); 00104 } 00105 00106 void APIENTRY errorCallback(GLenum errorCode) { 00107 const GLubyte* estring; 00108 00109 estring = gluErrorString(errorCode); 00110 fprintf(stderr, "Tessellation Error: %s\n", estring); 00111 exit(0); 00112 } 00113 00114 void APIENTRY endCallback(void) { 00115 glEnd(); 00116 } 00117 00118 void APIENTRY vertexCallback(GLvoid* vertex) { 00119 const GLdouble* pointer; 00120 00121 pointer = (GLdouble*) vertex; 00122 glVertex3dv((GLdouble*) vertex); 00123 } 00124 00125 void APIENTRY combineCallback(GLdouble coords[3], 00126 GLdouble* vertex_data[4], 00127 GLfloat weight[4], GLdouble** dataOut) { 00128 UNUSED_PARAMETER(weight); 00129 UNUSED_PARAMETER(*vertex_data); 00130 GLdouble* vertex; 00131 00132 vertex = (GLdouble*) malloc(7 * sizeof(GLdouble)); 00133 00134 vertex[0] = coords[0]; 00135 vertex[1] = coords[1]; 00136 vertex[2] = coords[2]; 00137 *dataOut = vertex; 00138 } 00139 00140 double glvert[6]; 00141 void 00142 GUIPolygon::drawGL(const GUIVisualizationSettings& s) const { 00143 UNUSED_PARAMETER(s); 00144 if (fill()) { 00145 if (myShape.size() < 3) { 00146 return; 00147 } 00148 } else { 00149 if (myShape.size() < 2) { 00150 return; 00151 } 00152 } 00153 glPushName(getGlID()); 00154 glPushMatrix(); 00155 glTranslated(0, 0, getLayer()); 00156 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); 00157 GLHelper::setColor(getColor()); 00158 if (fill()) { 00159 double* points = new double[myShape.size() * 3]; 00160 GLUtesselator* tobj = gluNewTess(); 00161 gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid(APIENTRY*)()) &glVertex3dv); 00162 gluTessCallback(tobj, GLU_TESS_BEGIN, (GLvoid(APIENTRY*)()) &beginCallback); 00163 gluTessCallback(tobj, GLU_TESS_END, (GLvoid(APIENTRY*)()) &endCallback); 00164 //gluTessCallback(tobj, GLU_TESS_ERROR, (GLvoid (APIENTRY*) ()) &errorCallback); 00165 gluTessCallback(tobj, GLU_TESS_COMBINE, (GLvoid(APIENTRY*)()) &combineCallback); 00166 gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD); 00167 gluTessBeginPolygon(tobj, NULL); 00168 gluTessBeginContour(tobj); 00169 for (size_t i = 0; i != myShape.size(); ++i) { 00170 points[3 * i] = myShape[(int) i].x(); 00171 points[3 * i + 1] = myShape[(int) i].y(); 00172 points[3 * i + 2] = 0; 00173 glvert[0] = myShape[(int) i].x(); 00174 glvert[1] = myShape[(int) i].y(); 00175 glvert[2] = 0; 00176 glvert[3] = 1; 00177 glvert[4] = 1; 00178 glvert[5] = 1; 00179 gluTessVertex(tobj, points + 3 * i, points + 3 * i) ; 00180 } 00181 gluTessEndContour(tobj); 00182 00183 gluTessEndPolygon(tobj); 00184 gluDeleteTess(tobj); 00185 delete[] points; 00186 } else { 00187 GLHelper::drawLine(myShape); 00188 GLHelper::drawBoxLines(myShape, 1.); 00189 } 00190 glPopName(); 00191 glPopMatrix(); 00192 } 00193 00194 00195 00196 int 00197 GUIPolygon::getLayer() const { 00198 return myLayer; 00199 } 00200 00201 00202 00203 /****************************************************************************/ 00204