vil_plane.cxx
Go to the documentation of this file.
1 // This is core/vil/vil_plane.cxx
2 //:
3 // \file
4 // \author Ian Scott.
5 //
6 // \verbatim
7 // Modifications
8 // 23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
9 // \endverbatim
10 //
11 //-----------------------------------------------------------------------------
12 
13 #include "vil_plane.h"
14 #include <cassert>
15 #ifdef _MSC_VER
16 # include <vcl_msvc_warnings.h>
17 #endif
18 
19 
21 {
22  return new vil_plane_image_resource(src, p);
23 }
24 
26  unsigned p):
27  src_(gi),
28  plane_(p)
29 {
30  assert (p <= src_->nplanes());
31 }
32 
34  unsigned j0, unsigned nj) const
35 {
36  vil_image_view_base_sptr vs = src_->get_copy_view(i0, ni, j0, nj);
37  if (!vs) return nullptr;
38 
39  switch (vs->pixel_format())
40  {
41 #define macro( F , T ) \
42  case F : \
43  return new vil_image_view<T > (vil_plane(static_cast<const vil_image_view<T >&>(*vs), plane_));
44 
45  macro(VIL_PIXEL_FORMAT_BYTE , vxl_byte )
46  macro(VIL_PIXEL_FORMAT_SBYTE , vxl_sbyte )
47 #if VXL_HAS_INT_64
48  macro(VIL_PIXEL_FORMAT_UINT_64 , vxl_uint_64 )
49  macro(VIL_PIXEL_FORMAT_INT_64 , vxl_int_64 )
50 #endif
51  macro(VIL_PIXEL_FORMAT_UINT_32 , vxl_uint_32 )
52  macro(VIL_PIXEL_FORMAT_INT_32 , vxl_int_32 )
53  macro(VIL_PIXEL_FORMAT_UINT_16 , vxl_uint_16 )
54  macro(VIL_PIXEL_FORMAT_INT_16 , vxl_int_16 )
57  macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT , std::complex<float>)
58  macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , std::complex<double>)
59 #undef macro
60  default:
61  return nullptr;
62  }
63 }
64 
65 
67  unsigned j0, unsigned nj) const
68 {
69  vil_image_view_base_sptr vs = src_->get_view(i0, ni, j0, nj);
70  if (!vs) return nullptr;
71 
72  switch (vs->pixel_format())
73  {
74 #define macro( F , T ) \
75  case F : \
76  return new vil_image_view<T > (vil_plane(static_cast<const vil_image_view<T >&>(*vs), plane_));
77 
78  macro(VIL_PIXEL_FORMAT_BYTE , vxl_byte )
79  macro(VIL_PIXEL_FORMAT_SBYTE , vxl_sbyte )
80 #if VXL_HAS_INT_64
81  macro(VIL_PIXEL_FORMAT_UINT_64 , vxl_uint_64 )
82  macro(VIL_PIXEL_FORMAT_INT_64 , vxl_int_64 )
83 #endif
84  macro(VIL_PIXEL_FORMAT_UINT_32 , vxl_uint_32 )
85  macro(VIL_PIXEL_FORMAT_INT_32 , vxl_int_32 )
86  macro(VIL_PIXEL_FORMAT_UINT_16 , vxl_uint_16 )
87  macro(VIL_PIXEL_FORMAT_INT_16 , vxl_int_16 )
90  macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT , std::complex<float>)
91  macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , std::complex<double>)
92 #undef macro
93  default:
94  return nullptr;
95  }
96 }
97 
98 
99 //: Put the data in this view back into the image source.
101  unsigned i0, unsigned j0)
102 {
103  if (im.nplanes() != 1) return false;
104  vil_image_view_base_sptr vs = src_->get_view(i0, im.ni(), j0, im.nj());
105  if (!vs || im.pixel_format() != vs->pixel_format()) return false;
106 
107  switch (vs->pixel_format())
108  {
109 #define macro( F , T ) \
110  case F : { \
111  const vil_image_view<T > view = static_cast<const vil_image_view<T >&>(im); \
112  vil_image_view<T > plane = vil_plane(static_cast<vil_image_view<T >&>(*vs), plane_); \
113  if (view == plane) return true; /* If we have already modified the data, do nothing */ \
114  for (unsigned j=0;j<view.nj();++j) \
115  for (unsigned i=0;i<view.ni();++i) \
116  plane(i,j) = view(i,j); \
117  return src_->put_view(*vs, i0, j0); }
118 
119  macro(VIL_PIXEL_FORMAT_BYTE , vxl_byte )
120  macro(VIL_PIXEL_FORMAT_SBYTE , vxl_sbyte )
121 #if VXL_HAS_INT_64
122  macro(VIL_PIXEL_FORMAT_UINT_64 , vxl_uint_64 )
123  macro(VIL_PIXEL_FORMAT_INT_64 , vxl_int_64 )
124 #endif
125  macro(VIL_PIXEL_FORMAT_UINT_32 , vxl_uint_32 )
126  macro(VIL_PIXEL_FORMAT_INT_32 , vxl_int_32 )
127  macro(VIL_PIXEL_FORMAT_UINT_16 , vxl_uint_16 )
128  macro(VIL_PIXEL_FORMAT_INT_16 , vxl_int_16 )
129  macro(VIL_PIXEL_FORMAT_FLOAT , float )
130  macro(VIL_PIXEL_FORMAT_DOUBLE , double )
131  macro(VIL_PIXEL_FORMAT_COMPLEX_FLOAT , std::complex<float>)
132  macro(VIL_PIXEL_FORMAT_COMPLEX_DOUBLE , std::complex<double>)
133 #undef macro
134  default:
135  return false;
136  }
137 }
An abstract base class of smart pointers to actual image data in memory.
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_plane.h:63
std::complex<float> is a scalar for vil's purposes.
unsigned nplanes() const override
Dimensions: Planes x ni x nj.
Definition: vil_plane.h:62
vil_image_resource_sptr src_
Reference to underlying image source.
Definition: vil_plane.h:85
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_plane.h:64
unsigned ni() const
Width.
unsigned nj() const
Height.
virtual enum vil_pixel_format pixel_format() const =0
Return a description of the concrete data pixel type.
bool put_view(const vil_image_view_base &im, unsigned i0, unsigned j0) override
Put the data in this view back into the image source.
Definition: vil_plane.cxx:99
A generic_image adaptor that behaves like a single plane version of its input.
Definition: vil_plane.h:56
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
vil_plane_image_resource(vil_image_resource_sptr const &, unsigned p)
Definition: vil_plane.cxx:24
vil_image_view< T > vil_plane(const vil_image_view< T > &im, unsigned p)
Return a view of im's plane p.
Definition: vil_plane.h:20
unsigned nplanes() const
Number of planes.
#define macro(F, T)
vil_image_view_base_sptr get_view() const
Create a read/write view of all the data.
std::complex<double> is a scalar for vil's purposes.