xmsgeom  1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 x1, double y1, double x2, double y2, VecInt &polyids, VecDbl &tvalues) override
 Intersect segment with polys and save intersected polys and t-values. More...
 
virtual void TraverseLineSegment (double x1, double y1, double x2, double y2, VecInt &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, std::vector< Pt3d > &a_pts) override
 Intersect segment with polys and save intersected polys and intersection points. More...
 
virtual int PolygonFromPoint (const Pt3d &a_pt) override
 Finds the polygon containing the point. More...
 

Private Member Functions

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...
 
void TraverseLineSegmentAll (double a_x1, double a_y1, double a_x2, double a_y2, VecInt &a_polyids, VecDbl &a_tvalues, std::vector< Pt3d > &a_pts)
 Intersect segment with polys and save intersected polys, t-values, and intersection points. 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.
 
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...
 

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 61 of file GmMultiPolyIntersector.cpp.

Constructor & Destructor Documentation

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 164 of file GmMultiPolyIntersector.cpp.

References BuildRTree(), CalculateBuffer(), m_boostPolys, m_d, xms::GmMultiPolyIntersectorData::m_points, and xms::GmMultiPolyIntersectorData::m_polys.

Member Function Documentation

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 227 of file GmMultiPolyIntersector.cpp.

References m_buffer.

Referenced by BuildRTree().

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 250 of file GmMultiPolyIntersector.cpp.

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

Referenced by GetBoostPoly().

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 394 of file GmMultiPolyIntersector.cpp.

References m_d, xms::GmMultiPolyIntersectorData::m_ixs, m_pt1, m_pt2, and XM_NODATA.

Referenced by TraverseLineSegmentAll().

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 238 of file GmMultiPolyIntersector.cpp.

References BuildBoostPoly(), and m_boostPolys.

Referenced by GetPolysForPoint(), and IntersectEachPolyWithLine().

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 310 of file GmMultiPolyIntersector.cpp.

References GetBoostPoly(), m_query, m_rtree, and XM_ASSERT.

Referenced by PolygonFromPoint(), and TraverseLineSegmentAll().

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 449 of file GmMultiPolyIntersector.cpp.

References m_startingId, and XM_NONE.

Referenced by TraverseLineSegmentAll().

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 369 of file GmMultiPolyIntersector.cpp.

References m_buffer, xms::Pt3< T >::x, and xms::Pt3< T >::y.

Referenced by IntersectEachPolyWithLine().

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 519 of file GmMultiPolyIntersector.cpp.

References GetPolysForPoint(), and XM_NONE.

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

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

Parameters
a_queryGmMultiPolyIntersectorQueryEnum

Definition at line 301 of file GmMultiPolyIntersector.cpp.

References m_query.

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  x1,
double  y1,
double  x2,
double  y2,
VecInt polyids,
VecDbl tvalues 
)
overridevirtual

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

Parameters
x1x coordinate of 1st point defining a line segment.
y1y coordinate of 1st point defining a line segment.
x2x coordinate of 2nd point defining a line segment.
y2y coordinate of 2nd point defining a line segment.
polyids1-based list of polygons intersected by line segment.
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 475 of file GmMultiPolyIntersector.cpp.

References TraverseLineSegmentAll().

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  x1,
double  y1,
double  x2,
double  y2,
VecInt polyids 
)
overridevirtual

Intersect segment with polys and save intersected polys.

Parameters
x1x coordinate of 1st point defining a line segment.
y1y coordinate of 1st point defining a line segment.
x2x coordinate of 2nd point defining a line segment.
y2y coordinate of 2nd point defining a line segment.
polyids1-based list of polygons intersected by line segment.

Definition at line 490 of file GmMultiPolyIntersector.cpp.

References TraverseLineSegmentAll().

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegment ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyids,
std::vector< Pt3d > &  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_polyids1-based list of polygons intersected by line segment.
a_ptsIntersection points.

Definition at line 507 of file GmMultiPolyIntersector.cpp.

References TraverseLineSegmentAll().

void xms::GmMultiPolyIntersectorImpl::TraverseLineSegmentAll ( double  a_x1,
double  a_y1,
double  a_x2,
double  a_y2,
VecInt a_polyids,
VecDbl a_tvalues,
std::vector< Pt3d > &  a_pts 
)
private

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_polyids1-based list of polygons intersected by line segment.
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 546 of file GmMultiPolyIntersector.cpp.

References ComputeTValues(), CreateLine(), EnsureEndPointsRepresented(), GetPolysForPoint(), IntersectEachPolyWithLine(), m_d, xms::GmMultiPolyIntersectorData::m_ixs, m_line, xms::GmMultiPolyIntersectorData::m_polys1, xms::GmMultiPolyIntersectorData::m_polys2, m_pt1, m_pt2, m_sorter, OffsetPolyIds(), xms::Pt3< T >::Set(), SortIntersections(), and XM_ASSERT.

Referenced by TraverseLineSegment().


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