TsArithmeticOperations.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/unittest/rp/arithmetic_operations/TsArithmeticOperations.cpp
22 
23  \brief Main file of test suit for Arithmetic Operations algorithm.
24 */
25 
26 // TerraLib
27 #include "../Config.h"
28 #include <terralib/rp.h>
29 #include <terralib/raster.h>
30 #include <terralib/memory.h>
31 
32 // Boost
33 #define BOOST_TEST_NO_MAIN
34 #include <boost/test/unit_test.hpp>
35 
36 BOOST_AUTO_TEST_SUITE (arithmetic_operations_tests)
37 
38 void loadDoubleRaster( const std::string& rasterFileName, std::unique_ptr< te::rst::Raster >& rasterPtr )
39 {
40  /* Open input raster */
41 
42  std::map<std::string, std::string> rinfo;
43  rinfo["URI"] = rasterFileName;
44  std::unique_ptr<te::rst::Raster> rin(te::rst::RasterFactory::open(rinfo));
45 
46  std::vector< te::rst::BandProperty * > bandsProperties;
47 
48  unsigned int bandIdx = 0;
49 
50  for( bandIdx = 0 ; bandIdx < rin->getNumberOfBands() ; ++bandIdx )
51  {
52  bandsProperties.push_back( new te::rst::BandProperty(
53  *rin->getBand( bandIdx )->getProperty() ) );
54  bandsProperties[ bandIdx ]->m_type = te::dt::DOUBLE_TYPE;
55  }
56 
57  rasterPtr.reset( new te::mem::ExpansibleRaster( 50, new te::rst::Grid(
58  *rin->getGrid() ), bandsProperties ) );
59 
60  const unsigned int nRows = rin->getNumberOfRows();
61  const unsigned int nCols = rin->getNumberOfColumns();
62  unsigned int row = 0;
63  unsigned int col = 0;
64  double value = 0;
65  for( bandIdx = 0 ; bandIdx < rin->getNumberOfBands() ; ++bandIdx )
66  {
67  for( row = 0 ; row < nRows ; ++row )
68  {
69  for( col = 0 ; col < nCols ; ++col )
70  {
71  rin->getValue( col, row, value, bandIdx );
72  rasterPtr->setValue( col, row, value, bandIdx );
73  }
74  }
75  }
76 }
77 
78 BOOST_AUTO_TEST_CASE (rasterSum_test)
79 {
80  /* Load input raster as a doubles raster */
81 
82  std::unique_ptr< te::rst::Raster > rin;
83  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
84  rin );
85 
86  /* Defining input parameters, the arithmetic operation will be
87  * band 0 + band 1 - band 2 */
88 
90  inputParams.m_arithmeticString = "R0:0 + R0:1";
91  inputParams.m_normalize = false;
92  inputParams.m_inputRasters.push_back(rin.get());
93 
94  /* Create output raster info */
95 
96  std::map<std::string, std::string> orinfo;
97  orinfo["URI"] = "terralib_unittest_arithmetic_RasterSum.tif";
98 
99  /* Defining output parameters */
100 
102  outputParams.m_rInfo = orinfo;
103  outputParams.m_rType = "GDAL";
104 
105  te::rp::ArithmeticOperations algorithmInstance;
106 
107  BOOST_CHECK(algorithmInstance.initialize(inputParams));
108  BOOST_CHECK(algorithmInstance.execute(outputParams));
109 
110  /* Open output raster */
111 
112  double inputValue1 = 0;
113  double inputValue2 = 0;
114  double outputValue = 0;
115  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
116  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
117  {
118  rin->getValue(c, r, inputValue1, 0);
119  rin->getValue(c, r, inputValue2, 1);
120  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
121  BOOST_CHECK_CLOSE( inputValue1 + inputValue2,
122  outputValue, 0.0000001 );
123  }
124 }
125 
126 BOOST_AUTO_TEST_CASE (rasterSumNormalize_test)
127 {
128  /* Load input raster as a doubles raster */
129 
130  /* Open input raster */
131 
132  std::map<std::string, std::string> rinfo;
133  rinfo["URI"] = TERRALIB_DATA_DIR "/geotiff/cbers2b_rgb342_crop.tif";
134  std::unique_ptr<te::rst::Raster> rin(te::rst::RasterFactory::open(rinfo));
135 
136  /* Defining input parameters, the arithmetic operation will be
137  * band 0 + band 1 - band 2 */
138 
140  inputParams.m_arithmeticString = "R0:0 + R0:1";
141  inputParams.m_normalize = true;
142  inputParams.m_inputRasters.push_back(rin.get());
143 
144  /* Create output raster info */
145 
146  std::map<std::string, std::string> orinfo;
147  orinfo["URI"] = "terralib_unittest_arithmetic_RasterSumNormalize.tif";
148 
149  /* Defining output parameters */
150 
152  outputParams.m_rInfo = orinfo;
153  outputParams.m_rType = "GDAL";
154 
155  te::rp::ArithmeticOperations algorithmInstance;
156 
157  BOOST_CHECK(algorithmInstance.initialize(inputParams));
158  BOOST_CHECK(algorithmInstance.execute(outputParams));
159 }
160 
161 BOOST_AUTO_TEST_CASE (rasterSubtraction_test)
162 {
163  /* Load input raster as a doubles raster */
164 
165  std::unique_ptr< te::rst::Raster > rin;
166  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
167  rin );
168 
169  /* Defining input parameters, the arithmetic operation will be
170  * band 0 + band 1 - band 2 */
171 
173  inputParams.m_arithmeticString = "R0:0 - R0:1";
174  inputParams.m_normalize = false;
175  inputParams.m_inputRasters.push_back(rin.get());
176 
177  /* Create output raster info */
178 
179  std::map<std::string, std::string> orinfo;
180  orinfo["URI"] = "terralib_unittest_arithmetic_RasterSubtraction.tif";
181 
182  /* Defining output parameters */
183 
185  outputParams.m_rInfo = orinfo;
186  outputParams.m_rType = "GDAL";
187 
188  te::rp::ArithmeticOperations algorithmInstance;
189 
190  BOOST_CHECK(algorithmInstance.initialize(inputParams));
191  BOOST_CHECK(algorithmInstance.execute(outputParams));
192 
193  /* Open output raster */
194 
195  double inputValue1 = 0;
196  double inputValue2 = 0;
197  double outputValue = 0;
198  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
199  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
200  {
201  rin->getValue(c, r, inputValue1, 0);
202  rin->getValue(c, r, inputValue2, 1);
203  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
204  BOOST_CHECK_CLOSE( ( inputValue1 - inputValue2 ),
205  outputValue, 0.0000001 );
206  }
207 }
208 
209 BOOST_AUTO_TEST_CASE (rasterProduct_test)
210 {
211  /* Load input raster as a doubles raster */
212 
213  std::unique_ptr< te::rst::Raster > rin;
214  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
215  rin );
216 
217  /* Defining input parameters, the arithmetic operation will be
218  * band 0 + band 1 - band 2 */
219 
221  inputParams.m_arithmeticString = "R0:0 * R0:1";
222  inputParams.m_normalize = false;
223  inputParams.m_inputRasters.push_back(rin.get());
224 
225  /* Create output raster info */
226 
227  std::map<std::string, std::string> orinfo;
228  orinfo["URI"] = "terralib_unittest_arithmetic_RasterProduct.tif";
229 
230  /* Defining output parameters */
231 
233  outputParams.m_rInfo = orinfo;
234  outputParams.m_rType = "GDAL";
235 
236  te::rp::ArithmeticOperations algorithmInstance;
237 
238  BOOST_CHECK(algorithmInstance.initialize(inputParams));
239  BOOST_CHECK(algorithmInstance.execute(outputParams));
240 
241  /* Open output raster */
242 
243  double inputValue1 = 0;
244  double inputValue2 = 0;
245  double outputValue = 0;
246  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
247  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
248  {
249  rin->getValue(c, r, inputValue1, 0);
250  rin->getValue(c, r, inputValue2, 1);
251  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
252  BOOST_CHECK_CLOSE( inputValue1 * inputValue2, outputValue, 0.0000001 );
253  }
254 }
255 
256 BOOST_AUTO_TEST_CASE (rasterDivision_test)
257 {
258  /* Load input raster as a doubles raster */
259 
260  std::unique_ptr< te::rst::Raster > rin;
261  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
262  rin );
263 
264  /* Defining input parameters, the arithmetic operation will be
265  * band 0 + band 1 - band 2 */
266 
268  inputParams.m_arithmeticString = "R0:0 / R0:1";
269  inputParams.m_normalize = false;
270  inputParams.m_inputRasters.push_back(rin.get());
271 
272  /* Create output raster info */
273 
274  std::map<std::string, std::string> orinfo;
275  orinfo["URI"] = "terralib_unittest_arithmetic_RasterDivision.tif";
276 
277  /* Defining output parameters */
278 
280  outputParams.m_rInfo = orinfo;
281  outputParams.m_rType = "GDAL";
282 
283  te::rp::ArithmeticOperations algorithmInstance;
284 
285  BOOST_CHECK(algorithmInstance.initialize(inputParams));
286  BOOST_CHECK(algorithmInstance.execute(outputParams));
287 
288  /* Open output raster */
289 
290  double inputValue1 = 0;
291  double inputValue2 = 0;
292  double outputValue = 0;
293  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
294  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
295  {
296  rin->getValue(c, r, inputValue1, 0);
297  rin->getValue(c, r, inputValue2, 1);
298  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
299  BOOST_CHECK_CLOSE( inputValue1 / inputValue2, outputValue, 0.0000001 );
300  }
301 }
302 
303 BOOST_AUTO_TEST_CASE (realSum_test)
304 {
305  /* Load input raster as a doubles raster */
306 
307  std::unique_ptr< te::rst::Raster > rin;
308  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
309  rin );
310 
311  /* Defining input parameters, the arithmetic operation will be
312  * band 0 + band 1 - band 2 */
313 
315  inputParams.m_arithmeticString = "R0:0 + 1";
316  inputParams.m_normalize = false;
317  inputParams.m_inputRasters.push_back(rin.get());
318 
319  /* Create output raster info */
320 
321  std::map<std::string, std::string> orinfo;
322  orinfo["URI"] = "terralib_unittest_arithmetic_RealSum.tif";
323 
324  /* Defining output parameters */
325 
327  outputParams.m_rInfo = orinfo;
328  outputParams.m_rType = "GDAL";
329 
330  te::rp::ArithmeticOperations algorithmInstance;
331 
332  BOOST_CHECK(algorithmInstance.initialize(inputParams));
333  BOOST_CHECK(algorithmInstance.execute(outputParams));
334 
335  /* Open output raster */
336 
337  double inputValue1 = 0;
338  double outputValue = 0;
339  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
340  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
341  {
342  rin->getValue(c, r, inputValue1, 0);
343  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
344  BOOST_CHECK_CLOSE( inputValue1 + 1.0, outputValue, 0.0000001 );
345  }
346 }
347 
348 BOOST_AUTO_TEST_CASE (realSubtraction_test)
349 {
350  /* Load input raster as a doubles raster */
351 
352  std::unique_ptr< te::rst::Raster > rin;
353  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
354  rin );
355 
356  /* Defining input parameters, the arithmetic operation will be
357  * band 0 + band 1 - band 2 */
358 
360  inputParams.m_arithmeticString = "R0:0 - 1";
361  inputParams.m_normalize = false;
362  inputParams.m_inputRasters.push_back(rin.get());
363 
364  /* Create output raster info */
365 
366  std::map<std::string, std::string> orinfo;
367  orinfo["URI"] = "terralib_unittest_arithmetic_RealSubtraction.tif";
368 
369  /* Defining output parameters */
370 
372  outputParams.m_rInfo = orinfo;
373  outputParams.m_rType = "GDAL";
374 
375  te::rp::ArithmeticOperations algorithmInstance;
376 
377  BOOST_CHECK(algorithmInstance.initialize(inputParams));
378  BOOST_CHECK(algorithmInstance.execute(outputParams));
379 
380  /* Open output raster */
381 
382  double inputValue1 = 0;
383  double outputValue = 0;
384  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
385  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
386  {
387  rin->getValue(c, r, inputValue1, 0);
388  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
389  BOOST_CHECK_CLOSE( inputValue1 - 1.0, outputValue, 0.0000001 );
390  }
391 }
392 
393 BOOST_AUTO_TEST_CASE (realSubtractionInverse_test)
394 {
395  /* Load input raster as a doubles raster */
396 
397  std::unique_ptr< te::rst::Raster > rin;
398  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
399  rin );
400 
401  /* Defining input parameters, the arithmetic operation will be
402  * band 0 + band 1 - band 2 */
403 
405  inputParams.m_arithmeticString = "1 - R0:0";
406  inputParams.m_normalize = false;
407  inputParams.m_inputRasters.push_back(rin.get());
408 
409  /* Create output raster info */
410 
411  std::map<std::string, std::string> orinfo;
412  orinfo["URI"] = "terralib_unittest_arithmetic_RealSubtractionInverse.tif";
413 
414  /* Defining output parameters */
415 
417  outputParams.m_rInfo = orinfo;
418  outputParams.m_rType = "GDAL";
419 
420  te::rp::ArithmeticOperations algorithmInstance;
421 
422  BOOST_CHECK(algorithmInstance.initialize(inputParams));
423  BOOST_CHECK(algorithmInstance.execute(outputParams));
424 
425  /* Open output raster */
426 
427  double inputValue1 = 0;
428  double outputValue = 0;
429  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
430  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
431  {
432  rin->getValue(c, r, inputValue1, 0);
433  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
434  BOOST_CHECK_CLOSE( 1.0 - inputValue1, outputValue, 0.0000001 );
435  }
436 }
437 
438 BOOST_AUTO_TEST_CASE (realProduct_test)
439 {
440  /* Load input raster as a doubles raster */
441 
442  std::unique_ptr< te::rst::Raster > rin;
443  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
444  rin );
445 
446  /* Defining input parameters, the arithmetic operation will be
447  * band 0 + band 1 - band 2 */
448 
450  inputParams.m_arithmeticString = "R0:0 * 2";
451  inputParams.m_normalize = false;
452  inputParams.m_inputRasters.push_back(rin.get());
453 
454  /* Create output raster info */
455 
456  std::map<std::string, std::string> orinfo;
457  orinfo["URI"] = "terralib_unittest_arithmetic_RealProduct.tif";
458 
459  /* Defining output parameters */
460 
462  outputParams.m_rInfo = orinfo;
463  outputParams.m_rType = "GDAL";
464 
465  te::rp::ArithmeticOperations algorithmInstance;
466 
467  BOOST_CHECK(algorithmInstance.initialize(inputParams));
468  BOOST_CHECK(algorithmInstance.execute(outputParams));
469 
470  /* Open output raster */
471 
472  double inputValue1 = 0;
473  double outputValue = 0;
474  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
475  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
476  {
477  rin->getValue(c, r, inputValue1, 0);
478  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
479  BOOST_CHECK_CLOSE( inputValue1 * 2.0, outputValue, 0.0000001 );
480  }
481 }
482 
483 BOOST_AUTO_TEST_CASE (realDivision_test)
484 {
485  /* Load input raster as a doubles raster */
486 
487  std::unique_ptr< te::rst::Raster > rin;
488  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
489  rin );
490 
491  /* Defining input parameters, the arithmetic operation will be
492  * band 0 + band 1 - band 2 */
493 
495  inputParams.m_arithmeticString = "R0:0 / 2";
496  inputParams.m_normalize = false;
497  inputParams.m_inputRasters.push_back(rin.get());
498 
499  /* Create output raster info */
500 
501  std::map<std::string, std::string> orinfo;
502  orinfo["URI"] = "terralib_unittest_arithmetic_RealDivision.tif";
503 
504  /* Defining output parameters */
505 
507  outputParams.m_rInfo = orinfo;
508  outputParams.m_rType = "GDAL";
509 
510  te::rp::ArithmeticOperations algorithmInstance;
511 
512  BOOST_CHECK(algorithmInstance.initialize(inputParams));
513  BOOST_CHECK(algorithmInstance.execute(outputParams));
514 
515  /* Open output raster */
516 
517  double inputValue1 = 0;
518  double outputValue = 0;
519  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
520  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
521  {
522  rin->getValue(c, r, inputValue1, 0);
523  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
524  BOOST_CHECK_CLOSE( inputValue1 / 2.0, outputValue, 0.0000001 );
525  }
526 }
527 
528 BOOST_AUTO_TEST_CASE (realDivisionInverse_test)
529 {
530  /* Load input raster as a doubles raster */
531 
532  std::unique_ptr< te::rst::Raster > rin;
533  loadDoubleRaster( TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
534  rin );
535 
536  /* Defining input parameters, the arithmetic operation will be
537  * band 0 + band 1 - band 2 */
538 
540  inputParams.m_arithmeticString = "1 / R0:0";
541  inputParams.m_normalize = false;
542  inputParams.m_inputRasters.push_back(rin.get());
543 
544  /* Create output raster info */
545 
546  std::map<std::string, std::string> orinfo;
547  orinfo["URI"] = "terralib_unittest_arithmetic_RealDivisionInverse.tif";
548 
549  /* Defining output parameters */
550 
552  outputParams.m_rInfo = orinfo;
553  outputParams.m_rType = "GDAL";
554 
555  te::rp::ArithmeticOperations algorithmInstance;
556 
557  BOOST_CHECK(algorithmInstance.initialize(inputParams));
558  BOOST_CHECK(algorithmInstance.execute(outputParams));
559 
560  /* Open output raster */
561 
562  double inputValue1 = 0;
563  double outputValue = 0;
564  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
565  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
566  {
567  rin->getValue(c, r, inputValue1, 0);
568  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
569  BOOST_CHECK_CLOSE( 1.0 / inputValue1, outputValue, 0.0000001 );
570  }
571 }
572 
573 BOOST_AUTO_TEST_CASE (diffGrid_test)
574 {
575  std::map<std::string, std::string> rinfo1;
576  rinfo1["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers_rgb342_crop1.tif";
577  std::unique_ptr<te::rst::Raster> rin1(te::rst::RasterFactory::open(rinfo1));
578 
579  std::map<std::string, std::string> rinfo2;
580  rinfo2["URI"] = TERRALIB_DATA_DIR"/geotiff/cbers_rgb342_crop2.tif";
581  std::unique_ptr<te::rst::Raster> rin2(te::rst::RasterFactory::open(rinfo2));
582 
583  /* Defining input parameters, the arithmetic operation will be
584  * band 0 + band 1 - band 2 */
585 
587  inputParams.m_arithmeticString = "R0:0 + R1:0";
588  inputParams.m_normalize = true;
589  inputParams.m_inputRasters.push_back(rin1.get());
590  inputParams.m_inputRasters.push_back(rin2.get());
591 
592  /* Create output raster info */
593 
594  std::map<std::string, std::string> orinfo;
595  orinfo["URI"] = "terralib_unittest_arithmetic_diffGrid.tif";
596 
597  /* Defining output parameters */
598 
600  outputParams.m_rInfo = orinfo;
601  outputParams.m_rType = "GDAL";
602 
603  te::rp::ArithmeticOperations algorithmInstance;
604 
605  BOOST_CHECK(algorithmInstance.initialize(inputParams));
606  BOOST_CHECK(algorithmInstance.execute(outputParams));
607 }
608 
609 BOOST_AUTO_TEST_CASE(exponential_test)
610 {
611  /* Load input raster as a doubles raster */
612 
613  std::unique_ptr< te::rst::Raster > rin;
614  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
615  rin);
616 
617  /* Defining input parameters, the arithmetic operation will be
618  * band 0 + band 1 - band 2 */
619 
621  inputParams.m_arithmeticString = "R0:0 ^ 2";
622  inputParams.m_normalize = false;
623  inputParams.m_inputRasters.push_back(rin.get());
624 
625  /* Create output raster info */
626 
627  std::map<std::string, std::string> orinfo;
628  orinfo["URI"] = "terralib_unittest_arithmetic_exponential.tif";
629 
630  /* Defining output parameters */
631 
633  outputParams.m_rInfo = orinfo;
634  outputParams.m_rType = "GDAL";
635 
636  te::rp::ArithmeticOperations algorithmInstance;
637 
638  BOOST_CHECK(algorithmInstance.initialize(inputParams));
639  BOOST_CHECK(algorithmInstance.execute(outputParams));
640 
641  /* Open output raster */
642 
643  double inputValue1 = 0;
644  double outputValue = 0;
645  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
646  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
647  {
648  rin->getValue(c, r, inputValue1, 0);
649  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
650  BOOST_CHECK_CLOSE(pow(inputValue1, 2.0), outputValue, 0.0000001);
651  }
652 }
653 
655 {
656  /* Load input raster as a doubles raster */
657 
658  std::unique_ptr< te::rst::Raster > rin;
659  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
660  rin);
661 
662  /* Defining input parameters, the arithmetic operation will be
663  * band 0 + band 1 - band 2 */
664 
666  inputParams.m_arithmeticString = "sqrt(R0:0)";
667  inputParams.m_normalize = false;
668  inputParams.m_inputRasters.push_back(rin.get());
669 
670  /* Create output raster info */
671 
672  std::map<std::string, std::string> orinfo;
673  orinfo["URI"] = "terralib_unittest_arithmetic_sqrt.tif";
674 
675  /* Defining output parameters */
676 
678  outputParams.m_rInfo = orinfo;
679  outputParams.m_rType = "GDAL";
680 
681  te::rp::ArithmeticOperations algorithmInstance;
682 
683  BOOST_CHECK(algorithmInstance.initialize(inputParams));
684  BOOST_CHECK(algorithmInstance.execute(outputParams));
685 
686  /* Open output raster */
687 
688  double inputValue1 = 0;
689  double outputValue = 0;
690  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
691  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
692  {
693  rin->getValue(c, r, inputValue1, 0);
694  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
695  BOOST_CHECK_CLOSE(sqrt(inputValue1), outputValue, 0.0000001);
696  }
697 }
698 
700 {
701  /* Load input raster as a doubles raster */
702 
703  std::unique_ptr< te::rst::Raster > rin;
704  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
705  rin);
706 
707  /* Defining input parameters, the arithmetic operation will be
708  * band 0 + band 1 - band 2 */
709 
711  inputParams.m_arithmeticString = "sin(R0:0)";
712  inputParams.m_normalize = false;
713  inputParams.m_inputRasters.push_back(rin.get());
714 
715  /* Create output raster info */
716 
717  std::map<std::string, std::string> orinfo;
718  orinfo["URI"] = "terralib_unittest_arithmetic_sin.tif";
719 
720  /* Defining output parameters */
721 
723  outputParams.m_rInfo = orinfo;
724  outputParams.m_rType = "GDAL";
725 
726  te::rp::ArithmeticOperations algorithmInstance;
727 
728  BOOST_CHECK(algorithmInstance.initialize(inputParams));
729  BOOST_CHECK(algorithmInstance.execute(outputParams));
730 
731  /* Open output raster */
732 
733  double inputValue1 = 0;
734  double outputValue = 0;
735  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
736  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
737  {
738  rin->getValue(c, r, inputValue1, 0);
739  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
740  BOOST_CHECK_CLOSE(sin(inputValue1), outputValue, 0.0000001);
741  }
742 }
743 
745 {
746  /* Load input raster as a doubles raster */
747 
748  std::unique_ptr< te::rst::Raster > rin;
749  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/landsat8_22768_ndvi.tif",
750  rin);
751 
752  /* Defining input parameters, the arithmetic operation will be
753  * band 0 + band 1 - band 2 */
754 
756  inputParams.m_arithmeticString = "asin(R0:0)";
757  inputParams.m_normalize = false;
758  inputParams.m_inputRasters.push_back(rin.get());
759 
760  /* Create output raster info */
761 
762  std::map<std::string, std::string> orinfo;
763  orinfo["URI"] = "terralib_unittest_arithmetic_asin.tif";
764 
765  /* Defining output parameters */
766 
768  outputParams.m_rInfo = orinfo;
769  outputParams.m_rType = "GDAL";
770 
771  te::rp::ArithmeticOperations algorithmInstance;
772 
773  BOOST_CHECK(algorithmInstance.initialize(inputParams));
774  BOOST_CHECK(algorithmInstance.execute(outputParams));
775 
776  /* Open output raster */
777 
778  double inputValue1 = 0;
779  double outputValue = 0;
780  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
781  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
782  {
783  rin->getValue(c, r, inputValue1, 0);
784 
785  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
786  BOOST_CHECK_CLOSE(asin(inputValue1), outputValue, 0.0000001);
787  }
788 }
789 
791 {
792  /* Load input raster as a doubles raster */
793 
794  std::unique_ptr< te::rst::Raster > rin;
795  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
796  rin);
797 
798  /* Defining input parameters, the arithmetic operation will be
799  * band 0 + band 1 - band 2 */
800 
802  inputParams.m_arithmeticString = "cos(R0:0)";
803  inputParams.m_normalize = false;
804  inputParams.m_inputRasters.push_back(rin.get());
805 
806  /* Create output raster info */
807 
808  std::map<std::string, std::string> orinfo;
809  orinfo["URI"] = "terralib_unittest_arithmetic_cos.tif";
810 
811  /* Defining output parameters */
812 
814  outputParams.m_rInfo = orinfo;
815  outputParams.m_rType = "GDAL";
816 
817  te::rp::ArithmeticOperations algorithmInstance;
818 
819  BOOST_CHECK(algorithmInstance.initialize(inputParams));
820  BOOST_CHECK(algorithmInstance.execute(outputParams));
821 
822  /* Open output raster */
823 
824  double inputValue1 = 0;
825  double outputValue = 0;
826  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
827  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
828  {
829  rin->getValue(c, r, inputValue1, 0);
830  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
831  BOOST_CHECK_CLOSE(cos(inputValue1), outputValue, 0.0000001);
832  }
833 }
834 
836 {
837  /* Load input raster as a doubles raster */
838 
839  std::unique_ptr< te::rst::Raster > rin;
840  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/landsat8_22768_ndvi.tif",
841  rin);
842 
843  /* Defining input parameters, the arithmetic operation will be
844  * band 0 + band 1 - band 2 */
845 
847  inputParams.m_arithmeticString = "acos(R0:0)";
848  inputParams.m_normalize = false;
849  inputParams.m_inputRasters.push_back(rin.get());
850 
851  /* Create output raster info */
852 
853  std::map<std::string, std::string> orinfo;
854  orinfo["URI"] = "terralib_unittest_arithmetic_acos.tif";
855 
856  /* Defining output parameters */
857 
859  outputParams.m_rInfo = orinfo;
860  outputParams.m_rType = "GDAL";
861 
862  te::rp::ArithmeticOperations algorithmInstance;
863 
864  BOOST_CHECK(algorithmInstance.initialize(inputParams));
865  BOOST_CHECK(algorithmInstance.execute(outputParams));
866 
867  /* Open output raster */
868 
869  double inputValue1 = 0;
870  double outputValue = 0;
871  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
872  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
873  {
874  rin->getValue(c, r, inputValue1, 0);
875 
876  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
877  BOOST_CHECK_CLOSE(acos(inputValue1), outputValue, 0.0000001);
878  }
879 }
880 
882 {
883  /* Load input raster as a doubles raster */
884 
885  std::unique_ptr< te::rst::Raster > rin;
886  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
887  rin);
888 
889  /* Defining input parameters, the arithmetic operation will be
890  * band 0 + band 1 - band 2 */
891 
893  inputParams.m_arithmeticString = "log(R0:0)";
894  inputParams.m_normalize = false;
895  inputParams.m_inputRasters.push_back(rin.get());
896 
897  /* Create output raster info */
898 
899  std::map<std::string, std::string> orinfo;
900  orinfo["URI"] = "terralib_unittest_arithmetic_log.tif";
901 
902  /* Defining output parameters */
903 
905  outputParams.m_rInfo = orinfo;
906  outputParams.m_rType = "GDAL";
907 
908  te::rp::ArithmeticOperations algorithmInstance;
909 
910  BOOST_CHECK(algorithmInstance.initialize(inputParams));
911  BOOST_CHECK(algorithmInstance.execute(outputParams));
912 
913  /* Open output raster */
914 
915  double inputValue1 = 0;
916  double outputValue = 0;
917  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
918  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
919  {
920  rin->getValue(c, r, inputValue1, 0);
921  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
922  BOOST_CHECK_CLOSE(log10(inputValue1), outputValue, 0.0000001);
923  }
924 }
925 
927 {
928  /* Load input raster as a doubles raster */
929 
930  std::unique_ptr< te::rst::Raster > rin;
931  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
932  rin);
933 
934  /* Defining input parameters, the arithmetic operation will be
935  * band 0 + band 1 - band 2 */
936 
938  inputParams.m_arithmeticString = "tan(R0:0)";
939  inputParams.m_normalize = false;
940  inputParams.m_inputRasters.push_back(rin.get());
941 
942  /* Create output raster info */
943 
944  std::map<std::string, std::string> orinfo;
945  orinfo["URI"] = "terralib_unittest_arithmetic_tan.tif";
946 
947  /* Defining output parameters */
948 
950  outputParams.m_rInfo = orinfo;
951  outputParams.m_rType = "GDAL";
952 
953  te::rp::ArithmeticOperations algorithmInstance;
954 
955  BOOST_CHECK(algorithmInstance.initialize(inputParams));
956  BOOST_CHECK(algorithmInstance.execute(outputParams));
957 
958  /* Open output raster */
959 
960  double inputValue1 = 0;
961  double outputValue = 0;
962  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
963  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
964  {
965  rin->getValue(c, r, inputValue1, 0);
966  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
967  BOOST_CHECK_CLOSE(tan(inputValue1), outputValue, 0.0000001);
968  }
969 }
970 
972 {
973  /* Load input raster as a doubles raster */
974 
975  std::unique_ptr< te::rst::Raster > rin;
976  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
977  rin);
978 
979  /* Defining input parameters, the arithmetic operation will be
980  * band 0 + band 1 - band 2 */
981 
983  inputParams.m_arithmeticString = "atan(R0:0)";
984  inputParams.m_normalize = false;
985  inputParams.m_inputRasters.push_back(rin.get());
986 
987  /* Create output raster info */
988 
989  std::map<std::string, std::string> orinfo;
990  orinfo["URI"] = "terralib_unittest_arithmetic_atan.tif";
991 
992  /* Defining output parameters */
993 
995  outputParams.m_rInfo = orinfo;
996  outputParams.m_rType = "GDAL";
997 
998  te::rp::ArithmeticOperations algorithmInstance;
999 
1000  BOOST_CHECK(algorithmInstance.initialize(inputParams));
1001  BOOST_CHECK(algorithmInstance.execute(outputParams));
1002 
1003  /* Open output raster */
1004 
1005  double inputValue1 = 0;
1006  double outputValue = 0;
1007  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
1008  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
1009  {
1010  rin->getValue(c, r, inputValue1, 0);
1011  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
1012  BOOST_CHECK_CLOSE(atan(inputValue1), outputValue, 0.0000001);
1013  }
1014 }
1015 
1017 {
1018  /* Load input raster as a doubles raster */
1019 
1020  std::unique_ptr< te::rst::Raster > rin;
1021  loadDoubleRaster(TERRALIB_DATA_DIR"/geotiff/cbers2b_rgb342_crop.tif",
1022  rin);
1023 
1024  /* Defining input parameters, the arithmetic operation will be
1025  * band 0 + band 1 - band 2 */
1026 
1028  inputParams.m_arithmeticString = "ln(R0:0)";
1029  inputParams.m_normalize = false;
1030  inputParams.m_inputRasters.push_back(rin.get());
1031 
1032  /* Create output raster info */
1033 
1034  std::map<std::string, std::string> orinfo;
1035  orinfo["URI"] = "terralib_unittest_arithmetic_ln.tif";
1036 
1037  /* Defining output parameters */
1038 
1040  outputParams.m_rInfo = orinfo;
1041  outputParams.m_rType = "GDAL";
1042 
1043  te::rp::ArithmeticOperations algorithmInstance;
1044 
1045  BOOST_CHECK(algorithmInstance.initialize(inputParams));
1046  BOOST_CHECK(algorithmInstance.execute(outputParams));
1047 
1048  /* Open output raster */
1049 
1050  double inputValue1 = 0;
1051  double outputValue = 0;
1052  for (unsigned int r = 0; r < rin->getNumberOfRows(); r++)
1053  for (unsigned int c = 0; c < rin->getNumberOfColumns(); c++)
1054  {
1055  rin->getValue(c, r, inputValue1, 0);
1056  outputParams.m_outputRasterPtr->getValue(c, r, outputValue, 0);
1057  BOOST_CHECK_CLOSE(log(inputValue1), outputValue, 0.0000001);
1058  }
1059 }
1060 
1061 BOOST_AUTO_TEST_SUITE_END()
std::string m_rType
Output raster data source type (as described in te::raster::RasterFactory ).
This file contains include headers for the memory data source of TerraLib.
A raster band description.
Definition: BandProperty.h:61
bool execute(AlgorithmOutputParameters &outputParams) _NOEXCEPT_OP(false)
Executes the algorithm using the supplied parameters.
bool m_normalize
Output values normalization will be performed to fit the original input raster values range (default:...
std::map< std::string, std::string > m_rInfo
The necessary information to create the output rasters (as described in te::raster::RasterFactory).
bool initialize(const AlgorithmInputParameters &inputParams) _NOEXCEPT_OP(false)
Initialize the algorithm instance making it ready for execution.
unsigned int unsigned int nCols
std::unique_ptr< te::rst::Raster > m_outputRasterPtr
The generated output registered raster.
URI C++ Library.
Definition: Attributes.h:37
ArithmeticOperations output parameters.
This file contains include headers for the TerraLib Raster Processing module.
std::vector< te::rst::Raster * > m_inputRasters
Input rasters vector.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
BOOST_AUTO_TEST_CASE(rasterSum_test)
Performs arithmetic operation over raster data.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
BOOST_AUTO_TEST_SUITE(arithmetic_operations_tests) void loadDoubleRaster(const std
unsigned int col
ArithmeticOperations input parameters.
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.
std::string m_arithmeticString
Arithmetic string.