All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 {
34 }
35 
37 {
38 // If previous calculated parameters were supplied, no need to do calcules
39 
40  if(isValid(newParameters))
41  {
42  m_internalParameters = newParameters;
43 
44  return true;
45  }
46  else
47  {
48 // No previous parameters given - Need to calculate the new transformation parameters
49 
50  m_internalParameters = newParameters;
51 
52  if(computeParameters( m_internalParameters))
53  {
54  return true;
55  }
56  else
57  {
58  m_internalParameters.reset();
59  return false;
60  }
61  }
62 }
63 
65 {
66  assert(isValid(params));
67 
68  const unsigned int tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
69 
70  double maxError = 0.0;
71  double currentError = 0.0;
72 
73  for(unsigned int tpIndex = 0; tpIndex < tiepointsSize; ++tpIndex)
74  {
75  currentError = getDirectMappingError( params.m_tiePoints[ tpIndex ], params );
76 
77  if( currentError > maxError )
78  {
79  maxError = currentError;
80  }
81  }
82 
83  return maxError;
84 }
85 
87 {
88  assert( isValid( params ) );
89 
90  const unsigned int tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
91 
92  double maxError = 0.0;
93 
94  double currentError = 0.0;
95 
96  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
97  {
98  currentError = getInverseMappingError( params.m_tiePoints[ tpIndex ], params );
99 
100  if( currentError > maxError )
101  {
102  maxError = currentError;
103  }
104  }
105 
106  return maxError;
107 }
108 
110  const std::vector< GTParameters::TiePoint >& tiePoints,
111  const GTParameters& params ) const
112 {
113  assert( isValid( params ) );
114 
115  const unsigned int tiepointsSize = static_cast<unsigned int>(tiePoints.size());
116 
117  if( tiepointsSize == 0 )
118  {
119  return 0.0;
120  }
121  else
122  {
123  double error2Sum = 0.0;
124 
125  double currentError = 0.0;
126 
127  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
128  {
129  currentError = getDirectMappingError( tiePoints[ tpIndex ], params );
130 
131  error2Sum += ( currentError * currentError );
132  }
133 
134  return sqrt( error2Sum / static_cast<double>(tiepointsSize) );
135  }
136 }
137 
139  const std::vector< GTParameters::TiePoint >& tiePoints,
140  const GTParameters& params ) const
141 {
142  assert( isValid( params ) );
143 
144  const unsigned int tiepointsSize = static_cast<unsigned int>(tiePoints.size());
145 
146  if( tiepointsSize == 0 )
147  {
148  return 0.0;
149  }
150  else
151  {
152  double error2Sum = 0.0;
153  double currentError = 0.0;
154 
155  for( unsigned int tpIndex = 0 ; tpIndex < tiepointsSize ; ++tpIndex )
156  {
157  currentError = getInverseMappingError( tiePoints[ tpIndex ],
158  params );
159 
160  error2Sum += ( currentError * currentError );
161  }
162 
163  return sqrt( error2Sum / static_cast<double>(tiepointsSize) );
164  }
165 }
166 
168 {
169  assert( isValid( params ) );
170 
171  Coord2D directMappedPoint;
172 
173  directMap( params, tiePoint.first, directMappedPoint );
174 
175  double diffX = tiePoint.second.x - directMappedPoint.x;
176  double diffY = tiePoint.second.y - directMappedPoint.y;
177 
178  return hypot( diffX, diffY );
179 }
180 
182 {
183  assert( isValid( params ) );
184 
185  Coord2D inverseMappedPoint;
186 
187  inverseMap( params, tiePoint.second, inverseMappedPoint );
188 
189  double diffX = tiePoint.first.x - inverseMappedPoint.x;
190  double diffY = tiePoint.first.y - inverseMappedPoint.y;
191 
192  return hypot( diffX, diffY );
193 }
195 {
196 }
197 
bool initialize(const GTParameters &newParameters)
Initialize the current transformation following the new supplied parameters.
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
double getInverseMappingError(const GTParameters::TiePoint &tiePoint, const GTParameters &params) const
Calculates the inverse mapping error for the supplied tie-point.
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...
2D Geometric transformation parameters.
Definition: GTParameters.h:50
double getMaxInverseMappingError() const
Calculates the current transformation maximum inverse mapping error.
virtual ~GeometricTransformation()
Virtual destructor.