core/vil/vil_copy.txx
Go to the documentation of this file.
00001 // This is core/vil/vil_copy.txx
00002 #ifndef vil_copy_txx_
00003 #define vil_copy_txx_
00004 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00005 #pragma implementation
00006 #endif
00007 //:
00008 // \file
00009 // \author Ian Scott, ISBE, Manchester
00010 // \date   4 Oct 2002
00011 
00012 #include "vil_copy.h"
00013 #include <vcl_cassert.h>
00014 #include <vil/vil_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 vil_copy_deep(const vil_image_view<T> &src, vil_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 vil_image_view<T> vil_copy_deep(const vil_image_view<T> &src)
00026 {
00027   vil_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 vil_copy_reformat(const vil_image_view<T> &src, vil_image_view<T> &dest)
00038 {
00039   assert (src.nplanes() == dest.nplanes() &&
00040           src.nj() == dest.nj() &&
00041           src.ni() == dest.ni());
00042   for (unsigned p = 0; p < dest.nplanes(); ++p)
00043     for (unsigned j = 0; j < dest.nj(); ++j)
00044       for (unsigned i = 0; i < dest.ni(); ++i)
00045         dest(i,j,p) = src(i,j,p);
00046 }
00047 
00048 
00049 //: Copy src to window in dest.
00050 // Size of window is defined by src.
00051 //  O(window.size).
00052 template<class T>
00053 void vil_copy_to_window(const vil_image_view<T> &src, vil_image_view<T> &dest,
00054                         unsigned i0, unsigned j0)
00055 {
00056   // check window is within dest's bounds
00057   assert(i0+src.ni() <= dest.ni() && j0+src.nj() <= dest.nj());
00058   assert (src.nplanes() == dest.nplanes());
00059 
00060   for (unsigned p = 0; p < dest.nplanes(); ++p)
00061     for (unsigned j = 0; j < src.nj(); ++j)
00062       for (unsigned i = 0; i < src.ni(); ++i)
00063         dest(i+i0,j+j0,p) = src(i,j,p);
00064 }
00065 
00066 
00067 // For everything else
00068 #define VIL_COPY_INSTANTIATE(T) \
00069 template void vil_copy_deep(const vil_image_view<T > &src, vil_image_view<T > &dest); \
00070 template void vil_copy_to_window(const vil_image_view<T > &src, vil_image_view<T > &dest, \
00071                                  unsigned i0, unsigned j0); \
00072 template void vil_copy_reformat(const vil_image_view<T > &src, vil_image_view<T > &dest); \
00073 template vil_image_view<T > vil_copy_deep(const vil_image_view<T > &rhs)
00074 
00075 #endif // vil_copy_txx_