GeometricTransformation.cpp
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.cpp
22 
23  \brief 2D Geometric transformation base class.
24 */
25 
26 // TerraLib
28 
29 // STL
30 #include <cmath>
31 
33 
35 {
36 // If previous calculated parameters were supplied, no need to do calcules
37 
38  if(isValid(newParameters))
39  {
40  m_internalParameters = newParameters;
41 
42  return true;
43  }
44  else
45  {
46 // No previous parameters given - Need to calculate the new transformation parameters
47 
48  m_internalParameters = newParameters;
49 
51  {
52  return true;
53  }
54  else
55  {
57  return false;
58  }
59  }
60 }
61 
63 {
64  assert(isValid(params));
65 
66  const unsigned int tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
67 
68  double maxError = 0.0;
69  double currentError = 0.0;
70 
71  for(unsigned int tpIndex = 0; tpIndex < tiepointsSize; ++tpIndex)
72  {
73  currentError = getDirectMappingError( params.m_tiePoints[ tpIndex ], params );
74 
75  if( currentError > maxError )
76  {
77  maxError = currentError;
78  }
79  }
80 
81  return maxError;
82 }
83 
85 {
86  assert( isValid( params ) );
87 
88  const unsigned int tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
89 
90  double maxError = 0.0;
91 
92  double currentError = 0.0;
93 
94  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
95  {
96  currentError = getInverseMappingError( params.m_tiePoints[ tpIndex ], params );
97 
98  if( currentError > maxError )
99  {
100  maxError = currentError;
101  }
102  }
103 
104  return maxError;
105 }
106 
108  const std::vector< GTParameters::TiePoint >& tiePoints,
109  const GTParameters& params ) const
110 {
111  assert( isValid( params ) );
112 
113  const unsigned int tiepointsSize = static_cast<unsigned int>(tiePoints.size());
114 
115  if( tiepointsSize == 0 )
116  {
117  return 0.0;
118  }
119  else
120  {
121  double error2Sum = 0.0;
122 
123  double currentError = 0.0;
124 
125  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
126  {
127  currentError = getDirectMappingError( tiePoints[ tpIndex ], params );
128 
129  error2Sum += ( currentError * currentError );
130  }
131 
132  return sqrt( error2Sum / static_cast<double>(tiepointsSize) );
133  }
134 }
135 
137  const std::vector< GTParameters::TiePoint >& tiePoints,
138  const GTParameters& params ) const
139 {
140  assert( isValid( params ) );
141 
142  const unsigned int tiepointsSize = static_cast<unsigned int>(tiePoints.size());
143 
144  if( tiepointsSize == 0 )
145  {
146  return 0.0;
147  }
148  else
149  {
150  double error2Sum = 0.0;
151  double currentError = 0.0;
152 
153  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
154  {
155  currentError = getInverseMappingError( tiePoints[ tpIndex ],
156  params );
157 
158  error2Sum += ( currentError * currentError );
159  }
160 
161  return sqrt( error2Sum / static_cast<double>(tiepointsSize) );
162  }
163 }
164 
166 {
167  assert( isValid( params ) );
168 
169  Coord2D directMappedPoint;
170 
171  directMap( params, tiePoint.first, directMappedPoint );
172 
173  double diffX = tiePoint.second.x - directMappedPoint.x;
174  double diffY = tiePoint.second.y - directMappedPoint.y;
175 
176  return hypot( diffX, diffY );
177 }
178 
180 {
181  assert( isValid( params ) );
182 
183  Coord2D inverseMappedPoint;
184 
185  inverseMap( params, tiePoint.second, inverseMappedPoint );
186 
187  double diffX = tiePoint.first.x - inverseMappedPoint.x;
188  double diffY = tiePoint.first.y - inverseMappedPoint.y;
189 
190  return hypot( diffX, diffY );
191 }
bool initialize(const GTParameters &newParameters)
Initialize the current transformation following the new supplied parameters.
virtual bool computeParameters(GTParameters &params) const =0
Calculate the transformation parameters following the new supplied tie-points.
2D Geometric transformation base class.
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.
double x
x-coordinate.
Definition: Coord2D.h:113
double getDirectMappingError(const GTParameters::TiePoint &tiePoint, const GTParameters &params) const
Calculates the direct mapping error for the supplied tie-point.
GeometricTransformation()
Default constructor.
double getInverseMapRMSE() const
Calculates root mean square inverse mapping error.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
GTParameters m_internalParameters
The current internal parameters.
double getInverseMappingError(const GTParameters::TiePoint &tiePoint, const GTParameters &params) const
Calculates the inverse mapping error for the supplied tie-point.
bool isValid() const
Tells if the current instance has a valid transformation.
double getMaxDirectMappingError() const
Calculates the current transformation maximum direct mapping error.
void reset()
Clear all internal allocated resources and reset the parameters instance to its initial state...
virtual void directMap(const GTParameters &params, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const =0
Direct mapping (from pt1 space into pt2 space).
2D Geometric transformation parameters.
Definition: GTParameters.h:50
double getMaxInverseMappingError() const
Calculates the current transformation maximum inverse mapping error.
virtual ~GeometricTransformation()
Virtual destructor.
virtual void inverseMap(const GTParameters &params, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const =0
Inverse mapping (from pt2 space into pt1 space).