29 #include "../geometry.h"
30 #include "../common/STLUtils.h"
31 #include "../common/Translator.h"
38 unsigned int& firstTile,
unsigned int& lastTile)
const
63 if( ( y < m_referencePolygon.getMBR()->getLowerLeftY() ) ||
64 ( y > m_referencePolygon.getMBR()->getUpperRightY() ) )
70 tileIndex = (
unsigned int)( (y - m_referencePolygon.getMBR()->getLowerLeftY() ) / m_dy );
81 : m_referencePolygon(pol)
91 unsigned int total_tiles_number = 1 +
94 for(
unsigned int i = 0; i < total_tiles_number; i++)
102 throw Exception(
TE_TR(
"Error adding ring") );
122 if( ri >= m_referencePolygon.getNumRings() )
127 unsigned int num_points = m_referencePolygon[ri]->getNPoints();
133 unsigned int numSegments = num_points - 1;
135 for(
unsigned int j = 0; j < numSegments; j++)
138 std::pair<unsigned int, unsigned int> segPointer(ri, j);
141 unsigned int firstTileIndex = 0;
142 unsigned int lastTileIndex = 0;
144 std::auto_ptr< te::gm::Point > cj(
145 (static_cast<te::gm::LinearRing*> (m_referencePolygon[ri]))->getPointN(j) );
146 std::auto_ptr< te::gm::Point > cjp1(
147 (static_cast<te::gm::LinearRing*> (m_referencePolygon[ri]))->getPointN(j + 1) );
149 if( getTileIndex(*cj, *cjp1, firstTileIndex, lastTileIndex) )
152 for(
unsigned int k = firstTileIndex; k <= lastTileIndex; k++)
153 m_tileIndex[k]->push_back(segPointer);
167 if( getTileIndex(y, tidx) )
169 assert( tidx < m_tileIndex.size() );
171 (*index) = m_tileIndex[tidx];
182 m_withinTileY = geometry.
getY();
184 if( getTile( m_withinTileY, &m_withinTileIndexPtr ) )
186 assert( m_withinTileIndexPtr );
188 m_withinTileX = geometry.
getX();
189 m_withinIsInside =
false;
191 for(
unsigned int i = 0 ; i < m_withinTileIndexPtr->size() ; ++i )
193 assert( ( ( *m_withinTileIndexPtr )[ i ].first < m_referencePolygon.getNumRings() ) );
194 assert( dynamic_cast< te::gm::LinearRing const* >( m_referencePolygon[
195 ( *m_withinTileIndexPtr )[ i ].first ] ) );
196 m_withinRingPtr = (
te::gm::LinearRing const*)m_referencePolygon[ ( *m_withinTileIndexPtr )[ i ].first ];
198 assert( ( *m_withinTileIndexPtr )[ i ].second < m_withinRingPtr->getNPoints() );
199 m_withinVtx0.x = m_withinRingPtr->getX( ( *m_withinTileIndexPtr )[ i ].second );
200 m_withinVtx0.y = m_withinRingPtr->getY( ( *m_withinTileIndexPtr )[ i ].second );
201 m_withinVtx1.x = m_withinRingPtr->getX( ( *m_withinTileIndexPtr )[ i ].second + 1 );
202 m_withinVtx1.y = m_withinRingPtr->getY( ( *m_withinTileIndexPtr )[ i ].second + 1 );
204 m_withinYFlag0 = (m_withinVtx0.y >= m_withinTileY);
206 m_withinYFlag1 = (m_withinVtx1.y >= m_withinTileY);
208 if(m_withinYFlag0 != m_withinYFlag1)
212 if(((m_withinVtx1.y - m_withinTileY) * (m_withinVtx0.x - m_withinVtx1.x) >=
213 (m_withinVtx1.x - m_withinTileX) * (m_withinVtx0.y - m_withinVtx1.y)) == m_withinYFlag1)
215 m_withinIsInside = !m_withinIsInside ;
220 return m_withinIsInside;
std::size_t getNumRings() const
It returns the number of rings in this CurvePolygon.
bool getTile(const double &y, TileSegIndex **index) const
Gets tile index.
~TileIndexer()
Destructor.
const te::gm::Polygon & m_referencePolygon
Reference polygon.
bool within(const te::gm::Point &geometry) const
It returns true if the given geometry is within the indexed reference polygon.
bool addRing(const unsigned int &ri)
Update the tile index with the information of the supplied ring.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
#define TE_TR(message)
It marks a string in order to get translated.
bool getTileIndex(const te::gm::Point &p1, const te::gm::Point &p2, unsigned int &firstTile, unsigned int &lastTile) const
Gets tile index intervals in y direction for a given segment.
A LinearRing is a LineString that is both closed and simple.
An exception class for the Raster module.
const double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
Polygon tile indexing class for optmized geometrical relational tests.
double m_dy
Tile resolution along "y" axis.
void clear()
Clear all internal resources.
TileIndexer(const TileIndexer &)
Constructor.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
std::vector< TileSegIndex * > m_tileIndex
Each tile segments index vector.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
double getHeight() const
It returns the envelope height.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
const double & getX() const
It returns the Point x-coordinate value.
void init()
Init internal variables.