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 <math.h>
38 #include <vector>
39 
40 namespace 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  /*! \brief Constructor. */
62  TileIndexer(const TileIndexer&);
63 
64  /*! \brief Copy overload. */
65  const TileIndexer& operator=(const TileIndexer&);
66 
67  /*!
68  \brief Gets tile index intervals in y direction for a given segment.
69 
70  \param p1 First segment coordinate.
71  \param p2 Second segment coordinate.
72  \param firstTile The first tile index that this segment intersects.
73  \param lastTile The last tile index that this segment intersects.
74  \return true if ok, false on errors.
75 
76  \note The segment does NOT need to be oriented.
77  */
78  bool getTileIndex(const te::gm::Point& p1, const te::gm::Point& p2,
79  unsigned int& firstTile, unsigned int& lastTile) const;
80 
81  /*!
82  \brief Gets tile index for y coordinate value.
83 
84  \param y Value of "y" coordinate.
85  \param tileIndex Index of corresponding tile.
86  \return true if ok, false on errors.
87  */
88  bool getTileIndex(const double& y, unsigned int& tileIndex) const;
89 
90  /*! \brief Init internal variables. */
91  void init();
92 
93  public:
94 
95  /*!
96  \brief Alternative Constructor.
97 
98  \param pol The polygon to index.
99  \param dy Tile size along "y" axis.
100  */
101  TileIndexer(const te::gm::Polygon& pol, const double& dy);
102 
103  /*! \brief Clear all internal resources. */
104  void clear();
105 
106  /*! \brief Destructor. */
107  ~TileIndexer();
108 
109  /*!
110  \brief Update the tile index with the information of the supplied ring.
111 
112  \param ri The ring index.
113  \return true, if ok, false on errors.
114  */
115  bool addRing(const unsigned int& ri);
116 
117  /*!
118  \brief Gets tile index.
119 
120  \param y The Y value.
121  \param index Output tile pointer.
122  \return true if ok, false on errors.
123  */
124  bool getTile(const double& y, TileSegIndex** index) const;
125 
126  /*! \brief Returns the polygon. */
127  inline const te::gm::Polygon& getPolygon() const
128  {
129  return m_referencePolygon;
130  };
131 
132  /*!
133  \brief It returns true if the given geometry is within the indexed reference polygon.
134 
135  \param rhs The other geometry to be compared.
136 
137  \return true if the given geometry is within the indexed reference polygon.
138  */
139  bool within(const te::gm::Point& geometry) const;
140 
141  protected:
142  double m_dy; //!< Tile resolution along "y" axis.
143  const te::gm::Polygon& m_referencePolygon; //!< Reference polygon.
144  std::vector<TileSegIndex*> m_tileIndex; //!< Each tile segments index vector.
145 
146  // Variables used by the method within
147 
148  mutable TileSegIndex* m_withinTileIndexPtr;
149  mutable double m_withinTileY;
150  mutable double m_withinTileX;
151  mutable bool m_withinIsInside;
152  mutable int m_withinYFlag0;
153  mutable int m_withinYFlag1;
157 
158  };
159 
160  } // end namespace rst
161 } // end namespace te
162 
163 #endif // __TERRALIB_RASTER_INTERNAL_TILEINDEXER_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
te::gm::Coord2D m_withinVtx1
Definition: TileIndexer.h:156
te::gm::Coord2D m_withinVtx0
Definition: TileIndexer.h:155
const te::gm::Polygon & m_referencePolygon
Reference polygon.
Definition: TileIndexer.h:143
Polygon tile indexing class for optmized geometrical relational tests.
Definition: TileIndexer.h:54
te::gm::LinearRing const * m_withinRingPtr
Definition: TileIndexer.h:154
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
const te::gm::Polygon & getPolygon() const
Returns the polygon.
Definition: TileIndexer.h:127
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
A point with x and y coordinate values.
Definition: Point.h:50
URI C++ Library.
double m_dy
Tile resolution along "y" axis.
Definition: TileIndexer.h:142
TileSegIndex * m_withinTileIndexPtr
Definition: TileIndexer.h:148
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
std::vector< TileSegIndex * > m_tileIndex
Each tile segments index vector.
Definition: TileIndexer.h:144
Configuration flags for the Raster module of TerraLib.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
Definition: TileIndexer.h:58