contrib/mul/vil3d/vil3d_from_image_2d.h
Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_from_image_2d.h
00002 #ifndef vil3d_from_image_2d_h_
00003 #define vil3d_from_image_2d_h_
00004 
00005 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00006 #pragma interface
00007 #endif
00008 
00009 //:
00010 // \file
00011 // \author Kevin de Souza
00012 
00013 #include <vil/vil_image_view.h>
00014 #include <vil3d/vil3d_image_view.h>
00015 #include <vcl_cassert.h>
00016 
00017 
00018 //: Return a 3D image view containing a single slice obtained from a 2D image.
00019 //  result(x,y,0,p)=im(x,y,p)
00020 // \relatesalso vil3d_image_view
00021 // \relatesalso vil_image_view
00022 // \note Assumes that input image planes (if more than 1) are stored separately,
00023 // i.e. that im.planestep()==im.ni()*im.nj()
00024 template <class T>
00025 inline vil3d_image_view<T> vil3d_from_image_2d(const vil_image_view<T>& im)
00026 {
00027   if (im.is_contiguous())
00028   {
00029     vcl_ptrdiff_t kstep = im.ni()*im.nj();
00030     unsigned nk = 1;
00031     vcl_ptrdiff_t pstep = im.planestep();
00032 
00033     // Insist on a particular ordering of input image data
00034     assert(pstep == kstep);
00035   
00036     return vil3d_image_view<T>(im.memory_chunk(),
00037                                im.top_left_ptr(),
00038                                im.ni(), im.nj(), nk, im.nplanes(),
00039                                im.istep(), im.jstep(), kstep, pstep);
00040   }
00041   else
00042   {
00043     return vil3d_image_view<T>();
00044   }
00045 }
00046 
00047 
00048 #endif // vil3d_from_image_2d_h_