openModeller
Version 1.4.0
|
00001 00029 #include <openmodeller/env_io/MapIterator.hh> 00030 #include <openmodeller/env_io/Map.hh> 00031 #include <openmodeller/env_io/GeoTransform.hh> 00032 00033 using std::pair; 00034 00035 // Default constructor for terminal 00036 MapIterator::MapIterator() : 00037 isTerminal( true ) 00038 { } 00039 00040 MapIterator::MapIterator( const Header& h, 00041 GeoTransform* gt ) : 00042 isTerminal( false ), 00043 gt( gt ), 00044 h( h ), 00045 xcur( 0 ), 00046 ycur( 0 ) 00047 {} 00048 00049 pair<Coord,Coord> MapIterator::operator*() const 00050 { 00051 pair<Coord,Coord> lonlat = h.convertXY2LonLat(xcur, ycur); 00052 gt->transfOut( &lonlat.first, &lonlat.second); 00053 return lonlat; 00054 } 00055 00056 MapIterator& MapIterator::operator++() 00057 { 00058 ++xcur; 00059 if (xcur >= h.xdim ) { 00060 ++ycur; 00061 xcur = 0; 00062 } 00063 return *this; 00064 } 00065 00066 MapIterator& MapIterator::operator--() 00067 { 00068 --xcur; 00069 if (xcur < 0 ) { 00070 --ycur; 00071 xcur = h.xdim-1; 00072 } 00073 return *this; 00074 } 00075 00076 MapIterator MapIterator::operator++(int) 00077 { 00078 MapIterator rval = *this; 00079 operator++(); 00080 return rval; 00081 } 00082 00083 MapIterator MapIterator::operator--(int) 00084 { 00085 MapIterator rval = *this; 00086 operator--(); 00087 return rval; 00088 } 00089 00090 bool 00091 MapIterator::isPastBounds() const 00092 { 00093 00094 // 00095 // Note, because the increment/decrement operators 00096 // manipulate x first then y the foolowing should be true: 00097 // 1. xcur is in [xmin,xmax) 00098 // 2. ycur is the true test for out of bounds. 00099 // Also, since I expect the majority of usage will be with operator++, 00100 // I expect the condition ycur>= ymax, to be the most likely test. 00101 return (ycur >= h.ydim) || 00102 (ycur < 0) || 00103 (xcur >= h.xdim) || 00104 (xcur < 0 ); 00105 00106 } 00107 00108 bool 00109 operator==( const MapIterator& lhs, const MapIterator& rhs ) 00110 { 00111 00112 if ( lhs.isTerminal ) { 00113 return rhs.isPastBounds(); 00114 } 00115 if ( rhs.isTerminal ) { 00116 return lhs.isPastBounds(); 00117 } 00118 00119 return (lhs.xcur == rhs.xcur) && (lhs.ycur == rhs.ycur); 00120 00121 } 00122 00123 bool 00124 operator!=( const MapIterator& lhs, const MapIterator& rhs ) 00125 { 00126 return ! (lhs == rhs ); 00127 } 00128 00129 #ifdef MPI_FOUND 00130 //new method for the parallel version 00131 void MapIterator::nextblock(int init_pixel) 00132 { 00133 00134 00135 00136 ycur=init_pixel/h.xdim; 00137 xcur=init_pixel%h.xdim; 00138 00139 00140 00141 } 00142 #endif