openModeller  Version 1.5.0
MapIterator.cpp
Go to the documentation of this file.
1 
32 
33 using std::pair;
34 
35 // Default constructor for terminal
37  isTerminal( true )
38 { }
39 
41  GeoTransform* gt ) :
42  isTerminal( false ),
43  gt( gt ),
44  h( h ),
45  xcur( 0 ),
46  ycur( 0 )
47 {}
48 
49 pair<Coord,Coord> MapIterator::operator*() const
50 {
51  pair<Coord,Coord> lonlat = h.convertXY2LonLat(xcur, ycur);
52  gt->transfOut( &lonlat.first, &lonlat.second);
53  return lonlat;
54 }
55 
57 {
58  ++xcur;
59  if (xcur >= h.xdim ) {
60  ++ycur;
61  xcur = 0;
62  }
63  return *this;
64 }
65 
67 {
68  --xcur;
69  if (xcur < 0 ) {
70  --ycur;
71  xcur = h.xdim-1;
72  }
73  return *this;
74 }
75 
77 {
78  MapIterator rval = *this;
79  operator++();
80  return rval;
81 }
82 
84 {
85  MapIterator rval = *this;
86  operator--();
87  return rval;
88 }
89 
90 bool
92 {
93 
94  //
95  // Note, because the increment/decrement operators
96  // manipulate x first then y the foolowing should be true:
97  // 1. xcur is in [xmin,xmax)
98  // 2. ycur is the true test for out of bounds.
99  // Also, since I expect the majority of usage will be with operator++,
100  // I expect the condition ycur>= ymax, to be the most likely test.
101  return (ycur >= h.ydim) ||
102  (ycur < 0) ||
103  (xcur >= h.xdim) ||
104  (xcur < 0 );
105 
106 }
107 
108 bool
109 operator==( const MapIterator& lhs, const MapIterator& rhs )
110 {
111 
112  if ( lhs.isTerminal ) {
113  return rhs.isPastBounds();
114  }
115  if ( rhs.isTerminal ) {
116  return lhs.isPastBounds();
117  }
118 
119  return (lhs.xcur == rhs.xcur) && (lhs.ycur == rhs.ycur);
120 
121 }
122 
123 bool
124 operator!=( const MapIterator& lhs, const MapIterator& rhs )
125 {
126  return ! (lhs == rhs );
127 }
128 
129 #ifdef MPI_FOUND
130 //new method for the parallel version
131 void MapIterator::nextblock(int init_pixel)
132 {
133 
134 
135 
136  ycur=init_pixel/h.xdim;
137  xcur=init_pixel%h.xdim;
138 
139 
140 
141 }
142 #endif
int xdim
Definition: Header.hh:72
int ydim
Definition: Header.hh:73
Definition: Header.hh:45
bool operator==(const MapIterator &lhs, const MapIterator &rhs)
std::pair< Coord, Coord > convertXY2LonLat(int x, int y) const
Definition: Header.cpp:149
GeoTransform * gt
Definition: MapIterator.hh:82
int transfOut(double *x, double *y) const
bool operator!=(const MapIterator &lhs, const MapIterator &rhs)
bool isTerminal
Definition: MapIterator.hh:80
MapIterator & operator++()
Definition: MapIterator.cpp:56
MapIterator & operator--()
Definition: MapIterator.cpp:66
bool isPastBounds() const
Definition: MapIterator.cpp:91
std::pair< Coord, Coord > operator*() const
Definition: MapIterator.cpp:49