Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

vil_image_view_base.h

Go to the documentation of this file.
00001 // This is core/vil/vil_image_view_base.h
00002 #ifndef vil_image_view_base_h_
00003 #define vil_image_view_base_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \brief A base class reference-counting view of some image data.
00010 // \author Ian Scott - Manchester
00011 //
00012 // \verbatim
00013 //  Modifications
00014 //   10 Sep. 2004 Peter Vanroose  Inlined all 1-line methods in class decl
00015 // \endverbatim
00016 
00017 #include <vcl_iosfwd.h>
00018 #include <vcl_string.h>
00019 #include <vcl_cassert.h>
00020 #include <vil/vil_pixel_format.h>
00021 #include <vil/vil_smart_ptr.h>
00022 
00023 //: An abstract base class of smart pointers to actual image data in memory.
00024 // If you want an actual image, try instantiating vil_image_view<T>.
00025 
00026 class vil_image_view_base
00027 {
00028  protected:
00029   //: Number of columns.
00030   unsigned ni_;
00031   //: Number of rasters.
00032   unsigned nj_;
00033   //: Number of planes.
00034   unsigned nplanes_;
00035 
00036   vil_image_view_base(unsigned n_i, unsigned n_j, unsigned n_planes):
00037   ni_(n_i), nj_(n_j), nplanes_(n_planes), reference_count_(0) {}
00038 
00039   //: Default is an empty one-plane image
00040   //  Don't set nplanes_ to zero as it confuses set_size(nx,ny) later
00041   vil_image_view_base(): ni_(0), nj_(0), nplanes_(1), reference_count_(0) {}
00042 
00043  public:
00044   // The destructor must be virtual so that the memory chunk is destroyed.
00045   virtual ~vil_image_view_base() { assert( reference_count_ == 0 ); }
00046 
00047   //: Width
00048   unsigned ni()  const {return ni_;}
00049   //: Height
00050   unsigned nj()  const {return nj_;}
00051   //: Number of planes
00052   unsigned nplanes() const {return nplanes_;}
00053 
00054   //: The number of pixels.
00055   unsigned long size() const { return ni_ * nj_ * nplanes_; }
00056 
00057   //: set_size current planes to width x height.
00058   // If already correct size, this function returns quickly
00059   virtual void set_size(unsigned width, unsigned height) =0;
00060 
00061   //: resize to width x height x n_planes.
00062   // If already correct size, this function returns quickly
00063   virtual void set_size(unsigned width, unsigned height, unsigned n_planes) =0;
00064 
00065   //: Print a 1-line summary of contents
00066   virtual void print(vcl_ostream&) const =0;
00067 
00068   //: Return class name
00069   virtual vcl_string is_a() const =0;
00070 
00071   //: Return a description of the concrete data pixel type.
00072   // For example if the value is VIL_PIXEL_FORMAT_BYTE,
00073   // you can safely cast, or assign the base class reference to
00074   // a vil_image_view<vxl_byte>.
00075   virtual enum vil_pixel_format pixel_format() const=0;
00076 
00077   //: True if this is (or is derived from) class s
00078   virtual bool is_class(vcl_string const& s) const { return s=="vil_image_view_base"; }
00079 
00080  private:
00081   // You probably should not use a vil_image_view in a vbl_smart_ptr, so the
00082   // ref functions are private
00083   friend class vil_smart_ptr<vil_image_view_base>;
00084   void ref() { ++reference_count_; }
00085   void unref() {
00086     assert(reference_count_>0);
00087     if (--reference_count_<=0) delete this;}
00088   int reference_count_;
00089 };
00090 
00091 
00092 //: An interface between vil_image_views and vil_image_resources
00093 // This object is used internally by vil to provide a type-independent
00094 // transient storage for a view as it is being assigned to a
00095 // vil_image_view<T> from a vil_image_resource::get_view(),
00096 // vil_load() or vil_convert_..() function call.
00097 // If you want a type independent image container, you are recommended to
00098 // use a vil_image_resource_sptr
00099 typedef vil_smart_ptr<vil_image_view_base> vil_image_view_base_sptr;
00100 
00101 //: Print a 1-line summary of contents
00102 inline
00103 vcl_ostream& operator<<(vcl_ostream& s, vil_image_view_base const& im)
00104 { im.print(s); return s; }
00105 
00106 #endif // vil_image_view_base_h_

Generated on Thu Jan 10 14:40:01 2008 for core/vil by  doxygen 1.4.4