contrib/mul/vil3d/vil3d_copy.txx
Go to the documentation of this file.
00001 // This is mul/vil3d/vil3d_copy.txx
00002 #ifndef vil3d_copy_txx_
00003 #define vil3d_copy_txx_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma implementation
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott, ISBE, Manchester
00010 // \date   2 Feb 2003
00011 
00012 #include "vil3d_copy.h"
00013 #include <vcl_cassert.h>
00014 #include <vil3d/vil3d_image_view.h>
00015 
00016 //: Create a copy of the data viewed by this, and return a view of copy.
00017 template<class T>
00018 void vil3d_copy_deep(const vil3d_image_view<T> &src, vil3d_image_view<T> &dest)
00019 {
00020   dest.deep_copy(src);
00021 }
00022 
00023 //: Create a copy of the data viewed by this, and return a view of copy.
00024 template<class T>
00025 vil3d_image_view<T> vil3d_copy_deep(const vil3d_image_view<T> &src)
00026 {
00027   vil3d_image_view<T> cpy;
00028   cpy.deep_copy(src);
00029   return cpy;
00030 }
00031 
00032 
00033 //: Copy src to dest, without changing dest's view parameters.
00034 // This is useful if you want to copy an image into a window on another image.
00035 // src and dest must have identical sizes, and types.
00036 template<class T>
00037 void vil3d_copy_reformat(const vil3d_image_view<T> &src, vil3d_image_view<T> &dest)
00038 {
00039   assert (src.nplanes() == dest.nplanes() &&
00040           src.nk() == dest.nk() && src.nj() == dest.nj() &&
00041           src.ni() == dest.ni());
00042   for (unsigned p = 0; p < dest.nplanes(); ++p)
00043     for (unsigned k = 0; k < dest.nk(); ++k)
00044       for (unsigned j = 0; j < dest.nj(); ++j)
00045         for (unsigned i = 0; i < dest.ni(); ++i)
00046           dest(i,j,k,p) = src(i,j,k,p);
00047 }
00048 
00049 
00050 //: Copy src to window in dest.
00051 // Size of window is defined by src.
00052 //  O(window.size).
00053 template<class T>
00054 void vil3d_copy_to_window(const vil3d_image_view<T> &src, vil3d_image_view<T> &dest,
00055                          unsigned i0, unsigned j0, unsigned k0)
00056 {
00057   // check window is within dest's bounds
00058   assert(i0+src.ni() <= dest.ni() && j0+src.nj() <= dest.nj() && k0+src.nk() <= dest.nk());
00059   assert (src.nplanes() == dest.nplanes());
00060 
00061   for (unsigned p = 0; p < dest.nplanes(); ++p)
00062     for (unsigned k = 0; k < src.nk(); ++k)
00063       for (unsigned j = 0; j < src.nj(); ++j)
00064         for (unsigned i = 0; i < src.ni(); ++i)
00065           dest(i+i0,j+j0,k+k0,p) = src(i,j,k,p);
00066 }
00067 
00068 
00069 // For everything else
00070 #define VIL3D_COPY_INSTANTIATE(T) \
00071 template void vil3d_copy_to_window(const vil3d_image_view<T > &, vil3d_image_view<T > &, \
00072                                   unsigned, unsigned, unsigned); \
00073 template void vil3d_copy_reformat(const vil3d_image_view<T > &, vil3d_image_view<T > &); \
00074 template vil3d_image_view<T > vil3d_copy_deep(const vil3d_image_view<T > &); \
00075 template void vil3d_copy_deep(const vil3d_image_view<T > &, vil3d_image_view<T > &)
00076 
00077 #endif // vil3d_copy_txx_