Loading...
Searching...
No Matches
TileIndexer.h
Go to the documentation of this file.
1/* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2
3 This file is part of the TerraLib - a Framework for building GIS enabled applications.
4
5 TerraLib is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 TerraLib is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with TerraLib. See COPYING. If not, write to
17 TerraLib Team at <terralib-team@terralib.org>.
18 */
19
20/*!
21 \file terralib/raster/TileIndexer.h
22
23 \brief Polygon tile indexing class for optmized geometrical relational tests.
24*/
25
26#ifndef __TERRALIB_RASTER_INTERNAL_TILEINDEXER_H
27#define __TERRALIB_RASTER_INTERNAL_TILEINDEXER_H
28
29// TerraLib
30#include "../geometry/Point.h"
31#include "../geometry/Polygon.h"
32#include "../geometry/LinearRing.h"
33#include "../geometry/Coord2D.h"
34#include "Config.h"
35
36// STL
37#include <cmath>
38#include <vector>
39
40namespace te
41{
42 namespace rst
43 {
44 /*!
45 \class TileIndexer
46
47 \brief Polygon tile indexing class for optmized geometrical relational tests.
48
49 \ingroup rst
50
51 \note The related polygon instance must always be valid (only the polygon
52 reference is stored internally).
53 */
55 {
56 public:
57 /*! \typedef Indexed elements node type (pair<ring index, seg index>). */
58 typedef std::vector<std::pair<unsigned int, unsigned int> > TileSegIndex;
59
60 protected:
61
62 /*! \brief Copy overload. */
64
65 /*!
66 \brief Gets tile index intervals in y direction for a given segment.
67
68 \param p1 First segment coordinate.
69 \param p2 Second segment coordinate.
70 \param firstTile The first tile index that this segment intersects.
71 \param lastTile The last tile index that this segment intersects.
72 \return true if ok, false on errors.
73
74 \note The segment does NOT need to be oriented.
75 */
76 bool getTileIndex(const te::gm::Point& p1, const te::gm::Point& p2,
77 unsigned int& firstTile, unsigned int& lastTile) const;
78
79 /*!
80 \brief Gets tile index for y coordinate value.
81
82 \param y Value of "y" coordinate.
83 \param tileIndex Index of corresponding tile.
84 \return true if ok, false on errors.
85 */
86 bool getTileIndex(const double& y, unsigned int& tileIndex) const;
87
88 /*! \brief Init internal variables. */
89 void init();
90
91 public:
92
93 /*! \brief Constructor. */
95
96 /*!
97 \brief Alternative Constructor.
98
99 \param pol The polygon to index.
100 \param dy Tile size along "y" axis.
101 */
102 TileIndexer(const te::gm::Polygon& pol, const double& dy);
103
104 /*! \brief Clear all internal resources. */
105 void clear();
106
107 /*! \brief Destructor. */
109
110 /*!
111 \brief Update the tile index with the information of the supplied ring.
112
113 \param ri The ring index.
114 \return true, if ok, false on errors.
115 */
116 bool addRing(const unsigned int& ri);
117
118 /*!
119 \brief Gets tile index.
120
121 \param y The Y value.
122 \param index Output tile pointer.
123 \return true if ok, false on errors.
124 */
125 bool getTile(const double& y, TileSegIndex** index) const;
126
127 /*! \brief Returns the polygon. */
128 inline const te::gm::Polygon& getPolygon() const
129 {
130 return m_referencePolygon;
131 };
132
133 /*!
134 \brief It returns true if the given geometry is within the indexed reference polygon.
135
136 \param rhs The other geometry to be compared.
137
138 \return true if the given geometry is within the indexed reference polygon.
139 */
140 bool within(const te::gm::Point& geometry) const;
141
142 /*!
143 \brief It returns true if the given geometry is within or touches the indexed reference polygon.
144
145 \param rhs The other geometry to be compared.
146
147 \return true if the given geometry is within the indexed reference polygon.
148 */
149 bool withinOrTouches(const te::gm::Point& geometry) const;
150
151 /*!
152 \brief Returns a clone of this instance (the caller of this method must thake the ownership of the returned pointer).
153 \return Returns a clone of this instance (the caller of this method must thake the ownership of the returned pointer).
154 */
156
157 protected:
158 double m_dy; //!< Tile resolution along "y" axis.
159 const te::gm::Polygon& m_referencePolygon; //!< Reference polygon.
160 std::vector<TileSegIndex*> m_tileIndex; //!< Each tile segments index vector.
161
162 // Variables used by the method within
163
165 mutable double m_withinTileY;
166 mutable double m_withinTileX;
167 mutable bool m_withinIsInside;
168 mutable int m_withinYFlag0;
169 mutable int m_withinYFlag1;
170 mutable int m_withinYEquals;
174
175 };
176
177 } // end namespace rst
178} // end namespace te
179
180#endif // __TERRALIB_RASTER_INTERNAL_TILEINDEXER_H
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:54
A point with x and y coordinate values.
Definition: Point.h:51
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:51
Polygon tile indexing class for optmized geometrical relational tests.
Definition: TileIndexer.h:55
const TileIndexer & operator=(const TileIndexer &)
Copy overload.
void init()
Init internal variables.
double m_dy
Tile resolution along "y" axis.
Definition: TileIndexer.h:158
bool getTile(const double &y, TileSegIndex **index) const
Gets tile index.
TileIndexer * clone() const
Returns a clone of this instance (the caller of this method must thake the ownership of the returned ...
void clear()
Clear all internal resources.
~TileIndexer()
Destructor.
std::vector< TileSegIndex * > m_tileIndex
Each tile segments index vector.
Definition: TileIndexer.h:160
TileSegIndex * m_withinTileIndexPtr
Definition: TileIndexer.h:164
TileIndexer(const te::gm::Polygon &pol, const double &dy)
Alternative Constructor.
bool withinOrTouches(const te::gm::Point &geometry) const
It returns true if the given geometry is within or touches the indexed reference polygon.
te::gm::Coord2D m_withinVtx1
Definition: TileIndexer.h:173
te::gm::Coord2D m_withinVtx0
Definition: TileIndexer.h:172
bool addRing(const unsigned int &ri)
Update the tile index with the information of the supplied ring.
const te::gm::Polygon & getPolygon() const
Returns the polygon.
Definition: TileIndexer.h:128
bool within(const te::gm::Point &geometry) const
It returns true if the given geometry is within the indexed reference polygon.
te::gm::LinearRing const * m_withinRingPtr
Definition: TileIndexer.h:171
bool getTileIndex(const double &y, unsigned int &tileIndex) const
Gets tile index for y coordinate value.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
Definition: TileIndexer.h:58
TileIndexer(const TileIndexer &)
Constructor.
const te::gm::Polygon & m_referencePolygon
Reference polygon.
Definition: TileIndexer.h:159
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.
TerraLib.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:41
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
Proxy configuration file for TerraView (see terraview_config.h).