All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
RSTGT.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/RSTGT.cpp
22 
23  \brief 2D Rotation/scale/translation(rigid body) Geometric transformation.
24 */
25 
26 // TerraLib
27 #include "../common/MatrixUtils.h"
28 #include "RSTGT.h"
29 
30 // STL
31 #include <cmath>
32 
34 {
35 }
36 
38 {
39 }
40 
41 const std::string& te::gm::RSTGT::getName() const
42 {
43  static std::string name( "RST" );
44  return name;
45 }
46 
47 bool te::gm::RSTGT::isValid( const GTParameters& params ) const
48 {
49  return ( ( params.m_directParameters.size() == 4 ) &&
50  ( params.m_inverseParameters.size() == 4 ) );
51 }
52 
53 void te::gm::RSTGT::directMap( const GTParameters& params, const double& pt1X,
54  const double& pt1Y, double& pt2X, double& pt2Y ) const
55 {
56  assert( isValid( params ) );
57 
58  pt2X = ( params.m_directParameters[0] * pt1X ) -
59  ( params.m_directParameters[1] * pt1Y ) +
60  params.m_directParameters[2];
61  pt2Y = ( params.m_directParameters[1] * pt1X ) +
62  ( params.m_directParameters[0] * pt1Y ) +
63  params.m_directParameters[3];
64 }
65 
66 void te::gm::RSTGT::inverseMap( const GTParameters& params, const double& pt2X,
67  const double& pt2Y, double& pt1X, double& pt1Y ) const
68 {
69  assert( isValid( params ) );
70 
71  pt1X = ( params.m_inverseParameters[0] * pt2X ) -
72  ( params.m_inverseParameters[1] * pt2Y ) +
73  params.m_inverseParameters[2];
74  pt1Y = ( params.m_inverseParameters[1] * pt2X ) +
75  ( params.m_inverseParameters[0] * pt2Y ) +
76  params.m_inverseParameters[3];
77 }
78 
80 {
81  return 2;
82 }
83 
85 {
86  te::gm::RSTGT* newTransPtr = new RSTGT;
87  newTransPtr->m_internalParameters = m_internalParameters;
88  return newTransPtr;
89 }
90 
92 {
93  m_computeParameters_tiepointsSize = params.m_tiePoints.size();
94  if( m_computeParameters_tiepointsSize < 2 ) return false;
95 
96  m_computeParameters_A.resize( 2 * m_computeParameters_tiepointsSize, 4 );
97  m_computeParameters_L.resize( 2 * m_computeParameters_tiepointsSize, 1 );
98 
99  for ( m_computeParameters_tpIdx = 0 ; m_computeParameters_tpIdx < m_computeParameters_tiepointsSize ; ++m_computeParameters_tpIdx )
100  {
101  m_computeParameters_index1 = m_computeParameters_tpIdx*2;
102  m_computeParameters_index2 = m_computeParameters_index1 + 1;
103 
104  const Coord2D& x_y = params.m_tiePoints[ m_computeParameters_tpIdx ].first;
105  const Coord2D& u_v = params.m_tiePoints[ m_computeParameters_tpIdx ].second;
106 
107  m_computeParameters_A( m_computeParameters_index1, 0 ) = x_y.x;
108  m_computeParameters_A( m_computeParameters_index1, 1 ) = -1.0 * x_y.y;
109  m_computeParameters_A( m_computeParameters_index1, 2 ) = 1.0;
110  m_computeParameters_A( m_computeParameters_index1, 3 ) = 0.0;
111 
112  m_computeParameters_A( m_computeParameters_index2, 0 ) = x_y.y;
113  m_computeParameters_A( m_computeParameters_index2, 1 ) = x_y.x;
114  m_computeParameters_A( m_computeParameters_index2, 2 ) = 0.0;
115  m_computeParameters_A( m_computeParameters_index2, 3 ) = 1.0;
116 
117  m_computeParameters_L( m_computeParameters_index1, 0 ) = u_v.x;
118  m_computeParameters_L( m_computeParameters_index2, 0 ) = u_v.y;
119  }
120 
121 // std::cout << std::endl << "L:" << std::endl << L << std::endl;
122 // std::cout << std::endl << "A:" << std::endl << A << std::endl;
123 
124  /* At calcule */
125  m_computeParameters_At = boost::numeric::ublas::trans( m_computeParameters_A );
126 
127  /* N calcule */
128  m_computeParameters_N = boost::numeric::ublas::prod( m_computeParameters_At, m_computeParameters_A );
129 
130  /* U calcule */
131  m_computeParameters_U = boost::numeric::ublas::prod( m_computeParameters_At, m_computeParameters_L );
132 
133  /* N_inv calcule */
134 
135  if ( te::common::GetInverseMatrix( m_computeParameters_N, m_computeParameters_N_inv ) )
136  {
137  /* direct parameters calcule */
138 
139  m_computeParameters_X = boost::numeric::ublas::prod( m_computeParameters_N_inv, m_computeParameters_U );
140 
141 // std::cout << std::endl << "X:" << std::endl << X << std::endl;
142 
143  params.m_directParameters.resize( 4 );
144  params.m_directParameters[0] = m_computeParameters_X(0,0);
145  params.m_directParameters[1] = m_computeParameters_X(1,0);
146  params.m_directParameters[2] = m_computeParameters_X(2,0);
147  params.m_directParameters[3] = m_computeParameters_X(3,0);
148 
149  /* inverse parameters calcule */
150 
151  m_computeParameters_XExpanded.resize( 3, 3 );
152  m_computeParameters_XExpanded( 0, 0 ) = m_computeParameters_X(0,0);
153  m_computeParameters_XExpanded( 0, 1 ) = -1.0 * m_computeParameters_X(1,0);
154  m_computeParameters_XExpanded( 0, 2 ) = m_computeParameters_X(2,0);
155  m_computeParameters_XExpanded( 1, 0 ) = m_computeParameters_X(1,0);
156  m_computeParameters_XExpanded( 1, 1 ) = m_computeParameters_X(0,0);
157  m_computeParameters_XExpanded( 1, 2 ) = m_computeParameters_X(3,0);
158  m_computeParameters_XExpanded( 2, 0 ) = 0;
159  m_computeParameters_XExpanded( 2, 1 ) = 0;
160  m_computeParameters_XExpanded( 2, 2 ) = 1;
161 
162 // std::cout << std::endl << "XExpanded:" << std::endl << XExpanded << std::endl;
163 
164  if( te::common::GetInverseMatrix( m_computeParameters_XExpanded, m_computeParameters_XExpandedInv ) )
165  {
166 // std::cout << std::endl << "XExpandedInv:" << std::endl << XExpandedInv << std::endl;
167 
168  params.m_inverseParameters.resize( 4 );
169  params.m_inverseParameters[0] = m_computeParameters_XExpandedInv(0,0);
170  params.m_inverseParameters[1] = m_computeParameters_XExpandedInv(1,0);
171  params.m_inverseParameters[2] = m_computeParameters_XExpandedInv(0,2);
172  params.m_inverseParameters[3] = m_computeParameters_XExpandedInv(1,2);
173 
174  return true;
175  }
176  else
177  {
178  return false;
179  }
180  }
181  else
182  {
183  return false;
184  }
185 }
186 
187 
2D Rotation/scale/translation (rigid body) Geometric transformation.
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
double y
y-coordinate.
Definition: Coord2D.h:114
void inverseMap(const GTParameters &params, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const
Inverse mapping (from pt2 space into pt1 space).
Definition: RSTGT.cpp:66
double x
x-coordinate.
Definition: Coord2D.h:113
std::vector< double > m_directParameters
Transformation numeric direct parameters.
Definition: GTParameters.h:100
RSTGT()
Default constructor.
Definition: RSTGT.cpp:33
const std::string & getName() const
Returns the current transformation name.
Definition: RSTGT.cpp:41
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
2D Geometric transformation base class.
void directMap(const GTParameters &params, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const
Direct mapping (from pt1 space into pt2 space).
Definition: RSTGT.cpp:53
GTParameters m_internalParameters
The current internal parameters.
2D Rotation/scale/translation(rigid body) Geometric transformation.
Definition: RSTGT.h:66
bool isValid() const
Tells if the current instance has a valid transformation.
~RSTGT()
Destructor.
Definition: RSTGT.cpp:37
bool GetInverseMatrix(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &outputMatrix)
Matrix inversion.
Definition: MatrixUtils.h:104
std::vector< double > m_inverseParameters
Transformation numeric inverse parameters.
Definition: GTParameters.h:101
unsigned int getMinRequiredTiePoints() const
Returns the minimum number of required tie-points for the current transformation. ...
Definition: RSTGT.cpp:79
GeometricTransformation * clone() const
Creat a clone copy of this instance.
Definition: RSTGT.cpp:84
2D Geometric transformation parameters.
Definition: GTParameters.h:50
bool computeParameters(GTParameters &params) const
Calculate the transformation parameters following the new supplied tie-points.
Definition: RSTGT.cpp:91