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


C++ vcl_vector::back方法代码示例

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


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

示例1: local_dynamic_programming

bool rgrsn_ldp::local_dynamic_programming(const vnl_matrix<double> & probMap, int nNeighborBin,
                                          vcl_vector<int> & optimalBins)
{
    const int N    = probMap.rows();
    const int nBin = probMap.cols();
    
    // dynamic programming
    vnl_matrix<double> accumulatedProbMap = vnl_matrix<double>(N, nBin);
    accumulatedProbMap.fill(0.0);
    vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
    lookbackTable.fill(0);
    // copy first row
    for (int c = 0; c<probMap.cols(); c++) {
        accumulatedProbMap[0][c] = probMap[0][c];
        lookbackTable[0][c] = c;
    }
    
    for (int r = 1; r <N; r++) {
        for (int c = 0; c<probMap.cols(); c++) {
            // lookup all possible place in the window
            double max_val = -1;
            int max_index  = -1;
            for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
                if (c + w <0 || c + w >= probMap.cols()) {
                    continue;
                }
                double val = probMap[r][c] + accumulatedProbMap[r-1][c+w];
                if (val > max_val) {
                    max_val = val;
                    max_index = c + w; // most probable path from the [r-1] row, in column c + w
                }
            }
            assert(max_index != -1);
            accumulatedProbMap[r][c] = max_val;
            lookbackTable[r][c]      = max_index;
        }
    }
    
    // lookback the table
    double max_prob    = -1.0;
    int max_prob_index = -1;
    for (int c = 0; c<accumulatedProbMap.cols(); c++) {
        if (accumulatedProbMap[N-1][c] > max_prob) {
            max_prob = accumulatedProbMap[N-1][c];
            max_prob_index = c;
        }
    }
    
    // back track
    optimalBins.push_back(max_prob_index);
    for (int r = N-1; r > 0; r--) {
        int bin = lookbackTable[r][optimalBins.back()];
        optimalBins.push_back(bin);
    }
    assert(optimalBins.size() == N);
    
  //  vcl_reverse(optimalBins.begin(), optimalBins.end());
    return true;
}
开发者ID:iefiac,项目名称:vxl_util,代码行数:59,代码来源:rgrsn_ldp.cpp

示例2: lineEllipseIntersection

int VglPlus::lineEllipseIntersection(const vgl_line_2d<double> & line, const vgl_ellipse_2d<double> & ellipse,
                                     vgl_point_2d<double> & pt1, vgl_point_2d<double> & pt2, bool isMajorAxis)
{
    vgl_polygon<double> poly = ellipse.polygon();
    assert(poly.num_sheets() == 1);
    int num = 0;
    //  printf("sheet number is %u\n", poly.num_sheets());
    const vcl_vector< vgl_point_2d< double > > sheet = poly[0];
    assert( sheet.size() > 1 );
    for ( unsigned int v = 0; v < sheet.size() - 1; v++ )
    {
        vgl_line_segment_2d< double > edge( sheet[v], sheet[v+1] );
        vgl_point_2d<double> p;
        bool isIntersection = vgl_intersection(line, edge, &p);
        if (isIntersection) {
            if (num == 0) {
                pt1 = p;
                num++;
            }
            else if(num == 1)
            {
                pt2 = p;
                num++;
            }
        }
        if (num == 2) {
            break;
        }
    }
    
    // last line segment
    if(num != 2)
    {
        vgl_line_segment_2d< double > edge( sheet.back(), sheet.front());
        vgl_point_2d<double> p;
        bool isIntersection = vgl_intersection(line, edge, &p);
        if (isIntersection) {
            if (num == 0) {
                pt1 = p;
                num++;
            }
            else if(num == 1)
            {
                pt2 = p;
                num++;
            }
        }
    }
    
    double disDif = 20;
    if (num == 2 && isMajorAxis) {
        double dis = vgl_distance(pt1, pt2);
        // distance of two points should be as the similar length of minor or major axis
        double dis1 = vgl_distance(ellipse.major_diameter().point1(), ellipse.major_diameter().point2());
        double dis2 = vgl_distance(ellipse.minor_diameter().point1(), ellipse.minor_diameter().point2());
        if (fabs(dis - dis1) >= disDif && fabs(dis - dis2) >= disDif) {
            num = 0;
        }
    }
    return num;
}
开发者ID:iefiac,项目名称:vxl_util,代码行数:61,代码来源:vgl_plus.cpp

示例3: local_dynamic_programming_log

