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


C++ Point2d::lengthSquared方法代码示例

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


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

示例1: optimize

void MapPoint::optimize(MapResourcesManager * manager,
                        int numberIterations, const Frame & frame, const Point2f & positionOnFrame)
{
    using namespace TMath;

    TVectord oldPosition = m_position, v_f;
    double chi2 = std::numeric_limits<double>::max();
    TWLS<double> wls(3);
    TVectord J_x(3), J_y(3);
    Point2d e;
    TMatrixd rotation(3, 3);

    for (auto it = m_features.cbegin(); it != m_features.cend(); ++it)
        manager->lock((*it)->keyFrame().get());

    Point2d localPoint = frame.camera()->unproject(positionOnFrame);

    for (int iteration = 0; iteration < numberIterations; ++iteration) {

        wls.clear();

        double new_chi2 = 0.0;

        // compute residuals
        {
            rotation = frame.rotation();

            v_f = rotation * m_position + frame.translation();

            if (v_f(2) > std::numeric_limits<float>::epsilon()) {
                const double z_inv_squared = 1.0 / (v_f(2) * v_f(2));

                J_x(0) = (rotation(0, 0) * v_f(2) - rotation(2, 0) * v_f(0)) * z_inv_squared;
                J_x(1) = (rotation(0, 1) * v_f(2) - rotation(2, 1) * v_f(0)) * z_inv_squared;
                J_x(2) = (rotation(0, 2) * v_f(2) - rotation(2, 2) * v_f(0)) * z_inv_squared;

                J_y(0) = (rotation(1, 0) * v_f(2) - rotation(2, 0) * v_f(1)) * z_inv_squared;
                J_y(1) = (rotation(1, 1) * v_f(2) - rotation(2, 1) * v_f(1)) * z_inv_squared;
                J_y(2) = (rotation(1, 2) * v_f(2) - rotation(2, 2) * v_f(1)) * z_inv_squared;

                e = localPoint - LocationOptimizer::project2d(v_f);

                wls.addMeasurement(e.x, J_x);
                wls.addMeasurement(e.y, J_y);

                new_chi2 += e.lengthSquared();
            }
        }
        auto it = m_features.cbegin();
        while (it != m_features.cend()) {

            std::shared_ptr<const KeyFrame> keyFrame = (*it)->keyFrame();
            TMath_assert(keyFrame && !keyFrame->isDeleted());

            rotation = keyFrame->rotation();

            v_f = rotation * m_position + keyFrame->translation();

            if (v_f(2) < std::numeric_limits<float>::epsilon()) {
                ++it;
                continue;
            }

            const double z_inv_squared = 1.0 / (v_f(2) * v_f(2));

            J_x(0) = (rotation(0, 0) * v_f(2) - rotation(2, 0) * v_f(0)) * z_inv_squared;
            J_x(1) = (rotation(0, 1) * v_f(2) - rotation(2, 1) * v_f(0)) * z_inv_squared;
            J_x(2) = (rotation(0, 2) * v_f(2) - rotation(2, 2) * v_f(0)) * z_inv_squared;

            J_y(0) = (rotation(1, 0) * v_f(2) - rotation(2, 0) * v_f(1)) * z_inv_squared;
            J_y(1) = (rotation(1, 1) * v_f(2) - rotation(2, 1) * v_f(1)) * z_inv_squared;
            J_y(2) = (rotation(1, 2) * v_f(2) - rotation(2, 2) * v_f(1)) * z_inv_squared;

            e = LocationOptimizer::project2d((*it)->localDir()) - LocationOptimizer::project2d(v_f);

            wls.addMeasurement(e.x, J_x);
            wls.addMeasurement(e.y, J_y);

            new_chi2 += e.lengthSquared();

            ++it;
        }

        wls.compute();

        // check if error increased
        if ((new_chi2 > chi2) || (std::isnan(wls.X()(0)))) {
            m_position = oldPosition; // roll-back
            break;
        }

        oldPosition = m_position;
        m_position += wls.X();

        chi2 = new_chi2;
    }

    for (auto it = m_features.cbegin(); it != m_features.cend(); ++it)
        manager->unlock((*it)->keyFrame().get());
}
开发者ID:,项目名称:,代码行数:100,代码来源:


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