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::auto_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::auto_ptr< TiePointsLocatorStrategyParameters >& defaultSpecParamsPtr ) const = 0;
79 
80  protected :
81 
82  /*!
83  \typedef FloatsMatrix
84  \brief A matrix do store float values.
85  */
87 
88  /*!
89  \typedef DoublesMatrix
90  \brief A matrix do store double values.
91  */
93 
94  /*!
95  \typedef UCharsMatrix
96  \brief A matrix do store unsigned char values.
97  */
99 
100  /*! Interest point type */
102  {
103  public :
104  unsigned int m_x; //!< Point X coord.
105 
106  unsigned int m_y; //!< Point Y coord.
107 
108  float m_feature1; //!< Interest point feature 1 value.
109 
110  float m_feature2; //!< Interest point feature 2 value.
111 
112  float m_feature3; //!< Interest point feature 3 value.
113 
115  : m_x( 0 ), m_y( 0 ), m_feature1( 0 ), m_feature2( 0 ),
116  m_feature3( 0 )
117  {
118  };
119 
121  {
122  operator=( other );
123  };
124 
126 
127  bool operator<( const InterestPointT& other ) const
128  {
129  return ( m_feature1 < other.m_feature1 );
130  };
131 
133  {
134  m_x = other.m_x;
135  m_y = other.m_y;
136  m_feature1 = other.m_feature1;
137  m_feature2 = other.m_feature2;
138  m_feature3 = other.m_feature3;
139  return *this;
140  };
141  };
142 
143  /*! Interest points set container type
144  */
145  typedef std::multiset< InterestPointT > InterestPointsSetT;
146 
147  /*! Interest points list container type
148  */
149  typedef std::list< InterestPointT > InterestPointsListT;
150 
151  /*! Matched Interest point type */
153  {
154  public :
155 
156  InterestPointT m_point1; //!< Interest point 1
157 
158  InterestPointT m_point2; //!< Interest point 2
159 
160  float m_feature; //!< Matched interest feature.
161 
163 
165  {
166  operator=( other );
167  };
168 
170  const InterestPointT& point2, const float& feature ) :
171  m_point1( point1 ), m_point2( point2 ),
172  m_feature( feature ) {};
173 
175 
176  bool operator<( const MatchedInterestPointsT& other ) const
177  {
178  return ( m_feature < other.m_feature );
179  };
180 
182  {
183  m_point1 = other.m_point1;
184  m_point2 = other.m_point2;
185  m_feature = other.m_feature;
186  return other;
187  };
188  };
189 
190  /*! Matched interest points container type
191  */
192  typedef std::multiset< MatchedInterestPointsT > MatchedInterestPointsSetT;
193 
194  /*!
195  \brief Initialize the strategy.
196  \param inputParameters Input parameters.
197  \return true if OK, false on errors.
198  */
199  virtual bool initialize(
200  const te::rp::TiePointsLocatorInputParameters& inputParameters ) = 0;
201 
202  /*!
203  \brief Clear all internal allocated resources and go back to the initial not-initialized state.
204  */
205  virtual void reset() = 0;
206 
207  /*!
208  \brief Returns a automatically calculated optimum maximum amount tie-points following the current parameters.
209  \return Returns a automatically calculated optimum maximum amount tie-points following the current parameters.
210  */
211  virtual unsigned int getAutoMaxTiePointsNumber() const = 0;
212 
213  /*!
214  \brief Try to find matched interest points.
215  \param matchedInterestPoints The matched interest points.
216  \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.
217  \param raster1ToRaster2TransfDMapError The expected transformation error.
218  \return true if OK, false on errors.
219  */
220  virtual bool getMatchedInterestPoints(
221  te::gm::GeometricTransformation const * const raster1ToRaster2TransfPtr,
222  const double raster1ToRaster2TransfDMapError,
223  MatchedInterestPointsSetT& matchedInterestPoints ) = 0;
224 
226 
227  /*!
228  \brief Load rasters data (normalized between 0 and 1).
229 
230  \param rasterPtr Input raster pointer.
231 
232  \param rasterBands Input raster bands.
233 
234  \param maskRasterPtr The related input mask raster pointer (or zero, if no mask raster is avaliable).
235 
236  \param maskRasterBand The input mask raster band to use.
237 
238  \param rasterTargetAreaLineStart The raster target area initial line.
239 
240  \param rasterTargetAreaColStart The raster target area initial column.
241 
242  \param rasterTargetAreaWidth The raster target area width.
243 
244  \param rasterTargetAreaHeight The raster target area height.
245 
246  \param desiredRescaleFactorX The desired Scale factor to be applied on the loaded data.
247 
248  \param desiredRescaleFactorY The desired Scale factor to be applied on the loaded data.
249 
250  \param rasterInterpMethod The interpolation used when loading the input raster.
251 
252  \param maxMemPercentUsage The maximum amount (percent) of memory to use for the loaded data [0,100].
253 
254  \param loadedRasterData The loaded raster data.
255 
256  \param loadedMaskRasterData The loaded mask raster data.
257 
258  \param desiredRescaleFactorX The real achieved Scale factor.
259 
260  \param desiredRescaleFactorY The real achieved Scale factor.
261 
262  \return true if ok, false on errors.
263  */
264  static bool loadRasterData(
265  te::rst::Raster const* rasterPtr,
266  const std::vector< unsigned int >& rasterBands,
267  te::rst::Raster const* maskRasterPtr,
268  const unsigned int maskRasterBand,
269  const unsigned int rasterTargetAreaLineStart,
270  const unsigned int rasterTargetAreaColStart,
271  const unsigned int rasterTargetAreaWidth,
272  const unsigned int rasterTargetAreaHeight,
273  const double desiredRescaleFactorX,
274  const double desiredRescaleFactorY,
275  const te::rst::Interpolator::Method rasterInterpMethod,
276  const unsigned char maxMemPercentUsage,
277  std::vector< boost::shared_ptr< FloatsMatrix > >& loadedRasterData,
278  UCharsMatrix& loadedMaskRasterData,
279  double& achievedRescaleFactorX,
280  double& achievedRescaleFactorY );
281 
282  /*!
283  \brief RoolUp a buffer of lines.
284 
285  \param bufferPtr Buffer pointer.
286 
287  \param bufferLinesNumber Buffer lines number.
288  */
289  template< typename BufferElementT >
290  static void roolUpBuffer( BufferElementT** bufferPtr,
291  const unsigned int& bufferLinesNumber )
292  {
293  assert( bufferPtr );
294  assert( bufferLinesNumber );
295 
296  unsigned int idx = 0;
297  BufferElementT* auxLinePtr = bufferPtr[ 0 ];
298  const unsigned int lastLineIdx = bufferLinesNumber - 1;
299 
300  for( idx = 0 ; idx < lastLineIdx ; ++idx )
301  {
302  bufferPtr[ idx ] = bufferPtr[ idx + 1 ];
303  }
304 
305  bufferPtr[ lastLineIdx ] = auxLinePtr;
306  }
307 
308  /*!
309  \brief Moravec interest points locator.
310 
311  \param rasterData The loaded raster data.
312 
313  \param interestPoints The found raster 1 interest points (coords related to rasterData lines/cols).
314 
315  \param tifFileName Tif file name.
316  */
317  static void createTifFromMatrix(
318  const FloatsMatrix& rasterData,
319  const InterestPointsSetT& interestPoints,
320  const std::string& tifFileName );
321 
322  /*!
323  \brief Save the generated features to tif files.
324 
325  \param features The features to be saved.
326 
327  \param validInteresPoints The interest pionts related to each feature inside the features matrix.
328 
329  \param fileNameStart The output file name beginning.
330  */
331  static void features2Tiff(
332  const DoublesMatrix& features,
333  const InterestPointsSetT& interestPoints,
334  const std::string& fileNameBeginning );
335 
336 
337  /*!
338  \brief Check for duplicated interest points.
339  \param x The duplicated tie-points X coord.
340  \param y The duplicated tie-points Y coord.
341  \return false if duplicated interest points were found.
342  */
343  static bool checkForDuplicatedInterestPoints( const InterestPointsSetT& interestPoints,
344  double& x, double& y );
345 
346  private:
347 
349 
350  const TiePointsLocatorStrategy& operator=( const TiePointsLocatorStrategy& );
351  };
352 
353  } // end namespace rp
354 } // end namespace te
355 
356 #endif
357 
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::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
URI C++ Library.
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.
bool operator<(const MatchedInterestPointsT &other) const
A generic template matrix.
Definition: Matrix.h:51
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.