void IntersectionInfoCache::makePolygonDrawData(std::vector<GeoLocation>& vecPoints, std::vector<uint16>& triangleIndexList, uint8 drawelement, //多边形描画数据 vector<IntersectionImageData>& imageData) { std::vector<PolygonTessVertex> points; uint32 pointcount = vecPoints.size(); points.reserve(pointcount); for(int32 i = 0;i < pointcount;++i) { PolygonTessVertex m_point; m_point.vertex.x = vecPoints[i].longitude; m_point.vertex.y = vecPoints[i].latitude; points.emplace_back(m_point); } TessPolygon(points, triangleIndexList); std::vector<GeoLocation> vecTessPoints; uint32 pointcountTess = points.size(); vecTessPoints.reserve(pointcountTess); for(int32 i = 0;i < pointcountTess;++i) { GeoLocation m_point; m_point.longitude = points[i].vertex.x; m_point.latitude = points[i].vertex.y; vecTessPoints.emplace_back(m_point); } IntersectionImageData tempimagedata; tempimagedata.drawelement = drawelement; tempimagedata.vertex.assign(vecTessPoints.begin(), vecTessPoints.end()); tempimagedata.index.assign(triangleIndexList.begin(), triangleIndexList.end()); imageData.emplace_back(tempimagedata); } void TessPolygon(std::vector<PolygonTessVertex> &points, std::vector<uint16> &triangleIndexList) { auto uiPointCount = points.size(); GLUtesselator* tobj = gluNewTess(); gluTessCallback(tobj, GLU_TESS_VERTEX_DATA, (_GLUfuncptr)PolygonVertexCallback); gluTessCallback(tobj, GLU_TESS_BEGIN_DATA, (_GLUfuncptr)PolygonBeginCallback); gluTessCallback(tobj, GLU_TESS_END_DATA, (_GLUfuncptr)PolygonEndCallback); gluTessCallback(tobj, GLU_TESS_ERROR_DATA, (_GLUfuncptr)PolygonErrorCallback); gluTessCallback(tobj, GLU_TESS_COMBINE_DATA, (_GLUfuncptr)PolygonCombineCallback); gluTessProperty(tobj, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO); PolygonData_t stPolygonData; gluTessBeginPolygon(tobj, &stPolygonData); gluTessBeginContour(tobj); /* for loop statement: the initial value of decltype(uiPointCount) Index is 0 / for(decltype(uiPointCount) Index = 0; Index < uiPointCount; ++Index) { stPolygonData.vecVertexArray.emplace_back(points[Index]); TessPolygonVertex tempTessVertex; tempTessVertex.location[0] = points[Index].vertex.x; tempTessVertex.location[1] = points[Index].vertex.y; gluTessNormal(tobj, 0.0, 0.0, 1.0); gluTessVertex(tobj, tempTessVertex.location, (GLvoid)Index); } gluTessEndContour(tobj); gluTessEndPolygon(tobj); gluDeleteTess(tobj); points.swap(stPolygonData.vecVertexArray); triangleIndexList.swap(stPolygonData.vecDrawIndices); }加上注释
时间: 2024-04-07 08:32:28 浏览: 70
x-geolocation:声明性地理位置API作为Web组件
这是一段C++代码,用于对一个多边形进行三角剖分,并生成多边形的描画数据。具体实现包括两个函数:makePolygonDrawData和TessPolygon。makePolygonDrawData函数中,首先将多边形的顶点坐标转换为PolygonTessVertex格式,然后调用TessPolygon函数进行三角剖分。最后将剖分后的顶点数据和三角形索引数据存储到IntersectionImageData结构体中,并将其存储到imageData向量中。
TessPolygon函数中,首先创建一个GLUtesselator对象,并设置回调函数,然后开始对多边形进行剖分。在剖分过程中,将多边形的顶点数据添加到PolygonData_t结构体中,并通过gluTessVertex函数将其传递给剖分器。最后将剖分后的顶点数据和三角形索引数据存储到PolygonData_t结构体中,并将其交换到函数参数中传递的向量中。
阅读全文