All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SpectralResponseFunctions.cpp
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/rp/SpectralResponseFunctions.cpp
22  \brief Spectral Response Functions.
23 */
24 
26 
27 namespace te
28 {
29  namespace rp
30  {
31  namespace srf
32  {
33  double interpolateSRF( const std::map< double, double >& sRFs,
34  const double& frequency )
35  {
36  std::map< double, double >::const_iterator it2 = sRFs.find( frequency );
37 
38  if( it2 == sRFs.end() )
39  {
40  it2 = sRFs.upper_bound( frequency );
41 
42  if( ( it2 == sRFs.begin() ) || ( it2 == sRFs.end() ) )
43  {
44  return 0.0;
45  }
46  else
47  {
48  std::map< double, double >::const_iterator it1 = it2;
49  --it1;
50 
51  double dist1 = frequency - it1->first;
52  assert( dist1 > 0.0 );
53  double dist2 = it2->first - frequency;
54  assert( dist2 > 0.0 );
55 
56  return (
57  ( it1->second * dist2 )
58  +
59  ( it2->second * dist1 )
60  )
61  /
62  ( dist1 + dist2 );
63  }
64  }
65  else
66  {
67  return it2->second;
68  }
69  }
70 
71  double getSRFArea( const std::map< double, double >& sRFs )
72  {
73  double returnValue = 0.0;
74 
75  std::map< double, double >::const_iterator it = sRFs.begin();
76  std::map< double, double >::const_iterator itPrev;
77  const std::map< double, double >::const_iterator itEnd = sRFs.end();
78 
79  while( it != itEnd )
80  {
81  if( it == sRFs.begin() )
82  {
83  itPrev = it;
84  }
85  else
86  {
87  returnValue += std::abs( it->second - itPrev->second ) *
88  ( it->first - itPrev->first ) / 2.0;
89  returnValue += ( it->first - itPrev->first ) *
90  std::min( it->second, itPrev->second );
91 
92  ++itPrev;
93  }
94 
95  ++it;
96  }
97 
98  return returnValue;
99  }
100 
101  void getIntersectionSRF( const std::map< double, double >& sRF1,
102  const std::map< double, double >& sRF2,
103  std::map< double, double >& intersectionSRF )
104  {
105  getUnionSRF( sRF1, sRF2, intersectionSRF );
106 
107  std::map< double, double >::const_iterator it = intersectionSRF.begin();
108  const std::map< double, double >::const_iterator itEnd = intersectionSRF.end();
109 
110  while( it != itEnd )
111  {
112  intersectionSRF[ it->first ] =
113  std::min(
114  interpolateSRF( sRF1, it->first ),
115  interpolateSRF( sRF2, it->first )
116  );
117 
118  ++it;
119  }
120  }
121 
122  void getUnionSRF( const std::map< double, double >& sRF1,
123  const std::map< double, double >& sRF2,
124  std::map< double, double >& unionSRF )
125  {
126  unionSRF = sRF2;
127 
128  std::map< double, double >::const_iterator it1 = sRF1.begin();
129  const std::map< double, double >::const_iterator it1End = sRF1.end();
130 
131  while( it1 != it1End )
132  {
133  unionSRF[ it1->first ] =
134  std::max(
135  interpolateSRF( unionSRF, it1->first ),
136  it1->second
137  );
138 
139  ++it1;
140  }
141  }
142 
143  }
144  }
145 } // end namespace te
146 
Spectral Response Functions.
void getIntersectionSRF(const std::map< double, double > &sRF1, const std::map< double, double > &sRF2, std::map< double, double > &intersectionSRF)
Return the intersetction SRF.
void getUnionSRF(const std::map< double, double > &sRF1, const std::map< double, double > &sRF2, std::map< double, double > &unionSRF)
Return the union SRF.
double interpolateSRF(const std::map< double, double > &sRFs, const double &frequency)
Return a SRF interpolated from the given SRFs.
double getSRFArea(const std::map< double, double > &sRFs)
Return the SRF area.