TiePointsLocatorStrategy.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 /*!
21  \file terralib/rp/TiePointsLocatorStrategy.h
22  \brief Tie-Pointsr locator strategy.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORSTRATEGY_H
26 #define __TERRALIB_RP_INTERNAL_TIEPOINTSLOCATORSTRATEGY_H
27 
28 #include "Config.h"
29 #include "Matrix.h"
31 #include "../geometry/GTParameters.h"
32 #include "../raster/Raster.h"
33 #include "../raster/Interpolator.h"
34 
35 #include <vector>
36 #include <set>
37 #include <string>
38 #include <list>
39 #include <memory>
40 
41 namespace te
42 {
43  namespace rp
44  {
45  // Forwards
46  class TiePointsLocator;
47 
48  /*!
49  \class TiePointsLocatorStrategy
50  \brief Tie-points locator strategy.
51  */
53  {
54  friend class TiePointsLocator;
55 
56  public:
57 
58  virtual ~TiePointsLocatorStrategy();
59 
60  /*!
61  \brief Returns a sub-sampled version of the given locator strategy specific input parameters.
62  \param subSampleOptimizationRescaleFactor Sub-sampled optimization tie-points search rescale factor.
63  \param inputSpecParams Input parameters (sub-sample factor 1).
64  \param subSampledSpecParamsPtr Sub-sampled parameters.
65  */
66  virtual void getSubSampledSpecStrategyParams(
67  const double subSampleOptimizationRescaleFactor,
68  const TiePointsLocatorStrategyParameters& inputSpecParams,
69  std::unique_ptr< TiePointsLocatorStrategyParameters >& subSampledSpecParamsPtr ) const = 0;
70 
71  /*!
72  \brief Returns a sub-sampled version of the given locator strategy specific input parameters.
73  \param subSampleOptimizationRescaleFactor Sub-sampled optimization tie-points search rescale factor.
74  \param inputSpecParams Input parameters (sub-sample factor 1).
75  \param subSampledSpecParams Sub-sampled parameters.
76  */
77  virtual void getDefaultSpecStrategyParams(
78  std::unique_ptr< TiePointsLocatorStrategyParameters >& defaultSpecParamsPtr ) const = 0;
79 
80  /*!
81  \brief Return the current error message if there is any.
82 
83  \return Return the current error message if there is any.
84  */
85  const std::string& getErrorMessage() const;
86 
87  protected :
88 
89  /*!
90  \typedef FloatsMatrix
91  \brief A matrix do store float values.
92  */
94 
95  /*!
96  \typedef DoublesMatrix
97  \brief A matrix do store double values.
98  */
100 
101  /*!
102  \typedef UCharsMatrix
103  \brief A matrix do store unsigned char values.
104  */
106 
107  /*! Interest point type */
109  {
110  public :
111  unsigned int m_x; //!< Point X coord.
112 
113  unsigned int m_y; //!< Point Y coord.
114 
115  float m_feature1; //!< Interest point feature 1 value.
116 
117  float m_feature2; //!< Interest point feature 2 value.
118 
119  float m_feature3; //!< Interest point feature 3 value.
120 
122  : m_x( 0 ), m_y( 0 ), m_feature1( 0 ), m_feature2( 0 ),
123  m_feature3( 0 )
124  {
125  };
126 
128  {
129  operator=( other );
130  };
131 
133 
134  bool operator<( const InterestPointT& other ) const
135  {
136  return ( m_feature1 < other.m_feature1 );
137  };
138 
140  {
141  m_x = other.m_x;
142  m_y = other.m_y;
143  m_feature1 = other.m_feature1;
144  m_feature2 = other.m_feature2;
145  m_feature3 = other.m_feature3;
146  return *this;
147  };
148  };
149 
150  /*! Interest points set container type
151  */
152  typedef std::multiset< InterestPointT > InterestPointsSetT;
153 
154  /*! Interest points list container type
155  */
156  typedef std::list< InterestPointT > InterestPointsListT;
157 
158  /*! Matched Interest point type */
160  {
161  public :
162 
163  InterestPointT m_point1; //!< Interest point 1
164 
165  InterestPointT m_point2; //!< Interest point 2
166 
167  float m_feature; //!< Matched interest feature.
168 
170 
172  {
173  operator=( other );
174  };
175 
177  const InterestPointT& point2, const float& feature ) :
178  m_point1( point1 ), m_point2( point2 ),
179  m_feature( feature ) {};
180 
182 
183  bool operator<( const MatchedInterestPointsT& other ) const
184  {
185  return ( m_feature < other.m_feature );
186  };
187 
189  {
190  m_point1 = other.m_point1;
191  m_point2 = other.m_point2;
192  m_feature = other.m_feature;
193  return other;
194  };
195  };
196 
197  /*! Matched interest points container type
198  */
199  typedef std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT;
200 
201  /*!
202  \brief Initialize the strategy.
203  \param inputParameters Input parameters.
204  \return true if OK, false on errors.
205  */
206  virtual bool initialize(
207  const te::rp::TiePointsLocatorInputParameters& inputParameters ) = 0;
208 
209  /*!
210  \brief Clear all internal allocated resources and go back to the initial not-initialized state.
211  */
212  virtual void reset();
213 
214  /*!
215  \brief Returns a automatically calculated optimum maximum amount tie-points following the current parameters.
216  \return Returns a automatically calculated optimum maximum amount tie-points following the current parameters.
217  */
218  virtual unsigned int getAutoMaxTiePointsNumber() const = 0;
219 
220  /*!
221  \brief Try to find matched interest points.
222  \param matchedInterestPoints The matched interest points.
223  \param raster1ToRaster2TransfPtr A pointer to a transformation (estimation) direct mapping raster 1 indexed coords into raster 2 indexed coords, of an empty pointer if there is no transformation avaliable.
224  \param raster1ToRaster2TransfDMapError The expected transformation error.
225  \return true if OK, false on errors.
226  */
227  virtual bool getMatchedInterestPoints(
228  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
229  const double raster1ToRaster2TransfDMapError,
230  MatchedInterestPointsSetT& matchedInterestPoints ) = 0;
231 
233 
234  /*!
235  \brief Load rasters data (normalized between 0 and 1).
236 
237  \param rasterPtr Input raster pointer.
238 
239  \param rasterBands Input raster bands.
240 
241  \param maskRasterPtr The related input mask raster pointer (or zero, if no mask raster is avaliable).
242 
243  \param maskRasterBand The input mask raster band to use.
244 
245  \param rasterTargetAreaLineStart The raster target area initial line.
246 
247  \param rasterTargetAreaColStart The raster target area initial column.
248 
249  \param rasterTargetAreaWidth The raster target area width.
250 
251  \param rasterTargetAreaHeight The raster target area height.
252 
253  \param desiredRescaleFactorX The desired Scale factor to be applied on the loaded data.
254 
255  \param desiredRescaleFactorY The desired Scale factor to be applied on the loaded data.
256 
257  \param rasterInterpMethod The interpolation used when loading the input raster.
258 
259  \param maxMemPercentUsage The maximum amount (percent) of memory to use for the loaded data [0,100].
260 
261  \param loadedRasterData The loaded raster data.
262 
263  \param loadedMaskRasterData The loaded mask raster data.
264 
265  \param desiredRescaleFactorX The real achieved Scale factor.
266 
267  \param desiredRescaleFactorY The real achieved Scale factor.
268 
269  \return true if ok, false on errors.
270  */
271  static bool loadRasterData(
272  te::rst::Raster const* rasterPtr,
273  const std::vector< unsigned int >& rasterBands,
274  te::rst::Raster const* maskRasterPtr,
275  const unsigned int maskRasterBand,
276  const unsigned int rasterTargetAreaLineStart,
277  const unsigned int rasterTargetAreaColStart,
278  const unsigned int rasterTargetAreaWidth,
279  const unsigned int rasterTargetAreaHeight,
280  const double desiredRescaleFactorX,
281  const double desiredRescaleFactorY,
282  const te::rst::Interpolator::Method rasterInterpMethod,
283  const unsigned char maxMemPercentUsage,
284  std::vector< boost::shared_ptr< FloatsMatrix > >& loadedRasterData,
285  UCharsMatrix& loadedMaskRasterData,
286  double& achievedRescaleFactorX,
287  double& achievedRescaleFactorY );
288 
289  /*!
290  \brief RoolUp a buffer of lines.
291 
292  \param bufferPtr Buffer pointer.
293 
294  \param bufferLinesNumber Buffer lines number.
295  */
296  template< typename BufferElementT >
297  static void roolUpBuffer( BufferElementT** bufferPtr,
298  const unsigned int& bufferLinesNumber )
299  {
300  assert( bufferPtr );
301  assert( bufferLinesNumber );
302 
303  unsigned int idx = 0;
304  BufferElementT* auxLinePtr = bufferPtr[ 0 ];
305  const unsigned int lastLineIdx = bufferLinesNumber - 1;
306 
307  for( idx = 0 ; idx < lastLineIdx ; ++idx )
308  {
309  bufferPtr[ idx ] = bufferPtr[ idx + 1 ];
310  }
311 
312  bufferPtr[ lastLineIdx ] = auxLinePtr;
313  }
314 
315  /*!
316  \brief Moravec interest points locator.
317 
318  \param rasterData The loaded raster data.
319 
320  \param interestPoints The found raster 1 interest points (coords related to rasterData lines/cols).
321 
322  \param tifFileName Tif file name.
323  */
324  static void createTifFromMatrix(
325  const FloatsMatrix& rasterData,
326  const InterestPointsSetT& interestPoints,
327  const std::string& tifFileName );
328 
329  /*!
330  \brief Save the generated features to tif files.
331 
332  \param features The features to be saved.
333 
334  \param validInteresPoints The interest pionts related to each feature inside the features matrix.
335 
336  \param fileNameStart The output file name beginning.
337  */
338  static void features2Tiff(
339  const DoublesMatrix& features,
340  const InterestPointsSetT& interestPoints,
341  const std::string& fileNameBeginning );
342 
343 
344  /*!
345  \brief Check for duplicated interest points.
346  \param x The duplicated tie-points X coord.
347  \param y The duplicated tie-points Y coord.
348  \return false if duplicated interest points were found.
349  */
350  static bool checkForDuplicatedInterestPoints( const InterestPointsSetT& interestPoints,
351  double& x, double& y );
352 
353  /*!
354  \brief Set the current error message.
355 
356  \param newErrorMessage New error message;
357  */
358  void setErrorMessage( const std::string& newErrorMessage );
359 
360  private:
361 
362  /*!
363  \brief Current error message.
364  */
365  std::string m_errorMessage;
366 
368 
370  };
371 
372  } // end namespace rp
373 } // end namespace te
374 
375 #endif
376 
te::rp::Matrix< float > FloatsMatrix
A matrix do store float values.
InterestPointT & operator=(const InterestPointT &other)
MatchedInterestPointsT(const InterestPointT &point1, const InterestPointT &point2, const float &feature)
2D Geometric transformation base class.
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
std::string m_errorMessage
Current error message.
bool operator<(const MatchedInterestPointsT &other) const
std::list< InterestPointT > InterestPointsListT
te::rp::Matrix< unsigned char > UCharsMatrix
A matrix do store unsigned char values.
An abstract class for raster data strucutures.
Definition: Raster.h:71
TerraLib.
std::multiset< InterestPointT > InterestPointsSetT
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
te::rp::Matrix< double > DoublesMatrix
A matrix do store double values.
Generic template matrix.
Tie-points locator strategy.
Tie points locator.
static void roolUpBuffer(BufferElementT **bufferPtr, const unsigned int &bufferLinesNumber)
RoolUp a buffer of lines.
Configuration flags for the Raster Processing module of TerraLib.
float m_feature3
Interest point feature 3 value.
A generic template matrix.
Definition: Matrix.h:55
bool operator<(const InterestPointT &other) const
float m_feature2
Interest point feature 2 value.
std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT
const MatchedInterestPointsT & operator=(const MatchedInterestPointsT &other)
TiePointsLocator input parameters.
float m_feature1
Interest point feature 1 value.