Vectorizer.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/Vectorizer.h
22 
23  \brief It implements the vectorizer, based on TerraLib 4 algorithm.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_VECTORIZER_H
27 #define __TERRALIB_RASTER_INTERNAL_VECTORIZER_H
28 
29 // The 8 cardinals directions used by vectorize method
30 #define NORTHWEST 0
31 #define NORTH 1
32 #define NORTHEAST 2
33 #define EAST 3
34 #define SOUTHEAST 4
35 #define SOUTH 5
36 #define SOUTHWEST 6
37 #define WEST 7
38 
39 // TerraLib
40 #include "../geometry/Coord2D.h"
41 #include "../geometry/LineString.h"
42 #include "../sam/rtree.h"
43 #include "Enums.h"
44 #include "Raster.h"
46 
47 // STL
48 #include <vector>
49 
50 namespace te
51 {
52  namespace rst
53  {
54 // Forward declaration.
55  class Raster;
56 
57  /*!
58  \class Vectorizer
59 
60  \brief It implements the vectorizer, based on TerraLib 4 algorithm.
61 
62  This algorithm implements a vectorizer, which is an algorithm to convert an
63  image with pixel-labels into a set of polygons. All connected pixels in the
64  image with the same label will define an individual polygon. This algorithm
65  is based on the implementation of the previous version of this library, the
66  TerraLib 4.
67 
68  \ingroup rst
69 
70  \sa Raster, Geometry
71  */
73  {
74  public:
75 
76  /*!
77  \brief Constructor.
78 
79  \param r The input raster.
80  \param b The selected band of the raster to be vectorized.
81  \param mp The maximum allowed number of polygons to be created (default = 0, unlimited).
82  */
83  Vectorizer(Raster* r, std::size_t b, unsigned int mp = 0);
84 
85  /*!
86  \brief Copy constructor.
87 
88  \param rhs The right-hand-side copy that would be used to copy from.
89  */
90  Vectorizer(const Vectorizer& rhs);
91 
92  /*! \brief Destructor. */
93  ~Vectorizer();
94 
95  /*!
96  \brief Assignment operator.
97 
98  \param rhs The right-hand-side copy that would be used to copy from.
99 
100  \return A reference to this object.
101  */
102  Vectorizer& operator=(const Vectorizer& rhs);
103 
104  /*!
105  \brief Returns true if current algorithm implementation runs ok, false otherwise.
106 
107  \param polygons The vector of polygons (will be cleared) to get the result of the vectorization.
108 
109  \note The caller of this method must take the ownership of the returned geometries and must delete them when necessary.
110  */
111  bool run(std::vector<te::gm::Geometry*>& polygons);
112 
113  protected :
114 
115  /*!
116  \brief Tests if the current point is a edge start.
117 
118  \param x X coord.
119  \param y Y coord.
120 
121  \return true if the current point is a edge start, false if not.
122  */
123  bool startingEdgeTest(const int& x, const int& y);
124 
125  /*!
126  \brief Detects an edge of a cell in Raster.
127 
128  \param i abscissa (column) of the upper-left point of the shape
129  \param j ordinate (line) of the upper-left point of the shape
130  \param line 2D Line.
131 
132  \return true if ok, otherwise false
133  */
134  bool detectEdge(long i, long j, te::gm::LinearRing& line);
135 
136 
137 
138  /*! \brief Clear all internally allocated resources. */
139  void clear();
140 
141  protected:
142 
143  double m_noDataValue; //!< The used dummy value.
144  Raster* m_rasterPtr; //!< A pointer to the input image.
145  te::gm::Coord2D m_directions[8]; //!< Directions vector.
146  double m_resX; //!< Resolution X.
147  double m_resY; //!< Resolution Y.
148  unsigned long m_nLines; //!< The number of lines.
149  unsigned long m_nColumns; //!< The number of columns.
150  unsigned int m_rasterBand; //!< The raster band to be used.
151  unsigned int m_maxPolygons; //!< The maximum allowed number of polygons to be created.
152  te::sam::rtree::Index<unsigned int, 8, 4>* m_rTreePolygons; //!< A RTree instance pointer to optimize the searching of points inside already created polygons
153  std::vector<VectorizerPolygonStructure> m_containerPolygons; //!< Vector of all polygons.
154  };
155  } // end namespace rst
156 } // end namespace te
157 
158 #endif // __TERRALIB_RASTER_INTERNAL_VECTORIZER_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
unsigned long m_nColumns
The number of columns.
Definition: Vectorizer.h:149
Raster * m_rasterPtr
A pointer to the input image.
Definition: Vectorizer.h:144
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
unsigned long m_nLines
The number of lines.
Definition: Vectorizer.h:148
te::sam::rtree::Index< unsigned int, 8, 4 > * m_rTreePolygons
A RTree instance pointer to optimize the searching of points inside already created polygons...
Definition: Vectorizer.h:152
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
double m_resX
Resolution X.
Definition: Vectorizer.h:146
Enumerations for the Raster module.
std::vector< VectorizerPolygonStructure > m_containerPolygons
Vector of all polygons.
Definition: Vectorizer.h:153
An abstract class for raster data strucutures.
unsigned int m_rasterBand
The raster band to be used.
Definition: Vectorizer.h:150
An abstract class for raster data strucutures.
Definition: Raster.h:71
unsigned int m_maxPolygons
The maximum allowed number of polygons to be created.
Definition: Vectorizer.h:151
URI C++ Library.
double m_resY
Resolution Y.
Definition: Vectorizer.h:147
It implements the vectorizer, based on TerraLib 4 algorithm.
Definition: Vectorizer.h:72
double m_noDataValue
The used dummy value.
Definition: Vectorizer.h:143
A polygon container node class.