GTFilter.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/geometry/GTFilter.h
22 
23  \brief 2D Geometric transformation outliers remotion filter.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_GTFILTER_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_GTFILTER_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "GTParameters.h"
33 
34 // STL
35 #include <map>
36 #include <memory>
37 #include <vector>
38 
39 // Boost
40 #include <boost/noncopyable.hpp>
41 #include <boost/thread.hpp>
42 
43 namespace te
44 {
45  namespace gm
46  {
47  /*!
48  \class GTFilter
49 
50  \brief 2D Geometric transformation tie-points filter (outliers remotion).
51  */
52  class TEGEOMEXPORT GTFilter : boost::noncopyable
53  {
54  public:
55 
56  /*! \brief RANSAC integer counter type. */
57  typedef unsigned long int RansacIntegerCounterT;
58 
59  /*! \brief RANSAC floating point counter type. */
60  typedef long double RansacFloatCounterT;
61 
62  /*! \brief Default constructor. */
63  GTFilter();
64 
65  /*! \brief Destructor. */
66  ~GTFilter();
67 
68  /*!
69  \brief Apply a RANSAC based outliers remotion strategy.
70 
71  \param transfName Transformation name (see te::gm::GTFactory dictionary for reference).
72  \param inputParams Input transformation parameters.
73  \param maxDirectMapError The maximum allowed direct mapping error.
74  \param maxInverseMapError The maximum allowed inverse mapping error.
75  \param maxIterations The maximum number of iterations (Use 0-zero to let this number be automatically found).
76  \param assurance 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.
77  \param enableMultiThread Enable multi-threaded processing (good for multi-processor or multi-core systems).
78  \param outTransf The generated output transformation (with the base mininum required tie-points set).
79  \param tiePointsWeights Optional tie-points weights (only positive values) or an empty vector if no weights must be used.
80  \param outTiePoints The filtered output tie-points (non-outliers) in agreenment with the generated transformation.
81 
82  \return true if OK, false on errors.
83 
84  \note Reference: Martin A. Fischler and Robert C. Bolles, Random Sample Consensus: A Paradigm for Model Fitting with Applications to Image Analysis and Automated Cartography, Communications of the ACM archive, Volume 24, Issue 6 (June 1981).
85  */
86  bool applyRansac(const std::string& transfName,
87  const GTParameters& inputParams,
88  const double maxDirectMapError,
89  const double maxInverseMapError,
90  const RansacIntegerCounterT& maxIterations,
91  const double& assurance,
92  const bool enableMultiThread,
93  const std::vector< double >& tiePointsWeights,
94  std::vector< te::gm::GTParameters::TiePoint >& outTiePoints,
95  std::auto_ptr< GeometricTransformation >& outTransf
96  );
97 
98  private:
99 
100  /*!
101  \class ApplyRansacThreadEntryThreadParams
102 
103  \brief Parameters used by the GTFilter::applyRansacThreadEntry method.
104  */
106  {
107  public:
108 
109  std::string const* m_transfNamePtr;
113  double m_assurance;
115  RansacIntegerCounterT* m_dynamicMaxIterationsPtr;
116  RansacIntegerCounterT m_procsNumber;
118  boost::mutex* m_mutexPtr;
120  std::map< double, GTParameters::TiePoint > const* m_tpsMapPtr; //!< A map from accumulated probabilities (normalized between 0 and 1) to tie-points data.
121  std::auto_ptr< GeometricTransformation >* m_bestTransformationPtrPtr;
125  std::vector< te::gm::GTParameters::TiePoint >* m_bestTiePoinsPtr;
126 
128 
130 
132 
133  const ApplyRansacThreadEntryThreadParams& operator=(
134  const ApplyRansacThreadEntryThreadParams& other );
135  };
136 
137  /*!
138  \brief Returns the tie-points convex hull area (GTParameters::TiePoint::first).
139 
140  \param tiePoints Tie points.
141 
142  \return The tie-points convex hull area
143  */
144  static double getPt1ConvexHullArea(const std::vector<GTParameters::TiePoint>& tiePoints);
145 
146  /*!
147  \brief Surf locator thread entry.
148 
149  \param paramsPtr A pointer to the thread parameters.
150  */
151  static void applyRansacThreadEntry(te::gm::GTFilter::ApplyRansacThreadEntryThreadParams* paramsPtr);
152 
153  };
154 
155  } // end namespace gm
156 } // end namespace te
157 
158 #endif // __TERRALIB_GEOMETRY_INTERNAL_GTFILTER_H
159 
long double RansacFloatCounterT
RANSAC floating point counter type.
Definition: GTFilter.h:60
2D Geometric transformation base class.
2D Geometric transformation parameters.
unsigned long int RansacIntegerCounterT
RANSAC integer counter type.
Definition: GTFilter.h:57
std::map< double, GTParameters::TiePoint > const * m_tpsMapPtr
A map from accumulated probabilities (normalized between 0 and 1) to tie-points data.
Definition: GTFilter.h:120
2D Geometric transformation tie-points filter (outliers remotion).
Definition: GTFilter.h:52
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
std::vector< te::gm::GTParameters::TiePoint > * m_bestTiePoinsPtr
Definition: GTFilter.h:125
Parameters used by the GTFilter::applyRansacThreadEntry method.
Definition: GTFilter.h:105
URI C++ Library.
std::auto_ptr< GeometricTransformation > * m_bestTransformationPtrPtr
Definition: GTFilter.h:121
2D Geometric transformation parameters.
Definition: GTParameters.h:50
Configuration flags for the Vector Geometry Model of TerraLib.