bool rgrsn_ldp::local_dynamic_programming_log(const vnl_matrix<double> & probMap, int nNeighborBin,
                                              vcl_vector<int> & optimalBins)
{
    // find minimum path
    const int N    = probMap.rows();
    const int nBin = probMap.cols();
    const double epsilon = 0.01;
    
    vnl_matrix<double> negLogProbMap(N, nBin);
    for (int r = 0; r<N; r++) {
        for (int c = 0; c <nBin; c++) {
            negLogProbMap(r, c) = -log(probMap(r, c) + epsilon);
        }
    }
    
    // dynamic programming
    vnl_matrix<double> accumulatedMap = vnl_matrix<double>(N, nBin);
    accumulatedMap.fill(0.0);
    vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
    lookbackTable.fill(0);
    // copy first row
    for (int c = 0; c<negLogProbMap.cols(); c++) {
        accumulatedMap[0][c] = negLogProbMap[0][c];
    }
    
    for (int r = 1; r <N; r++) {
        for (int c = 0; c<negLogProbMap.cols(); c++) {
            // lookup all possible place in the window
            double min_val = INT_MAX;
            int index      = -1;
            for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
                if (c + w <0 || c + w >= negLogProbMap.cols()) {
                    continue;
                }
                double val = negLogProbMap[r][c] + accumulatedMap[r-1][c+w];
                if (val < min_val) {
                    min_val = val;
                    index = c + w;
                }
            }
            assert(index != -1);
            accumulatedMap[r][c] = min_val;
            lookbackTable[r][c]  = index;
        }
    }
    
    // lookback the table
    double min_val = INT_MAX;
    int initIndex  = -1;
    for (int c = 0; c<accumulatedMap.cols(); c++) {
        if (accumulatedMap[N-1][c] < min_val) {
            min_val = accumulatedMap[N-1][c];
            initIndex = c;
        }
    }
    
    // back track
    optimalBins.push_back(initIndex);
    for (int r = N-1; r > 0; r--) {
        int bin = lookbackTable[r][optimalBins.back()];
        optimalBins.push_back(bin);
    }
    assert(optimalBins.size() == N);
    
    vcl_reverse(optimalBins.begin(), optimalBins.end());
    return true;
}
开发者ID:iefiac,项目名称:vxl_util,代码行数:67,代码来源:rgrsn_ldp.cpp

示例4: viterbi

bool rgrsn_ldp::viterbi(const vnl_matrix<double> & prob_map, const vnl_vector<double> & transition,
                        vcl_vector<int> & optimal_bins)
{
    
    const int N    = prob_map.rows();
    const int nBin = prob_map.cols();
    const int nNeighborBin = transition.size()/2;
    const double epsilon = 0.01;
    
    // dynamic programming
    vnl_matrix<double> log_accumulatedProbMap = vnl_matrix<double>(N, nBin);
    log_accumulatedProbMap.fill(0.0);
    vnl_matrix<int> lookbackTable = vnl_matrix<int>(N, nBin);
    lookbackTable.fill(0);
    // copy first row
    for (int c = 0; c<prob_map.cols(); c++) {
        log_accumulatedProbMap[0][c] = log(prob_map[0][c] + epsilon);
        lookbackTable[0][c] = c;
    }
    vnl_vector<double> log_transition = vnl_vector<double>(transition.size(), 0);
    
    for (int i = 0; i<transition.size(); i++) {
        log_transition[i] = log(transition[i] + epsilon);
    }
    
    for (int r = 1; r <N; r++) {
        for (int c = 0; c<prob_map.cols(); c++) {
            // lookup all possible place in the window
            double max_val = vcl_numeric_limits<int>::min();
            int max_index  = -1;
            for (int w = -nNeighborBin; w <= nNeighborBin; w++) {
                if (c + w < 0 || c + w >= prob_map.cols()) {
                    continue;
                }
                assert(w + nNeighborBin >= 0 && w + nNeighborBin < transition.size());
                double val = log_accumulatedProbMap[r-1][c+w] + log_transition[w + nNeighborBin];
                if (val > max_val) {
                    max_val = val;
                    max_index = c + w; // most probable path from the [r-1] row, in column c + w
                }
            }
            assert(max_index != -1);
            log_accumulatedProbMap[r][c] = max_val + log(prob_map[r][c] + epsilon);
            lookbackTable[r][c]          = max_index;
        }
    }
    
    // lookback the table
    double max_prob    = vcl_numeric_limits<int>::min();
    int max_prob_index = -1;
    for (int c = 0; c<log_accumulatedProbMap.cols(); c++) {
        if (log_accumulatedProbMap[N-1][c] > max_prob) {
            max_prob = log_accumulatedProbMap[N-1][c];
            max_prob_index = c;
        }
    }
    
    // back track
    optimal_bins.push_back(max_prob_index);
    for (int r = N-1; r > 0; r--) {
        int bin = lookbackTable[r][optimal_bins.back()];
        optimal_bins.push_back(bin);
    }
    assert(optimal_bins.size() == N);
    vcl_reverse(optimal_bins.begin(), optimal_bins.end());
    return true;
}
开发者ID:iefiac,项目名称:vxl_util,代码行数:67,代码来源:rgrsn_ldp.cpp


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