TsGeometricTransformations.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 // Unit-Test TerraLib
22 #include "../Config.h"
23 
24 // TerraLib
25 #include <terralib/geometry.h>
26 
27 #include <boost/lexical_cast.hpp>
28 
29 #include <memory>
30 
31 #include <cmath>
32 
34 
36 {
37 }
38 
40 {
41 }
42 
44  const std::vector< te::gm::GTParameters::TiePoint >& tiePoints,
45  const te::gm::GeometricTransformation& transformation,
46  double maxError ) const
47 {
48  CPPUNIT_ASSERT( transformation.isValid() );
49 
50  te::gm::Coord2D dMappedCoord;
51  te::gm::Coord2D iMappedCoord;
52  double diffx = 0;
53  double diffy = 0;
54  double derror = 0;
55  double ierror = 0;
56  bool OKStatus = true;
57 
58  for( unsigned int tpIdx = 0 ; tpIdx < tiePoints.size() ; ++tpIdx )
59  {
60  transformation.directMap( tiePoints[ tpIdx ].first, dMappedCoord );
61  diffx = dMappedCoord.x - tiePoints[ tpIdx ].second.x;
62  diffy = dMappedCoord.y - tiePoints[ tpIdx ].second.y;
63  derror = sqrt( ( diffx * diffx ) + ( diffy * diffy ) );
64 
65  transformation.inverseMap( tiePoints[ tpIdx ].second, iMappedCoord );
66  diffx = iMappedCoord.x - tiePoints[ tpIdx ].first.x;
67  diffy = iMappedCoord.y - tiePoints[ tpIdx ].first.y;
68  ierror = sqrt( ( diffx * diffx ) + ( diffy * diffy ) );
69 
70  if( derror > maxError )
71  {
72  OKStatus = false;
73 
74  std::cout << std::endl <<
75  "["
76  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.x )
77  + ","
78  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.y )
79  + "]->["
80  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.x )
81  + ","
82  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.y )
83  + "] was direct-mapped as ["
84  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.x )
85  + ","
86  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.y )
87  + "]->["
88  + boost::lexical_cast<std::string>( dMappedCoord.x )
89  + ","
90  + boost::lexical_cast<std::string>( dMappedCoord.y )
91  + "] derror:"
92  + boost::lexical_cast<std::string>( derror )
93  << std::endl;
94  }
95 
96  if( ierror > maxError )
97  {
98  OKStatus = false;
99 
100  std::cout << std::endl <<
101  "["
102  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.x )
103  + ","
104  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].first.y )
105  + "]<-["
106  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.x )
107  + ","
108  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.y )
109  + "] was inverse-mapped as ["
110  + boost::lexical_cast<std::string>( iMappedCoord.x )
111  + ","
112  + boost::lexical_cast<std::string>( iMappedCoord.y )
113  + "]<-["
114  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.x )
115  + ","
116  + boost::lexical_cast<std::string>( tiePoints[ tpIdx ].second.y )
117  + " ierror:"
118  + boost::lexical_cast<std::string>( ierror )
119  << std::endl;
120  }
121  }
122 
123  if( !OKStatus )
124  {
125  CPPUNIT_FAIL( "Tie-points checking failed" );
126  }
127 }
128 
130 {
131  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
132  te::gm::GTFactory::make( "RST" ) );
133  CPPUNIT_ASSERT( transfPtr.get() != 0 );
134 
135  te::gm::GTParameters transfParams;
136 
137  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
138  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, -1.0 ) ) );
139  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
140  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( -1.0, 0.0 ) ) );
141 // transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
142 // te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 0.0, 1.0 ) ) );
143 // transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
144 // te::gm::Coord2D( 1.0, 0.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
145 
146  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
147 
148  CPPUNIT_ASSERT( transfPtr->getName() == "RST" );
149 
150  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
151 }
152 
154 {
155  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
156  te::gm::GTFactory::make( "Affine" ) );
157  CPPUNIT_ASSERT( transfPtr.get() != 0 );
158 
159  te::gm::GTParameters transfParams;
160 
161  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
162  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
163  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
164  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( -1.0, -2.0 ) ) );
165  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
166  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( -1.0, 0.0 ) ) );
167 // transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
168 // te::gm::Coord2D( 1.0, 0.0 ), te::gm::Coord2D( 1.0, 2.0 ) ) );
169 
170 
171  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
172 
173  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
174 
175 testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
176 }
177 
179 {
180  // translation X+1
181 
182  {
183  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
184  te::gm::GTFactory::make( "Affine" ) );
185  CPPUNIT_ASSERT( transfPtr.get() != 0 );
186 
187  te::gm::GTParameters transfParams;
188 
189  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
190  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
191  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
192  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 1.0, 1.0 ) ) );
193  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
194  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 2.0, 1.0 ) ) );
195 
196 
197  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
198  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
199 
200  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
201 
202  double translationX = 0;
203  double translationY = 0;
204  double scalingFactorX = 0;
205  double scalingFactorY = 0;
206  double skew = 0;
207  double squeeze = 0;
208  double scaling = 0;
209  double rotation = 0;
210 
211  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
212  transfPtr->getParameters().m_directParameters,
213  translationX, translationY, scalingFactorX, scalingFactorY, skew,
214  squeeze, scaling, rotation ) );
215 
216  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, translationX, 0.00000000001 );
217  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
218  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
219  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
220  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
221  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
222  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
223  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
224  }
225 
226  // translation X+1
227 
228  {
229  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
230  te::gm::GTFactory::make( "Affine" ) );
231  CPPUNIT_ASSERT( transfPtr.get() != 0 );
232 
233  te::gm::GTParameters transfParams;
234 
235  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
236  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( -1.0, 0.0 ) ) );
237  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
238  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( -1.0, 1.0 ) ) );
239  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
240  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 0.0, 1.0 ) ) );
241 
242 
243  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
244  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
245 
246  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
247 
248  double translationX = 0;
249  double translationY = 0;
250  double scalingFactorX = 0;
251  double scalingFactorY = 0;
252  double skew = 0;
253  double squeeze = 0;
254  double scaling = 0;
255  double rotation = 0;
256 
257  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
258  transfPtr->getParameters().m_directParameters,
259  translationX, translationY, scalingFactorX, scalingFactorY, skew,
260  squeeze, scaling, rotation ) );
261 
262  CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.0, translationX, 0.00000000001 );
263  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
264  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
265  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
266  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
267  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
268  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
269  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
270  }
271 
272  // translation Y+1
273 
274  {
275  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
276  te::gm::GTFactory::make( "Affine" ) );
277  CPPUNIT_ASSERT( transfPtr.get() != 0 );
278 
279  te::gm::GTParameters transfParams;
280 
281  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
282  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 1.0 ) ) );
283  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
284  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, 2.0 ) ) );
285  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
286  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, 2.0 ) ) );
287 
288 
289  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
290  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
291 
292  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
293 
294  double translationX = 0;
295  double translationY = 0;
296  double scalingFactorX = 0;
297  double scalingFactorY = 0;
298  double skew = 0;
299  double squeeze = 0;
300  double scaling = 0;
301  double rotation = 0;
302 
303  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
304  transfPtr->getParameters().m_directParameters,
305  translationX, translationY, scalingFactorX, scalingFactorY, skew,
306  squeeze, scaling, rotation ) );
307 
308  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
309  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, translationY, 0.00000000001 );
310  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
311  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
312  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
313  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
314  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
315  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
316  }
317 
318  // translation Y-1
319 
320  {
321  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
322  te::gm::GTFactory::make( "Affine" ) );
323  CPPUNIT_ASSERT( transfPtr.get() != 0 );
324 
325  te::gm::GTParameters transfParams;
326 
327  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
328  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, -1.0 ) ) );
329  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
330  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
331  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
332  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
333 
334 
335  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
336  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
337 
338  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
339 
340  double translationX = 0;
341  double translationY = 0;
342  double scalingFactorX = 0;
343  double scalingFactorY = 0;
344  double skew = 0;
345  double squeeze = 0;
346  double scaling = 0;
347  double rotation = 0;
348 
349  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
350  transfPtr->getParameters().m_directParameters,
351  translationX, translationY, scalingFactorX, scalingFactorY, skew,
352  squeeze, scaling, rotation ) );
353 
354  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
355  CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.0, translationY, 0.00000000001 );
356  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
357  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
358  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
359  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
360  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
361  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
362  }
363 
364  // 90 deg clock wise rotation around the center
365 
366  {
367  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
368  te::gm::GTFactory::make( "Affine" ) );
369  CPPUNIT_ASSERT( transfPtr.get() != 0 );
370 
371  te::gm::GTParameters transfParams;
372 
373  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
374  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
375  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
376  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
377  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
378  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, -1.0 ) ) );
379 
380 
381  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
382  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
383 
384  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
385 
386  double translationX = 0;
387  double translationY = 0;
388  double scalingFactorX = 0;
389  double scalingFactorY = 0;
390  double skew = 0;
391  double squeeze = 0;
392  double scaling = 0;
393  double rotation = 0;
394 
395  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
396  transfPtr->getParameters().m_directParameters,
397  translationX, translationY, scalingFactorX, scalingFactorY, skew,
398  squeeze, scaling, rotation ) );
399 
400  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
401  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
402  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
403  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
404  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
405  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
406  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
407  CPPUNIT_ASSERT_DOUBLES_EQUAL( -1.570796, rotation, 0.001 );
408  }
409 
410  // 90 deg counter clock wise rotation around the center
411 
412  {
413  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
414  te::gm::GTFactory::make( "Affine" ) );
415  CPPUNIT_ASSERT( transfPtr.get() != 0 );
416 
417  te::gm::GTParameters transfParams;
418 
419  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
420  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
421  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
422  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( -1.0, 0.0 ) ) );
423  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
424  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( -1.0, 1.0 ) ) );
425 
426 
427  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
428  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
429 
430  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
431 
432  double translationX = 0;
433  double translationY = 0;
434  double scalingFactorX = 0;
435  double scalingFactorY = 0;
436  double skew = 0;
437  double squeeze = 0;
438  double scaling = 0;
439  double rotation = 0;
440 
441  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
442  transfPtr->getParameters().m_directParameters,
443  translationX, translationY, scalingFactorX, scalingFactorY, skew,
444  squeeze, scaling, rotation ) );
445 
446  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
447  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
448  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
449  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
450  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
451  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, squeeze, 0.00000000001 );
452  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scaling, 0.00000000001 );
453  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.570796, rotation, 0.001 );
454  }
455 
456  // scale +2X
457 
458  {
459  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
460  te::gm::GTFactory::make( "Affine" ) );
461  CPPUNIT_ASSERT( transfPtr.get() != 0 );
462 
463  te::gm::GTParameters transfParams;
464 
465  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
466  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
467  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
468  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, 1.0 ) ) );
469  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
470  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 2.0, 1.0 ) ) );
471 
472 
473  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
474  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
475 
476  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
477 
478  double translationX = 0;
479  double translationY = 0;
480  double scalingFactorX = 0;
481  double scalingFactorY = 0;
482  double skew = 0;
483  double squeeze = 0;
484  double scaling = 0;
485  double rotation = 0;
486 
487  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
488  transfPtr->getParameters().m_directParameters,
489  translationX, translationY, scalingFactorX, scalingFactorY, skew,
490  squeeze, scaling, rotation ) );
491 
492  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
493  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
494  CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, scalingFactorX, 0.00000000001 );
495  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
496  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
497  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, squeeze, 0.0001 );
498  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, scaling, 0.0001 );
499  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
500  }
501 
502  // scale -2X
503 
504  {
505  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
506  te::gm::GTFactory::make( "Affine" ) );
507  CPPUNIT_ASSERT( transfPtr.get() != 0 );
508 
509  te::gm::GTParameters transfParams;
510 
511  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
512  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
513  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
514  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, 1.0 ) ) );
515  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
516  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( -2.0, 1.0 ) ) );
517 
518 
519  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
520  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
521 
522  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
523 
524  double translationX = 0;
525  double translationY = 0;
526  double scalingFactorX = 0;
527  double scalingFactorY = 0;
528  double skew = 0;
529  double squeeze = 0;
530  double scaling = 0;
531  double rotation = 0;
532 
533  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
534  transfPtr->getParameters().m_directParameters,
535  translationX, translationY, scalingFactorX, scalingFactorY, skew,
536  squeeze, scaling, rotation ) );
537 
538  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
539  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
540  CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, scalingFactorX, 0.00000000001 );
541  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorY, 0.00000000001 );
542  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
543  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106, squeeze, 0.0001 );
544  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, scaling, 0.0001 );
545  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
546  }
547 
548  // scale 2Y
549 
550  {
551  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
552  te::gm::GTFactory::make( "Affine" ) );
553  CPPUNIT_ASSERT( transfPtr.get() != 0 );
554 
555  te::gm::GTParameters transfParams;
556 
557  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
558  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
559  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
560  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, 2.0 ) ) );
561  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
562  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, 2.0 ) ) );
563 
564 
565  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
566  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
567 
568  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
569 
570  double translationX = 0;
571  double translationY = 0;
572  double scalingFactorX = 0;
573  double scalingFactorY = 0;
574  double skew = 0;
575  double squeeze = 0;
576  double scaling = 0;
577  double rotation = 0;
578 
579  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
580  transfPtr->getParameters().m_directParameters,
581  translationX, translationY, scalingFactorX, scalingFactorY, skew,
582  squeeze, scaling, rotation ) );
583 
584  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
585  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
586  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
587  CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, scalingFactorY, 0.00000000001 );
588  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
589  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.707106, squeeze, 0.0001 );
590  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, scaling, 0.0001 );
591  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
592  }
593 
594  // scale -2Y
595 
596  {
597  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
598  te::gm::GTFactory::make( "Affine" ) );
599  CPPUNIT_ASSERT( transfPtr.get() != 0 );
600 
601  te::gm::GTParameters transfParams;
602 
603  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
604  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
605  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
606  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( 0.0, -2.0 ) ) );
607  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
608  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, -2.0 ) ) );
609 
610 
611  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
612  CPPUNIT_ASSERT( transfPtr->getName() == "Affine" );
613 
614  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
615 
616  double translationX = 0;
617  double translationY = 0;
618  double scalingFactorX = 0;
619  double scalingFactorY = 0;
620  double skew = 0;
621  double squeeze = 0;
622  double scaling = 0;
623  double rotation = 0;
624 
625  CPPUNIT_ASSERT( te::gm::AffineGT::decompose(
626  transfPtr->getParameters().m_directParameters,
627  translationX, translationY, scalingFactorX, scalingFactorY, skew,
628  squeeze, scaling, rotation ) );
629 
630  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationX, 0.00000000001 );
631  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, translationY, 0.00000000001 );
632  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.0, scalingFactorX, 0.00000000001 );
633  CPPUNIT_ASSERT_DOUBLES_EQUAL( 2.0, scalingFactorY, 0.00000000001 );
634  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, skew, 0.00000000001 );
635  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, squeeze, 0.0001 );
636  CPPUNIT_ASSERT_DOUBLES_EQUAL( 1.414213, scaling, 0.0001 );
637  CPPUNIT_ASSERT_DOUBLES_EQUAL( 0.0, rotation, 0.00000000001 );
638  }
639 }
640 
642 {
643  {
644  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
645  te::gm::GTFactory::make( "SecondDegreePolynomial" ) );
646  CPPUNIT_ASSERT( transfPtr.get() != 0 );
647 
648  te::gm::GTParameters transfParams;
649 
650  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
651  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
652  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
653  te::gm::Coord2D( 1.0, 0.0 ), te::gm::Coord2D( 1.0, 0.0 ) ) );
654  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
655  te::gm::Coord2D( 2.0, 0.0 ), te::gm::Coord2D( 2.0, 0.0 ) ) );
656  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
657  te::gm::Coord2D( 2.0, 2.0 ), te::gm::Coord2D( 2.0, 2.0 ) ) );
658  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
659  te::gm::Coord2D( 1.0, 2.0 ), te::gm::Coord2D( 1.0, 2.0 ) ) );
660  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
661  te::gm::Coord2D( 0.0, 2.0 ), te::gm::Coord2D( 0.0, 2.0 ) ) );
662  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
663  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, 1.0 ) ) );
664 
665 
666  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
667 
668  CPPUNIT_ASSERT( transfPtr->getName() == "SecondDegreePolynomial" );
669 
670  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
671  }
672 
673  {
674  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
675  te::gm::GTFactory::make( "SecondDegreePolynomial" ) );
676  CPPUNIT_ASSERT( transfPtr.get() != 0 );
677 
678  te::gm::GTParameters transfParams;
679 
680  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
681  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 1.0, -1.0 ) ) );
682  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
683  te::gm::Coord2D( 1.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
684  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
685  te::gm::Coord2D( 2.0, 0.0 ), te::gm::Coord2D( 1.0, 1.0 ) ) );
686  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
687  te::gm::Coord2D( 2.0, 2.0 ), te::gm::Coord2D( -1.0, 1.0 ) ) );
688  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
689  te::gm::Coord2D( 1.0, 2.0 ), te::gm::Coord2D( -2.0, 0.0 ) ) );
690  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
691  te::gm::Coord2D( 0.0, 2.0 ), te::gm::Coord2D( -1.0, -1.0 ) ) );
692  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
693  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( -1.0, 0.0 ) ) );
694 
695 
696  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
697 
698  CPPUNIT_ASSERT( transfPtr->getName() == "SecondDegreePolynomial" );
699 
700  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
701  }
702 }
703 
705 {
706  {
707  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
708  te::gm::GTFactory::make( "ThirdDegreePolynomial" ) );
709  CPPUNIT_ASSERT( transfPtr.get() != 0 );
710 
711  te::gm::GTParameters transfParams;
712 
713  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
714  te::gm::Coord2D( -5.0, -16.0 ), te::gm::Coord2D( -5.0, -16.0 ) ) );
715  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
716  te::gm::Coord2D( -4.0, -8.0 ), te::gm::Coord2D( -4.0, -8.0 ) ) );
717  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
718  te::gm::Coord2D( -3.0, -4.0 ), te::gm::Coord2D( -3.0, -4.0 ) ) );
719  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
720  te::gm::Coord2D( -2.0, -2.0 ), te::gm::Coord2D( -2.0, -2.0 ) ) );
721  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
722  te::gm::Coord2D( -1.0, -1.0 ), te::gm::Coord2D( -1.0, -1.0 ) ) );
723  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
724  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
725  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
726  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( 1.0, 1.0 ) ) );
727  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
728  te::gm::Coord2D( 2.0, 2.0 ), te::gm::Coord2D( 2.0, 2.0 ) ) );
729  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
730  te::gm::Coord2D( 3.0, 4.0 ), te::gm::Coord2D( 3.0, 4.0 ) ) );
731  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
732  te::gm::Coord2D( 4.0, 8.0 ), te::gm::Coord2D( 4.0, 8.0 ) ) );
733  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
734  te::gm::Coord2D( 5.0, 16.0 ), te::gm::Coord2D( 5.0, 16.0 ) ) );
735  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
736  te::gm::Coord2D( 6.0, 32.0 ), te::gm::Coord2D( 6.0, 32.0 ) ) );
737 
738  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
739 
740  CPPUNIT_ASSERT( transfPtr->getName() == "ThirdDegreePolynomial" );
741 
742  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
743  }
744 
745  {
746  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
747  te::gm::GTFactory::make( "ThirdDegreePolynomial" ) );
748  CPPUNIT_ASSERT( transfPtr.get() != 0 );
749 
750  te::gm::GTParameters transfParams;
751 
752  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
753  te::gm::Coord2D( -10.0, -16.0 ), te::gm::Coord2D( -5.0, -16.0 ) ) );
754  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
755  te::gm::Coord2D( -8.0, -8.0 ), te::gm::Coord2D( -4.0, -8.0 ) ) );
756  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
757  te::gm::Coord2D( -6.0, -4.0 ), te::gm::Coord2D( -3.0, -4.0 ) ) );
758  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
759  te::gm::Coord2D( -4.0, -2.0 ), te::gm::Coord2D( -2.0, -2.0 ) ) );
760  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
761  te::gm::Coord2D( -2.0, -1.0 ), te::gm::Coord2D( -1.0, -1.0 ) ) );
762  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
763  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 0.0, 0.0 ) ) );
764  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
765  te::gm::Coord2D( 2.0, 1.0 ), te::gm::Coord2D( 1.0, 1.0 ) ) );
766  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
767  te::gm::Coord2D( 4.0, 2.0 ), te::gm::Coord2D( 2.0, 2.0 ) ) );
768  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
769  te::gm::Coord2D( 6.0, 4.0 ), te::gm::Coord2D( 3.0, 4.0 ) ) );
770  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
771  te::gm::Coord2D( 8.0, 8.0 ), te::gm::Coord2D( 4.0, 8.0 ) ) );
772  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
773  te::gm::Coord2D( 10.0, 16.0 ), te::gm::Coord2D( 5.0, 16.0 ) ) );
774  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
775  te::gm::Coord2D( 12.0, 32.0 ), te::gm::Coord2D( 6.0, 32.0 ) ) );
776 
777  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
778 
779  CPPUNIT_ASSERT( transfPtr->getName() == "ThirdDegreePolynomial" );
780 
781  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
782  }
783 }
784 
786 {
787  std::unique_ptr< te::gm::GeometricTransformation > transfPtr(
788  te::gm::GTFactory::make( "Projective" ) );
789  CPPUNIT_ASSERT( transfPtr.get() != 0 );
790 
791  te::gm::GTParameters transfParams;
792 
793  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
794  te::gm::Coord2D( 0.0, 0.0 ), te::gm::Coord2D( 1.0, -2.0 ) ) );
795  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
796  te::gm::Coord2D( 0.0, 1.0 ), te::gm::Coord2D( -1.0, -1.0 ) ) );
797  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
798  te::gm::Coord2D( 1.0, 1.0 ), te::gm::Coord2D( -1.0, 1.0 ) ) );
799  transfParams.m_tiePoints.push_back( te::gm::GTParameters::TiePoint(
800  te::gm::Coord2D( 1.0, 0.0 ), te::gm::Coord2D( 1.0, 2.0 ) ) );
801 
802 
803  CPPUNIT_ASSERT( transfPtr->initialize( transfParams ) );
804 
805  CPPUNIT_ASSERT( transfPtr->getName() == "Projective" );
806 
807  testTiePoints( transfParams.m_tiePoints, *transfPtr, 0.00001 );
808 }
std::vector< TiePoint > m_tiePoints
Tie points.
Definition: GTParameters.h:95
double y
y-coordinate.
Definition: Coord2D.h:114
double x
x-coordinate.
Definition: Coord2D.h:113
virtual bool isValid(const GTParameters &params) const =0
Verifies if the supplied parameters already has a valid transformation.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
2D Geometric transformation base class.
void tcAffine()
Test Case: Affine transformation.
std::pair< Coord2D, Coord2D > TiePoint
Tie point type definition.
Definition: GTParameters.h:59
Test suite for Geometric Transformations.
void tcProjectiveGT()
Test Case: Projective transformation.
void tcThirdDegreePolynomialGT()
Test Case: Third degree polynomial transformation.
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...
Definition: AffineGT.cpp:188
void tcSecondDegreePolynomialGT()
Test Case: Second degree polynomial transformation.
CPPUNIT_TEST_SUITE_REGISTRATION(TsGeometricTransformations)
void testTiePoints(const std::vector< te::gm::GTParameters::TiePoint > &tiePoints, const te::gm::GeometricTransformation &transformation, double maxError) const
static GeometricTransformation * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
void tcAffineDecompose()
Test Case: Affine transformation decompose method.
virtual void directMap(const GTParameters &params, const double &pt1X, const double &pt1Y, double &pt2X, double &pt2Y) const =0
Direct mapping (from pt1 space into pt2 space).
2D Geometric transformation parameters.
Definition: GTParameters.h:50
This file contains include headers for the Vector Geometry model of TerraLib.
Test suite for Geometric Transformations.
void tcRSTGT()
Test Case: RST transformation.
virtual void inverseMap(const GTParameters &params, const double &pt2X, const double &pt2Y, double &pt1X, double &pt1Y) const =0
Inverse mapping (from pt2 space into pt1 space).