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. */
73 
74  /*! \brief Destructor. */
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 
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 
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  */
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  */
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 
GeometricTransformation.h
2D Geometric transformation base class.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_dynamicMaxConsLowQualityIterationsPtr
RansacIntegerCounterT * m_dynamicMaxConsLowQualityIterationsPtr
Definition: GTFilter.h:144
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams
Parameters used by the GTFilter::applyRansacThreadEntry method.
Definition: GTFilter.h:135
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::ApplyRansacThreadEntryThreadParams
ApplyRansacThreadEntryThreadParams()
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::~ApplyRansacThreadEntryThreadParams
~ApplyRansacThreadEntryThreadParams()
te::gm::GTFilter::RansacSetData::RansacSetData
RansacSetData()
te
TerraLib.
Definition: AddressGeocodingOp.h:52
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::ApplyRansacThreadEntryThreadParams
ApplyRansacThreadEntryThreadParams(const ApplyRansacThreadEntryThreadParams &other)
te::gm::GTFilter::RansacSetData::m_area1
double m_area1
Definition: GTFilter.h:120
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_mutexPtr
std::mutex * m_mutexPtr
Definition: GTFilter.h:148
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_globalConsecutiveLowQualitySetsCounterPtr
RansacIntegerCounterT * m_globalConsecutiveLowQualitySetsCounterPtr
Definition: GTFilter.h:156
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_maxFoundGlobalItIMapErrorPtr
double * m_maxFoundGlobalItIMapErrorPtr
Definition: GTFilter.h:153
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::operator=
const ApplyRansacThreadEntryThreadParams & operator=(const ApplyRansacThreadEntryThreadParams &other)
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_bestSetDataPtr
RansacSetData * m_bestSetDataPtr
Definition: GTFilter.h:151
te::gm::GTFilter::getExcpectedIterationsNumber
static RansacIntegerCounterT getExcpectedIterationsNumber(const unsigned int goodTPNumber, const unsigned int totalTPNumber, const unsigned int modelRequiredTPNumber)
Returns the number of expected iterations to be performed.
te::gm::GTFilter::RansacSetData::m_tiePoins
std::vector< te::gm::GTParameters::TiePoint > m_tiePoins
Definition: GTFilter.h:123
te::gm::GTFilter::RansacIntegerCounterT
unsigned long int RansacIntegerCounterT
RANSAC integer counter type.
Definition: GTFilter.h:55
te::gm::GTFilter::RansacSetData
Parameters used by the GTFilter::applyRansacThreadEntry method.
Definition: GTFilter.h:115
te::gm::GTFilter::RansacSetData::~RansacSetData
~RansacSetData()
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_useDynamicIterationsNumber
bool m_useDynamicIterationsNumber
Definition: GTFilter.h:142
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_transfName
std::string m_transfName
Definition: GTFilter.h:138
te::gm::GTParameters
2D Geometric transformation parameters.
Definition: GTParameters.h:51
TEGEOMEXPORT
#define TEGEOMEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:76
te::gm::GTFilter::applyRansacThreadEntry
static void applyRansacThreadEntry(te::gm::GTFilter::ApplyRansacThreadEntryThreadParams *paramsPtr)
Surf locator thread entry.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_procsNumber
RansacIntegerCounterT m_procsNumber
Definition: GTFilter.h:146
te::gm::GTFilter::RansacSetData::m_maxDirectMapError
double m_maxDirectMapError
Definition: GTFilter.h:118
te::gm::GTFilter::RansacFloatCounterT
long double RansacFloatCounterT
RANSAC floating point counter type.
Definition: GTFilter.h:58
te::gm::GTFilter::RansacSetData::m_transformationParams
GTParameters m_transformationParams
Definition: GTFilter.h:122
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_tpsMapPtr
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
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_globalIterationsCounterPtr
RansacIntegerCounterT * m_globalIterationsCounterPtr
Definition: GTFilter.h:155
te::gm::GTFilter::getTPsConvexHullArea
static void getTPsConvexHullArea(const std::vector< GTParameters::TiePoint > &tiePoints, double &area1, double &area2)
Returns the tie-points convex hull area.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_globalConsInvalidIterationsCounterPtr
RansacIntegerCounterT * m_globalConsInvalidIterationsCounterPtr
Definition: GTFilter.h:157
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_allowedMaxDirectMapError
double m_allowedMaxDirectMapError
Definition: GTFilter.h:140
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_maxFoundGlobalItDMapErrorPtr
double * m_maxFoundGlobalItDMapErrorPtr
Definition: GTFilter.h:152
GTParameters.h
2D Geometric transformation parameters.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_dynamicMaxConsInvalidIterationsPtr
RansacIntegerCounterT * m_dynamicMaxConsInvalidIterationsPtr
Definition: GTFilter.h:145
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_inputGTParamsPtr
GTParameters const * m_inputGTParamsPtr
Definition: GTFilter.h:139
te::gm::GTFilter::GTFilter
GTFilter()
Default constructor.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_keepRunningFlagPtr
bool * m_keepRunningFlagPtr
Definition: GTFilter.h:149
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_areaRestT
RANSACAreaRestrictionType m_areaRestT
Definition: GTFilter.h:154
te::gm::GTFilter
2D Geometric transformation tie-points filter (outliers remotion).
Definition: GTFilter.h:51
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_dynamicMaxIterationsPtr
RansacIntegerCounterT * m_dynamicMaxIterationsPtr
Definition: GTFilter.h:143
Config.h
Proxy configuration file for TerraView (see terraview_config.h).
te::gm::GTFilter::~GTFilter
~GTFilter()
Destructor.
te::gm::GTFilter::RANSACAreaRestrictionType
RANSACAreaRestrictionType
Definition: GTFilter.h:65
te::gm::GTFilter::RansacSetData::m_maxInverseMapError
double m_maxInverseMapError
Definition: GTFilter.h:119
te::gm::GTFilter::RansacSetData::m_area2
double m_area2
Definition: GTFilter.h:121
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_returnValuePtr
bool * m_returnValuePtr
Definition: GTFilter.h:147
te::gm::GTFilter::applyRansac
bool applyRansac(const std::string &transfName, const GTParameters &inputParams, const double allowedMaxDirectMapError, const double allowedMaxInverseMapError, const RansacIntegerCounterT &maxIterations, const bool enableMultiThread, const RANSACAreaRestrictionType areaRestT, const std::vector< double > &tiePointsWeights, std::vector< te::gm::GTParameters::TiePoint > &outTiePoints, std::unique_ptr< GeometricTransformation > &outTransf)
Apply a RANSAC based outliers remotion strategy.
te::gm::GTFilter::ApplyRansacThreadEntryThreadParams::m_allowedMaxInverseMapError
double m_allowedMaxInverseMapError
Definition: GTFilter.h:141