grid_map_dynamic.cpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Includes
00010 *****************************************************************************/
00011 #include <iostream>
00012 #include <gtest/gtest.h>
00013 #include <ecl/linear_algebra.hpp>
00014 #include <ecl/formatters/floats.hpp>
00015 #include "../../include/ecl/maps/grid_map.hpp"
00016 
00017 /*****************************************************************************
00018 ** Using
00019 *****************************************************************************/
00020 
00021 using std::cout;
00022 using std::endl;
00023 using ecl::RightAlign;
00024 using ecl::Format;
00025 using ecl::GridMap;
00026 using ecl::linear_algebra::Vector2d;
00027 using ecl::linear_algebra::Vector2i;
00028 
00029 /*****************************************************************************
00030 ** Namespaces
00031 *****************************************************************************/
00032 
00033 namespace ecl {
00034 namespace maps {
00035 namespace tests {
00036 
00037 /*****************************************************************************
00038 ** Cells
00039 *****************************************************************************/
00040 
00041 class Cell {
00042 public:
00043         Cell() : i(0), j(0) {};
00044         unsigned int i;
00045         unsigned int j;
00046 };
00047 
00048 
00049 } // namespace tests
00050 } // namespace maps
00051 } // namespace ecl
00052 
00053 /*****************************************************************************
00054 ** Using
00055 *****************************************************************************/
00056 
00057 using ecl::maps::tests::Cell;
00058 
00059 /*****************************************************************************
00060 ** Tests
00061 *****************************************************************************/
00062 
00063 TEST(GridMapTests,allEggsInOneBasket) {
00064         // Haven't got around to running this properly through gtests yet.
00065         SUCCEED();
00066 }
00067 /*****************************************************************************
00068 ** Main program
00069 *****************************************************************************/
00070 
00071 int main(int argc, char **argv) {
00072 
00073     Format<double> format; format.width(8); format.precision(2); format.align(RightAlign);
00074 
00075     cout << endl;
00076     cout << "***********************************************************" << endl;
00077     cout << "                 Construction" << endl;
00078     cout << "***********************************************************" << endl;
00079     cout << endl;
00080 
00081     std::cout << "Creating a 5x5 grid map over the world area [0.0,0.0]->[10.0,10.0]" << std::endl;
00082     GridMap<Cell> map(5,5, 0.0,0.0,2.0);
00083     GridMap<Cell> map2(5,5, 0.0, 0.0, 1.0 );
00084 
00085     typedef GridMap<Cell> Map;
00086 
00087     cout << endl;
00088     cout << "***********************************************************" << endl;
00089     cout << "                  Iteration" << endl;
00090     cout << "***********************************************************" << endl;
00091     cout << endl;
00092 
00093     Map::iterator iter;
00094     int i = 0;
00095     int j = 0;
00096     for ( iter = map.begin(); iter != map.end(); ++iter ) {
00097         iter->i = i; iter->j = j;
00098         ++j;
00099         if ( j == map.cols() ) {
00100                 j = 0;
00101                 ++i;
00102         }
00103     }
00104     Map::const_iterator const_iter;
00105     std::cout << std::endl;
00106     for ( const_iter = map.begin(); const_iter != map.end(); ++const_iter ) {
00107         std::cout << "[" << const_iter->i << "," << const_iter->j << "]" << std::endl;
00108     }
00109     std::cout << std::endl;
00110 
00111     std::cout << "Front: " << "[" << map.front().i << "," << map.front().j << "]" << std::endl;
00112     std::cout << "Back: " << "[" << map.back().i << "," << map.back().j << "]" << std::endl;
00113     std::cout << std::endl;
00114 
00115     for ( j = map.rows(); j > 0; --j ) {
00116         unsigned int index = j - 1;
00117         for ( i = 0; i < map.cols(); ++i ) {
00118             std::cout << "[" << map(i,index).i << "," << map(i,index).j << "]";
00119         }
00120         std::cout << std::endl;
00121     }
00122     std::cout << std::endl;
00123 
00124     cout << endl;
00125     cout << "***********************************************************" << endl;
00126     cout << "                  Transform" << endl;
00127     cout << "***********************************************************" << endl;
00128     cout << endl;
00129 
00130     Vector2i cell_coords = map.cellCoordinates(1.5,2.3);
00131     std::cout << "Cell coordinates [1.5,2.3]->[" << cell_coords[0] << "," << cell_coords[1] << "]" << std::endl;
00132 
00133     Vector2d world_coords = map.worldCoordinates(2,3);
00134     std::cout << "World coordinates [2,3]   ->[" << world_coords[0] << "," << world_coords[1] << "]" << std::endl;
00135 
00136     cout << endl;
00137         cout << "***********************************************************" << endl;
00138         cout << "                  Comparison and remap" << endl;
00139         cout << "***********************************************************" << endl;
00140         if( map == map2 )
00141         {
00142                 std::cout <<"map is equal to map2 " << std::endl;
00143         }
00144         else
00145         {
00146                 std::cout <<"map is not equal to map2 " << std::endl;
00147         }
00148 
00149         std::cout << "Performs map2=map" << std::endl;
00150         map2 = map;
00151 
00152         for ( j = map2.rows(); j > 0; --j ) {
00153                 unsigned int index = j - 1;
00154                 for ( i = 0; i < map2.cols(); ++i ) {
00155                         std::cout << "[" << map2(i,index).i << "," << map2(i,index).j << "]";
00156                 }
00157                 std::cout << std::endl;
00158         }
00159         std::cout << std::endl;
00160 
00161         if( map != map2 )
00162         {
00163                 std::cout <<"map is not equal to map2 " << std::endl;
00164         }
00165         else
00166         {
00167                 std::cout <<"map is equal to map2 " << std::endl;
00168         }
00169 
00170     cout << endl;
00171     cout << "***********************************************************" << endl;
00172     cout << "                      Passed" << endl;
00173     cout << "***********************************************************" << endl;
00174     cout << endl;
00175 
00176     testing::InitGoogleTest(&argc,argv);
00177     return RUN_ALL_TESTS();
00178 }
00179 
00180 


ecl_maps
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:25