registration 自适应的参数评估

const ParametersType oldParameters = this->m_Transform->GetParameters();
            const auto numPara = this->m_Transform->GetNumberOfParameters();

            const auto numSamples = static_cast<const int>(this->m_SamplePoints.size());
            std::vector<glm::dvec3> oldMappedVoxels(numSamples);

            for (int c = 0; c < numSamples; c++)
            {
                auto point = this->m_SamplePoints[c];
                oldMappedVoxels[c] = this->m_Transform->TransformPoint(point);
            }
            ParametersType deltaParameters(numPara);
            ScalesType tmpParamScales(numPara);
            for (int p = 0; p < numPara; p++)
            {
                ScalesType sampleShifts(numSamples);
                std::fill(deltaParameters.begin(), deltaParameters.end(), 0);
                deltaParameters[p] = this->m_SmallParameterVariation;
                this->m_Transform->SetParameters(deltaParameters);
                for (int c = 0; c < numSamples; c++)
                {
                    auto point = this->m_SamplePoints[c];
                    glm::dvec3 newMappedVoxel = this->m_Transform->TransformPoint(point);
                    sampleShifts[c] = glm::distance(oldMappedVoxels[c], newMappedVoxel);
                }
                tmpParamScales[p] = *max_element(sampleShifts.begin(), sampleShifts.end());
                this->m_Transform->SetParameters(oldParameters);
            }     
            for (int i = 0; i < numPara; i++)
            {
                tmpParamScales[i] *= tmpParamScales[i];
                //normalize to unit variation
                tmpParamScales[i] *= 1/ glm::sqrt(this->m_SmallParameterVariation);
            }
double maxStep = 0 ;
        double maxShift = 0;
        double factor = 1;
        if (this->m_SamplePoints.size() > 0 && this->m_Transform != nullptr)
        {
            const auto numPara = step.size();
            const auto numSamples = static_cast<const int>(this->m_SamplePoints.size());

            for (int p = 0; p < numPara; p++)
            {
                if (maxStep < std::abs(step[p]))
                {
                    maxStep = std::abs(step[p]);
                }
            }
            factor = this->m_SmallParameterVariation / maxStep;
            ParametersType smallStep(this->m_Transform->GetParameters());
            std::fill(smallStep.begin(), smallStep.end(), 0);

            //Use a small step to have a linear approximation.
           
                smallStep[0] = step[0] * factor;
                smallStep[1] = step[1] * factor;
                smallStep[2] = step[2] * factor;
                smallStep[3] = step[3] * factor;
                smallStep[4] = step[4] * factor;
                smallStep[5] = step[5] * factor;
            //ComputeMaximumVoxelShift
            const ParametersType oldParameters = this->m_Transform->GetParameters();
            //
            //printf("oldParameters : ");
            //for (int i = 0; i < oldParameters.size(); i++)
            //    printf(" %f , ", oldParameters[i]);
            //printf(" \n ");

            std::vector<glm::dvec3> oldMappedVoxels(numSamples);

            for (int c = 0; c < numSamples; c++)
            {
                auto point = this->m_SamplePoints[c];
                oldMappedVoxels[c] = this->m_Transform->TransformPoint(point);
            }

            //printf("smallStep : ");
            //for (int i = 0; i < smallStep.size(); i++)
            //    printf(" %f , ", smallStep[i]);
            //printf(" \n ");

            this->m_Transform->SetParameters(smallStep);
            ScalesType sampleShifts(numSamples);
            for (int c = 0; c < numSamples; c++)
            {
                auto point = this->m_SamplePoints[c];
                glm::dvec3 newMappedVoxel = this->m_Transform->TransformPoint(point);
                sampleShifts[c] = glm::distance(oldMappedVoxels[c], newMappedVoxel);
            }
            maxShift = *max_element(sampleShifts.begin(), sampleShifts.end());            
        }
        double stepScale = maxShift / factor;
        double compensatedSummation=0;
        double m_LearningRate = this->m_MaximumStepSizeInPhysicalUnits / stepScale;
        for (int dim = 0; dim < step.size(); ++dim)
        {
            const double weighted = step[dim];
            compensatedSummation += weighted * weighted;
        }
        const double gradientMagnitude = std::sqrt(compensatedSummation);
        m_LearningRate *= gradientMagnitude;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值