GeometricTransformation.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/GeometricTransformation.h
22 
23  \brief 2D Geometric transformation base class.
24 */
25 
26 #ifndef __TERRALIB_GEOMETRY_INTERNAL_GEOMETRICTRANSFORMATION_H
27 #define __TERRALIB_GEOMETRY_INTERNAL_GEOMETRICTRANSFORMATION_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "GTParameters.h"
32 
33 // STL
34 #include <cassert>
35 
36 // Boost
37 #include <boost/noncopyable.hpp>
38 
39 namespace te
40 {
41  namespace gm
42  {
43 // Forward declaration
44  class GTFilter;
45  class GTParameters;
46 
47  struct Coord2D;
48 
49  /*!
50  \class GeometricTransformation
51 
52  \brief 2D Geometric transformation base class.
53 
54  \ingroup geometry
55  */
56  class TEGEOMEXPORT GeometricTransformation : public boost::noncopyable
57  {
58  friend class GTFilter;
59 
60  public:
61 
62  /*! \brief Virtual destructor. */
63  virtual ~GeometricTransformation();
64 
65  /*!
66  \brief Returns the current transformation name.
67 
68  \return The current transformation name.
69  */
70  virtual const std::string& getName() const = 0;
71 
72  /*!
73  \brief Verifies if the supplied parameters already has a valid transformation.
74 
75  \param params Transformation parameters.
76 
77  \return true if a transformation is already defined, false otherwise.
78  */
79  virtual bool isValid(const GTParameters& params) const = 0;
80 
81  /*!
82  \brief Tells if the current instance has a valid transformation.
83 
84  \return true if a transformation is already defined, false otherwise.
85  */
86  bool isValid() const
87  {
88  return isValid(m_internalParameters);
89  };
90 
91  /*!
92  \brief Initialize the current transformation following the new supplied parameters.
93 
94  \param newparams The new parameters.
95 
96  \return true if OK, false on errors.
97  */
98  bool initialize(const GTParameters& newParameters);
99 
100  /*!
101  \brief Returns a reference of the current internal transformation parameters.
102 
103  \return A reference of the current internal transformation parameters.
104  */
106  {
107  return m_internalParameters;
108  };
109 
110  /*!
111  \brief Direct mapping (from pt1 space into pt2 space).
112 
113  \param params Transformation parameters.
114  \param pt1X pt1 X coordinate.
115  \param pt1Y pt1 Y coordinate.
116  \param pt2X pt2 X coordinate.
117  \param pt2Y pt2 Y coordinate.
118  */
119  virtual void directMap(const GTParameters& params,
120  const double& pt1X,
121  const double& pt1Y,
122  double& pt2X,
123  double& pt2Y) const = 0;
124 
125  /*!
126  \brief Direct mapping ( from pt1 space into pt2 space ).
127 
128  \param pt1X pt1 X coordinate.
129  \param pt1Y pt1 Y coordinate.
130  \param pt2X pt2 X coordinate.
131  \param pt2Y pt2 Y coordinate.
132  */
133  void directMap(const double& pt1X,
134  const double& pt1Y,
135  double& pt2X,
136  double& pt2Y) const
137  {
138  assert(isValid(m_internalParameters));
139 
140  directMap(m_internalParameters, pt1X, pt1Y, pt2X, pt2Y);
141  };
142 
143  /*!
144  \brief Direct mapping (from pt1 space into pt2 space).
145 
146  \param params Transformation parameters.
147  \param pt1 pt1 coordinate.
148  \param pt2 pt2 coordinate.
149  */
150  void directMap(const GTParameters& params, const Coord2D& pt1, Coord2D& pt2) const
151  {
152  directMap(params, pt1.x, pt1.y, pt2.x, pt2.y);
153  };
154 
155  /*!
156  \brief Direct mapping (from pt1 space into pt2 space).
157 
158  \param pt1 pt1 coordinate.
159  \param pt2 pt2 coordinate.
160  */
161  void directMap(const Coord2D& pt1, Coord2D& pt2) const
162  {
163  assert(isValid(m_internalParameters));
164 
165  directMap(m_internalParameters, pt1.x, pt1.y, pt2.x, pt2.y);
166  };
167 
168  /*!
169  \brief Inverse mapping (from pt2 space into pt1 space).
170 
171  \param params Transformation parameters.
172  \param pt1X pt1 X coordinate.
173  \param pt1Y pt1 Y coordinate.
174  \param pt2X pt2 X coordinate.
175  \param pt2Y pt2 Y coordinate.
176  */
177  virtual void inverseMap(const GTParameters& params,
178  const double& pt2X,
179  const double& pt2Y,
180  double& pt1X,
181  double& pt1Y) const = 0;
182 
183  /*!
184  \brief Inverse mapping (from pt2 space into pt1 space).
185 
186  \param pt1X pt1 X coordinate.
187  \param pt1Y pt1 Y coordinate.
188  \param pt2X pt2 X coordinate.
189  \param pt2Y pt2 Y coordinate.
190  */
191  void inverseMap(const double& pt2X,
192  const double& pt2Y,
193  double& pt1X,
194  double& pt1Y) const
195  {
196  assert(isValid(m_internalParameters));
197 
198  inverseMap(m_internalParameters, pt2X, pt2Y, pt1X, pt1Y);
199  };
200 
201  /*!
202  \brief Inverse mapping ( from pt2 space into pt1 space ).
203 
204  \param params Transformation parameters.
205  \param pt2 pt2 coordinate.
206  \param pt1 pt1 coordinate.
207  */
208  void inverseMap(const GTParameters& params, const Coord2D& pt2, Coord2D& pt1) const
209  {
210  inverseMap(params, pt2.x, pt2.y, pt1.x, pt1.y);
211  };
212 
213  /*!
214  \brief Inverse mapping (from pt2 space into pt1 space).
215 
216  \param pt2 pt2 coordinate.
217  \param pt1 pt1 coordinate.
218  */
219  void inverseMap(const Coord2D& pt2, Coord2D& pt1) const
220  {
221  assert(isValid(m_internalParameters));
222 
223  inverseMap(m_internalParameters, pt2.x, pt2.y, pt1.x, pt1.y);
224  };
225 
226  /*!
227  \brief Calculates maximum direct mapping error for the supplied parameters.
228 
229  \param params Transformation parameters.
230 
231  \return The maximum direct mapping error for the supplied parameters.
232  */
233  double getMaxDirectMappingError(const GTParameters& params) const;
234 
235  /*!
236  \brief Calculates the current transformation maximum direct mapping error.
237 
238  \return The current maximum direct mapping error.
239  */
241  {
242  return getMaxDirectMappingError(m_internalParameters);
243  };
244 
245  /*!
246  \brief Calculates maximum inverse mapping error for the supplied parameters.
247 
248  \param params Transformation parameters.
249 
250  \return The maximum inverse mapping error for the supplied parameters.
251  */
252  double getMaxInverseMappingError(const GTParameters& params) const;
253 
254  /*!
255  \brief Calculates the current transformation maximum inverse mapping error.
256 
257  \return The current maximum inverse mapping error.
258  */
260  {
261  return getMaxInverseMappingError( m_internalParameters );
262  };
263 
264  /*!
265  \brief Calculates root mean square direct mapping error for the supplied tie-points using the supplied parameters.
266 
267  \param tiePoints The tie-points.
268 
269  \param params Transformation parameters.
270 
271  \return The root mean square error.
272  */
273  double getDirectMapRMSE( const std::vector< GTParameters::TiePoint >& tiePoints,
274  const GTParameters& params ) const;
275 
276  /*!
277  \brief Calculates root mean square direct mapping error for the supplied parameters.
278 
279  \param params Transformation parameters.
280 
281  \return The root mean square error.
282  */
283  double getDirectMapRMSE( const GTParameters& params ) const
284  {
285  return getDirectMapRMSE( params.m_tiePoints, params );
286  };
287 
288  /*!
289  \brief Calculates root mean square direct mapping error for the supplied tie-points.
290 
291  \param tiePoints The tie-points.
292 
293  \return The root mean square error.
294  */
295  double getDirectMapRMSE( const std::vector< GTParameters::TiePoint >& tiePoints ) const
296  {
297  return getDirectMapRMSE( tiePoints, m_internalParameters );
298  };
299 
300  /*!
301  \brief Calculates root mean square direct mapping error.
302 
303  \return The root mean square error.
304  */
305  double getDirectMapRMSE() const
306  {
307  return getDirectMapRMSE( m_internalParameters );
308  };
309 
310  /*!
311  \brief Calculates root mean square inverse mapping error for the supplied tie-points using the supplied parameters.
312 
313  \param tiePoints The tie-points.
314 
315  \param params Transformation parameters.
316 
317  \return The root mean square error.
318  */
319  double getInverseMapRMSE( const std::vector< GTParameters::TiePoint >& tiePoints,
320  const GTParameters& params ) const;
321 
322  /*!
323  \brief Calculates root mean square inverse mapping error for the supplied parameters.
324 
325  \param params Transformation parameters.
326 
327  \return The root mean square error.
328  */
329  double getInverseMapRMSE( const GTParameters& params ) const
330  {
331  return getInverseMapRMSE( params.m_tiePoints, params );
332  };
333 
334  /*!
335  \brief Calculates root mean square inverse mapping error for the supplied tie-points.
336 
337  \param tiePoints The tie-points.
338 
339  \return The root mean square error.
340  */
341  double getInverseMapRMSE( const std::vector< GTParameters::TiePoint >& tiePoints ) const
342  {
343  return getInverseMapRMSE( tiePoints, m_internalParameters );
344  };
345 
346  /*!
347  \brief Calculates root mean square inverse mapping error.
348 
349  \return The root mean square error.
350  */
351  double getInverseMapRMSE() const
352  {
353  return getInverseMapRMSE( m_internalParameters );
354  };
355 
356  /*!
357  \brief Calculates the direct mapping error for the supplied tie-point.
358 
359  \param tiePoint The tie-point.
360 
361  \param params Transformation parameters.
362 
363  \return The current maximum direct mapping error.
364  */
365  double getDirectMappingError(const GTParameters::TiePoint& tiePoint, const GTParameters& params) const;
366 
367  /*!
368  \brief Calculates the direct mapping error for the supplied tie-point.
369 
370  \param tiePoint The tie-point.
371 
372  \return The current direct mapping error.
373  */
374  double getDirectMappingError( const GTParameters::TiePoint& tiePoint ) const
375  {
376  return getDirectMappingError( tiePoint, m_internalParameters );
377  };
378 
379  /*!
380  \brief Calculates the inverse mapping error for the supplied tie-point.
381 
382  \param tiePoint The tie-point.
383 
384  \param params Transformation parameters.
385 
386  \return The current maximum inverse mapping error.
387  */
388  double getInverseMappingError( const GTParameters::TiePoint& tiePoint, const GTParameters& params ) const;
389 
390  /*!
391  \brief Calculates the inverse mapping error for the supplied tie-point.
392 
393  \param tiePoint The tie-point.
394 
395  \return The current inverse mapping error.
396  */
397  double getInverseMappingError( const GTParameters::TiePoint& tiePoint ) const
398  {
399  return getInverseMappingError( tiePoint, m_internalParameters );
400  };
401 
402  /*!
403  \brief Returns the minimum number of required tie-points for the current transformation.
404 
405  \return The minimum number of required tie-points for the current transformation.
406  */
407  virtual unsigned int getMinRequiredTiePoints() const = 0;
408 
409  /*!
410  \brief Creat a clone copy of this instance.
411 
412  \return A clone copy of this instance (the caller of this method must take the ownership of the returned object and delete it when appropriate.
413  */
414  virtual GeometricTransformation* clone() const = 0;
415 
416  protected:
417 
418  /*! \brief Default constructor. */
420 
421  /*!
422  \brief Calculate the transformation parameters following the new supplied tie-points.
423 
424  \param params Transformation parameters.
425 
426  \return true if OK, false on errors.
427  */
428  virtual bool computeParameters( GTParameters& params ) const = 0;
429 
430  protected:
431 
432  GTParameters m_internalParameters; //!< The current internal parameters.
433  };
434 
435  } // end namespace gm
436 } // end namespace te
437 
438 #endif // __TERRALIB_GEOMETRY_INTERNAL_GEOMETRICTRANSFORMATION_H
439 
void directMap(const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const
Direct mapping ( from pt1 space into pt2 space ).
double getDirectMapRMSE(const std::vector< GTParameters::TiePoint > &tiePoints) const
Calculates root mean square direct mapping error for the supplied tie-points.
void inverseMap(const Coord2D &pt2, Coord2D &pt1) const
Inverse mapping (from pt2 space into pt1 space).
double getInverseMappingError(const GTParameters::TiePoint &tiePoint) const
Calculates the inverse mapping error for the supplied tie-point.
void inverseMap(const GTParameters &params, const Coord2D &pt2, Coord2D &pt1) const
Inverse mapping ( from pt2 space into pt1 space ).
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
double y
y-coordinate.
Definition: Coord2D.h:114
double getDirectMapRMSE() const
Calculates root mean square direct mapping error.
2D Geometric transformation parameters.
double x
x-coordinate.
Definition: Coord2D.h:113
void inverseMap(const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const
Inverse mapping (from pt2 space into pt1 space).
double getInverseMapRMSE() const
Calculates root mean square inverse mapping error.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
2D Geometric transformation base class.
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
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
GTParameters m_internalParameters
The current internal parameters.
double getInverseMapRMSE(const std::vector< GTParameters::TiePoint > &tiePoints) const
Calculates root mean square inverse mapping error for the supplied tie-points.
URI C++ Library.
bool isValid() const
Tells if the current instance has a valid transformation.
double getInverseMapRMSE(const GTParameters &params) const
Calculates root mean square inverse mapping error for the supplied parameters.
void directMap(const Coord2D &pt1, Coord2D &pt2) const
Direct mapping (from pt1 space into pt2 space).
double getMaxDirectMappingError() const
Calculates the current transformation maximum direct mapping error.
void directMap(const GTParameters &params, const Coord2D &pt1, Coord2D &pt2) const
Direct mapping (from pt1 space into pt2 space).
2D Geometric transformation parameters.
Definition: GTParameters.h:50
Configuration flags for the Vector Geometry Model of TerraLib.
double getMaxInverseMappingError() const
Calculates the current transformation maximum inverse mapping error.
const GTParameters & getParameters() const
Returns a reference of the current internal transformation parameters.
double getDirectMapRMSE(const GTParameters &params) const
Calculates root mean square direct mapping error for the supplied parameters.
double getDirectMappingError(const GTParameters::TiePoint &tiePoint) const
Calculates the direct mapping error for the supplied tie-point.