core/vil/vil_transpose.h
Go to the documentation of this file.
00001 // This is core/vil/vil_transpose.h
00002 #ifndef vil_transpose_h_
00003 #define vil_transpose_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 
00014 
00015 //: Create a view which appears as the transpose of this view.
00016 //  i.e. transpose(i,j,p) = view(j,i,p). O(1).
00017 // \relatesalso vil_image_view
00018 template<class T>
00019 inline vil_image_view<T> vil_transpose(const vil_image_view<T>& v)
00020 {
00021   // Create view with i and j switched
00022   return vil_image_view<T>(v.memory_chunk(),v.top_left_ptr(),
00023                            v.nj(),v.ni(),v.nplanes(),
00024                            v.jstep(),v.istep(),v.planestep());
00025 }
00026 
00027 
00028 //: Transpose an image.
00029 // \relatesalso vil_image_resource
00030 vil_image_resource_sptr vil_transpose(const vil_image_resource_sptr &src);
00031 
00032 
00033 //: A generic_image adaptor that behaves like a transposed version of its input
00034 class vil_transpose_image_resource : public vil_image_resource
00035 {
00036   //: Reference to underlying image source
00037   vil_image_resource_sptr src_;
00038   //: You can't construct one of these directly, use vil_transpose() instead.
00039   vil_transpose_image_resource(vil_image_resource_sptr const&);
00040   friend vil_image_resource_sptr vil_transpose(const vil_image_resource_sptr &src);
00041 
00042  public:
00043   inline unsigned nplanes() const { return src_->nplanes(); }
00044   inline unsigned ni() const { return src_->nj(); }
00045   inline unsigned nj() const { return src_->ni(); }
00046 
00047   inline enum vil_pixel_format pixel_format() const { return src_->pixel_format(); }
00048 
00049   virtual vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
00050                                                  unsigned j0, unsigned nj) const;
00051 
00052   virtual vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
00053                                             unsigned j0, unsigned nj) const;
00054 
00055   //: Put the data in this view back into the image source.
00056   virtual bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0);
00057 
00058   //: Extra property information
00059   virtual bool get_property(char const* tag, void* property_value = 0) const {
00060     return src_->get_property(tag, property_value); }
00061 };
00062 
00063 #endif // vil_transpose_h_