four. Handle multiple polygons

 

Handle multiple polygons with polygon processing almost, that is more than one cycle, then the need gpu information save it on the line

 

bool AkGisWidget::SendGpuMultiPolygon(OGRMultiPolygon *pMultiPolygonIn)

{

    QOpenGLVertexArrayObject * on;

    QOpenGLBuffer *vbo;//{QOpenGLBuffer::VertexBuffer};

    QOpenGLBuffer * ebo;} // {QOpenGLBuffer :: IndexBuffer;

 

    vao = new QOpenGLVertexArrayObject;

    vbo = new QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);

//    ebo = new QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);

 

 

    int pointsCount =0;

    int sizeOffset = 0;

    int countOffset = 0;

    FeatureDesc featureDesc;

    featureDesc.vecVex.push_back(0);

    featureDesc.vecIdx.push_back(0);

 

    int polyCnt= pMultiPolygonIn->getNumGeometries();

    std :: vector <float> verticess; // all points

    std :: vector <unsigned int> indicess; // all indexes

 

// loop polygon

    for (int i = 0; i < polyCnt; ++i)

    {

        OGRPolygon* pPolygon = pMultiPolygonIn->getGeometryRef(i)->toPolygon();

 

        OGRPoint ptTemp;

        int numInteriorRings = pPolygon->getNumInteriorRings();

 

        // outer ring

        OGRLinearRing * poExteriorRing pPolygon- => getExteriorRing ();

        int numExteriorRingPoints = poExteriorRing->getNumPoints();

 

        int polygonPointsCount = numExteriorRingPoints;

        float* vertices = new float[polygonPointsCount * 5 * sizeof(float)];

        int iStride = 0;

 

        using Point = std::array<double, 2>;

        std::vector<std::vector<Point>> polygon;

 

        std::vector<Point> exteriorRing;

        exteriorRing.reserve(numExteriorRingPoints);

        int index = 0;

        for (int i = 0; i < numExteriorRingPoints; ++i) {

            poExteriorRing->getPoint(i, &ptTemp);

            exteriorRing.push_back ({ptTemp.getX () ptTemp.getY ()});

 

            vertices[index] =  ptTemp.getX();

            vertices [index + 1] = ptTemp.getY ();

            vertices[index + 2] = 0.5;

            vertices[index + 3] = 0.6;

            vertices[index + 4] = 0.1;

            index += 5;

        }

        for (int i = 0; i < index; ++i) {

            verticess.push_back(vertices[i]);

        }

 

        polygon.emplace_back(exteriorRing);

 

        std::vector<unsigned int> indices = mapbox::earcut<unsigned int>(polygon);

 

        if(numExteriorRingPoints==4)

            qDebug()<<"exteriorRingPointsCount interiorRingsCount"<<numExteriorRingPoints<<"indices.size()"<<indices.size()

                   <<vertices[0]<<vertices[1]<<vertices[5]<<vertices[6]<<vertices[10]<<vertices[11]<<vertices[15]<<vertices[16]

                  <<exteriorRing.size()<<exteriorRing[0].at(0)<<exteriorRing[0].at(1);

 

 

        //qDebug()<<"indices"<<sizeof(unsigned int)<<index<<indices.size();

 

// Add the index number

        if (countOffset > 0)

            std::for_each(indices.begin(), indices.end(), [&countOffset](auto& value) {value += countOffset; });

 

        for(int i = 0 ;i <indices.size();i++)

            indicess.push_back(indices[i]);

 

        countOffset += polygonPointsCount;

 

        featureDesc.vecVex.push_back(polygonPointsCount);//点数

        featureDesc.vecIdx.push_back (indices.size ()); // index number

 

    }

    qDebug()<<"polyCnt"<<polyCnt<<"verticess"<<verticess.size()<<"indicess"<<indicess.size();

 

// gpu sent to

    vbo->create();

    VBO> bind ();

    vbo->allocate(&verticess[0],verticess.size()*4);

 

    QOpenGLVertexArrayObject::Binder vaoBind(vao);

 

int offset=0;

// save the segment index

    //for(int j=0;j<1;j++)

    for(int j=0;j<featureDesc.vecIdx.size()-1;j++)

    {

        ebo = new QOpenGLBuffer(QOpenGLBuffer::IndexBuffer);

 

        ebo->create();

        ebo->bind();

        ebo->allocate(&indicess[offset],(featureDesc.vecIdx[j+1])*4);

        featureDesc.vecEbo.push_back(ebo);

        offset+= featureDesc.vecIdx[j+1];

        qDebug()<<"ebo"<<ebo->bufferId()<<"offset"<<offset;

    }

 

    featureDesc.type = 6 ;

    featureDesc.indexCnt = indicess.size();

    featureDesc.vexCnt = verticess.size();

    featureDesc.vao = VAO;

    featureDesc.vbo = VBO;

    featureDesc.ebo = tribe;

    featureDesc.shader = &polygonShader;

 

    vecFeatureDesc.append(featureDesc);

 

    glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)0);

    glEnableVertexAttribArray(0);

    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), (void*)(2 * sizeof(float)));

    glEnableVertexAttribArray(1);

 

    vbo->release();

    return true;

}

Guess you like

Origin www.cnblogs.com/fkess/p/12506449.html