RasterSummaryManager.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/RasterSummaryManager.h
22 
23  \brief A singleton for keeping raster summaries (most statistics).
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_RASTERSUMMARYMANAGER_H
27 #define __TERRALIB_RASTER_INTERNAL_RASTERSUMMARYMANAGER_H
28 
29 // TerraLib
30 #include "../common/Singleton.h"
31 #include "../common/Enums.h"
32 #include "Config.h"
33 #include "Enums.h"
34 #include "RasterSummary.h"
35 
36 //STL
37 #include <list>
38 #include <mutex>
39 
40 namespace te
41 {
42  namespace rst
43  {
44 // Forward declaration
45  class Raster;
46 
47  /*!
48  \class RasterSummaryManager
49 
50  \brief A singleton for keeping raster summaries (most statistics).
51  It stores an internal map of raster conn info str and their
52  respective summaries.
53 
54  \ingroup rst
55 
56  \sa RasterSummary, BandSummary.
57  */
58  class TERASTEREXPORT RasterSummaryManager : public te::common::Singleton<RasterSummaryManager>
59  {
61 
62  public:
63 
64  /*!
65  \brief Searches for a raster summary.
66  \param raster The raster to be found.
67  \param summary The found raster summary.
68  \return true if the summary has been found, false if not found.
69  \note This is a thread safe method (an internal mutex is used).
70  */
71  bool find(const Raster* raster, RasterSummary& summary ) const;
72 
73  /*!
74  \brief Searches for a band summary.
75  \param raster The raster to be found.
76  \param rowStart The starting row.
77  \param colStart The starting column.
78  \param finalRow The final row.
79  \param finalCol The final column.
80  \param histoBins The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
81  \param sampleStep The row/column step used when reading pixels (to read all pixels sampleStep=1, to read half of pixels use sampleStep=2 );
82  \param summary The found raster summary.
83  \return true if the summary has been found, false if not found.
84  \note This is a thread safe method (an internal mutex is used).
85  */
86  bool find(const Raster* raster, const unsigned int bandIndex,
87  const unsigned int rowStart, const unsigned int colStart,
88  const unsigned int finalRow, const unsigned int finalCol,
89  const unsigned int histoBins, const unsigned int sampleStep,
90  BandSummary& summary ) const;
91 
92  /*!
93  \brief Removes the summary from the specified raster.
94  \param raster The raster to be found.
95  \param rowStart The starting row.
96  \param colStart The starting column.
97  \param finalRow The final row.
98  \param finalCol The final column.
99  \param histoBins The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
100  \param sampleStep The row/column step used when reading pixels (to read all pixels sampleStep=1, to read half of pixels use sampleStep=2 );
101  */
102  void remove(const Raster* raster, const unsigned int bandIndex,
103  const unsigned int rowStart, const unsigned int colStart,
104  const unsigned int finalRow, const unsigned int finalCol,
105  const unsigned int histoBins, const unsigned int sampleStep);
106 
107  /*!
108  \brief Removes all summary ocurrences related to the specified raster pointer
109  \param raster The raster pointer to remove the summary.
110  \note This is a thread safe method (an internal mutex is used).
111  */
112  void remove(const Raster* raster);
113 
114  /*!
115  \brief Removes all raster summary entries.
116  \note This is a thread safe method (an internal mutex is used).
117  \note All cached info will be removed.
118  */
119  void removeAll();
120 
121  /*!
122  \brief It searches for a raster summary. If not found it creates the summary and returns it.
123  \param raster The raster to be found.
124  \param readall If false, the cache will be used or if true the entire image will be read again (can be slow).
125  \param summary The found raster summary.
126  \return true if ok, false on errors.
127  \note This is a thread safe method (an internal mutex is used).
128  */
129  bool get( const Raster* raster, bool readall, RasterSummary& summary );
130 
131  /*!
132  \brief It searches for a raster summary. If not found it creates the summary and returns it.
133  \param raster The raster to be found.
134  \param rowStart The starting row.
135  \param colStart The starting column.
136  \param finalRow The final row.
137  \param finalCol The final column.
138  \param histoBins The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
139  \param sampleStep The row/column step used when reading pixels (to read all pixels sampleStep=1, to read half of pixels use sampleStep=2 );
140  \param readall Force the reading the entire image (can be slow) for computing min and max values.
141  \param summary The found raster summary.
142  \return true if ok, false on errors.
143  \note This is a thread safe method (an internal mutex is used).
144  */
145  bool get( const Raster* raster, const unsigned int rowStart,
146  const unsigned int colStart, const unsigned int finalRow,
147  const unsigned int finalCol, const unsigned int histoBins,
148  const unsigned int sampleStep, bool readall, RasterSummary& summary );
149 
150  /*!
151  \brief Searches for a band summary and creates it if it does not exist.
152  \param raster The raster to be found.
153  \param bandIndex Band index.
154  \param readall If false, the cache will be used or if true the entire image will be read again (can be slow).
155  \param summary The found band summary.
156  \return true if ok, false on errors.
157  \note This is a thread safe method (an internal mutex is used).
158  */
159  bool get( const Raster* raster, const unsigned int bandIndex, bool readall, BandSummary& summary );
160 
161  /*!
162  \brief Searches for a band summary and creates it if it does not exist.
163  \param raster The raster to be found.
164  \param bandIndex Band index.
165  \param rowStart The starting row.
166  \param colStart The starting column.
167  \param finalRow The final row.
168  \param finalCol The final column.
169  \param histoBins The number of bins (intervals from minimum pixel to maximum). When b = 0, the histogram will be divided according to all pixel values.
170  \param sampleStep The row/column step used when reading pixels (to read all pixels sampleStep=1, to read half of pixels use sampleStep=2 );
171  \param readall Force the reading the entire image (can be slow) for computing min and max values.
172  \param summary The found band summary.
173  \return true if the summary has been found, false if not found.
174  \note This is a thread safe method (an internal mutex is used).
175  */
176  bool get( const Raster* raster, const unsigned int bandIndex,
177  const unsigned int rowStart, const unsigned int colStart,
178  const unsigned int finalRow, const unsigned int finalCol,
179  const unsigned int histoBins, const unsigned int sampleStep,
180  bool readall, BandSummary& summary );
181 
182  /*! \brief Destructor. */
184 
185  /*!
186  \brief Enable/disable the cache of deleted rasters.
187  \param enabled Enable or disable this feature.
188  \note Only rasters without the write policy can be cached.
189  */
190  void enableDeletedRastersCache( const bool enabled );
191 
192  /*!
193  \brief Set the default rasters histograms bins.
194  \param binsNumber Histograms bins number ( When b = 0, the histogram will be divided according to all pixel values.).
195  */
196  void setDefaultRasterHistSize( const unsigned int binsNumber );
197 
198  /*!
199  \brief Get the default rasters histograms bins.
200  \return Get the default rasters histograms bins.
201  */
202  unsigned int getDefaultRasterHistSize();
203 
204  protected:
205 
206  /*!
207  \class SumManKey
208  \brief Summary manager key.
209  \ingroup rst
210  \sa RasterSummary, BandSummary.
211  */
212  class SumManKey
213  {
214  public :
215  unsigned int m_bandIndex;
216  unsigned int m_rowStart;
217  unsigned int m_colStart;
218  unsigned int m_finalRow;
219  unsigned int m_finalCol;
220  unsigned int m_histoBins;
221  unsigned int m_sampleStep;
222  Raster const* m_rasterPtr; // not used in comparison operators
223  te::common::AccessPolicy m_rasterPolicy; // not used in comparison operators
224  std::map<std::string, std::string> m_connInfo;
226 
228 
229  SumManKey(const SumManKey& other);
230 
232 
233  bool operator==( const SumManKey& other ) const;
234 
235  bool operator<( const SumManKey& other ) const;
236 
237  SumManKey& operator=(const SumManKey& other);
238  };
239 
240  typedef std::list< SumManKey > SummaryContT;
241 
243 
244  private:
245 
247  unsigned int m_defRastersHistBins;
248  SummaryContT m_rasterSummaries; //!< A rasters band summaries.
249  mutable std::mutex m_syncMutex; //!< Internal mutex.
250  };
251 
252  } // end namespace rst
253 } // end namespace te
254 
255 #endif // __TERRALIB_RASTER_INTERNAL_RASTERSUMMARYMANAGER_H
256 
te::rst::RasterSummaryManager::SumManKey::m_connInfo
std::map< std::string, std::string > m_connInfo
Definition: RasterSummaryManager.h:224
RasterSummary.h
RasterSummary is just a typedef of a boost::ptr_vector.
te::rst::RasterSummaryManager::SummaryContT
std::list< SumManKey > SummaryContT
Definition: RasterSummaryManager.h:240
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::rst::RasterSummaryManager::SumManKey::operator==
bool operator==(const SumManKey &other) const
te::rst::Raster
An abstract class for raster data strucutures.
Definition: Raster.h:72
te::rst::RasterSummaryManager::SumManKey::m_finalCol
unsigned int m_finalCol
Definition: RasterSummaryManager.h:219
te::rst::RasterSummaryManager::SumManKey
Summary manager key.
Definition: RasterSummaryManager.h:213
te::rst::RasterSummaryManager::find
bool find(const Raster *raster, const unsigned int bandIndex, const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins, const unsigned int sampleStep, BandSummary &summary) const
Searches for a band summary.
te::rst::RasterSummaryManager::setDefaultRasterHistSize
void setDefaultRasterHistSize(const unsigned int binsNumber)
Set the default rasters histograms bins.
te::rst::RasterSummaryManager::SumManKey::m_sampleStep
unsigned int m_sampleStep
Definition: RasterSummaryManager.h:221
te::rst::RasterSummaryManager::SumManKey::m_rowStart
unsigned int m_rowStart
Definition: RasterSummaryManager.h:216
te::rst::RasterSummaryManager::get
bool get(const Raster *raster, const unsigned int bandIndex, const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins, const unsigned int sampleStep, bool readall, BandSummary &summary)
Searches for a band summary and creates it if it does not exist.
te::rst::RasterSummaryManager::RasterSummaryManager
RasterSummaryManager()
TERASTEREXPORT
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:63
te::rst::RasterSummaryManager::m_enableDeletedRastersCache
bool m_enableDeletedRastersCache
Definition: RasterSummaryManager.h:246
te::rst::RasterSummaryManager::~RasterSummaryManager
~RasterSummaryManager()
Destructor.
Enums.h
Enumerations of XML module.
te::rst::RasterSummaryManager::get
bool get(const Raster *raster, const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins, const unsigned int sampleStep, bool readall, RasterSummary &summary)
It searches for a raster summary. If not found it creates the summary and returns it.
te::rst::RasterSummaryManager::get
bool get(const Raster *raster, bool readall, RasterSummary &summary)
It searches for a raster summary. If not found it creates the summary and returns it.
te::rst::RasterSummaryManager::SumManKey::operator<
bool operator<(const SumManKey &other) const
te::rst::RasterSummaryManager::SumManKey::m_histoBins
unsigned int m_histoBins
Definition: RasterSummaryManager.h:220
te::rst::RasterSummaryManager::m_defRastersHistBins
unsigned int m_defRastersHistBins
Definition: RasterSummaryManager.h:247
te::rst::RasterSummaryManager::SumManKey::m_bandIndex
unsigned int m_bandIndex
Definition: RasterSummaryManager.h:215
te::common::Singleton
Template support for singleton pattern.
Definition: Singleton.h:101
te::rst::RasterSummaryManager::SumManKey::operator=
SumManKey & operator=(const SumManKey &other)
te::rst::RasterSummaryManager::m_rasterSummaries
SummaryContT m_rasterSummaries
A rasters band summaries.
Definition: RasterSummaryManager.h:248
te::rst::RasterSummaryManager::SumManKey::m_colStart
unsigned int m_colStart
Definition: RasterSummaryManager.h:217
te::rst::RasterSummaryManager::SumManKey::SumManKey
SumManKey(const SumManKey &other)
te::rst::RasterSummaryManager::find
bool find(const Raster *raster, RasterSummary &summary) const
Searches for a raster summary.
te::rst::RasterSummaryManager::SumManKey::m_rasterPtr
Raster const * m_rasterPtr
Definition: RasterSummaryManager.h:222
te::rst::RasterSummaryManager::enableDeletedRastersCache
void enableDeletedRastersCache(const bool enabled)
Enable/disable the cache of deleted rasters.
te::rst::RasterSummaryManager
A singleton for keeping raster summaries (most statistics). It stores an internal map of raster conn ...
Definition: RasterSummaryManager.h:59
te::rst::RasterSummaryManager::SumManKey::SumManKey
SumManKey()
te::rst::RasterSummaryManager::SumManKey::m_finalRow
unsigned int m_finalRow
Definition: RasterSummaryManager.h:218
te::rst::RasterSummaryManager::getDefaultRasterHistSize
unsigned int getDefaultRasterHistSize()
Get the default rasters histograms bins.
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::rst::RasterSummaryManager::remove
void remove(const Raster *raster, const unsigned int bandIndex, const unsigned int rowStart, const unsigned int colStart, const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins, const unsigned int sampleStep)
Removes the summary from the specified raster.
te::rst::RasterSummary
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
te::rst::RasterSummaryManager::remove
void remove(const Raster *raster)
Removes all summary ocurrences related to the specified raster pointer.
te::rst::BandSummary
A summary of a raster band (most statistics).
Definition: BandSummary.h:48
te::rst::RasterSummaryManager::removeAll
void removeAll()
Removes all raster summary entries.
te::rst::RasterSummaryManager::SumManKey::m_rasterPolicy
te::common::AccessPolicy m_rasterPolicy
Definition: RasterSummaryManager.h:223
te::rst::RasterSummaryManager::SumManKey::~SumManKey
~SumManKey()
te::rst::RasterSummaryManager::m_syncMutex
std::mutex m_syncMutex
Internal mutex.
Definition: RasterSummaryManager.h:249
te::rst::RasterSummaryManager::SumManKey::m_summary
BandSummary m_summary
Definition: RasterSummaryManager.h:225
te::common::AccessPolicy
AccessPolicy
Supported data access policies (can be used as bitfield).
Definition: Enums.h:41
te::rst::RasterSummaryManager::get
bool get(const Raster *raster, const unsigned int bandIndex, bool readall, BandSummary &summary)
Searches for a band summary and creates it if it does not exist.