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