core/vil/vil_plane.h
Go to the documentation of this file.
00001 // This is core/vil/vil_plane.h
00002 #ifndef vil_plane_h_
00003 #define vil_plane_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott.
00010 
00011 #include <vil/vil_image_resource.h>
00012 #include <vil/vil_image_view.h>
00013 #include <vcl_cassert.h>
00014 
00015 
00016 //: Return a view of im's plane p.
00017 //  O(1).
00018 // \relatesalso vil_image_view
00019 template<class T>
00020 inline vil_image_view<T> vil_plane(const vil_image_view<T> &im, unsigned p)
00021 {
00022   assert(p<im.nplanes());
00023   return vil_image_view<T>(im.memory_chunk(),im.top_left_ptr()+p*im.planestep(),im.ni(),im.nj(),1,
00024                            im.istep(),im.jstep(),im.planestep());
00025 }
00026 
00027 //: Return a view of a selection of im's planes.
00028 // You can select any equally-spaced sequence of planes.
00029 // \param first The index of the first plane you want to select.
00030 // \param skip The spacing in your selection - will be 1 for adjacent planes.
00031 // \param n The total number of planes in your selection.
00032 //
00033 //  O(1).
00034 template<class T>
00035 inline vil_image_view<T> vil_planes(const vil_image_view<T> &im,
00036                                     unsigned first, int skip,
00037                                     unsigned n)
00038 {
00039   assert(first<im.nplanes());
00040   assert(int(first) + int(n)*skip >= 0);
00041   assert((unsigned)(first + n*skip) <= im.nplanes());
00042   return vil_image_view<T>(im.memory_chunk(),
00043                            im.top_left_ptr()+first*im.planestep(),
00044                            im.ni(),im.nj(),n,
00045                            im.istep(),im.jstep(),skip*im.planestep());
00046 }
00047 
00048 
00049 //: Return a specific plane of an image.
00050 // \relatesalso vil_image_resource
00051 vil_image_resource_sptr vil_plane(const vil_image_resource_sptr &src, unsigned p);
00052 
00053 
00054 //: A generic_image adaptor that behaves like a single plane version of its input
00055 // For implementation use only - use vil_plane() to create one.
00056 class vil_plane_image_resource : public vil_image_resource
00057 {
00058   vil_plane_image_resource(vil_image_resource_sptr const&, unsigned p);
00059   friend vil_image_resource_sptr vil_plane(const vil_image_resource_sptr &src, unsigned p);
00060  public:
00061 
00062   virtual unsigned nplanes() const { return 1; }
00063   virtual unsigned ni() const { return src_->ni(); }
00064   virtual unsigned nj() const { return src_->nj(); }
00065 
00066   virtual enum vil_pixel_format pixel_format() const { return src_->pixel_format(); }
00067 
00068   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00069                                                  unsigned j0, unsigned nj) const;
00070 
00071   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
00072                                             unsigned j0, unsigned nj) const;
00073 
00074 
00075   //: Put the data in this view back into the image source.
00076   virtual bool put_view(const vil_image_view_base& im, unsigned i0,
00077                         unsigned j0);
00078 
00079   //: Extra property information
00080   virtual bool get_property(char const* tag, void* property_value = 0) const {
00081     return src_->get_property(tag, property_value); }
00082 
00083  protected:
00084   //: Reference to underlying image source
00085   vil_image_resource_sptr src_;
00086   //: which plane.
00087   unsigned plane_;
00088 };
00089 
00090 #endif // vil_plane_h_