00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00024
00025
00026
00027
00028
00029
00031
00032 #ifndef __CVD_IMAGE_REF_H__
00033 #define __CVD_IMAGE_REF_H__
00034
00035 #include <iostream>
00036 #include <cctype>
00037 #include <cvd/exceptions.h>
00038
00039 namespace CVD {
00040
00042
00044
00047 class ImageRef
00048 {
00049 public:
00050
00051
00053 inline ImageRef();
00057 inline ImageRef(int xp, int yp);
00060 inline ImageRef(std::istream& is);
00061
00062
00063
00068 inline bool next(const ImageRef& max);
00073 inline bool prev(const ImageRef& max);
00080 inline bool next(const ImageRef& min, const ImageRef& max);
00087 inline bool prev(const ImageRef& min, const ImageRef& max);
00088
00090 inline void home();
00094 inline void end(const ImageRef& size);
00095
00096
00097
00098
00101 inline ImageRef& operator=(const ImageRef& ref);
00104 inline bool operator==(const ImageRef& ref) const;
00107 inline bool operator!=(const ImageRef& ref) const;
00109 inline ImageRef operator-() const;
00112 inline ImageRef& operator*=(const double scale);
00115 inline ImageRef& operator/=(const double scale);
00118 inline ImageRef& operator+=(const ImageRef rhs);
00121 inline ImageRef& operator-=(const ImageRef rhs);
00124 inline ImageRef operator*(const double scale) const;
00127 inline ImageRef operator/(const double scale) const;
00130 inline ImageRef operator+(const ImageRef rhs) const;
00133 inline ImageRef operator-(const ImageRef rhs) const;
00136 inline ImageRef& operator<<=(int i);
00139 inline ImageRef& operator>>=(int i);
00142 inline ImageRef operator>>(int i) const;
00145 inline ImageRef operator<<(int i) const;
00151 inline bool operator<(const ImageRef & other) const;
00155 inline bool operator>(const ImageRef & other) const;
00156
00158 inline unsigned int mag_squared() const;
00159
00161 inline int area() const;
00162
00164 inline ImageRef dot_times(const ImageRef &ref) const;
00165
00167 inline int& operator[](int i);
00168
00170 inline int operator[](int i) const;
00171
00172
00174 inline ImageRef shiftl(int i) const;
00176 inline ImageRef shiftr(int i) const;
00177
00178
00179 int x;
00180 int y;
00181
00182 };
00183
00188 inline ImageRef operator*(const int scale, const ImageRef& ref);
00189
00190 namespace Exceptions
00191 {
00193 struct BadSubscript: public CVD::Exceptions::All {BadSubscript(){};};
00194 }
00195
00196
00197 #include <cvd/internal/image_ref_implementation.hh>
00198
00199
00200
00205 inline std::ostream& operator<<(std::ostream& os, const ImageRef& ref)
00206 {
00207 return os << "[" << ref.x << " " << ref.y << "]";
00208 }
00209
00212 inline std::istream& operator>>(std::istream& is, ImageRef& ref)
00213 {
00214
00215
00216 is >> std::ws;
00217
00218 unsigned char c = is.get();
00219
00220 if(is.eof())
00221 return is;
00222
00223 if(c == '(' )
00224 {
00225 is >> std::ws >> ref.x >> std::ws;
00226
00227 if(is.get() != ',')
00228 goto bad;
00229
00230 is >> std::ws >> ref.y >> std::ws;
00231
00232 if(is.get() != ')')
00233 goto bad;
00234 }
00235 else if(c == '[' )
00236 {
00237 is >> std::ws >> ref.x >> std::ws >> ref.y >> std::ws;
00238 if(is.get() != ']')
00239 goto bad;
00240 }
00241 else if(isdigit(c))
00242 {
00243 is.unget();
00244 is >> ref.x >> ref.y;
00245 }
00246 else
00247 goto bad;
00248
00249 return is;
00250
00251 bad:
00252 is.setstate(std::ios_base::badbit);
00253
00254 return is;
00255 }
00256
00259 const ImageRef ImageRef_zero(0, 0);
00260
00261
00262 }
00263
00264
00265 #endif