contrib/gel/gevd/gevd_bufferxy.h
Go to the documentation of this file.
00001 #ifndef gevd_bufferxy_h_
00002 #define gevd_bufferxy_h_
00003 //:
00004 // \file
00005 //
00006 //=======================================================================
00007 // This object is a block of memory which may be accessed by an
00008 // (x,y) coordinate.  Addressing is performed using a pair of arrays
00009 // which store pointers to the x columns and y rows.
00010 //
00011 // \author   Brian DeCleene
00012 // \date     Nov. 16, 1990.
00013 //
00014 // \verbatim
00015 //  Modifications:
00016 //   Peter Vanroose - Nov. 4 1996.
00017 //     - Copy constructor added: fixes bug (xra & yra were not copied)
00018 //   Peter Vanroose - June 30 1997.
00019 //     - Constructor added that allows to supply allocated memory.
00020 //   Peter Vanroose - Aug 17 1999.
00021 //     - File dump I/O added.
00022 //   J.L. Mundy - Dec 27 2004.
00023 //     - added support for vil
00024 // \endverbatim
00025 //=======================================================================
00026 
00027 #include "gevd_memory_mixin.h"
00028 #include <vcl_iostream.h>
00029 #include <vil1/vil1_image.h>
00030 #include <vil/vil_image_resource.h>
00031 
00032 class gevd_bufferxy : public gevd_memory_mixin
00033 {
00034   // Parameters which define the size of the buffer.
00035   int B;    // Bits per pixel
00036   int X;    // X dimension in pixels.
00037   int Y;    // Y dimension in pixels.
00038 
00039   // Array for accessing the memory.
00040   unsigned char** yra;
00041   unsigned int*   xra;
00042 
00043  protected:
00044   void Init(int X, int Y, int B);
00045   gevd_bufferxy(); // the default constructor should not be used.
00046 
00047   // SET ROUTINES FOR BUFFER SIZE
00048   inline void SetBitsPixel(int d)         { B = d; }
00049   inline void SetBytesPixel(int d)        { B = 8*d; }
00050   inline void SetSizeX(int x)             { X = x; }
00051   inline void SetSizeY(int y)             { Y = y; }
00052 
00053  public:
00054 
00055   gevd_bufferxy(int X, int Y, int B);
00056   gevd_bufferxy(int X, int Y, int B, void* memptr);
00057   gevd_bufferxy(vil1_image const &img);
00058   gevd_bufferxy(vil_image_resource_sptr const& img);
00059   ~gevd_bufferxy();
00060   gevd_bufferxy(gevd_bufferxy const&);
00061 
00062   // ACCESS ROUTINES FOR DIMENSIONS
00063   inline int GetBitsPixel()       const { return B; }
00064   inline int GetBytesPixel()      const { return (B+7)/8; }
00065   inline int GetSizeX()           const { return X; }
00066   inline int GetSizeY()           const { return Y; }
00067   inline int GetArea()            const { return GetSizeX()*GetSizeY(); }
00068   inline int GetSize()            const { return GetArea()*GetBytesPixel(); }
00069 
00070   // ELEMENT ADDRESSING METHOD
00071   inline void* GetBuffer()             { return GetBufferPtr(); }
00072   inline const void* GetBuffer() const { return GetBufferPtr(); }
00073   inline void* GetElementAddr(int x, int y)          { return xra[x]+yra[y]; }
00074   inline const void* GetElementAddr(int x,int y)const{ return xra[x]+yra[y]; }
00075 
00076   // FILE I/O
00077   void dump(const char* filename); // write to file
00078   gevd_bufferxy(const char* filename);  // read from file
00079 
00080   friend vcl_ostream& operator<<(vcl_ostream& os, gevd_bufferxy const& b) {
00081     return os << "gevd_bufferxy(width=" << b.GetSizeX() << ",height="
00082               << b.GetSizeY() << ",bits_per_pixel=" << b.GetBitsPixel() << ")";
00083   }
00084 };
00085 
00086 #endif // gevd_bufferxy_h_