xmsgrid  1.0
xms::GmMultiPolyIntersectorImpl Class Reference

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...

Inheritance diagram for xms::GmMultiPolyIntersectorImpl:
xms::GmMultiPolyIntersector

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...
 
GmBstPoly3dGetBoostPoly (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
 
RtreeBoxm_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< GmBstPoly3dm_boostPolys
 Polygons as boost geom polygons.
 
BSHP< GmMultiPolyIntersectionSorterm_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< GmMultiPolyIntersectorNew (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...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GmMultiPolyIntersectorImpl()

xms::GmMultiPolyIntersectorImpl::GmMultiPolyIntersectorImpl ( const VecPt3d a_points,
const VecInt2d a_polys,
BSHP< GmMultiPolyIntersectionSorter a_sorter,
int  a_startingId = 1 
)

constructor

Parameters
a_pointsThe points that make up the polygon.
a_polys0-based indexes into a_points array to define polygons. The first point is NOT repeated as the last point.
a_sorterClass to clean up and sort the intersections the way you want them.
a_startingIdIf 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.

Member Function Documentation

◆ BufferTheBox()

void xms::GmMultiPolyIntersectorImpl::BufferTheBox ( GmBstBox3d box) const
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.

Parameters
boxThe box.

Definition at line 262 of file GmMultiPolyIntersector.cpp.

References m_buffer.

Referenced by BuildRTree().

◆ BuildBoostPoly()

void xms::GmMultiPolyIntersectorImpl::BuildBoostPoly ( int  a_polyIdx,
GmBstPoly3d a_boostPoly 
) const
private

Build a boost polygon given a polygon index.

Parameters
a_polyIdxThe polygon index.
a_boostPolyGmBstPoly3d.

Definition at line 288 of file GmMultiPolyIntersector.cpp.

References m_d, xms::GmMultiPolyIntersectorData::m_points, and xms::GmMultiPolyIntersectorData::m_polys.

Referenced by GetBoostPoly().

◆ ComputeTValues()

void xms::GmMultiPolyIntersectorImpl::ComputeTValues ( )
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().

◆ GetBoostPoly()

GmBstPoly3d & xms::GmMultiPolyIntersectorImpl::GetBoostPoly ( int  a_polyIdx)
private

Create and return a boost polygon given a polygon index.

Parameters
a_polyIdxThe polygon index.
Returns
GmBstPoly3d.

Definition at line 274 of file GmMultiPolyIntersector.cpp.

References BuildBoostPoly(), and m_boostPolys.

Referenced by GetPolysForPoint(), and IntersectEachPolyWithLine().

◆ GetPolysForPoint()

void xms::GmMultiPolyIntersectorImpl::GetPolysForPoint ( Pt3d  pt,
SetInt a_poly 
)
private

Find the set of polygons intersected (in or on) by the point.

Parameters
ptpoint loction
a_poly1-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().

◆ OffsetPolyIds()

void xms::GmMultiPolyIntersectorImpl::OffsetPolyIds ( VecInt polyIds) const
private

If polygon IDs should start at something other than 1, we handle that here.

Parameters
polyIds1-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().

◆ PointsOnSegment()

void xms::GmMultiPolyIntersectorImpl::PointsOnSegment ( const GmBstPoly3d a_poly,
const GmBstLine3d a_line,
std::deque< Pt3d > &  a_output 
)
private

Check if the points on the outside of the polygon lie on the line segment.

Parameters
a_polyGmBstPoly3d.
a_lineGmBstLine3d.
a_outputOutput.

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().

◆ PolygonFromPoint()

int xms::GmMultiPolyIntersectorImpl::PolygonFromPoint ( const Pt3d a_pt)
overridevirtual

Finds the polygon containing the point.

Parameters
a_ptthe location of the point
Returns
the polygon id

Definition at line 718 of file GmMultiPolyIntersector.cpp.

References GetPolysForPoint(), and XM_NONE.

◆ RemoveDuplicateTValues()

void xms::GmMultiPolyIntersectorImpl::RemoveDuplicateTValues ( VecInt a_polyIds,
VecDbl a_tValues,
VecPt3d a_pts 
)
private

Removes duplicate T Values and updates the polygon ID and point vectors.

Parameters
a_polyIdslist of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor.
a_tValuesValues 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_ptsIntersection points.

Definition at line 665 of file GmMultiPolyIntersector.cpp.

References GTEQ_TOL(), and XM_ZERO_TOL.

Referenced by TraverseLineSegment().

◆ SetQuery()

void xms::GmMultiPolyIntersectorImpl::SetQuery ( GmMultiPolyIntersectorQueryEnum  a_query)
overridevirtual

Set the query to use (covered by, intersects...).

Parameters
a_queryGmMultiPolyIntersectorQueryEnum

Definition at line 344 of file GmMultiPolyIntersector.cpp.

References m_query.

◆ TraverseLineSegment() [1/4]

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyIds,
VecDbl a_tValues 
)
overridevirtual

Intersect segment with polys and save intersected polys and t-values.

Parameters
a_x1x coordinate of 1st point defining a line segment.
a_y1y coordinate of 1st point defining a line segment.
a_x2x coordinate of 2nd point defining a line segment.
a_y2y coordinate of 2nd point defining a line segment.
a_polyIdslist of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor.
a_tValuesValues 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().

◆ TraverseLineSegment() [2/4]

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyIds 
)
overridevirtual

Intersect segment with polys and save intersected polys.

Parameters
a_x1x coordinate of 1st point defining a line segment.
a_y1y coordinate of 1st point defining a line segment.
a_x2x coordinate of 2nd point defining a line segment.
a_y2y coordinate of 2nd point defining a line segment.
a_polyIdslist 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().

◆ TraverseLineSegment() [3/4]

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyIds,
VecPt3d a_pts 
)
overridevirtual

Intersect segment with polys and save intersected polys and intersection points.

Parameters
a_x1x coordinate of 1st point defining a line segment.
a_y1y coordinate of 1st point defining a line segment.
a_x2x coordinate of 2nd point defining a line segment.
a_y2y coordinate of 2nd point defining a line segment.
a_polyIdslist of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor.
a_ptsIntersection points.

Definition at line 585 of file GmMultiPolyIntersector.cpp.

References TraverseLineSegment().

◆ TraverseLineSegment() [4/4]

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyIds,
VecDbl a_tValues,
VecPt3d a_pts 
)
overridevirtual

Intersect segment with polys and save intersected polys, t-values, and intersection points.

Parameters
a_x1x coordinate of 1st point defining a line segment.
a_y1y coordinate of 1st point defining a line segment.
a_x2x coordinate of 2nd point defining a line segment.
a_y2y coordinate of 2nd point defining a line segment.
a_polyIdslist of polygons intersected by line segment. Can be zero or 1 based depending on a_startingId passed to constructor.
a_tValuesValues 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_ptsIntersection 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.


The documentation for this class was generated from the following file: