Ejemplo n.º 1
0
BezierPath createBezierPath(const std::vector<Geometry2d::Point>& controls) {
    Planning::BezierPath interp;
    size_t degree = controls.size();

    // generate coefficients
    vector<float> coeffs;
    for (size_t i = 0; i < degree; ++i) {
        coeffs.push_back(binomialCoefficient(degree - 1, i));
    }

    size_t nrPoints = 20;
    float inc = 1.0 / nrPoints;
    for (size_t t = 1; t < nrPoints - 1; ++t)
        interp.points.push_back(evaluateBezier(t * inc, controls, coeffs));
    interp.points.push_back(controls.at(controls.size() - 1));

    return interp;
}
Ejemplo n.º 2
0
float bezierLength(const std::vector<Geometry2d::Point>& controls,
                   const std::vector<float>& coeffs) {
    // linear interpolation of points
    vector<Point> interp;
    interp.push_back(controls.at(0));
    size_t nrPoints = 20;
    float inc = 1.0 / nrPoints;
    for (size_t t = 1; t < nrPoints - 1; ++t)
        interp.push_back(evaluateBezier(t * inc, controls, coeffs));
    interp.push_back(controls.at(controls.size() - 1));

    // find the distance
    float length = 0.0;
    for (size_t i = 1; i < interp.size(); ++i)
        length += interp.at(i).distTo(interp.at(i - 1));

    return length;
}
Ejemplo n.º 3
0
void BezierWidget::computeVerticesCL()
{
    computeMatrices();
    allocVertices();

#ifdef USE_VBOS
    if (vertexBuffer && context.supportsObjectSharing()) {
        // Acquire the vertex buffers from OpenGL.
        context.acquire(positionBuffer);
        context.acquire(texCoordBuffer);
    }
#endif

    evaluateBezier.setGlobalWorkSize(subdivisionSize, subdivisionSize);
    evaluateBezier(positionBuffer, texCoordBuffer,
                   matrixX, matrixY, matrixZ, subdivisionSize);

#ifdef USE_VBOS
    if (vertexBuffer && context.supportsObjectSharing()) {
        // Release the vertex buffers from OpenCL back to OpenGL.
        context.release(positionBuffer);
        context.release(texCoordBuffer).waitForFinished();
    } else if (vertexBuffer) {
        // Read the results directly into the vertex buffers.
        vertexBuffer->bind();
        GLfloat *mapped = (GLfloat *)vertexBuffer->map(QGLBuffer::WriteOnly);
        positionBuffer.read(mapped, numVertices * sizeof(GLfloat) * 4);
        vertexBuffer->unmap();
        vertexBuffer->release();
        texBuffer->bind();
        mapped = (GLfloat *)texBuffer->map(QGLBuffer::WriteOnly);
        texCoordBuffer.read(mapped, numVertices * sizeof(GLfloat) * 2);
        texBuffer->unmap();
        texBuffer->release();
    } else {
        positionBuffer.read(positions, numVertices * sizeof(GLfloat) * 4);
        texCoordBuffer.read(texCoords, numVertices * sizeof(GLfloat) * 2);
    }
#else
    positionBuffer.read(positions, numVertices * sizeof(GLfloat) * 4);
    texCoordBuffer.read(texCoords, numVertices * sizeof(GLfloat) * 2);
#endif
}