当前位置: 首页>>代码示例>>C++>>正文


C++ PointArray::data方法代码示例

本文整理汇总了C++中PointArray::data方法的典型用法代码示例。如果您正苦于以下问题:C++ PointArray::data方法的具体用法?C++ PointArray::data怎么用?C++ PointArray::data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PointArray的用法示例。


在下文中一共展示了PointArray::data方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: curve

PointArray<256> CurveFitter::curve(const PointArray<256> &curvePoints, int count)
{
    PointArray<256> points;
    points.resize(count);

    curve(curvePoints.count(), curvePoints.data(), count, points.data());

    return points;
}
开发者ID:daivanov,项目名称:Curves,代码行数:9,代码来源:curvefitter.cpp

示例2: splitCasteljau

void CurveFitter::splitCasteljau(const PointArray<256> &curve, qreal t,
    PointArray<256> &left, PointArray<256> &right)
{
    left.resize(curve.count());
    right.resize(curve.count());
    splitCasteljau(curve.count(), curve.data(), t, left.data(), right.data());
}
开发者ID:daivanov,项目名称:Curves,代码行数:7,代码来源:curvefitter.cpp

示例3: fit

qreal CurveFitter::fit(const PointArray<256> &points, PointArray<256> &curve,
    Transformation transformation)
{
    /* Init input data */
    int sz = 2 * points.count();
    qreal *pdata = const_cast<qreal*>(points.data());

    qreal *x;
    qreal mean[2] = {.0, .0};
    qreal std[2] = {.0, .0};
    if (transformation == AFFINE) {
        x = new qreal[sz];
        for (int i = 0; i < sz; i += 2) {
            mean[0] += pdata[i];
            mean[1] += pdata[i + 1];
        }
        mean[0] /= (sz / 2);
        mean[1] /= (sz / 2);

        for (int i = 0; i < sz; i += 2) {
            std[0] += (pdata[i] - mean[0]) * (pdata[i] - mean[0]);
            std[1] += (pdata[i + 1] - mean[1]) * (pdata[i + 1] - mean[1]);
        }
        std[0] = qSqrt(std[0] / (sz / 2));
        std[1] = qSqrt(std[1] / (sz / 2));

        qreal minStd = qMin(std[0], std[1]);
        std[0] /= minStd;
        std[1] /= minStd;

        for (int i = 0; i < sz; i += 2) {
            x[i] = (pdata[i] - mean[0]) / std[0];
            x[i + 1] = (pdata[i + 1] - mean[1]) / std[1];
        }
    } else {
        x = pdata;
    }

    InternalData data(sz / 2);
    curve.resize(SPLINE_ORDER);
    data.pxy = curve.data();
    chordLengthParam(sz / 2, x, data.ts, CHORD_LENGTH);

    qreal segmentLen = (sz / (SPLINE_ORDER - 1));
    /* Init middle points of Bezier curve */
    for (int i = 2; i < SPLINE_SIZE - 2; i += 2) {
        int idx = (i / 2) * segmentLen;
        idx -= idx % 2;
        data.pxy[i] = x[idx];
        data.pxy[i + 1] = x[idx + 1];
    }

    /* Init first point of Bezier curve */
    data.pxy[0] = x[0];
    data.pxy[1] = x[1];

    int idx = (segmentLen - (int)segmentLen % 2);
    data.pxy[2] = (x[idx] - x[0]) * 2 + x[0];
    data.pxy[3] = (x[idx + 1] - x[1]) * 2 + x[1];

    data.pxy[SPLINE_SIZE - 4] = (x[sz - 2 - idx] - x[sz - 2]) * 2 + x[sz - 2];
    data.pxy[SPLINE_SIZE - 3] = (x[sz - 1 - idx] - x[sz - 1]) * 2 + x[sz - 1];

    /* Init last point of Bezier curve */
    data.pxy[SPLINE_SIZE - 2] = x[sz - 2];
    data.pxy[SPLINE_SIZE - 1] = x[sz - 1];

    /* info[0]= ||e||_2 at initial p.
     * info[1-4]=[ ||e||_2, ||J^T e||_inf,  ||Dp||_2, \mu/max[J^T J]_ii ], all computed at estimated p.
     * info[5]= # iterations,
     * info[6]=reason for terminating: 1 - stopped by small gradient J^T e
     *                                 2 - stopped by small Dp
     *                                 3 - stopped by itmax
     *                                 4 - singular matrix. Restart from current p with increased \mu
     *                                 5 - no further error reduction is possible. Restart with increased mu
     *                                 6 - stopped by small ||e||_2
     *                                 7 - stopped by invalid (i.e. NaN or Inf) "func" values; a user error
     * info[7]= # function evaluations
     * info[8]= # Jacobian evaluations
     * info[9]= # linear systems solved, i.e. # attempts for reducing error
     */
    qreal info[LM_INFO_SZ];
    qreal *p = data.pxy + 2;
    int m = SPLINE_SIZE - 2 * 2;
    int n = sz;
    qreal fnorm = INT_MAX, fnormPrev;

    int totalIters = 0;
    do {
        /* Optimize spline shape */
        dlevmar_dif(CurveFitter::func, p, x, m, n, MAX_ITER, NULL, info, NULL,
            NULL, &data);

        /* Residuals */
        fnormPrev = fnorm;
        fnorm = info[1] / sz;
        qDebug() << "Termination reason" << info[6]
                 << "after" << info[5] << "iterations"
                 << "error" << fnorm;

//.........这里部分代码省略.........
开发者ID:daivanov,项目名称:Curves,代码行数:101,代码来源:curvefitter.cpp


注:本文中的PointArray::data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。