예제 #1
0
void LinePath::calculateParallelLine() {
    int midCount = count() / 2;
    double ATAN = atan(1.0);
    int lineDist = 10;
    //get  1/8(M) and 7/8(T) point
    QPoint a = getPoint( midCount - 1 );
    QPoint b = getPoint( midCount );
    int mx = ( a.x() + b.x() ) / 2;
    int my = ( a.y() + b.y() ) / 2;
    int tx = ( mx + b.x() ) / 2;
    int ty = ( my + b.y() ) / 2;
    //find dist between M and T points
    int distX = ( mx - tx );
    distX *= distX;
    int distY = ( my - ty );
    distY *= distY;
    double dist = sqrt( double(distX + distY) );
    double angle = atan2( double(ty - my), double(tx - mx) ) + ( ATAN * 2 );
    //find point from M to start line from.
    double cosx = cos( angle ) * lineDist;
    double siny = sin( angle ) * lineDist;
    QPoint pointM( mx + (int)cosx, my + (int)siny );
    //find dist between P(xb, yb)
    distX = ( tx - b.x() );
    distX *= distX;
    distY = ( ty - b.y() );
    distY *= distY;
    dist = sqrt( double(distX + distY) );
    //find point from T to end line
    cosx = cos( angle ) * lineDist;
    siny = sin( angle ) * lineDist;
    QPoint pointT( tx + (int)cosx, ty + (int)siny );
    m_ParallelLines[ 1 ] = pointM;
    m_ParallelLines[ 0 ] = pointT;

    int arrowDist = 5;
    angle = atan2( double(pointT.y() - pointM.y()),
                   double(pointT.x() - pointM.x()) );
    double arrowSlope = angle + ATAN;
    cosx = ( cos( arrowSlope ) ) * arrowDist;
    siny = ( sin( arrowSlope ) ) * arrowDist;
    m_ParallelLines[ 2 ] = QPoint( pointT.x() - (int)cosx, pointT.y() - (int)siny );
    arrowSlope = angle - ATAN;
    cosx = ( cos( arrowSlope )  ) * arrowDist;
    siny = ( sin( arrowSlope ) ) * arrowDist;
    m_ParallelLines[ 3 ] = QPoint( pointT.x() - (int)cosx, pointT.y() - (int)siny );
}
예제 #2
0
void TopView::drawTopViewLines(int rows_interval, int cols_interval, bool fg_tag)
{
    topview_BG.setTo(cv::Scalar(0, 0, 0, 0));

    // Background color
    cv::Point pts[4];
    pts[0] = pointT(img_grid[0][0]);
    pts[1] = pointT(img_grid[0][img_col]);
    pts[2] = pointT(img_grid[img_row][img_col]);
    pts[3] = pointT(img_grid[img_row][0]);
    cv::fillConvexPoly(topview_BG, pts, 4, color_BG, 8, 0);

    // distance tag
    int distance, text_dev, font_size, line_thickness;
    // 30 m
    distance = 3000;
    text_dev = 100;
    font_size = 1;
    line_thickness = 1;
    cv::Point pt1 = cv::Point(0, max_distance - distance);
    cv::Point pt2 = cv::Point(chord_length, max_distance - distance);
    cv::line(topview_BG, pointT(pt1), pointT(pt2), color_tag, line_thickness, 8, 0);
    pt1.y += text_dev;
    cv::putText(topview_BG, "30 m", pointT(pt1), cv::FONT_HERSHEY_PLAIN, font_size, color_tag, 1);
    // 2 m
    distance = 200;
    pt1.y = max_distance - distance;
    pt2.y = max_distance - distance;
    cv::line(topview_BG, pointT(pt1), pointT(pt2), color_tag, line_thickness, 8, 0);
    pt1.y += text_dev;
    cv::putText(topview_BG, "2 m", pointT(pt1), cv::FONT_HERSHEY_PLAIN, font_size, color_tag, 1);
    // 1 m
    distance = 100;
    pt1.y = max_distance - distance;
    pt2.y = max_distance - distance;
    cv::line(topview_BG, pointT(pt1), pointT(pt2), color_tag, line_thickness, 8, 0);
    pt1.y += text_dev;
    cv::putText(topview_BG, "1 m", pointT(pt1), cv::FONT_HERSHEY_PLAIN, font_size, color_tag, 1);


    if (fg_tag) {
        // 20 m
        distance = 2000;
        pt1.y = max_distance - distance;
        pt2.y = max_distance - distance;
        cv::line(topview_BG, pointT(pt1), pointT(pt2), color_tag, line_thickness, 8, 0);
        pt1.y += text_dev;
        cv::putText(topview_BG, "20 m", pointT(pt1), cv::FONT_HERSHEY_PLAIN, font_size, color_tag, 1);
        // 10 m
        distance = 1000;
        pt1.y = max_distance - distance;
        pt2.y = max_distance - distance;
        cv::line(topview_BG, pointT(pt1), pointT(pt2), color_tag, line_thickness, 8, 0);
        pt1.y += text_dev;
        cv::putText(topview_BG, "10 m", pointT(pt1), cv::FONT_HERSHEY_PLAIN, font_size, color_tag, 1);
    }

    // draw lines
    line_thickness = 1;
    for (int r = 0; r < img_row + 1; r += rows_interval) {
        cv::line(topview_BG, pointT(img_grid[r][0]), pointT(img_grid[r][img_col]), color_line, line_thickness, 8, 0);
    }
    for (int c = 0; c < img_col_half + 1; c += cols_interval) {
#ifdef debug_info_sv_topview
        std::cout<<img_col_half + 1 - c<<" ";
#endif
        cv::line(topview_BG, pointT(img_grid[0][img_col_half - c]),
                pointT(img_grid[img_row][img_col_half - c]), color_line, line_thickness, 8, 0);
        cv::line(topview_BG, pointT(img_grid[0][img_col_half + c]),
                pointT(img_grid[img_row][img_col_half + c]), color_line, line_thickness, 8, 0);
    }
#ifdef debug_info_sv_topview
    std::cout<<std::endl;
#endif
}