Go to the documentation of this file.00001
00014 #ifndef LGL_RASTER_HPP
00015 #define LGL_RASTER_HPP
00016
00017 #include <iostream>
00018 #include <algorithm>
00019
00020
00021 namespace jafar {
00022 namespace lgl {
00023
00027 struct RasterPoint {
00028 int x;
00029 int y;
00030
00031 RasterPoint():x(0),y(0) {}
00032 RasterPoint(int _x,int _y):x(_x),y(_y) {}
00033
00034 void set(int _x, int _y) {x=_x;y=_y;}
00035
00036 bool operator==(const RasterPoint &rhs) const
00037 {
00038 return (x == rhs.x) && (y == rhs.y);
00039 }
00040
00041 bool operator!=(const RasterPoint &rhs) const
00042 {
00043 return (x != rhs.x) || (y != rhs.y);
00044 }
00045
00046 };
00047
00049 struct RasterCellIndex {
00050
00051 int i;
00052 int j;
00053
00054 RasterCellIndex():i(0),j(0) {}
00055 RasterCellIndex(int _i,int _j):i(_i),j(_j) {}
00056
00057 void set(int _i, int _j) {i=_i;j=_j;}
00058
00059 bool operator==(const RasterCellIndex &rhs) const
00060 {
00061 return (i == rhs.i) && (j == rhs.j);
00062 }
00063
00064 bool operator!=(const RasterCellIndex &rhs) const
00065 {
00066 return (i != rhs.i) || (j != rhs.j);
00067 }
00068
00069 };
00070
00071 std::ostream& operator<< (std::ostream& out, const RasterCellIndex& cell);
00072
00090 class RasterRect {
00091 public:
00092
00093 RasterRect();
00094 RasterRect( int _xroot, int _yroot, int _xsize, int _ysize );
00095
00099 bool isValid() const;
00100
00101 int &rLeft();
00102 int &rTop();
00103 int &rRight();
00104 int &rBottom();
00105
00106
00109 int xroot()const;
00112 int yroot()const;
00119 int xend()const;
00126 int yend()const;
00127
00128 void setXTopLeft( int pos );
00129 void setYTopLeft( int pos );
00130 void setXBottomRight( int pos );
00131 void setYBottomRight( int pos );
00132 void setX( int x );
00133 void setY( int y );
00134
00135 RasterPoint topLeft() const;
00136 RasterPoint bottomRight() const;
00137 RasterPoint topRight() const;
00138 RasterPoint bottomLeft() const;
00140 RasterPoint center() const;
00141
00142 void rect( int& _xtopleft, int& _ytopleft, int& _xsize, int& _ysize ) const;
00143 void coords( int& xtopleft, int& ytopleft, int& xbottomright, int& ybottomright ) const;
00144
00145 void setRect( int x, int y, int w, int h );
00146 void setCoords( int xtopleft, int ytopleft, int xbottomright, int ybottomright );
00147
00149 int size()const;
00150
00154 int xsize() const { return xpsize; }
00155
00159 int ysize() const { return ypsize; }
00160
00161 RasterRect& operator=(const RasterRect &rect);
00162
00173 bool contains( const RasterCellIndex& cell, bool inside=true) const;
00174
00183 bool contains( const RasterRect &r, bool inside=true ) const;
00184
00186 bool intersects( const RasterRect &r, RasterRect &result ) const;
00187
00188 friend bool operator==( const RasterRect &, const RasterRect & );
00189 friend bool operator!=( const RasterRect &, const RasterRect & );
00190 friend std::ostream& operator<<(std::ostream&, const RasterRect &);
00191
00193 int xtopleft;
00195 int ytopleft;
00197 int xbottomright;
00199 int ybottomright;
00200
00202 int xpsize;
00204 int ypsize;
00205
00206 };
00207
00208 bool operator==( const RasterRect &, const RasterRect & );
00209 bool operator!=( const RasterRect &, const RasterRect & );
00210
00214 class Raster {
00215 public:
00216
00217 enum CLUSTERING_FUNCTION {CF_EQUALITY, CF_STD_DEV};
00218
00219 Raster(CLUSTERING_FUNCTION cf=CF_EQUALITY):
00220 clusteringF(cf)
00221 {}
00222
00223 virtual ~Raster() {}
00224
00225 void setClusteringF(CLUSTERING_FUNCTION cf);
00226 CLUSTERING_FUNCTION getClusteringF();
00227
00228 void setClusteringThres(double _cfthreshold);
00229 double getClusteringThres();
00230
00231 RasterRect getRasterRect() const;
00232
00234 bool inside(const RasterRect& rect);
00235
00237 bool validIndex(const RasterCellIndex& index) const;
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00254
00255
00256 protected:
00257
00258 CLUSTERING_FUNCTION clusteringF;
00259 double cfthreshold;
00260
00261 int xroot;
00262 int yroot;
00263 int xsize;
00264 int ysize;
00265
00266
00267
00268 };
00269 }
00270 }
00271
00272 #endif