contrib/mul/vil3d/vil3d_plane.h
Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_plane.h
00002 #ifndef vil3d_plane_h_
00003 #define vil3d_plane_h_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma interface
00006 #endif
00007 //:
00008 // \file
00009 // \author Tim Cootes.
00010 
00011 #include <vil3d/vil3d_image_view.h>
00012 #include <vcl_cassert.h>
00013 
00014 
00015 //: Return a view of im's plane p.
00016 //  O(1).
00017 // \relatesalso vil3d_image_view
00018 template<class T>
00019 inline vil3d_image_view<T> vil3d_plane(const vil3d_image_view<T> &im, unsigned p)
00020 {
00021   assert(p<im.nplanes());
00022   return vil3d_image_view<T>(im.memory_chunk(),
00023                              im.origin_ptr()+p*im.planestep(),
00024                              im.ni(),im.nj(),im.nk(),1,
00025                              im.istep(),im.jstep(),im.kstep(),im.planestep());
00026 }
00027 
00028 
00029 //: Return a view of a selection of im's planes.
00030 // You can select any equally-spaced sequence of planes.
00031 // \param first The index of the first plane you want to select.
00032 // \param skip The spacing in your selection - will be 1 for adjacent planes.
00033 // \param n The total number of planes in your selection.
00034 //  O(1).
00035 template<class T>
00036 inline vil3d_image_view<T> vil3d_planes(const vil3d_image_view<T> &im,
00037                                         unsigned first, int skip,
00038                                         unsigned n)
00039 {
00040   assert(first<im.nplanes());
00041 #ifndef NDEBUG
00042   int end = first + n*skip;
00043   assert(end >= 0);
00044   assert((unsigned)end <= im.nplanes());
00045 #endif // NDEBUG
00046   return vil3d_image_view<T>(im.memory_chunk(),
00047     im.origin_ptr()+first*im.planestep(), im.ni(), im.nj(), im.nk(), n,
00048     im.istep(),im.jstep(),im.kstep(), skip*im.planestep());
00049 }
00050 
00051 
00052 #endif // vil3d_plane_h_