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 
33 te::gm::RSTGT::RSTGT() = default;
34 
35 te::gm::RSTGT::~RSTGT() = default;
36 
37 const std::string& te::gm::RSTGT::getName() const
38 {
39  static std::string name( "RST" );
40  return name;
41 }
42 
43 bool te::gm::RSTGT::isValid( const GTParameters& params ) const
44 {
45  return ( ( params.m_directParameters.size() == 4 ) &&
46  ( params.m_inverseParameters.size() == 4 ) );
47 }
48 
49 void te::gm::RSTGT::directMap( const GTParameters& params, const double& pt1X,
50  const double& pt1Y, double& pt2X, double& pt2Y ) const
51 {
52  assert( isValid( params ) );
53 
54  pt2X = ( params.m_directParameters[0] * pt1X ) -
55  ( params.m_directParameters[1] * pt1Y ) +
56  params.m_directParameters[2];
57  pt2Y = ( params.m_directParameters[1] * pt1X ) +
58  ( params.m_directParameters[0] * pt1Y ) +
59  params.m_directParameters[3];
60 }
61 
62 void te::gm::RSTGT::inverseMap( const GTParameters& params, const double& pt2X,
63  const double& pt2Y, double& pt1X, double& pt1Y ) const
64 {
65  assert( isValid( params ) );
66 
67  pt1X = ( params.m_inverseParameters[0] * pt2X ) -
68  ( params.m_inverseParameters[1] * pt2Y ) +
69  params.m_inverseParameters[2];
70  pt1Y = ( params.m_inverseParameters[1] * pt2X ) +
71  ( params.m_inverseParameters[0] * pt2Y ) +
72  params.m_inverseParameters[3];
73 }
74 
76 {
77  return 2;
78 }
79 
81 {
82  te::gm::RSTGT* newTransPtr = new RSTGT;
84  return newTransPtr;
85 }
86 
88 {
89  m_computeParameters_tiepointsSize = static_cast<unsigned int>(params.m_tiePoints.size());
90  if( m_computeParameters_tiepointsSize < 2 ) return false;
91 
94 
96  {
99 
100  const Coord2D& x_y = params.m_tiePoints[ m_computeParameters_tpIdx ].first;
101  const Coord2D& u_v = params.m_tiePoints[ m_computeParameters_tpIdx ].second;
102 
107 
112 
115  }
116 
117 // std::cout << std::endl << "L:" << std::endl << L << std::endl;
118 // std::cout << std::endl << "A:" << std::endl << A << std::endl;
119 
120  /* At calcule */
121  m_computeParameters_At = boost::numeric::ublas::trans( m_computeParameters_A );
122 
123  /* N calcule */
124  m_computeParameters_N = boost::numeric::ublas::prod( m_computeParameters_At, m_computeParameters_A );
125 
126  /* U calcule */
127  m_computeParameters_U = boost::numeric::ublas::prod( m_computeParameters_At, m_computeParameters_L );
128 
129  /* N_inv calcule */
130 
132  {
133  /* direct parameters calcule */
134 
136 
137 // std::cout << std::endl << "X:" << std::endl << X << std::endl;
138 
139  params.m_directParameters.resize( 4 );
140  params.m_directParameters[0] = m_computeParameters_X(0,0);
141  params.m_directParameters[1] = m_computeParameters_X(1,0);
142  params.m_directParameters[2] = m_computeParameters_X(2,0);
143  params.m_directParameters[3] = m_computeParameters_X(3,0);
144 
145  /* inverse parameters calcule */
146 
147  m_computeParameters_XExpanded.resize( 3, 3 );
154  m_computeParameters_XExpanded( 2, 0 ) = 0;
155  m_computeParameters_XExpanded( 2, 1 ) = 0;
156  m_computeParameters_XExpanded( 2, 2 ) = 1;
157 
158 // std::cout << std::endl << "XExpanded:" << std::endl << XExpanded << std::endl;
159 
161  {
162 // std::cout << std::endl << "XExpandedInv:" << std::endl << XExpandedInv << std::endl;
163 
164  params.m_inverseParameters.resize( 4 );
169 
170  return true;
171  }
172  else
173  {
174  return false;
175  }
176  }
177  else
178  {
179  return false;
180  }
181 }
182 
183 
unsigned int m_computeParameters_tpIdx
Definition: RSTGT.h:95
2D Rotation/scale/translation (rigid body) Geometric transformation.
boost::numeric::ublas::matrix< double > m_computeParameters_N
Definition: RSTGT.h:100
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
double y
y-coordinate.
Definition: Coord2D.h:114
unsigned int m_computeParameters_tiepointsSize
Definition: RSTGT.h:96
boost::numeric::ublas::matrix< double > m_computeParameters_L
Definition: RSTGT.h:98
boost::numeric::ublas::matrix< double > m_computeParameters_U
Definition: RSTGT.h:101
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:62
double x
x-coordinate.
Definition: Coord2D.h:113
std::vector< double > m_directParameters
Transformation numeric direct parameters.
Definition: GTParameters.h:100
RSTGT()
Default constructor.
const std::string & getName() const
Returns the current transformation name.
Definition: RSTGT.cpp:37
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:49
GTParameters m_internalParameters
The current internal parameters.
2D Rotation/scale/translation(rigid body) Geometric transformation.
Definition: RSTGT.h:66
boost::numeric::ublas::matrix< double > m_computeParameters_A
Definition: RSTGT.h:97
boost::numeric::ublas::matrix< double > m_computeParameters_XExpanded
Definition: RSTGT.h:104
bool isValid() const
Tells if the current instance has a valid transformation.
boost::numeric::ublas::matrix< double > m_computeParameters_X
Definition: RSTGT.h:103
boost::numeric::ublas::matrix< double > m_computeParameters_N_inv
Definition: RSTGT.h:102
unsigned int m_computeParameters_index2
Definition: RSTGT.h:94
boost::numeric::ublas::matrix< double > m_computeParameters_XExpandedInv
Definition: RSTGT.h:105
~RSTGT()
Destructor.
bool GetInverseMatrix(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &outputMatrix)
Matrix inversion.
Definition: MatrixUtils.h:143
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:75
GeometricTransformation * clone() const
Creat a clone copy of this instance.
Definition: RSTGT.cpp:80
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:87
unsigned int m_computeParameters_index1
Definition: RSTGT.h:93
boost::numeric::ublas::matrix< double > m_computeParameters_At
Definition: RSTGT.h:99