All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
GeometricRefining.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 Mul
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/GeometricRefining.h
22  \brief Geometric (and positioning) correction of a already geo-referenced raster using a set of reference rasters.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_GEOMETRICREFINING_H
26 #define __TERRALIB_RP_INTERNAL_GEOMETRICREFINING_H
27 
28 #include "Algorithm.h"
29 #include "FeedersRaster.h"
30 #include "TiePointsLocator.h"
31 #include "../raster/Raster.h"
32 #include "../raster/Interpolator.h"
33 #include "../geometry/GeometricTransformation.h"
34 #include "../geometry/Polygon.h"
35 
36 #include <vector>
37 #include <string>
38 #include <memory>
39 
40 namespace te
41 {
42  namespace rp
43  {
44  /*!
45  \class GeometricRefining
46  \brief Geometric (and positioning) correction/refining of a already geo-referenced raster using a set of small reference rasters.
47  \ingroup rp_gen
48  \note Reference: CASTEJON, E. F. ; FONSECA, L. M. G. ; ARCANJO, J. S. . Melhoria da geometria e posicionamento de imagens orbitais de média resolução - Um experimento com dados CBERS-CCD. In: XVI Simpósio Brasileiro de Sensoriamento Remoto - SBSR, 2013, Foz do Iguaçu, PR - Brasil. Anais do XVI Simpósio Brasileiro de Sensoriamento Remoto - SBSR, 2013.
49  */
51  {
52  public:
53 
54  /*!
55  \class InputParameters
56  \brief Input parameters
57  */
59  {
60  public:
61 
62  te::rst::Raster const* m_inRasterPtr; //!< Input raster pointer.
63 
64  std::vector< unsigned int > m_inRasterBands2Process; //!< Bands to process from the input raster.
65 
66  std::vector< unsigned int > m_inRasterTPLocationBands; //!< Input raster bands used for tie-points location.
67 
68  FeederConstRaster* m_referenceRastersPtr; //!< A feeder of reference rasters.
69 
70  std::vector< double > m_referenceRastersWeights; //!< A vector of weights for each reference raster, or an empty vector if all reference rasters have the same weight.
71 
72  std::vector< std::vector< unsigned int > > m_referenceTPLocationBands; //!< Reference rasters bands used for tie-points location.
73 
74  bool m_enableMultiThread; //!< Enable/Disable the use of threads (default:true).
75 
76  bool m_enableProgress; //!< Enable/Disable the progress interface (default:false).
77 
78  te::rst::Interpolator::Method m_interpMethod; //!< The raster interpolator method (default:NearestNeighbor).
79 
80  te::rp::TiePointsLocator::InputParameters m_locatorParams; //!< The parameters used by the tie-points locator when matching each raster (feeder) against the input raster (m_RasterPtr),leave untouched to use the default values.
81 
82  double m_minInRasterCoveredAreaPercent; //!< The mininumum required area percent (from the input raster ) covered by tie-points - valid range [0,100] (default:25).
83 
84  double m_minrReferenceRasterCoveredAreaPercent; //!< The mininumum required area percent (from each reference raster ) covered by tie-points - valid range [0,100] (default:50).
85 
86  double m_minrReferenceRasterRequiredTiePointsFactor; //!< The mininumum required tie-points factor over the minimum number of tie-points required by the choosen transformation model (from each reference raster ) covered by tie-points - valid range: positive numbers (default:1.5).
87 
88  unsigned int m_inRasterSubSectorsFactor; //!< A positive factor used to devide the input raster area into sectors ,(efault value: 3 ( 3 x 3 = 9 sub-sectors).
89 
90  unsigned int m_inRasterExpectedRowError; //!< The expected row position error for the given input raster (pixels units), default value:10.
91 
92  unsigned int m_inRasterExpectedColError; //!< The expected column position error for the given input raster (pixels units), default value:10.
93 
94  int m_inRasterExpectedRowDisplacement; //!< The expected input raster row displacement (pixel units, default:0)
95 
96  int m_inRasterExpectedColDisplacement; //!< The expected input raster row displacement (pixel units, default:0)
97 
98  bool m_processAllReferenceRasters; //!< If true, all reference rasters will be processed, if false the matching can finish when minimum quality criterias are achieved (default:true).
99 
100  bool m_enableRasterCache; //!< If true, a internal raster data cache will be used (defaul:true).
101 
102  std::string m_geomTransfName; //!< The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFactory inherited classes to find each factory key/name, default:affine).
103 
104  double m_geomTransfMaxTiePointError; //!< The maximum allowed tie-point error (pixels unit, default: 2);
105 
106  double m_outliersRemotionAssurance; //!< The error-free selection assurance - valid range (0-1) - Use Lower values for good tie-points sets - Higher values may increase the number of iterations. Use 0-zero to let this number be automatically found (default:0.75).
107 
108  unsigned int m_outliersRemotionMaxIterations; //!< The maximum number of iterations (Use 0-zero to let this number be automatically found, default:0).
109 
110  double m_outputNoDataValue; //!< The pixel value used where no output raster data is avaliable (defaul:0).
111 
112  InputParameters();
113 
114  InputParameters( const InputParameters& );
115 
116  ~InputParameters();
117 
118  //overload
119  void reset() throw( te::rp::Exception );
120 
121  //overload
122  const InputParameters& operator=( const InputParameters& params );
123 
124  //overload
125  AbstractParameters* clone() const;
126  };
127 
128  /*!
129  \class OutputParameters
130  \brief Output parameters
131  */
133  {
134  public:
135 
136  /*!
137  \brief Reference rasters matching info.
138  */
140  {
141  public :
142  /*!
143  \brief The matching result status.
144  */
145  enum Status
146  {
147  NotMatched, //!< Raster not matched.
148  Fail, //!< Raster matching failed.
149  Success //!< Raster matching success.
150  };
151 
152  Status m_status; //!< Matching result status
153 
154  unsigned int m_referenceRasterIndex; //!< Reference raster index.
155 
156  unsigned int m_searchAreaRowStart; //!< The searched area (over the input image) first row.
157 
158  unsigned int m_searchAreaColStart; //!< The searched area (over the input image) first column.
159 
160  unsigned int m_searchAreaWidth; //!< The searched area width (over the input image).
161 
162  unsigned int m_searchAreaHeigh; //!< The searched area height (over the input image).
163 
164  unsigned int m_matchedPositionRowStart; //!< The reference image matched position first row (over the input image).
165 
166  unsigned int m_matchedPositionColStart; //!< The reference image matched position first column (over the input image).
167 
168  unsigned int m_matchedPositionWidth; //!< The reference image matched position width (over the input image).
169 
170  unsigned int m_matchedPositionHeight; //!< The reference image matched position height (over the input image).
171 
172  std::vector< te::gm::GTParameters::TiePoint > m_tiePoints; //!< The tie-points generated by matching (first: input raster lines/cols, second:input raster corrected world coords).
173 
174  MatchingResult() : m_status( NotMatched ), m_referenceRasterIndex( 0 ),
175  m_searchAreaRowStart( 0 ), m_searchAreaColStart( 0 ), m_searchAreaWidth( 0 ),
176  m_searchAreaHeigh( 0 ), m_matchedPositionRowStart( 0 ),
177  m_matchedPositionColStart( 0 ), m_matchedPositionWidth( 0 ),
178  m_matchedPositionHeight( 0 ) {};
180  };
181 
182  double m_inRasterCoveredAreaPercent; //!< The area percent (from the input raster ) covered by tie-points - valid range [0,100].
183 
184  std::string m_rType; //!< Output raster data source type (as described in te::raster::RasterFactory ).
185 
186  std::map< std::string, std::string > m_rInfo; //!< The necessary information to create the raster (as described in te::raster::RasterFactory).
187 
188  std::auto_ptr< te::rst::Raster > m_outputRasterPtr; //!< A pointer the generated output raster.
189 
190  std::vector< MatchingResult > m_matchingResult; //!< The matching result status for all given reference rasters.
191 
192  std::auto_ptr< te::gm::GeometricTransformation > m_geomTransPtr; //!< The geometric transformation (direct mapping raster lines/cols to input raster corrected world coords) used to generate the output raster.
193 
194  std::vector< te::gm::GTParameters::TiePoint > m_tiePoints; //!< The tie-points in agreenment with the geometric transformation given by m_geomTransPtr (first: input raster lines/cols, second:input raster corrected world coords).
195 
197 
199 
200  ~OutputParameters();
201 
202  //overload
203  void reset() throw( te::rp::Exception );
204 
205  //overload
206  const OutputParameters& operator=( const OutputParameters& params );
207 
208  //overload
209  AbstractParameters* clone() const;
210  };
211 
213 
215 
216  //overload
217  bool execute( AlgorithmOutputParameters& outputParams ) throw( te::rp::Exception );
218 
219  //overload
220  void reset() throw( te::rp::Exception );
221 
222  //overload
223  bool initialize( const AlgorithmInputParameters& inputParams ) throw( te::rp::Exception );
224 
225  bool isInitialized() const;
226 
227  protected:
228 
229  /*!
230  \brief Reference rasters matching info.
231  */
233  {
234  unsigned int m_referenceRasterIndex; //!< Reference raster index.
235  std::vector< te::gm::GTParameters::TiePoint > m_tiePoints; //!< The tie-points generated by matching (first: input rasters lines/cols, second:input raster world coords).
236  double m_convexHullAreaPercent; //!< The tie points covered area percent [0,1].
237  };
238 
239  GeometricRefining::InputParameters m_inputParameters; //!< Input execution parameters.
240 
241  bool m_isInitialized; //!< Tells if this instance is initialized.
242 
243  /*!
244  \brief Convesion from matching infor tie-points to a vector of tie-points
245 
246  \param inTiePoints Input tie-points.
247 
248  \param outTiePoints Output tie-points //!< The tie-points generated by matching (first: input rasters lines/cols, second:input raster world coords).
249 
250  \param outTiePointsWeights Output tie-points weights.
251  */
252  void convert(
253  const std::vector< InternalMatchingInfo >& inTiePoints,
254  std::vector< te::gm::GTParameters::TiePoint >& outTiePoints,
255  std::vector< double >& outTiePointsWeights ) const;
256 
257  /*!
258  \brief Returns the tie points converx hull area.
259 
260  \param tiePoints Input tie-points.
261 
262  \param useTPSecondCoordPair If true the sencond tie-point component (te::gm::GTParameters::TiePoint::second) will be used for the area calcule, otherwize the first component will be used.
263 
264  \return Returns the tie points converx hull area.
265  */
266  double getTPConvexHullArea(
267  const std::vector< te::gm::GTParameters::TiePoint >& tiePoints,
268  const bool useTPSecondCoordPair ) const;
269 
270  /*!
271  \brief Returns the tie points converx hull.
272 
273  \param tiePoints Input tie-points.
274 
275  \param useTPSecondCoordPair If true the sencond tie-point component (te::gm::GTParameters::TiePoint::second) will be used for the area calcule, otherwize the first component will be used.
276 
277  \return Returns true if ok. false on errors.
278  */
279  bool getTPConvexHull(
280  const std::vector< te::gm::GTParameters::TiePoint >& tiePoints,
281  const bool useTPSecondCoordPair,
282  std::auto_ptr< te::gm::Surface >& convexHullPtr ) const;
283 
284  /*!
285  \brief Try to instantiate a valid geometric transformation following the user parameters.
286 
287  \param inTiePoints Input tie-points.
288 
289  \param baseGeometricTransformPtr The output base geometric transformation (with the minumim required tie-points).
290 
291  \param baseTransAgreementTiePoints The filtered output tie-points (non-outliers) in agreenment with the generated base transformation.
292 
293  \param convexHullAreaPercent The input raster area percent covered by tie-points - range [0,100].
294 
295  \return true if OK, false on errors.
296  */
297  bool getTransformation( const std::vector< InternalMatchingInfo >& inTiePoints,
298  std::auto_ptr< te::gm::GeometricTransformation >& baseGeometricTransformPtr,
299  std::vector< te::gm::GTParameters::TiePoint >& baseTransAgreementTiePoints,
300  double& convexHullAreaPercent ) const;
301  };
302 
303  } // end namespace rp
304 } // end namespace te
305 
306 #endif
307 
unsigned int m_inRasterExpectedColError
The expected column position error for the given input raster (pixels units), default value:10...
unsigned int m_referenceRasterIndex
Reference raster index.
double m_outputNoDataValue
The pixel value used where no output raster data is avaliable (defaul:0).
Geometric (and positioning) correction/refining of a already geo-referenced raster using a set of sma...
te::rst::Interpolator::Method m_interpMethod
The raster interpolator method (default:NearestNeighbor).
unsigned int m_matchedPositionWidth
The reference image matched position width (over the input image).
double m_inRasterCoveredAreaPercent
The area percent (from the input raster ) covered by tie-points - valid range [0,100].
double m_minrReferenceRasterCoveredAreaPercent
The mininumum required area percent (from each reference raster ) covered by tie-points - valid range...
int m_inRasterExpectedRowDisplacement
The expected input raster row displacement (pixel units, default:0)
double m_geomTransfMaxTiePointError
The maximum allowed tie-point error (pixels unit, default: 2);.
unsigned int m_searchAreaRowStart
The searched area (over the input image) first row.
TiePointsLocator input parameters.
Raster Processing algorithm output parameters base interface.
unsigned int m_matchedPositionColStart
The reference image matched position first column (over the input image).
double m_minInRasterCoveredAreaPercent
The mininumum required area percent (from the input raster ) covered by tie-points - valid range [0...
te::rst::Raster const * m_inRasterPtr
Input raster pointer.
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The tie-points generated by matching (first: input raster lines/cols, second:input raster corrected w...
bool m_enableMultiThread
Enable/Disable the use of threads (default:true).
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
std::auto_ptr< te::gm::GeometricTransformation > m_geomTransPtr
The geometric transformation (direct mapping raster lines/cols to input raster corrected world coords...
unsigned int m_searchAreaHeigh
The searched area height (over the input image).
Raster Processing algorithm base interface.
Definition: Algorithm.h:41
std::vector< std::vector< unsigned int > > m_referenceTPLocationBands
Reference rasters bands used for tie-points location.
std::auto_ptr< te::rst::Raster > m_outputRasterPtr
A pointer the generated output raster.
bool m_isInitialized
Tells if this instance is initialized.
std::vector< double > m_referenceRastersWeights
A vector of weights for each reference raster, or an empty vector if all reference rasters have the s...
An abstract class for raster data strucutures.
Definition: Raster.h:71
GeometricRefining::InputParameters m_inputParameters
Input execution parameters.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:111
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The tie-points generated by matching (first: input rasters lines/cols, second:input raster world coor...
bool m_enableRasterCache
If true, a internal raster data cache will be used (defaul:true).
Raster Processing algorithm base interface class.
std::vector< unsigned int > m_inRasterTPLocationBands
Input raster bands used for tie-points location.
unsigned int m_inRasterExpectedRowError
The expected row position error for the given input raster (pixels units), default value:10...
unsigned int m_inRasterSubSectorsFactor
A positive factor used to devide the input raster area into sectors ,(efault value: 3 ( 3 x 3 = 9 sub...
Method
Allowed interpolation methods.
Definition: Interpolator.h:61
std::map< std::string, std::string > m_rInfo
The necessary information to create the raster (as described in te::raster::RasterFactory).
double m_outliersRemotionAssurance
The error-free selection assurance - valid range (0-1) - Use Lower values for good tie-points sets - ...
Feeder from a input rasters.
Definition: FeedersRaster.h:45
unsigned int m_referenceRasterIndex
Reference raster index.
unsigned int m_matchedPositionHeight
The reference image matched position height (over the input image).
int m_inRasterExpectedColDisplacement
The expected input raster row displacement (pixel units, default:0)
double m_convexHullAreaPercent
The tie points covered area percent [0,1].
bool m_enableProgress
Enable/Disable the progress interface (default:false).
unsigned int m_outliersRemotionMaxIterations
The maximum number of iterations (Use 0-zero to let this number be automatically found, default:0).
TiePointsLocator locator.
Raster Processing algorithm input parameters base interface.
std::string convert(const path &v)
URI path to string.
Definition: path.cpp:219
std::vector< unsigned int > m_inRasterBands2Process
Bands to process from the input raster.
FeederConstRaster * m_referenceRastersPtr
A feeder of reference rasters.
unsigned int m_searchAreaWidth
The searched area width (over the input image).
std::string m_geomTransfName
The name of the geometric transformation used to ensure tie-points consistency (see each te::gm::GTFa...
unsigned int m_matchedPositionRowStart
The reference image matched position first row (over the input image).
Raster objects feeders.
std::vector< MatchingResult > m_matchingResult
The matching result status for all given reference rasters.
unsigned int m_searchAreaColStart
The searched area (over the input image) first column.
bool m_processAllReferenceRasters
If true, all reference rasters will be processed, if false the matching can finish when minimum quali...
te::rp::TiePointsLocator::InputParameters m_locatorParams
The parameters used by the tie-points locator when matching each raster (feeder) against the input ra...
std::vector< te::gm::GTParameters::TiePoint > m_tiePoints
The tie-points in agreenment with the geometric transformation given by m_geomTransPtr (first: input ...
double m_minrReferenceRasterRequiredTiePointsFactor
The mininumum required tie-points factor over the minimum number of tie-points required by the choose...