// This is oxl/mvl/LineSegSet.cxx //: // \file #include #include #include #include "LineSegSet.h" #ifdef _MSC_VER # include "vcl_msvc_warnings.h" #endif #include #include // Default ctor LineSegSet::LineSegSet(): hlines_(0) { conditioner_ = nullptr; } // Copy ctor LineSegSet::LineSegSet(const LineSegSet& that): hlines_(0) { operator=(that); } // Assignment LineSegSet& LineSegSet::operator=(const LineSegSet& that) = default; // Destructor LineSegSet::~LineSegSet() = default; //: Construct from ascii file LineSegSet::LineSegSet(const char* filename, const HomgMetric& c) { std::ifstream f(filename); load_ascii(f, c); } //: Load lines from ASCII file bool LineSegSet::load_ascii(std::istream& f, HomgMetric const& c) { vnl_matrix L; f >> L; int cols = L.columns(); if (cols != 6 && cols != 4) { std::cerr << "Load failed -- there are " << L.columns() << " data per row\n"; return false; } conditioner_ = c; hlines_.resize(0); for (unsigned i = 0; i < L.rows(); ++i) { double x1 = L(i,0); double y1 = L(i,1); double x2 = L(i,2); double y2 = L(i,3); #if 0 double theta; double avemag; if (cols == 6) { theta = L(i,4); avemag = L(i,5); } else { theta = 0; avemag = 0; } #endif HomgPoint2D p1(x1, y1); HomgPoint2D p2(x2, y2); HomgLineSeg2D line(p1, p2); hlines_.push_back(c.image_to_homg_line(line)); } std::cerr << "Loaded " << size() << " line segments\n"; return true; } int LineSegSet::FindNearestLineIndex(double /*x*/, double /*y*/) { std::cerr <<"LineSegSet::FindNearestLineIndex not yet implemented\n"; return -1; #if 0 // commented out double mindist=-1.0f; int mini=-1; for (unsigned int i=0; i(x,y)); // distance to the support line else dist = std::min(// closest distance with endpoints vgl_distance(dl.get_point1(),vgl_point_2d(x,y)), vgl_distance(dl.get_point2(),vgl_point_2d(x,y))); if (mini<0 || dist= 0) return &hlines_[i]; else return nullptr; }