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