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 #include <thread>
39 #include <mutex>
40 
41 namespace te
42 {
43  namespace gm
44  {
45  /*!
46  \class GTFilter
47 
48  \brief 2D Geometric transformation tie-points filter (outliers remotion).
49  */
51  {
52  public:
53 
54  /*! \brief RANSAC integer counter type. */
55  typedef unsigned long int RansacIntegerCounterT;
56 
57  /*! \brief RANSAC floating point counter type. */
58  typedef long double RansacFloatCounterT;
59 
60  /*!
61  \enum RansacAreaRestrictionType
62  \brief Spatial relations between geometric objects.
63  */
65  {
66  RANSAC_NO_AREA_REST = 0, /*!< No area restriction. */
67  RANSAC_BBOX_AREA_REST = 1, /*!< Preference will be given to tie-points groups with bigger bounding-box areas. */
68  RANSAC_CHULL_AREA_REST = 2 /*!< Preference will be given to tie-points groups with bigger convex hull areas. */
69  };
70 
71  /*! \brief Default constructor. */
72  GTFilter();
73 
74  /*! \brief Destructor. */
75  ~GTFilter();
76 
77  /*!
78  \brief Apply a RANSAC based outliers remotion strategy.
79 
80  \param transfName Transformation name (see te::gm::GTFactory dictionary for reference).
81  \param inputParams Input transformation parameters.
82  \param allowedMaxDirectMapError The maximum allowed direct mapping error.
83  \param allowedMaxInverseMapError The maximum allowed inverse mapping error.
84  \param maxIterations The maximum number of iterations (Use 0-zero to let this number be automatically found).
85  \param enableMultiThread Enable multi-threaded processing (good for multi-processor or multi-core systems).
86  \param outTransf The generated output transformation (with the base mininum required tie-points set).
87  \param tiePointsWeights Optional tie-points weights (only positive values) or an empty vector if no weights must be used.
88  \param outTiePoints The filtered output tie-points (non-outliers) in agreenment with the generated transformation.
89  \param areaRestT RANSAC area restriction type.
90 
91  \return true if OK, false on errors.
92 
93  \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).
94  */
95  bool applyRansac(const std::string& transfName,
96  const GTParameters& inputParams,
97  const double allowedMaxDirectMapError,
98  const double allowedMaxInverseMapError,
99  const RansacIntegerCounterT& maxIterations,
100  const bool enableMultiThread,
101  const RANSACAreaRestrictionType areaRestT,
102  const std::vector< double >& tiePointsWeights,
103  std::vector< te::gm::GTParameters::TiePoint >& outTiePoints,
104  std::unique_ptr< GeometricTransformation >& outTransf
105  );
106 
107  protected:
108 
109  /*!
110  \class RansacSetData
111 
112  \brief Parameters used by the GTFilter::applyRansacThreadEntry method.
113  */
115  {
116  public:
117 
120  double m_area1;
121  double m_area2;
123  std::vector< te::gm::GTParameters::TiePoint > m_tiePoins;
124 
125  RansacSetData();
126  ~RansacSetData();
127  };
128 
129  /*!
130  \class ApplyRansacThreadEntryThreadParams
131 
132  \brief Parameters used by the GTFilter::applyRansacThreadEntry method.
133  */
135  {
136  public:
137 
138  std::string m_transfName;
148  std::mutex* m_mutexPtr;
150  std::map< double, GTParameters::TiePoint > const* m_tpsMapPtr; //!< A map from accumulated probabilities (normalized between 0 and 1) to tie-points data.
158 
160 
162 
163  private :
164 
166 
167  const ApplyRansacThreadEntryThreadParams& operator=(
168  const ApplyRansacThreadEntryThreadParams& other );
169  };
170 
171  /*!
172  \brief Returns the tie-points convex hull area.
173  \param area1 GTParameters::TiePoint::first area.
174  \param area2 GTParameters::TiePoint::second area.
175  \param tiePoints Tie points.
176  */
177  static void getTPsConvexHullArea(
178  const std::vector<GTParameters::TiePoint>& tiePoints,
179  double& area1, double& area2 );
180 
181  /*!
182  \brief Surf locator thread entry.
183 
184  \param paramsPtr A pointer to the thread parameters.
185  */
186  static void applyRansacThreadEntry(te::gm::GTFilter::ApplyRansacThreadEntryThreadParams* paramsPtr);
187 
188  /*!
189  \brief Returns the number of expected iterations to be performed.
190  \param goodTPNumber Number of good tie-points.
191  \param totalTPNumber Total number of tie-points.
192  \param modelRequiredTPNumber Model minimum required tie-points.
193  \return The number of expected iterations to be performed.
194  */
195  static RansacIntegerCounterT getExcpectedIterationsNumber(
196  const unsigned int goodTPNumber,
197  const unsigned int totalTPNumber,
198  const unsigned int modelRequiredTPNumber );
199 
200  };
201 
202  } // end namespace gm
203 } // end namespace te
204 
205 #endif // __TERRALIB_GEOMETRY_INTERNAL_GTFILTER_H
206 
long double RansacFloatCounterT
RANSAC floating point counter type.
Definition: GTFilter.h:58
2D Geometric transformation base class.
std::vector< te::gm::GTParameters::TiePoint > m_tiePoins
Definition: GTFilter.h:123
2D Geometric transformation parameters.
unsigned long int RansacIntegerCounterT
RANSAC integer counter type.
Definition: GTFilter.h:55
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:150
RansacIntegerCounterT * m_globalConsecutiveLowQualitySetsCounterPtr
Definition: GTFilter.h:156
2D Geometric transformation tie-points filter (outliers remotion).
Definition: GTFilter.h:50
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
Parameters used by the GTFilter::applyRansacThreadEntry method.
Definition: GTFilter.h:134
TerraLib.
GTParameters m_transformationParams
Definition: GTFilter.h:122
RansacIntegerCounterT * m_globalIterationsCounterPtr
Definition: GTFilter.h:155
Parameters used by the GTFilter::applyRansacThreadEntry method.
Definition: GTFilter.h:114
RansacIntegerCounterT * m_dynamicMaxConsInvalidIterationsPtr
Definition: GTFilter.h:145
2D Geometric transformation parameters.
Definition: GTParameters.h:50
RansacIntegerCounterT * m_globalConsInvalidIterationsCounterPtr
Definition: GTFilter.h:157
RansacIntegerCounterT * m_dynamicMaxConsLowQualityIterationsPtr
Definition: GTFilter.h:144
Configuration flags for the Vector Geometry Model of TerraLib.