All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RasterSummaryManager.cpp
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/RasterSummaryManager.cpp
22 
23  \brief A singleton for keeping raster summaries (most statistics).
24 */
25 
26 // TerraLib
27 #include "Band.h"
28 #include "Raster.h"
29 #include "RasterSummary.h"
30 #include "RasterSummaryManager.h"
31 
32 // STL
33 #include <complex>
34 
36 {
37  if (m_rasterSummaries.find(raster) != m_rasterSummaries.end())
38  m_rasterSummaries.erase(raster);
39 
40  m_rasterSummaries.insert(raster, summary);
41 }
42 
44 {
45  if (m_rasterSummaries.find(raster) == m_rasterSummaries.end())
46  return 0;
47 
48  return &m_rasterSummaries.at(raster);
49 }
50 
52 {
53  m_rasterSummaries.erase(raster);
54 }
55 
57 {
58  boost::ptr_map<const Raster*, RasterSummary>::iterator it = m_rasterSummaries.find(raster);
59 
60  te::rst::RasterSummary* rs = 0;
61 
62  if(it == m_rasterSummaries.end())
63  {
64  rs = new te::rst::RasterSummary(raster->getNumberOfBands());
65 
66  for (std::size_t i = 0; i < raster->getNumberOfBands(); i++)
67  rs->push_back(new te::rst::BandSummary());
68 
69  add(raster, rs);
70  }
71  else
72  rs = it->second;
73  //rs = new te::rst::RasterSummary(*find(raster));
74 
75  for (std::size_t b = 0; b < raster->getNumberOfBands(); b++)
76  {
77  te::rst::BandSummary& bs = (*rs)[b];
78 
79  if (types & te::rst::SUMMARY_R_HISTOGRAM && bs.m_histogramR == 0)
80  {
81  bs.m_histogramR = new std::map<double, unsigned>(raster->getBand(b)->getHistogramR());
82 
83  std::map<double, unsigned>::iterator it = bs.m_histogramR->begin();
84 
85  if (!bs.m_minVal)
86  bs.m_minVal = new std::complex<double>(it->first, 0.0);
87  else
88  bs.m_minVal = new std::complex<double>(it->first, bs.m_minVal->imag());
89 
90  it = bs.m_histogramR->end();
91 
92  if (!bs.m_maxVal)
93  bs.m_maxVal = new std::complex<double>((--it)->first, 0.0);
94  else
95  bs.m_maxVal = new std::complex<double>((--it)->first, bs.m_maxVal->imag());
96  }
97 
98  if (types & te::rst::SUMMARY_I_HISTOGRAM && bs.m_histogramI == 0)
99  {
100  bs.m_histogramI = new std::map<double, unsigned>(raster->getBand(b)->getHistogramI());
101 
102  std::map<double, unsigned>::iterator it = bs.m_histogramI->begin();
103 
104  if (!bs.m_minVal)
105  bs.m_minVal = new std::complex<double>(0.0, it->first);
106  else
107  bs.m_minVal = new std::complex<double>(bs.m_minVal->real(), it->first);
108 
109  it = bs.m_histogramI->end();
110 
111  if (!bs.m_maxVal)
112  bs.m_maxVal = new std::complex<double>(0.0, (--it)->first);
113  else
114  bs.m_maxVal = new std::complex<double>(bs.m_maxVal->real(), (--it)->first);
115  }
116 
117  if (types & te::rst::SUMMARY_MIN && bs.m_minVal == 0)
118  bs.m_minVal = new std::complex<double>(raster->getBand(b)->getMinValue());
119 
120  if (types & te::rst::SUMMARY_MAX && bs.m_maxVal == 0)
121  bs.m_maxVal = new std::complex<double>(raster->getBand(b)->getMaxValue());
122 
123  if (types & te::rst::SUMMARY_STD && bs.m_stdVal == 0)
124  bs.m_stdVal = new std::complex<double>(raster->getBand(b)->getStdValue());
125 
126  if (types & te::rst::SUMMARY_MEAN && bs.m_meanVal == 0)
127  bs.m_meanVal = new std::complex<double>(raster->getBand(b)->getMeanValue());
128  }
129 
130  return rs;
131 }
132 
134 {
135 }
136 
138 {
139 }
140 
Calculate the histogram for the imaginary part.
Definition: Enums.h:45
std::map< double, unsigned int > * m_histogramR
The histogram (a map of occurring values and frequency) of the real part of a band.
Definition: BandSummary.h:82
virtual std::complex< double > getMinValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the minimum occurring value in a window of the band.
Definition: Band.cpp:80
std::complex< double > * m_minVal
The minimum occurring values (real and imaginary), default is std::numeric_limits::min().
Definition: BandSummary.h:78
A singleton for keeping raster summaries (most statistics).
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
std::complex< double > * m_stdVal
The standard deviation of the occurring values (real and imaginary), default is 1.0.
Definition: BandSummary.h:80
virtual std::map< double, unsigned > getHistogramR(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0, unsigned int b=0) const
It computes and returns the histogram occurring values (real part) in a window of the band...
Definition: Band.cpp:202
std::map< double, unsigned int > * m_histogramI
The histogram (a map of occurring values and frequency) of the imaginary part of a band...
Definition: BandSummary.h:83
const RasterSummary * get(const Raster *raster, const SummaryTypes st)
It searches for a raster summary. If not found it creates the summary and returns it...
void add(const Raster *raster, RasterSummary *summary)
Adds a new entry in the summary manager.
virtual std::map< double, unsigned > getHistogramI(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0, unsigned int b=0) const
It computes and returns the histogram occurring values (imaginary part) in a window of the band...
Definition: Band.cpp:276
std::complex< double > * m_maxVal
The maximum occurring values (real and imaginary), default is std::numeric_limits::max().
Definition: BandSummary.h:79
const RasterSummary * find(const Raster *raster) const
It searches for a raster summary.
An abstract class for raster data strucutures.
virtual std::complex< double > getStdValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the standard deviation of the occurring values in a window of the band...
Definition: Band.cpp:138
An abstract class for raster data strucutures.
Definition: Raster.h:71
boost::ptr_map< const Raster *, RasterSummary > m_rasterSummaries
A map of rasters and their respective summaries.
Calculate the standard deviation value.
Definition: Enums.h:42
SummaryTypes
Types for the BandSummary.
Definition: Enums.h:38
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
RasterSummary is just a typedef of a boost::ptr_vector.
virtual std::complex< double > getMaxValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the maximum occurring value in a window of the band.
Definition: Band.cpp:109
A summary of a raster band (most statistics).
Definition: BandSummary.h:47
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
Definition: RasterSummary.h:44
It gives access to values in one band (dimension) of a raster.
virtual std::complex< double > getMeanValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the mean of the occurring values in a window of the band. ...
Definition: Band.cpp:173
Calculate the min value.
Definition: Enums.h:40
Calculate the max value.
Definition: Enums.h:41
void remove(const Raster *raster)
Removes the summary from the specified raster.
Calculate the mean value.
Definition: Enums.h:43
std::complex< double > * m_meanVal
The mean of the occurring values (real and imaginary), default is 0.0.
Definition: BandSummary.h:81
Calculate the histogram for the real part.
Definition: Enums.h:44