Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

RectZ.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Geometry_RectZ_h
00002 #define Impala_Core_Geometry_RectZ_h
00003 
00004 #include <iostream>
00005 
00006 namespace Impala
00007 {
00008 namespace Core
00009 {
00010 namespace Geometry
00011 {
00012 
00013 /* * Class definition for (2d) rectangle in Z (integer coordinates).
00014  */
00015 /* class not up to date with naming conventions: use Rectangle
00016 class RectZ {
00017 public:
00018 
00019     int mULX;
00020     int mULY;
00021     int mLRX;
00022     int mLRY;
00023 
00024     RectZ()
00025     {
00026         mULX = mULY = mLRX = mLRY = 0;
00027     }
00028 
00029     RectZ(int upperLeftX, int upperLeftY, int lowerRightX, int lowerRightY)
00030         : mULX(upperLeftX), mULY(upperLeftY), mLRX(lowerRightX), mLRY(lowerRightY)
00031     {
00032     }
00033 
00034     RectZ(int x1, int y1, int x2, int y2, bool check)
00035         : mULX(x1), mULY(y1), mLRX(x2), mLRY(y2)
00036     {
00037         if (check)
00038         {
00039             mULX = (x1 < x2) ? x1 : x2;
00040             mULY = (y1 < y2) ? y1 : y2;
00041             mLRX = (x1 < x2) ? x2 : x1;
00042             mLRY = (y1 < y2) ? y2 : y1;
00043         }
00044     }
00045 
00046     bool
00047     Valid() const
00048     {
00049         return !((mULX==0) && (mULY==0) && (mLRX==0) && (mLRY==0));
00050     }
00051 
00052     inline int
00053     Width() const
00054     {
00055         return mLRX - mULX + 1;
00056     }
00057 
00058     inline int
00059     Height() const
00060     {
00061         return mLRY - mULY + 1;
00062     }
00063 
00064     inline int
00065     Left() const
00066     {
00067         return mULX;
00068     }
00069 
00070     inline int
00071     Top() const
00072     {
00073         return mULY;
00074     }
00075 
00076     inline int
00077     Right() const
00078     {
00079         return mLRX;
00080     }
00081 
00082     inline int
00083     Bottom() const
00084     {
00085         return mLRY;
00086     }
00087 
00088     inline int&
00089     Left()
00090     {
00091         return mULX;
00092     }
00093 
00094     inline int&
00095     Top()
00096     {
00097         return mULY;
00098     }
00099 
00100     inline int&
00101     Right()
00102     {
00103         return mLRX;
00104     }
00105 
00106     inline int&
00107     Bottom()
00108     {
00109         return mLRY;
00110     }
00111 
00112     inline bool
00113     IsInside(int x, int y)
00114     {
00115         if(x < Right() &&
00116            x > Left() &&
00117            y > Top() &&
00118            y < Bottom())
00119            return true;
00120         return false;
00121     }
00122 
00123     void
00124     CheckSize()
00125     {
00126         if ((mULX == mLRX) && (mULY == mLRY))
00127             mULX = mULY = mLRX = mLRY = 0;
00128     }
00129 
00130     int
00131     operator==(const RectZ& r) const
00132     {
00133         return ((mULX == r.mULX) && (mULY == r.mULY) && (mLRX == r.mLRX) &&
00134                 (mLRY == r.mLRY));
00135     }
00136 
00137 };
00138 
00139 inline std::ostream&
00140 operator<<(std::ostream& os, const RectZ& r)
00141 {
00142     os << "\"" << r.Left() << " " << r.Top() << " ";
00143     os << r.Right() << " " << r.Bottom() << "\"";
00144     return os;
00145 }
00146 
00147 inline std::istream&
00148 operator>>(std::istream& is, RectZ& r)
00149 {
00150     // if the stream does not contain the correct format, the line is flushed
00151     char c;
00152     is >> c;
00153 
00154     if (c != '"')
00155     {
00156         while(!is.eof() && c!='\n')
00157             is.read(&c, 1);
00158     }
00159     else
00160     {
00161         is >> r.Left() >> r.Top() >> r.Right() >> r.Bottom() >> c;
00162         if (c!='"')
00163             while(!is.eof() && c!='\n')
00164                 is.read(&c, 1);
00165     }
00166     return is;
00167 }
00168 */
00169 
00170 } // namespace Geometry
00171 } // namespace Core
00172 } // namespace Impala
00173 
00174 #endif

Generated on Fri Mar 19 09:31:10 2010 for ImpalaSrc by  doxygen 1.5.1