示例#1
0
bool VglPlus::mergeTwolineSegmentOnALine(const vgl_line_segment_2d<double> & seg1,
                                         const vgl_line_segment_2d<double> & seg2,
                                         vgl_line_segment_2d<double> & merged_seg)
{
    double cosVal = fabs(cos_angle(seg1.direction(), seg2.direction()));
    if (cosVal < cos(5.0/180.0*vnl_math::pi)) {
        return false;
    }   
    
    double dis_max = -1.0;
    vcl_vector<vgl_point_2d<double> > pts;
    pts.push_back(seg1.point1());
    pts.push_back(seg1.point2());
    pts.push_back(seg2.point1());
    pts.push_back(seg2.point2());
    // loop all combination and choose the longest one
    for (int i = 0; i<pts.size(); i++) {
        for (int j = i+1; j<pts.size(); j++) {
            double dis = vgl_distance(pts[i], pts[j]);
            if (dis > dis_max) {
                dis_max = dis;
                merged_seg = vgl_line_segment_2d<double>(pts[i], pts[j]);
            }
        }
    }
    return true;
}
示例#2
0
bool vgl_intersection(vgl_line_segment_2d<double> lineSegment0, vgl_line_segment_2d<double> lineSegment1, vgl_point_2d<double> &intersectionPoint)
{
  vgl_point_3d<double> lineSegment03DP0(lineSegment0.point1().x(), lineSegment0.point1().y(), 0);
  vgl_point_3d<double> lineSegment03DP1(lineSegment0.point2().x(), lineSegment0.point2().y(), 0);
  vgl_line_segment_3d<double> lineSegment03D(lineSegment03DP0, lineSegment03DP1);


  vgl_point_3d<double> lineSegment13DP0(lineSegment1.point1().x(), lineSegment1.point1().y(), 0);
  vgl_point_3d<double> lineSegment13DP1(lineSegment1.point2().x(), lineSegment1.point2().y(), 0);
  vgl_line_segment_3d<double> lineSegment13D(lineSegment13DP0, lineSegment13DP1);

  vgl_point_3d<double> intersectionPoint3D;
  bool isIntersect = vgl_intersection(lineSegment03D, lineSegment13D, intersectionPoint3D);

  intersectionPoint.set(intersectionPoint3D.x(), intersectionPoint3D.y());

  return isIntersect;
}
示例#3
0
void VilDraw::draw_segment(vil_image_view<vxl_byte> &image,
                           const vgl_line_segment_2d<double> & seg,
                           const vcl_vector<vxl_byte> & colour,
                           int lineWidth)
{
    assert(image.nplanes() == 3 || image.nplanes() == 1);
    assert(colour.size() == 3);
    
    vil_image_view<vxl_byte> rgb_image = image;
    if (image.nplanes() == 1) {
        image = VilUtil::gray_2_rgb(image);
    }
    VilAlgoPlus::fill_line(image, seg.point1(), seg.point2(), colour);
}
示例#4
0
void VglPlus::parallelMove(const vgl_line_segment_2d<double> & initSeg, double distance,
                           vgl_line_segment_2d<double> & seg1, vgl_line_segment_2d<double> & seg2)
{
    // CCW rotated
    vgl_vector_2d<double> orthDir = rotated(initSeg.direction(), vnl_math::pi/2.0);
    orthDir = normalize(orthDir);
    
    vgl_point_2d<double> p1 = initSeg.point1();
    vgl_point_2d<double> p2 = initSeg.point2();
    
    vgl_vector_2d<double> dp = distance * orthDir;
    vgl_point_2d<double> p3(p1.x() + dp.x(), p1.y() + dp.y());
    vgl_point_2d<double> p4(p2.x() + dp.x(), p2.y() + dp.y());
    
    seg1 = vgl_line_segment_2d<double>(p3, p4);
    
    dp = -1.0 * dp;
    vgl_point_2d<double> p5(p1.x() + dp.x(), p1.y() + dp.y());
    vgl_point_2d<double> p6(p2.x() + dp.x(), p2.y() + dp.y());
    seg2 = vgl_line_segment_2d<double>(p5, p6);
}
示例#5
0
vcl_vector<vgl_point_2d<double> > VglPlus::intersection(const vgl_ellipse_2d<double> & ellipse, const vgl_line_segment_2d<double> & seg)
{
    vgl_conic<double> conic = vgl_conic<double>(ellipse);
    vcl_vector<vgl_point_2d<double> > intersections;
    
    vgl_homg_line_2d<double> homg_line(vgl_homg_point_2d<double>(seg.point1()), vgl_homg_point_2d<double>(seg.point2()));
    
    vcl_list<vgl_homg_point_2d<double> > pts = vgl_homg_operators_2d<double>::intersection(conic, homg_line);
    for (vcl_list<vgl_homg_point_2d<double>>::iterator ite = pts.begin(); ite != pts.end(); ite++) {
        if (ite->w() != 0.0) {
            double x = ite->x()/ite->w();
            double y = ite->y()/ite->w();
            double dis = vgl_distance(vgl_point_2d<double>(x, y), seg);
            if (dis < 1.0) {
                intersections.push_back(vgl_point_2d<double>(x, y));
            }
        }
    }
    
    return intersections;
}
示例#6
0
bool VglPlus::isLeftSide(const vgl_line_segment_2d<double> & seg, const vgl_point_2d<double> & p)
{
    vgl_point_2d<double> b = seg.point1();
    vgl_point_2d<double> a = seg.point2();
    return ((b.x() - a.x())*(p.y() - a.y()) - (b.y() - a.y())*(p.x() - a.x())) > 0;
}