27 #include "../common/MatrixUtils.h"
34 #include <boost/numeric/ublas/matrix.hpp>
46 static std::string name(
"Affine" );
57 const double& pt1Y,
double& pt2X,
double& pt2Y )
const
59 assert( isValid( params ) );
70 const double& pt2Y,
double& pt1X,
double& pt1Y )
const
72 assert( isValid( params ) );
96 const unsigned int tiepointsSize =
static_cast<unsigned int>(params.
m_tiePoints.size());
98 if( tiepointsSize < getMinRequiredTiePoints() )
101 boost::numeric::ublas::matrix< double >
L( 2*tiepointsSize, 1 );
102 boost::numeric::ublas::matrix< double >
A( 2*tiepointsSize, 6 );
103 unsigned int index1 = 0;
104 unsigned int index2 = 0;
106 for (
unsigned int tpIdx = 0 ; tpIdx < tiepointsSize ; ++tpIdx)
114 A( index1, 0 ) = x_y.
x ;
115 A( index1, 1 ) = x_y.
y ;
124 A( index2, 3 ) = x_y.
x ;
125 A( index2, 4 ) = x_y.
y ;
128 L( index1, 0) = u_v.
x;
129 L( index2, 0) = u_v.
y;
133 boost::numeric::ublas::matrix< double > At( boost::numeric::ublas::trans( A ) ) ;
136 boost::numeric::ublas::matrix< double > N( boost::numeric::ublas::prod( At, A ) );
139 boost::numeric::ublas::matrix< double > U( boost::numeric::ublas::prod( At, L ) );
142 boost::numeric::ublas::matrix< double > N_inv;
148 boost::numeric::ublas::matrix< double > X(
149 boost::numeric::ublas::prod( N_inv, U ) );
161 boost::numeric::ublas::matrix< double > XExpanded( 3, 3 );
162 XExpanded( 0, 0 ) = X(0,0);
163 XExpanded( 0, 1 ) = X(1,0);
164 XExpanded( 0, 2 ) = X(2,0);
165 XExpanded( 1, 0 ) = X(3,0);
166 XExpanded( 1, 1 ) = X(4,0);
167 XExpanded( 1, 2 ) = X(5,0);
168 XExpanded( 2, 0 ) = 0;
169 XExpanded( 2, 1 ) = 0;
170 XExpanded( 2, 2 ) = 1;
172 boost::numeric::ublas::matrix< double > XExpandedInv;
199 double& translationX,
double& translationY,
200 double& scalingFactorX,
double& scalingFactorY,
double& skew,
201 double& squeeze,
double& scaling,
double& rotation )
203 assert( transfParams.size() == 6 );
205 double APar = transfParams[ 0 ];
206 double BPar = transfParams[ 1 ];
207 double CPar = transfParams[ 3 ];
208 double DPar = transfParams[ 4 ];
210 double determinant = ( APar * DPar ) - ( BPar * CPar );
212 if( determinant == 0.0 )
216 else if( determinant < 0.0 )
218 APar = transfParams[ 1 ];
219 BPar = transfParams[ 0 ];
220 CPar = transfParams[ 4 ];
221 DPar = transfParams[ 3 ];
223 determinant = ( APar * DPar ) - ( BPar * CPar );
226 const double FVar = 1.0 / ( ( APar * APar ) +
229 skew = ( ( APar * BPar ) + ( CPar * DPar ) ) * FVar;
231 squeeze = 1.0 / sqrt( FVar * determinant );
233 scaling = sqrt( determinant );
235 scalingFactorX = scaling * squeeze;
237 scalingFactorY = scaling / squeeze;
239 translationX = transfParams[ 2 ];
241 translationY = transfParams[ 5 ];
243 rotation = atan( CPar / APar );
void inverseMap(const GTParameters ¶ms, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const
Inverse mapping (from pt2 space into pt1 space).
static bool decompose(const std::vector< double > &transfParams, double &translationX, double &translationY, double &scalingFactorX, double &scalingFactorY, double &skew, double &squeeze, double &scaling, double &rotation)
Returns the basic set of transform parameters given by the decomposition of a given affine transforma...
An utility struct for representing 2D coordinates.
void directMap(const GTParameters ¶ms, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const
Direct mapping (from pt1 space into pt2 space).
bool isValid() const
Tells if the current instance has a valid transformation.
2D Affine Geometric transformation.
std::vector< TiePoint > m_tiePoints
Tie points.
const std::string & getName() const
Returns the current transformation name.
unsigned int getMinRequiredTiePoints() const
Returns the minimum number of required tie-points for the current transformation. ...
GTParameters m_internalParameters
The current internal parameters.
std::vector< double > m_inverseParameters
Transformation numeric inverse parameters.
bool getInverseMatrix(const boost::numeric::ublas::matrix< T > &inputMatrix, boost::numeric::ublas::matrix< T > &outputMatrix)
Matrix inversion.
GeometricTransformation * clone() const
Creat a clone copy of this instance.
2D Geometric transformation base class.
AffineGT()
Default constructor.
std::vector< double > m_directParameters
Transformation numeric direct parameters.
2D Geometric transformation parameters.
2D Affine Geometric transformation.
bool computeParameters(GTParameters ¶ms) const
Calculate the transformation parameters following the new supplied tie-points.