SecondDegreePolynomialGT.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/SecondDegreePolynomialGT.cpp
22 
23  \brief Second Degree Polynomial Geometric transformation.
24 */
25 
26 // TerraLib
27 #include "../common/MatrixUtils.h"
29 
30 // STL
31 #include <cmath>
32 
34 
36 
38 {
39  static std::string name( "SecondDegreePolynomial" );
40  return name;
41 }
42 
44 {
45  return ( ( params.m_directParameters.size() == 12 ) &&
46  ( params.m_inverseParameters.size() == 12 ) );
47 }
48 
49 void te::gm::SecondDegreePolynomialGT::directMap( const GTParameters& params, const double& pt1X,
50  const double& pt1Y, double& pt2X, double& pt2Y ) const
51 {
52  assert( isValid( params ) );
53 
54  pt2X =
55  params.m_directParameters[ 0 ] +
56  ( params.m_directParameters[ 1 ] * pt1X ) +
57  ( params.m_directParameters[ 2 ] * pt1Y ) +
58  ( params.m_directParameters[ 3 ] * pt1X * pt1Y ) +
59  ( params.m_directParameters[ 4 ] * pt1X * pt1X ) +
60  ( params.m_directParameters[ 5 ] * pt1Y * pt1Y );
61 
62  pt2Y =
63  params.m_directParameters[ 6 ] +
64  ( params.m_directParameters[ 7 ] * pt1X ) +
65  ( params.m_directParameters[ 8 ] * pt1Y ) +
66  ( params.m_directParameters[ 9 ] * pt1X * pt1Y ) +
67  ( params.m_directParameters[ 10 ] * pt1X * pt1X ) +
68  ( params.m_directParameters[ 11 ] * pt1Y * pt1Y );
69 }
70 
71 void te::gm::SecondDegreePolynomialGT::inverseMap( const GTParameters& params, const double& pt2X,
72  const double& pt2Y, double& pt1X, double& pt1Y ) const
73 {
74  assert( isValid( params ) );
75 
76  pt1X =
77  params.m_inverseParameters[ 0 ] +
78  ( params.m_inverseParameters[ 1 ] * pt2X ) +
79  ( params.m_inverseParameters[ 2 ] * pt2Y ) +
80  ( params.m_inverseParameters[ 3 ] * pt2X * pt2Y ) +
81  ( params.m_inverseParameters[ 4 ] * pt2X * pt2X ) +
82  ( params.m_inverseParameters[ 5 ] * pt2Y * pt2Y );
83 
84  pt1Y =
85  params.m_inverseParameters[ 6 ] +
86  ( params.m_inverseParameters[ 7 ] * pt2X ) +
87  ( params.m_inverseParameters[ 8 ] * pt2Y ) +
88  ( params.m_inverseParameters[ 9 ] * pt2X * pt2Y ) +
89  ( params.m_inverseParameters[ 10 ] * pt2X * pt2X ) +
90  ( params.m_inverseParameters[ 11 ] * pt2Y * pt2Y );
91 }
92 
94 {
95  return 7;
96 }
97 
99 {
102  return newTransPtr;
103 }
104 
106 {
107  /* Reference: Remote Sensing - Models and Methods For Image Processing
108  Second Edition
109  Robert A. Schowengerdt
110  Academic Press
111  */
112 
113  // Creating the equation system parameters
114 
115  m_computeParameters_tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
117 
124 
126  {
127  const Coord2D& pt1 = params.m_tiePoints[ m_computeParameters_tpIdx ].first;
128 
135 
136  const Coord2D& pt2 = params.m_tiePoints[ m_computeParameters_tpIdx ].second;
137 
144 
146 
148 
150 
152  }
153 
154  // Solving...
155 
157 
159 
161 
163 
165 
167 
168  // Copying the parameters to output
169 
170  params.m_directParameters.resize( 12 );
171  params.m_directParameters[ 0 ] = m_computeParameters_A( 0, 0 );
172  params.m_directParameters[ 1 ] = m_computeParameters_A( 1, 0 );
173  params.m_directParameters[ 2 ] = m_computeParameters_A( 2, 0 );
174  params.m_directParameters[ 3 ] = m_computeParameters_A( 3, 0 );
175  params.m_directParameters[ 4 ] = m_computeParameters_A( 4, 0 );
176  params.m_directParameters[ 5 ] = m_computeParameters_A( 5, 0 );
177  params.m_directParameters[ 6 ] = m_computeParameters_B( 0, 0 );
178  params.m_directParameters[ 7 ] = m_computeParameters_B( 1, 0 );
179  params.m_directParameters[ 8 ] = m_computeParameters_B( 2, 0 );
180  params.m_directParameters[ 9 ] = m_computeParameters_B( 3, 0 );
181  params.m_directParameters[ 10 ] = m_computeParameters_B( 4, 0 );
182  params.m_directParameters[ 11 ] = m_computeParameters_B( 5, 0 );
183 
184  params.m_inverseParameters.resize( 12 );
185  params.m_inverseParameters[ 0 ] = m_computeParameters_AI( 0, 0 );
186  params.m_inverseParameters[ 1 ] = m_computeParameters_AI( 1, 0 );
187  params.m_inverseParameters[ 2 ] = m_computeParameters_AI( 2, 0 );
188  params.m_inverseParameters[ 3 ] = m_computeParameters_AI( 3, 0 );
189  params.m_inverseParameters[ 4 ] = m_computeParameters_AI( 4, 0 );
190  params.m_inverseParameters[ 5 ] = m_computeParameters_AI( 5, 0 );
191  params.m_inverseParameters[ 6 ] = m_computeParameters_BI( 0, 0 );
192  params.m_inverseParameters[ 7 ] = m_computeParameters_BI( 1, 0 );
193  params.m_inverseParameters[ 8 ] = m_computeParameters_BI( 2, 0 );
194  params.m_inverseParameters[ 9 ] = m_computeParameters_BI( 3, 0 );
195  params.m_inverseParameters[ 10 ] = m_computeParameters_BI( 4, 0 );
196  params.m_inverseParameters[ 11 ] = m_computeParameters_BI( 5, 0 );
197 
198  return true;
199 }
200 
201 
boost::numeric::ublas::matrix< double > m_computeParameters_PinvWI
Second Degree Polynomial Geometric transformation.
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
const std::string & getName() const
Returns the current transformation name.
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
Second Degree Polynomial Geometric transformation.
std::vector< double > m_directParameters
Transformation numeric direct parameters.
Definition: GTParameters.h:100
SecondDegreePolynomialGT()
Default constructor.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
boost::numeric::ublas::matrix< double > m_computeParameters_XI
2D Geometric transformation base class.
boost::numeric::ublas::matrix< double > m_computeParameters_A
boost::numeric::ublas::matrix< double > m_computeParameters_AI
te::gm::Point * pt2
bool GetPseudoInverseMatrix(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &outputMatrix)
Pseudo matrix inversion.
Definition: MatrixUtils.h:191
GTParameters m_internalParameters
The current internal parameters.
te::gm::Point * pt1
boost::numeric::ublas::matrix< double > m_computeParameters_WI
bool isValid() const
Tells if the current instance has a valid transformation.
boost::numeric::ublas::matrix< double > m_computeParameters_W
bool computeParameters(GTParameters &params) const
Calculate the transformation parameters following the new supplied tie-points.
boost::numeric::ublas::matrix< double > m_computeParameters_YI
void inverseMap(const GTParameters &params, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const
Inverse mapping (from pt2 space into pt1 space).
std::vector< double > m_inverseParameters
Transformation numeric inverse parameters.
Definition: GTParameters.h:101
boost::numeric::ublas::matrix< double > m_computeParameters_B
2D Geometric transformation parameters.
Definition: GTParameters.h:50
unsigned int getMinRequiredTiePoints() const
Returns the minimum number of required tie-points for the current transformation. ...
GeometricTransformation * clone() const
Creat a clone copy of this instance.
boost::numeric::ublas::matrix< double > m_computeParameters_PinvW
void directMap(const GTParameters &params, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const
Direct mapping (from pt1 space into pt2 space).
boost::numeric::ublas::matrix< double > m_computeParameters_Y
boost::numeric::ublas::matrix< double > m_computeParameters_BI
boost::numeric::ublas::matrix< double > m_computeParameters_X