vil_copy.hxx
Go to the documentation of this file.
1 // This is core/vil/vil_copy.hxx
2 #ifndef vil_copy_hxx_
3 #define vil_copy_hxx_
4 //:
5 // \file
6 // \author Ian Scott, ISBE, Manchester
7 // \date 4 Oct 2002
8 
9 #include "vil_copy.h"
10 #include <cassert>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 #include <vil/vil_image_view.h>
15 
16 //: Create a copy of the data viewed by this, and return a view of copy.
17 template<class T>
19 {
20  dest.deep_copy(src);
21 }
22 
23 //: Create a copy of the data viewed by this, and return a view of copy.
24 template<class T>
26 {
28  cpy.deep_copy(src);
29  return cpy;
30 }
31 
32 
33 //: Copy src to dest, without changing dest's view parameters.
34 // This is useful if you want to copy an image into a window on another image.
35 // src and dest must have identical sizes, and types.
36 template<class T>
38 {
39  assert (src.nplanes() == dest.nplanes() &&
40  src.nj() == dest.nj() &&
41  src.ni() == dest.ni());
42  for (unsigned p = 0; p < dest.nplanes(); ++p)
43  for (unsigned j = 0; j < dest.nj(); ++j)
44  for (unsigned i = 0; i < dest.ni(); ++i)
45  dest(i,j,p) = src(i,j,p);
46 }
47 
48 
49 //: Copy src to window in dest.
50 // Size of window is defined by src.
51 // O(window.size).
52 template<class T>
54  unsigned i0, unsigned j0)
55 {
56  // check window is within dest's bounds
57  assert(i0+src.ni() <= dest.ni() && j0+src.nj() <= dest.nj());
58  assert (src.nplanes() == dest.nplanes());
59 
60  for (unsigned p = 0; p < dest.nplanes(); ++p)
61  for (unsigned j = 0; j < src.nj(); ++j)
62  for (unsigned i = 0; i < src.ni(); ++i)
63  dest(i+i0,j+j0,p) = src(i,j,p);
64 }
65 
66 
67 // For everything else
68 #define VIL_COPY_INSTANTIATE(T) \
69 template void vil_copy_deep(const vil_image_view<T > &src, vil_image_view<T > &dest); \
70 template void vil_copy_to_window(const vil_image_view<T > &src, vil_image_view<T > &dest, \
71  unsigned i0, unsigned j0); \
72 template void vil_copy_reformat(const vil_image_view<T > &src, vil_image_view<T > &dest); \
73 template vil_image_view<T > vil_copy_deep(const vil_image_view<T > &rhs)
74 
75 #endif // vil_copy_hxx_
void vil_copy_to_window(const vil_image_view< T > &src, vil_image_view< T > &dest, unsigned i0, unsigned j0)
Copy src to window in dest.
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
unsigned ni() const
Width.
unsigned nj() const
Height.
Various image copying functions.
void deep_copy(const vil_image_view< T > &src)
Make a copy of the data in src and set this to view it.
void vil_copy_reformat(const vil_image_view< T > &src, vil_image_view< T > &dest)
Copy src to dest, without changing dest's view parameters.
A base class reference-counting view of some image data.
unsigned nplanes() const
Number of planes.
bool vil_copy_deep(const vil_image_resource_sptr &src, vil_image_resource_sptr &dest)
Copy src to dest.
Definition: vil_copy.cxx:45