BlenderRule.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 #ifndef __TERRALIB_RP_INTERNAL_BLENDERRULE_H
21 #define __TERRALIB_RP_INTERNAL_BLENDERRULE_H
22 
23 #include "Config.h"
24 #include "BlenderTypeDefs.h"
25 #include "../raster/Raster.h"
26 #include "../raster/Interpolator.h"
27 #include "../geometry/MultiPolygon.h"
28 #include "../geometry/GeometricTransformation.h"
29 
30 #include <memory>
31 #include <vector>
32 
33 namespace te
34 {
35  namespace rp
36  {
37  class Blender;
38 
39  /*!
40  \class Blender Rule
41  \brief A rule used by the te::rst::Blender classe.
42  \ingroup rp_optical
43  */
45  {
46  public:
47 
48  virtual ~BlenderRule();
49 
50  /*!
51  \brief Return the current error message if there is any.
52 
53  \return Return the current error message if there is any.
54  */
55  const std::string& getErrorMessage() const;
56 
57  protected:
58 
59  friend class Blender;
60 
61  bool m_forceRaster1NoDataValue; //!< Use noDataValue as the input raster 1 no-data value (The original rasters no-data values will be ignored)
62  bool m_forceRaster2NoDataValue; //!< Use noDataValue as the input raster 2 no-data value (The original rasters no-data values will be ignored)
63  te::rst::Raster const * m_raster1Ptr; //!< Input raster 1.
64  te::rst::Raster const * m_raster2Ptr; //!< Input raster 2.
65  std::unique_ptr< te::gm::MultiPolygon > m_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.
66  std::unique_ptr< te::gm::MultiPolygon > m_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.
67  std::unique_ptr< 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).
68  te::rst::Interpolator::Method m_interpMethod1; //!< The interpolation method to use when reading raster 1 data.
69  te::rst::Interpolator::Method m_interpMethod2; //!< The interpolation method to use when reading raster 2 data.
70  double m_outputNoDataValue; //!< The output raster no-data value.
71  std::vector< unsigned int > m_raster1Bands; //!< Input raster 1 band indexes to use.
72  std::vector< unsigned int > m_raster2Bands; //!< Input raster 2 band indexes to use.
73  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).
74  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).
75  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).
76  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).
77  std::string m_errorMessage; //!< Current error message.
78 
79  BlenderRule( const BlenderRule& other );
80 
81  const BlenderRule& operator=( const BlenderRule& other );
82 
84 
85  /*!
86  \brief Inititate the blender instance.
87  \param raster1 Input raster 1.
88  \param raster1Bands Input raster 1 band indexes to use.
89  \param raster2 Input raster 2.
90  \param raster2Bands Input raster 2 band indexes to use (this vector has the same size as raster1Bands).
91  \param interpMethod1 The interpolation method to use when reading raster 1 data.
92  \param interpMethod2 The interpolation method to use when reading raster 2 data.
93  \param noDataValue The value returned where there is no pixel data bo blend.
94  \param forceRaster1NoDataValue Use noDataValue as the input raster 1 no-data value (The original rasters no-data values will be ignored)
95  \param forceRaster2NoDataValue Use noDataValue as the input raster 1 no-data value (The original rasters no-data values will be ignored)
96  \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).
97  \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).
98  \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).
99  \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).
100  \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.
101  \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.
102  \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).
103  \return true if ok, false on errors
104  \note Aboute scale and offset parametrs: outValue = ( inputValue * scale ) + offset
105  */
106  virtual bool initialize(
107  const te::rst::Raster& raster1,
108  const std::vector< unsigned int >& raster1Bands,
109  const te::rst::Raster& raster2,
110  const std::vector< unsigned int >& raster2Bands,
111  const te::rst::Interpolator::Method& interpMethod1,
112  const te::rst::Interpolator::Method& interpMethod2,
113  const double& noDataValue,
114  const bool forceRaster1NoDataValue,
115  const bool forceRaster2NoDataValue,
116  const std::vector< double >& pixelOffsets1,
117  const std::vector< double >& pixelScales1,
118  const std::vector< double >& pixelOffsets2,
119  const std::vector< double >& pixelScales2,
120  te::gm::MultiPolygon const * const r1ValidDataDelimiterPtr,
121  te::gm::MultiPolygon const * const r2ValidDataDelimiterPtr,
122  const te::gm::GeometricTransformation& geomTransformation );
123 
124  /*!
125  \brief Blend a pixel value using the current parameters.
126  \param line1 Line (raster 1 reference).
127  \param col1 Column (raster 1 reference).
128  \param line2 Line (raster 2).
129  \param col2 Column (raster 2).
130  \param blendedValuesPtr A pointer to a pre-allocated vector where the blended values will be stored.
131  \note The caller of this method must be aware that the returned blended value may be outside the original input rasters valid values range.
132  \note Raster 1 values have precedence over raster 2 values (when applicable).
133  */
134  virtual void getBlendedValues( const double& line1, const double& col1,
135  const double& line2, const double& col2, double* const blendedValuesPtr ) const = 0;
136 
137  /*!
138  \brief Create a clone of this instance.
139  \return A clone of this instance.
140  \note The caller of this method must take othe owndershipd of the returned pointer.
141  */
142  virtual BlenderRule* clone() const = 0;
143 
144  /*!
145  \brief Set the current error message.
146 
147  \param newErrorMessage New error message;
148  */
149  void setErrorMessage( const std::string& newErrorMessage );
150 
151  private :
152 
153  void initState();
154 
155  void clear();
156 
157  };
158 
159  } // end namespace rp
160 } // end namespace te
161 
162 #endif
163 
2D Geometric transformation base class.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:51
virtual ~BlenderRule()
te::rst::Raster const * m_raster1Ptr
Input raster 1.
Definition: BlenderRule.h:63
te::rst::Interpolator::Method m_interpMethod1
The interpolation method to use when reading raster 1 data.
Definition: BlenderRule.h:68
bool m_forceRaster2NoDataValue
Use noDataValue as the input raster 2 no-data value (The original rasters no-data values will be igno...
Definition: BlenderRule.h:62
std::vector< double > m_pixelScales2
The values scale to be applied to raster 2 pixel values before the blended value calcule (one element...
Definition: BlenderRule.h:76
virtual bool initialize(const te::rst::Raster &raster1, const std::vector< unsigned int > &raster1Bands, const te::rst::Raster &raster2, const std::vector< unsigned int > &raster2Bands, const te::rst::Interpolator::Method &interpMethod1, const te::rst::Interpolator::Method &interpMethod2, const double &noDataValue, const bool forceRaster1NoDataValue, const bool forceRaster2NoDataValue, const std::vector< double > &pixelOffsets1, const std::vector< double > &pixelScales1, const std::vector< double > &pixelOffsets2, const std::vector< double > &pixelScales2, te::gm::MultiPolygon const *const r1ValidDataDelimiterPtr, te::gm::MultiPolygon const *const r2ValidDataDelimiterPtr, const te::gm::GeometricTransformation &geomTransformation)
Inititate the blender instance.
std::unique_ptr< te::gm::MultiPolygon > m_r2ValidDataDelimiterPtr
A pointer to a geometry (raster 2 world/projected coords) delimiting the raster region with valid dat...
Definition: BlenderRule.h:66
std::vector< unsigned int > m_raster1Bands
Input raster 1 band indexes to use.
Definition: BlenderRule.h:71
bool m_forceRaster1NoDataValue
Use noDataValue as the input raster 1 no-data value (The original rasters no-data values will be igno...
Definition: BlenderRule.h:61
std::unique_ptr< te::gm::GeometricTransformation > m_geomTransformationPtr
A transformation mapping raster 1 pixels ( te::gm::GTParameters::TiePoint::first ) to raster 2 ( te::...
Definition: BlenderRule.h:67
const std::string & getErrorMessage() const
Return the current error message if there is any.
virtual void getBlendedValues(const double &line1, const double &col1, const double &line2, const double &col2, double *const blendedValuesPtr) const =0
Blend a pixel value using the current parameters.
BlenderRule(const BlenderRule &other)
te::rst::Interpolator::Method m_interpMethod2
The interpolation method to use when reading raster 2 data.
Definition: BlenderRule.h:69
te::rst::Raster const * m_raster2Ptr
Input raster 2.
Definition: BlenderRule.h:64
std::vector< unsigned int > m_raster2Bands
Input raster 2 band indexes to use.
Definition: BlenderRule.h:72
std::vector< double > m_pixelOffsets2
The values offset to be applied to raster 2 pixel values before the blended value calcule (one elemen...
Definition: BlenderRule.h:75
double m_outputNoDataValue
The output raster no-data value.
Definition: BlenderRule.h:70
virtual BlenderRule * clone() const =0
Create a clone of this instance.
std::unique_ptr< te::gm::MultiPolygon > m_r1ValidDataDelimiterPtr
A pointer to a geometry (raster 1 world/projected coords) delimiting the raster region with valid dat...
Definition: BlenderRule.h:65
std::vector< double > m_pixelScales1
The values scale to be applied to raster 1 pixel values before the blended value calcule (one element...
Definition: BlenderRule.h:74
const BlenderRule & operator=(const BlenderRule &other)
std::string m_errorMessage
Current error message.
Definition: BlenderRule.h:77
void setErrorMessage(const std::string &newErrorMessage)
Set the current error message.
std::vector< double > m_pixelOffsets1
The values offset to be applied to raster 1 pixel values before the blended value calcule (one elemen...
Definition: BlenderRule.h:73
Blended pixel value calculation for two overlaped rasters.
Definition: Blender.h:61
An abstract class for raster data strucutures.
Definition: Raster.h:72
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:93
TerraLib.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Proxy configuration file for TerraView (see terraview_config.h).