contrib/mul/vil3d/vil3d_image_view_base.h

Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_image_view_base.h
00002 #ifndef vil3d_image_view_base_h_
00003 #define vil3d_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 vil3d_image_view<T>.
00025 
00026 class vil3d_image_view_base
00027 {
00028  protected:
00029   //: Number of columns.
00030   unsigned ni_;
00031   //: Number of rasters.
00032   unsigned nj_;
00033   //: Number of slices.
00034   unsigned nk_;
00035   //: Number of planes.
00036   unsigned nplanes_;
00037 
00038   vil3d_image_view_base(unsigned ni, unsigned nj, unsigned nk, unsigned nplanes):
00039   ni_(ni), nj_(nj), nk_(nk), nplanes_(nplanes), reference_count_(0) {}
00040 
00041   //: Default is an empty one-plane image
00042   //  Don't set nplanes_ to zero as it confuses set_size(nx,ny,nz) later
00043   vil3d_image_view_base(): ni_(0), nj_(0), nk_(0), nplanes_(1), reference_count_(0) {}
00044 
00045  public:
00046   // The destructor must be virtual so that the memory chunk is destroyed.
00047   virtual ~vil3d_image_view_base() {}
00048 
00049   //: Width
00050   unsigned ni()  const {return ni_;}
00051   //: Height
00052   unsigned nj()  const {return nj_;}
00053   //: Depth
00054   unsigned nk()  const {return nk_;}
00055   //: Number of planes
00056   unsigned nplanes() const {return nplanes_;}
00057 
00058   //: The number of pixels.
00059   unsigned long size() const { return ni_ * nj_ * nk_ * nplanes_; }
00060 
00061   //: resize current planes to ni x nj * nk
00062   // If already correct size, this function returns quickly
00063   virtual void set_size(unsigned ni, unsigned nj, unsigned nk) =0;
00064 
00065   //: resize to ni x nj * nk with nplanes planes.
00066   // If already correct size, this function returns quickly
00067   virtual void set_size(unsigned ni, unsigned nj, unsigned nk, unsigned nplanes) =0;
00068 
00069   //: Print a 1-line summary of contents
00070   virtual void print(vcl_ostream&) const =0;
00071 
00072   //: Return class name
00073   virtual vcl_string is_a() const =0;
00074 
00075   //: Return a description of the concrete data pixel type.
00076   // For example if the value is VIL_PIXEL_FORMAT_BYTE,
00077   // you can safely cast, or assign the base class reference to
00078   // a vil3d_image_view<vxl_byte>.
00079   virtual enum vil_pixel_format pixel_format() const=0;
00080 
00081   //: True if this is (or is derived from) class s
00082   virtual bool is_class(vcl_string const& s) const { return s=="vil3d_image_view_base"; }
00083 
00084  private:
00085   // You probably should not use a vil3d_image_view in a vbl_smart_ptr, so the
00086   // ref functions are private
00087   friend class vil_smart_ptr<vil3d_image_view_base>;
00088   void ref() { ++reference_count_; }
00089   void unref() {
00090     assert(reference_count_>0);
00091     if (--reference_count_<=0) delete this;}
00092   int reference_count_;
00093 };
00094 
00095 //: An interface between vil3d_image_views and vil3d_image_resources
00096 // This object is used internally by vil to provide a type-independent
00097 // transient storage for a view as it is being assigned to a
00098 // vil3d_image_view<T> from a vil3d_image_resource::get_view(),
00099 // vil3d_load() or vil3d_convert_..() function call.
00100 // If you want a type independent image container, you are recommended to
00101 // use a vil3d_image_resource_sptr
00102 typedef vil_smart_ptr<vil3d_image_view_base> vil3d_image_view_base_sptr;
00103 
00104 //: Print a 1-line summary of contents
00105 inline
00106 vcl_ostream& operator<<(vcl_ostream& s, vil3d_image_view_base const& im) {
00107   im.print(s); return s;
00108 }
00109 
00110 #endif // vil3d_image_view_base_h_

Generated on Mon Nov 23 05:15:07 2009 for contrib/mul/vil3d by  doxygen 1.5.1