| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | #include <boost/numeric/ublas/matrix.hpp> |
| | #include <boost/numeric/ublas/io.hpp> |
| | #include <boost/geometry.hpp> |
| | #include <boost/geometry/geometries/register/point.hpp> |
| | #include <boost/geometry/index/rtree.hpp> |
| |
|
| | #include "lc_rect.h" |
| | #include "lc_rtree.h" |
| | #include "rs.h" |
| | #include "rs_vector.h" |
| |
|
| | namespace bg = boost::geometry; |
| | namespace bgi = boost::geometry::index; |
| | using BPoint = bg::model::point<double, 2, bg::cs::cartesian> ; |
| | using BBox = bg::model::box<BPoint>; |
| | using TreeValue = std::pair<BBox, unsigned>; |
| |
|
| | namespace lc { |
| |
|
| | namespace geo { |
| |
|
| | struct RTree::RTreeImpl: public bgi::rtree< TreeValue, bgi::quadratic<16> > |
| | { |
| | RTreeImpl(double tolerance): |
| | m_tolerance{tolerance}, |
| | m_halfBox{0.5 * m_tolerance, 0.5 * m_tolerance} |
| | {} |
| |
|
| | BPoint ToPoint(const RS_Vector& point) const |
| | { |
| | return {point.x, point.y}; |
| | } |
| |
|
| | static RS_Vector ToPoint(const BBox& box) |
| | { |
| | auto min = box.min_corner(); |
| | auto max = box.max_corner(); |
| | auto center = RS_Vector{min.get<0>()+max.get<0>(), min.get<1>()+max.get<1>() } * 0.5; |
| | return center; |
| | } |
| |
|
| | BBox ToBox(const RS_Vector& point) const |
| | { |
| | return {ToPoint(point - m_halfBox), ToPoint(point + m_halfBox)}; |
| | } |
| |
|
| | BBox ToBox(const LC_Rect& rect) const |
| | { |
| | return {ToPoint(rect.lowerLeftCorner()), ToPoint(rect.upperRightCorner())}; |
| | } |
| |
|
| | RS_VectorSolutions Intersects(const BBox& box) const |
| | { |
| | std::vector<TreeValue> result_s; |
| | query(bgi::intersects(box), std::back_inserter(result_s)); |
| | RS_VectorSolutions ret; |
| | for(const auto& [box, index]: result_s) |
| | ret.push_back(ToPoint(box)); |
| | return ret; |
| | } |
| |
|
| | double m_tolerance = RS_TOLERANCE; |
| | RS_Vector m_halfBox{false}; |
| | }; |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | RTree::RTree(double toleranceSize): |
| | m_pRTree{std::make_unique<RTreeImpl>(toleranceSize)} |
| | {} |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | RTree::RTree(const RS_VectorSolutions& points, double toleranceSize): |
| | m_pRTree{std::make_unique<RTreeImpl>(toleranceSize)} |
| | { |
| | for(const RS_Vector& point: points) |
| | Insert(point); |
| | } |
| |
|
| |
|
| |
|
| | |
| | |
| | |
| | |
| | |
| | bool RTree::Insert(const RS_Vector& point) |
| | { |
| |
|
| | |
| | BBox b = m_pRTree->ToBox(point); |
| | |
| | m_pRTree->insert({b, m_pRTree->size()}); |
| | return true; |
| | } |
| | |
| | |
| | |
| | |
| | |
| | bool RTree::Insert(const Area& area) |
| | { |
| | |
| | BBox b = m_pRTree->ToBox(area); |
| | |
| | m_pRTree->insert(std::make_pair(b, m_pRTree->size())); |
| | return true; |
| | } |
| |
|
| | RS_VectorSolutions RTree::NearestNeighbors(const RS_Vector& point) const |
| | { |
| | |
| | BBox box = m_pRTree->ToBox(point); |
| | |
| | return m_pRTree->Intersects(box); |
| | } |
| |
|
| | RS_VectorSolutions RTree::PointsInBox(const Area& area) const |
| | { |
| | |
| | BBox box = m_pRTree->ToBox(area); |
| | return m_pRTree->Intersects(box); |
| | } |
| |
|
| | } |
| | } |
| | |
| |
|