All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Blender.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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/Blender.h
22  \brief Blended pixel value calculation for two overlaped rasters.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_BLENDER_H
26 #define __TERRALIB_RP_INTERNAL_BLENDER_H
27 
28 #include "Config.h"
29 #include "Macros.h"
30 #include "../raster/Grid.h"
31 #include "../raster/Raster.h"
32 #include "../raster/Interpolator.h"
33 #include "../geometry/Polygon.h"
34 #include "../geometry/MultiPolygon.h"
35 #include "../geometry/Point.h"
36 #include "../geometry/GeometricTransformation.h"
37 
38 #include <boost/noncopyable.hpp>
39 
40 #include <vector>
41 #include <complex>
42 #include <memory>
43 
44 namespace te
45 {
46  namespace rp
47  {
48  /*!
49  \class Blender
50  \brief Blended pixel value calculation for two overlaped rasters.
51  \details The overlap between the two images is modeled by the given geometric transformation direct mapping input raster 1 indexed coords (line, column) to input raster 2 indexed coords.
52  */
53  class TERPEXPORT Blender : public boost::noncopyable
54  {
55  public:
56 
57  /*! \enum BlendMethod Pixel Blend methods. */
59  {
60  InvalidBlendMethod = 0, //!< Invalid blending method.
61  NoBlendMethod = 1, //!< No blending performed.
62  EuclideanDistanceMethod = 2 //!< Euclidean distance method.
63  };
64 
65  /*! Default constructor. */
66  Blender();
67 
68  /*! Default destructor. */
69  ~Blender();
70 
71  /*!
72  \brief Inititate the blender instance.
73  \param raster1 Input raster 1.
74  \param raster1Bands Input raster 1 band indexes to use.
75  \param raster2 Input raster 2.
76  \param raster2Bands Input raster 2 band indexes to use (this vector has the same size as raster1Bands).
77  \param blendMethod The blend method to apply.
78  \param interpMethod1 The interpolation method to use when reading raster 1 data.
79  \param interpMethod2 The interpolation method to use when reading raster 2 data.
80  \param noDataValue The value returned where there is no pixel data bo blend.
81  \param forceInputNoDataValue Use noDataValue as the input rasters no-data value (The original rasters no-data values will be ignored)
82  \param pixelOffsets1 The values offset to be applied to raster 1 pixel values before the blended value calcule (one element for each used raster channel/band).
83  \param pixelScales1 The values scale to be applied to raster 1 pixel values before the blended value calcule (one element for each used raster channel/band).
84  \param pixelOffsets2 The values offset to be applied to raster 2 pixel values before the blended value calcule (one element for each used raster channel/band).
85  \param pixelScales2 The values scale to be applied to raster 2 pixel values before the blended value calcule (one element for each used raster channel/band).
86  \param r1ValidDataDelimiterPtr A pointer to a geometry (raster 1 world/projected coords) delimiting the raster region with valid data, or null if all raster data area is valid.
87  \param r2ValidDataDelimiterPtr A pointer to a geometry (raster 2 world/projected coords) delimiting the raster region with valid data, or null if all raster data area is valid.
88  \param geomTransformation A transformation mapping raster 1 pixels ( te::gm::GTParameters::TiePoint::first ) to raster 2 pixels ( te::gm::GTParameters::TiePoint::second ) (Note: all coords are indexed by lines/columns).
89  \return true if ok, false on errors
90  */
91  bool initialize(
92  const te::rst::Raster& raster1,
93  const std::vector< unsigned int >& raster1Bands,
94  const te::rst::Raster& raster2,
95  const std::vector< unsigned int >& raster2Bands,
96  const BlendMethod& blendMethod,
97  const te::rst::Interpolator::Method& interpMethod1,
98  const te::rst::Interpolator::Method& interpMethod2,
99  const double& noDataValue,
100  const bool forceInputNoDataValue,
101  const std::vector< double >& pixelOffsets1,
102  const std::vector< double >& pixelScales1,
103  const std::vector< double >& pixelOffsets2,
104  const std::vector< double >& pixelScales2,
105  te::gm::Polygon const * const r1ValidDataDelimiterPtr,
106  te::gm::Polygon const * const r2ValidDataDelimiterPtr,
107  const te::gm::GeometricTransformation& geomTransformation );
108 
109 
110  /*!
111  \brief Blend a pixel value using the current parameters.
112  \param line Line (raster 1 reference).
113  \param col Column (raster 1 reference).
114  \param values Blended values for each band.
115  \note The caller of this method must be aware that the returned blended value may be outside the original input rasters valid values range.
116  \note Raster 1 values have precedence over raster 2 values (when applicable).
117  */
118  inline void getBlendedValues( const double& line, const double& col,
119  std::vector< double >& values )
120  {
121  TERP_DEBUG_TRUE_OR_THROW( m_blendFuncPtr, "Invalid blend function pointer" );
122  (this->*m_blendFuncPtr)( line, col, values );
123  };
124 
125  protected:
126 
127  /*!
128  \brief Type definition for the a bleding function pointer.
129  \param line Raster 1 Line.
130  \param col Raster 1 Column.
131  \param values Blended values for each band.
132  */
133  typedef void (Blender::*BlendFunctPtr)( const double& line,
134  const double& col, std::vector< double >& values );
135 
136  BlendMethod m_blendMethod; //!< The blend method to apply.
137  BlendFunctPtr m_blendFuncPtr; //!< The current blend function.
138  te::rst::Raster const* m_raster1Ptr; //!< Input raster 1.
139  te::rst::Raster const* m_raster2Ptr; //!< Input raster 2.
140  std::auto_ptr< te::gm::MultiPolygon > m_intersectionPtr; //!< The Intersection geometry ( Multipolygon geometry - raster 1 indexed coods).
141  std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r1IntersectionSegmentsPoints; //!< A sub-set of the intersection polygon wich is part of raster 1 valid data polygon ( raster 1 indexed coods).
142  std::size_t m_r1IntersectionSegmentsPointsSize; //!< Size of m_r1IntersectionSegmentsPoints;
143  std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r2IntersectionSegmentsPoints; //!< A sub-set of the intersection polygon wich is part of raster 2 valid data polygon ( raster 1 indexed coods).
144  std::size_t m_r2IntersectionSegmentsPointsSize; //!< Size of m_r2IntersectionSegmentsPoints;
145  te::gm::GeometricTransformation* m_geomTransformationPtr; //!< A transformation mapping raster 1 pixels ( te::gm::GTParameters::TiePoint::first ) to raster 2 ( te::gm::GTParameters::TiePoint::second ) (Note: all coords are indexed by lines/columns).
146  te::rst::Interpolator::Method m_interpMethod1; //!< The interpolation method to use when reading raster 1 data.
147  te::rst::Interpolator::Method m_interpMethod2; //!< The interpolation method to use when reading raster 2 data.
148  double m_outputNoDataValue; //!< The output raster no-data value.
149  te::rst::Interpolator* m_interp1; //!< Raster 1 interpolator instance pointer.
150  te::rst::Interpolator* m_interp2; //!< Raster 2 interpolator instance pointer.
151  std::vector< unsigned int > m_raster1Bands; //!< Input raster 1 band indexes to use.
152  std::vector< unsigned int > m_raster2Bands; //!< Input raster 2 band indexes to use.
153  std::vector< double > m_pixelOffsets1; //!< The values offset to be applied to raster 1 pixel values before the blended value calcule (one element for each used raster channel/band).
154  std::vector< double > m_pixelScales1; //!< The values scale to be applied to raster 1 pixel values before the blended value calcule (one element for each used raster channel/band).
155  std::vector< double > m_pixelOffsets2; //!< The values offset to be applied to raster 2 pixel values before the blended value calcule (one element for each used raster channel/band).
156  std::vector< double > m_pixelScales2; //!< The values scale to be applied to raster 2 pixel values before the blended value calcule (one element for each used raster channel/band).
157  std::vector< double > m_raster1NoDataValues; //! Raster 1 no-data values (on value per band).
158  std::vector< double > m_raster2NoDataValues; //! Raster 2 no-data values (on value per band).
159 
160  // variables used by the noBlendMethodImp method
167  std::complex< double > m_noBlendMethodImp_cValue;
170 
171  // variables used by the euclideanDistanceMethodImp method
175  std::complex< double > m_euclideanDistanceMethodImp_cValue1;
176  std::complex< double > m_euclideanDistanceMethodImp_cValue2;
184 
185 
186  /*! \brief Reset the instance to its initial default state. */
187  void initState();
188 
189  /*! \brief Clear all internal allocated resources. */
190  void clear();
191 
192  /*!
193  \brief Implementation for NoBlendMethod.
194  \param line Raster 1 Line.
195  \param col Raster 1 Column.
196  \param values Blended values for each band.
197  */
198  void noBlendMethodImp( const double& line1, const double& col1,
199  std::vector< double >& values );
200 
201  /*!
202  \brief Implementation for EuclideanDistanceMethod.
203  \param line Raster 1 Line.
204  \param col Raster 1 Column.
205  \param values Blended values for each band.
206  */
207  void euclideanDistanceMethodImp( const double& line1, const double& col1,
208  std::vector< double >& values );
209  };
210 
211  } // end namespace rp
212 } // end namespace te
213 
214 #endif // __TERRALIB_RP_INTERNAL_ALGORITHM_H
215 
std::vector< unsigned int > m_raster1Bands
Input raster 1 band indexes to use.
Definition: Blender.h:151
te::rst::Interpolator * m_interp1
Raster 1 interpolator instance pointer.
Definition: Blender.h:149
#define TERP_DEBUG_TRUE_OR_THROW(value, message)
Checks if value is true and throws an exception if not.
Definition: Macros.h:356
std::vector< double > m_pixelOffsets2
The values offset to be applied to raster 2 pixel values before the blended value calcule (one elemen...
Definition: Blender.h:155
std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r1IntersectionSegmentsPoints
A sub-set of the intersection polygon wich is part of raster 1 valid data polygon ( raster 1 indexed ...
Definition: Blender.h:141
std::vector< unsigned int > m_raster2Bands
Input raster 2 band indexes to use.
Definition: Blender.h:152
double m_euclideanDistanceMethodImp_aux1
Definition: Blender.h:182
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
std::size_t m_euclideanDistanceMethodImp_vecIdx
Definition: Blender.h:181
std::vector< double > m_pixelScales2
The values scale to be applied to raster 2 pixel values before the blended value calcule (one element...
Definition: Blender.h:156
std::complex< double > m_euclideanDistanceMethodImp_cValue2
Definition: Blender.h:176
te::rst::Interpolator * m_interp2
Raster 2 interpolator instance pointer.
Definition: Blender.h:150
te::rst::Interpolator::Method m_interpMethod1
The interpolation method to use when reading raster 1 data.
Definition: Blender.h:146
double m_noBlendMethodImp_Point2Col
Definition: Blender.h:166
Blended pixel value calculation for two overlaped rasters.
Definition: Blender.h:53
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
Definition: Interpolator.h:51
te::gm::GeometricTransformation * m_geomTransformationPtr
A transformation mapping raster 1 pixels ( te::gm::GTParameters::TiePoint::first ) to raster 2 ( te::...
Definition: Blender.h:145
BlendMethod m_blendMethod
The blend method to apply.
Definition: Blender.h:136
void getBlendedValues(const double &line, const double &col, std::vector< double > &values)
Blend a pixel value using the current parameters.
Definition: Blender.h:118
Method
Allowed interpolation methods.
Definition: Interpolator.h:58
double m_noBlendMethodImp_Point1XProj1
Raster 2 no-data values (on value per band).
Definition: Blender.h:161
std::complex< double > m_euclideanDistanceMethodImp_cValue1
Definition: Blender.h:175
te::rst::Raster const * m_raster1Ptr
Input raster 1.
Definition: Blender.h:138
double m_euclideanDistanceMethodImp_Point2Line
Definition: Blender.h:173
unsigned int m_euclideanDistanceMethodImp_BandIdx
Definition: Blender.h:177
std::vector< double > m_raster1NoDataValues
Definition: Blender.h:157
te::rst::Raster const * m_raster2Ptr
Input raster 2.
Definition: Blender.h:139
double m_euclideanDistanceMethodImp_Point2Col
Definition: Blender.h:174
std::size_t m_r2IntersectionSegmentsPointsSize
Size of m_r2IntersectionSegmentsPoints;.
Definition: Blender.h:144
std::auto_ptr< te::gm::MultiPolygon > m_intersectionPtr
The Intersection geometry ( Multipolygon geometry - raster 1 indexed coods).
Definition: Blender.h:140
A point with x and y coordinate values.
Definition: Point.h:50
double m_outputNoDataValue
The output raster no-data value.
Definition: Blender.h:148
std::vector< double > m_raster2NoDataValues
Raster 1 no-data values (on value per band).
Definition: Blender.h:158
te::gm::Point m_euclideanDistanceMethodImp_auxPoint
Definition: Blender.h:172
std::size_t m_r1IntersectionSegmentsPointsSize
Size of m_r1IntersectionSegmentsPoints;.
Definition: Blender.h:142
double m_euclideanDistanceMethodImp_currDist
Definition: Blender.h:178
double m_noBlendMethodImp_Value
Definition: Blender.h:168
Configuration flags for the Raster Processing module of TerraLib.
double m_euclideanDistanceMethodImp_aux2
Definition: Blender.h:183
unsigned int m_noBlendMethodImp_BandIdx
Definition: Blender.h:169
2D Geometric transformation base class.
double m_noBlendMethodImp_Point1XProj2
Definition: Blender.h:163
te::rst::Interpolator::Method m_interpMethod2
The interpolation method to use when reading raster 2 data.
Definition: Blender.h:147
std::vector< std::pair< te::gm::Coord2D, te::gm::Coord2D > > m_r2IntersectionSegmentsPoints
A sub-set of the intersection polygon wich is part of raster 2 valid data polygon ( raster 1 indexed ...
Definition: Blender.h:143
std::vector< double > m_pixelOffsets1
The values offset to be applied to raster 1 pixel values before the blended value calcule (one elemen...
Definition: Blender.h:153
An abstract class for raster data strucutures.
Definition: Raster.h:70
double m_noBlendMethodImp_Point1YProj2
Definition: Blender.h:164
double m_euclideanDistanceMethodImp_dist2
Definition: Blender.h:180
double m_noBlendMethodImp_Point1YProj1
Definition: Blender.h:162
std::vector< double > m_pixelScales1
The values scale to be applied to raster 1 pixel values before the blended value calcule (one element...
Definition: Blender.h:154
double m_noBlendMethodImp_Point2Line
Definition: Blender.h:165
BlendFunctPtr m_blendFuncPtr
The current blend function.
Definition: Blender.h:137
std::complex< double > m_noBlendMethodImp_cValue
Definition: Blender.h:167
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:91
double m_euclideanDistanceMethodImp_dist1
Definition: Blender.h:179