xmsgrid
1.0
|
Used to intersect a line segment with any number of polygons in 2D. Returns the intersected polygons in order along with t values. May be an alternative to SurfaceIter and feiTraverseLineSegment2. More...
Public Member Functions | |
GmMultiPolyIntersectorImpl (const VecPt3d &a_points, const VecInt2d &a_polys, BSHP< GmMultiPolyIntersectionSorter > a_sorter, int a_startingId=1) | |
constructor More... | |
virtual void | SetQuery (GmMultiPolyIntersectorQueryEnum a_query) override |
Set the query to use (covered by, intersects...). More... | |
virtual void | TraverseLineSegment (double a_x1, double a_y1, double a_x2, double a_y2, VecInt &a_polyIds, VecDbl &a_tValues) override |
Intersect segment with polys and save intersected polys and t-values. More... | |
virtual void | TraverseLineSegment (double a_x1, double a_y1, double a_x2, double a_y2, VecInt &a_polyIds) override |
Intersect segment with polys and save intersected polys. More... | |
virtual void | TraverseLineSegment (double a_x1, double a_y1, double a_x2, double a_y2, VecInt &a_polyIds, VecPt3d &a_pts) override |
Intersect segment with polys and save intersected polys and intersection points. More... | |
virtual void | TraverseLineSegment (double a_x1, double a_y1, double a_x2, double a_y2, VecInt &a_polyIds, VecDbl &a_tValues, VecPt3d &a_pts) override |
Intersect segment with polys and save intersected polys, t-values, and intersection points. More... | |
virtual int | PolygonFromPoint (const Pt3d &a_pt) override |
Finds the polygon containing the point. More... | |
Private Member Functions | |
void | RemoveDuplicateTValues (VecInt &a_polyIds, VecDbl &a_tValues, VecPt3d &a_pts) |
Removes duplicate T Values and updates the polygon ID and point vectors. More... | |
void | CalculateBuffer () |
Calculate a small buffer distance by which we expand all polygon bounding boxes. | |
void | BufferTheBox (GmBstBox3d &box) const |
Because the rtree intersection fails in some cases where the line is on an edge, we slightly expand the bounding box of the poly to ensure that it comes back as a potential intersection. This may result in more false positives but until boost geometry starts working correctly, it's the best idea we've got. More... | |
GmBstPoly3d & | GetBoostPoly (int a_polyIdx) |
Create and return a boost polygon given a polygon index. More... | |
void | BuildBoostPoly (int a_polyIdx, GmBstPoly3d &a_boostPoly) const |
Build a boost polygon given a polygon index. More... | |
void | BuildRTree () |
Create a boost rtree of polygon extents. | |
void | CreateLine () |
Creates a boost geom line of the current line segment. | |
void | GetPolysForPoint (Pt3d pt, SetInt &poly) |
Find the set of polygons intersected (in or on) by the point. More... | |
void | EnsureEndPointsRepresented () |
Because unfortunately intersecting the line with the poly doesn't always create an intersection if a point is on the polygon edge. | |
void | IntersectEachPolyWithLine () |
Go through results (potential polygons) and intersect each one. | |
void | ComputeTValues () |
Compute t values (0.0 - 1.0) from the intersection. More... | |
void | SortIntersections () |
Does a preliminary sort of the intersections by t value. | |
void | OffsetPolyIds (VecInt &polyIds) const |
If polygon IDs should start at something other than 1, we handle that here. More... | |
void | PointsOnSegment (const GmBstPoly3d &a_poly, const GmBstLine3d &a_line, std::deque< Pt3d > &a_output) |
Check if the points on the outside of the polygon lie on the line segment. More... | |
Private Attributes | |
GmMultiPolyIntersectorData | m_d |
Point and poly data. | |
Pt3d | m_pt1 |
1st line segment point | |
Pt3d | m_pt2 |
2nd line segment point | |
RtreeBox * | m_rtree |
Rtree used to find polygons. | |
GmBstLine3d | m_line |
Current line segment. | |
double | m_buffer |
Small buffer around each bounding box. | |
double | m_xyTol |
XY tolerance for computing t-values. | |
int | m_startingId |
Offset if polys start at something other than one. | |
std::vector< GmBstPoly3d > | m_boostPolys |
Polygons as boost geom polygons. | |
BSHP< GmMultiPolyIntersectionSorter > | m_sorter |
Sorter used to process results. | |
GmMultiPolyIntersectorQueryEnum | m_query |
Type of query (intersect, covered by...) | |
Additional Inherited Members | |
Static Public Member Functions inherited from xms::GmMultiPolyIntersector | |
static boost::shared_ptr< GmMultiPolyIntersector > | New (const std::vector< Pt3d > &a_points, const std::vector< std::vector< int > > &a_polys, boost::shared_ptr< GmMultiPolyIntersectionSorter > a_sorter, int a_startingId=1) |
Creates a new GmMultiPolyIntersectorImpl object. More... | |
Used to intersect a line segment with any number of polygons in 2D. Returns the intersected polygons in order along with t values. May be an alternative to SurfaceIter and feiTraverseLineSegment2.
Definition at line 62 of file GmMultiPolyIntersector.cpp.
xms::GmMultiPolyIntersectorImpl::GmMultiPolyIntersectorImpl | ( | const VecPt3d & | a_points, |
const VecInt2d & | a_polys, | ||
BSHP< GmMultiPolyIntersectionSorter > | a_sorter, | ||
int | a_startingId = 1 |
||
) |
constructor
a_points | The points that make up the polygon. |
a_polys | 0-based indexes into a_points array to define polygons. The first point is NOT repeated as the last point. |
a_sorter | Class to clean up and sort the intersections the way you want them. |
a_startingId | If the polygon IDs should start at something other than 1, specify the starting value. |
Definition at line 185 of file GmMultiPolyIntersector.cpp.
References BuildRTree(), CalculateBuffer(), m_boostPolys, m_d, xms::GmMultiPolyIntersectorData::m_points, and xms::GmMultiPolyIntersectorData::m_polys.
|
private |
Because the rtree intersection fails in some cases where the line is on an edge, we slightly expand the bounding box of the poly to ensure that it comes back as a potential intersection. This may result in more false positives but until boost geometry starts working correctly, it's the best idea we've got.
box | The box. |
Definition at line 262 of file GmMultiPolyIntersector.cpp.
References m_buffer.
Referenced by BuildRTree().
|
private |
Build a boost polygon given a polygon index.
a_polyIdx | The polygon index. |
a_boostPoly | GmBstPoly3d. |
Definition at line 288 of file GmMultiPolyIntersector.cpp.
References m_d, xms::GmMultiPolyIntersectorData::m_points, and xms::GmMultiPolyIntersectorData::m_polys.
Referenced by GetBoostPoly().
|
private |
Compute t values (0.0 - 1.0) from the intersection.
t values are the percent (0.0 - 1.0) distance from the line segment start to each intersection.
Definition at line 446 of file GmMultiPolyIntersector.cpp.
References xms::gmPtDistanceAlongSegment(), xms::gmXyTol(), m_d, xms::GmMultiPolyIntersectorData::m_ixs, m_pt1, m_pt2, and XM_NODATA.
Referenced by TraverseLineSegment().
|
private |
Create and return a boost polygon given a polygon index.
a_polyIdx | The polygon index. |
Definition at line 274 of file GmMultiPolyIntersector.cpp.
References BuildBoostPoly(), and m_boostPolys.
Referenced by GetPolysForPoint(), and IntersectEachPolyWithLine().
Find the set of polygons intersected (in or on) by the point.
pt | point loction |
a_poly | 1-based polygon ID. |
Definition at line 353 of file GmMultiPolyIntersector.cpp.
References GetBoostPoly(), m_query, m_rtree, and XM_ASSERT.
Referenced by PolygonFromPoint(), and TraverseLineSegment().
|
private |
If polygon IDs should start at something other than 1, we handle that here.
polyIds | 1-based list of polygons intersected by line segment. |
Definition at line 514 of file GmMultiPolyIntersector.cpp.
References m_startingId, and XM_NONE.
Referenced by TraverseLineSegment().
|
private |
Check if the points on the outside of the polygon lie on the line segment.
a_poly | GmBstPoly3d. |
a_line | GmBstLine3d. |
a_output | Output. |
Definition at line 419 of file GmMultiPolyIntersector.cpp.
References xms::gmEqualPointsXY(), xms::gmOnLineAndBetweenEndpointsWithTol(), m_buffer, xms::Pt3< T >::x, and xms::Pt3< T >::y.
Referenced by IntersectEachPolyWithLine().
|
overridevirtual |
Finds the polygon containing the point.
a_pt | the location of the point |
Definition at line 718 of file GmMultiPolyIntersector.cpp.
References GetPolysForPoint(), and XM_NONE.
|
private |
Removes duplicate T Values and updates the polygon ID and point vectors.
a_polyIds | list of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor. |
a_tValues | Values from 0.0 to 1.0 representing where on the line segment the intersection with the polygon in polyids occurs. If there are any t values there are always at least 2 and all represent where the line enters the polygon, except the last which represents where it exited. There would therefore be one more t value than poly id but we make the sizes equal by always making the last poly id -1. |
a_pts | Intersection points. |
Definition at line 665 of file GmMultiPolyIntersector.cpp.
References GTEQ_TOL(), and XM_ZERO_TOL.
Referenced by TraverseLineSegment().
|
overridevirtual |
Set the query to use (covered by, intersects...).
a_query | GmMultiPolyIntersectorQueryEnum |
Definition at line 344 of file GmMultiPolyIntersector.cpp.
References m_query.
|
overridevirtual |
Intersect segment with polys and save intersected polys and t-values.
a_x1 | x coordinate of 1st point defining a line segment. |
a_y1 | y coordinate of 1st point defining a line segment. |
a_x2 | x coordinate of 2nd point defining a line segment. |
a_y2 | y coordinate of 2nd point defining a line segment. |
a_polyIds | list of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor. |
a_tValues | Values from 0.0 to 1.0 representing where on the line segment the intersection with the polygon in polyids occurs. If there are any t values there are always at least 2 and all represent where the line enters the polygon, except the last which represents where it exited. There would therefore be one more t value than poly id but we make the sizes equal by always making the last poly id -1. |
Definition at line 545 of file GmMultiPolyIntersector.cpp.
Referenced by TraverseLineSegment().
|
overridevirtual |
Intersect segment with polys and save intersected polys.
a_x1 | x coordinate of 1st point defining a line segment. |
a_y1 | y coordinate of 1st point defining a line segment. |
a_x2 | x coordinate of 2nd point defining a line segment. |
a_y2 | y coordinate of 2nd point defining a line segment. |
a_polyIds | list of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor. |
Definition at line 564 of file GmMultiPolyIntersector.cpp.
References TraverseLineSegment().
|
overridevirtual |
Intersect segment with polys and save intersected polys and intersection points.
a_x1 | x coordinate of 1st point defining a line segment. |
a_y1 | y coordinate of 1st point defining a line segment. |
a_x2 | x coordinate of 2nd point defining a line segment. |
a_y2 | y coordinate of 2nd point defining a line segment. |
a_polyIds | list of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor. |
a_pts | Intersection points. |
Definition at line 585 of file GmMultiPolyIntersector.cpp.
References TraverseLineSegment().
|
overridevirtual |
Intersect segment with polys and save intersected polys, t-values, and intersection points.
a_x1 | x coordinate of 1st point defining a line segment. |
a_y1 | y coordinate of 1st point defining a line segment. |
a_x2 | x coordinate of 2nd point defining a line segment. |
a_y2 | y coordinate of 2nd point defining a line segment. |
a_polyIds | list of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor. |
a_tValues | Values from 0.0 to 1.0 representing where on the line segment the intersection with the polygon in polyids occurs. If there are any t values there are always at least 2 and all represent where the line enters the polygon, except the last which represents where it exited. There would therefore be one more t value than poly id but we make the sizes equal by always making the last poly id -1. |
a_pts | Intersection points. |
Definition at line 614 of file GmMultiPolyIntersector.cpp.
References ComputeTValues(), CreateLine(), EnsureEndPointsRepresented(), GetPolysForPoint(), xms::gmXyTol(), IntersectEachPolyWithLine(), m_d, xms::GmMultiPolyIntersectorData::m_ixs, m_line, xms::GmMultiPolyIntersectorData::m_polys1, xms::GmMultiPolyIntersectorData::m_polys2, m_pt1, m_pt2, m_sorter, m_xyTol, OffsetPolyIds(), RemoveDuplicateTValues(), xms::Pt3< T >::Set(), SortIntersections(), and XM_ASSERT.