⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 areafeature.cpp

📁 开源的电子海图程序
💻 CPP
字号:
#include "areafeature.h"#include "util.h"#ifndef CALLBACK#define CALLBACK#endifvoid CALLBACK errorCallback(GLenum errorCode){   const GLubyte *estring;   estring = gluErrorString(errorCode);   fprintf(stderr, "Tessellation Error: %s\n", estring);   exit(0);}void CALLBACK combineCallback(GLdouble coords[3],                      GLdouble *vertex_data[4],                     GLfloat weight[4], GLdouble **dataOut ){   GLdouble *vertex = (GLdouble *) malloc(2 * sizeof(GLdouble));   vertex[0] = coords[0];   vertex[1] = coords[1];   *dataOut = vertex;}AreaFeature::AreaFeature(){}AreaFeature::~AreaFeature(){}void AreaFeature::Draw(std::map<int, EdgeVector> &edge_vectors_map){    int contour_count = contours.size();    for (int i = 0; i < contour_count; i++) {        int ref_count = contours[i].size();        GLUtesselator *tobj = gluNewTess();        if (!tobj) {            std::cerr << "AreaFeature::Draw():"                      << " error creating tesselator" << std::endl;        }        gluTessCallback(tobj, GLU_BEGIN, (GLvoid (*) ())&glBegin);        gluTessCallback(tobj, GLU_VERTEX, (GLvoid (*) ())&glVertex2dv);        gluTessCallback(tobj, GLU_END, (GLvoid (*) ())&glEnd);        gluTessCallback(tobj, GLU_TESS_ERROR,                     (GLvoid (CALLBACK*) ()) &errorCallback);        gluTessCallback(tobj, GLU_TESS_COMBINE,                    (GLvoid (CALLBACK*) ()) &combineCallback);        gluTessBeginPolygon(tobj, NULL);        gluTessBeginContour(tobj);         for (int j = 0; j < ref_count; j++) {            std::vector<sg2d_t> *sg2ds =                edge_vectors_map[contours[i][j]].GetSG2DsPtr();            int node_count = sg2ds->size();            for (int k = 0; k < node_count-1; k++) {                gluTessVertex(tobj, (*sg2ds)[k].long_lat,                                    (*sg2ds)[k].long_lat);            }        }        gluTessEndContour(tobj);        gluTessEndPolygon(tobj);        gluDeleteTess(tobj);     }}int AreaFeature::CompleteContours(std::map<int, EdgeVector> &edge_vectors_map){    int ref_count = ref_record_ids.size();    std::vector<int> contour_edges;    // iterate through each edge, we record the first edge's first    // vertex, we then go through each last vertex of each edge    // to check if it equals the first edge's first vertex. if it    // does we have a contour.    sg2d_t *first_vertex =        edge_vectors_map[ref_record_ids[0]].GetNode(0);    for (int i = 0; i < ref_count; i++) {        int node_count =           edge_vectors_map[ref_record_ids[i]].GetSize();        sg2d_t *last_vertex =           edge_vectors_map[ref_record_ids[i]].GetNode(node_count-1);        contour_edges.push_back(ref_record_ids[i]);        if ((first_vertex->long_lat[0] == last_vertex->long_lat[0]) &&            (first_vertex->long_lat[1] == last_vertex->long_lat[1])) {            // we've found a complete contour! push it back and            // get a new beginning vertex.            contours.push_back(contour_edges);            contour_edges.clear();            if (i > (ref_count - 1))                first_vertex =                    edge_vectors_map[ref_record_ids[i]].GetNode(0);        }    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -