All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TileIndexer.h
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 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 "Config.h"
31 
32 // STL
33 #include <math.h>
34 #include <vector>
35 
36 namespace te
37 {
38  namespace gm
39  {
40 // Forward declarations
41  class Point;
42  class Polygon;
43  }
44 
45  namespace rst
46  {
47  /*!
48  \class TileIndexer
49 
50  \brief Polygon tile indexing class for optmized geometrical relational tests.
51 
52  \note The related polygon instance must always be valid (only the polygon
53  reference is stored internally).
54  */
56  {
57  public:
58  /*! \typedef Indexed elements node type (pair<ring index, seg index>). */
59  typedef std::vector<std::pair<unsigned int, unsigned int> > TileSegIndex;
60 
61  protected:
62  /*! \brief Constructor. */
63  TileIndexer(const TileIndexer&);
64 
65  /*! \brief Copy overload. */
66  const TileIndexer& operator=(const TileIndexer&);
67 
68  /*!
69  \brief Gets tile index intervals in y direction for a given segment.
70 
71  \param p1 First segment coordinate.
72  \param p2 Second segment coordinate.
73  \param firstTile The first tile index that this segment intersects.
74  \param lastTile The last tile index that this segment intersects.
75 
76  \note The segment does NOT need to be oriented.
77  */
78  void 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  */
87  void getTileIndex(const double& y, unsigned int& tileIndex) const;
88 
89  /*! \brief Init internal variables. */
90  void init();
91 
92  public:
93 
94  /*!
95  \brief Alternative Constructor.
96 
97  \param pol The polygon to index.
98  \param dy Tile size along "y" axis.
99  */
100  TileIndexer(const te::gm::Polygon& pol, const double& dy);
101 
102  /*! \brief Clear all internal resources. */
103  void clear();
104 
105  /*! \brief Destructor. */
106  ~TileIndexer();
107 
108  /*!
109  \brief Update the tile index with the information of the supplied ring.
110 
111  \param ri The ring index.
112  */
113  void addRing(const unsigned int& ri);
114 
115  /*!
116  \brief Gets tile index.
117 
118  \param y The Y value.
119  \param index Output tile pointer (NULL if not found).
120  */
121  void getTile(const double& y, TileSegIndex** index) const;
122 
123  /*! \brief Returns the polygon. */
124  const te::gm::Polygon& getPolygon() const;
125 
126  protected:
127  double m_dy; //!< Tile resolution along "y" axis.
128  const te::gm::Polygon& m_referencePolygon; //!< Reference polygon.
129  std::vector<TileSegIndex*> m_tileIndex; //!< Each tile segments index vector.
130 
131  };
132 
133  } // end namespace rst
134 } // end namespace te
135 
136 #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:65
const te::gm::Polygon & m_referencePolygon
Reference polygon.
Definition: TileIndexer.h:128
Polygon tile indexing class for optmized geometrical relational tests.
Definition: TileIndexer.h:55
A point with x and y coordinate values.
Definition: Point.h:50
double m_dy
Tile resolution along "y" axis.
Definition: TileIndexer.h:127
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:129
Configuration flags for the Raster module of TerraLib.
std::vector< std::pair< unsigned int, unsigned int > > TileSegIndex
Definition: TileIndexer.h:59