All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Vectorizer.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/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 Tests if the current point is a edge start.
106 
107  \param x X coord.
108  \param y Y coord.
109 
110  \return true if the current point is a edge start, false if not.
111  */
112  bool startingEdgeTest(const int& x, const int& y);
113 
114  /*!
115  \brief Detects an edge of a cell in Raster.
116 
117  \param i abscissa (column) of the upper-left point of the shape
118  \param j ordinate (line) of the upper-left point of the shape
119  \param line 2D Line.
120 
121  \return true if ok, otherwise false
122  */
123  bool detectEdge(long i, long j, te::gm::LineString& line);
124 
125  /*!
126  \brief Returns true if current algorithm implementation runs ok, false otherwise.
127 
128  \param polygons The vector of polygons (will be cleared) to get the result of the vectorization.
129  */
130  bool run(std::vector<te::gm::Geometry*>& polygons);
131 
132  /*! \brief Clear all internally allocated resources. */
133  void clear();
134 
135  protected:
136 
137  bool m_useNoData; //!< Flag indication for dummy value use (rotulated image).
138  double m_noDataValue; //!< The used dummy value.
139  Raster* m_raster; //!< The input image.
140  te::gm::Coord2D m_directions[8]; //!< Directions vector.
141  double m_resX; //!< Resolution X.
142  double m_resY; //!< Resolution Y.
143  unsigned long m_nLines; //!< The number of lines.
144  unsigned long m_nColumns; //!< The number of columns.
145  unsigned int m_rasterBand; //!< The raster band to be used.
146  unsigned int m_maxPolygons; //!< The maximum allowed number of polygons to be created.
147  te::sam::rtree::Index<unsigned int, 8, 4>* m_rTreePolygons; //!< A RTree instance pointer to optimize the searching of points inside already created polygons
148  std::vector<VectorizerPolygonStructure> m_containerPolygons; //!< Vector of all polygons.
149  };
150  } // end namespace rst
151 } // end namespace te
152 
153 #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:65
unsigned long m_nColumns
The number of columns.
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:143
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:147
double m_resX
Resolution X.
Definition: Vectorizer.h:141
Enumerations for the Raster module.
LineString is a curve with linear interpolation between points.
Definition: LineString.h:62
std::vector< VectorizerPolygonStructure > m_containerPolygons
Vector of all polygons.
Definition: Vectorizer.h:148
An abstract class for raster data strucutures.
unsigned int m_rasterBand
The raster band to be used.
Definition: Vectorizer.h:145
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:146
double m_resY
Resolution Y.
Definition: Vectorizer.h:142
It implements the vectorizer, based on TerraLib 4 algorithm.
Definition: Vectorizer.h:72
double m_noDataValue
The used dummy value.
Definition: Vectorizer.h:138
bool m_useNoData
Flag indication for dummy value use (rotulated image).
Definition: Vectorizer.h:137
A polygon container node class.
Raster * m_raster
The input image.
Definition: Vectorizer.h:139