vil_plane.h
Go to the documentation of this file.
1 // This is core/vil/vil_plane.h
2 #ifndef vil_plane_h_
3 #define vil_plane_h_
4 //:
5 // \file
6 // \author Ian Scott.
7 
9 #include <vil/vil_image_view.h>
10 #include <cassert>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 
16 //: Return a view of im's plane p.
17 // O(1).
18 // \relatesalso vil_image_view
19 template<class T>
20 inline vil_image_view<T> vil_plane(const vil_image_view<T> &im, unsigned p)
21 {
22  assert(p<im.nplanes());
23  return vil_image_view<T>(im.memory_chunk(),im.top_left_ptr()+p*im.planestep(),im.ni(),im.nj(),1,
24  im.istep(),im.jstep(),im.planestep());
25 }
26 
27 //: Return a view of a selection of im's planes.
28 // You can select any equally-spaced sequence of planes.
29 // \param first The index of the first plane you want to select.
30 // \param skip The spacing in your selection - will be 1 for adjacent planes.
31 // \param n The total number of planes in your selection.
32 //
33 // O(1).
34 template<class T>
36  unsigned first, int skip,
37  unsigned n)
38 {
39  assert(first<im.nplanes());
40  assert(int(first) + int(n)*skip >= 0);
41  assert((unsigned)(first + n*skip) <= im.nplanes());
42  return vil_image_view<T>(im.memory_chunk(),
43  im.top_left_ptr()+first*im.planestep(),
44  im.ni(),im.nj(),n,
45  im.istep(),im.jstep(),skip*im.planestep());
46 }
47 
48 
49 //: Return a specific plane of an image.
50 // \relatesalso vil_image_resource
52 
53 
54 //: A generic_image adaptor that behaves like a single plane version of its input
55 // For implementation use only - use vil_plane() to create one.
57 {
59  friend vil_image_resource_sptr vil_plane(const vil_image_resource_sptr &src, unsigned p);
60  public:
61 
62  unsigned nplanes() const override { return 1; }
63  unsigned ni() const override { return src_->ni(); }
64  unsigned nj() const override { return src_->nj(); }
65 
66  enum vil_pixel_format pixel_format() const override { return src_->pixel_format(); }
67 
68  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned ni,
69  unsigned j0, unsigned nj) const override;
70 
71  vil_image_view_base_sptr get_view(unsigned i0, unsigned ni,
72  unsigned j0, unsigned nj) const override;
73 
74 
75  //: Put the data in this view back into the image source.
76  bool put_view(const vil_image_view_base& im, unsigned i0,
77  unsigned j0) override;
78 
79  //: Extra property information
80  bool get_property(char const* tag, void* property_value = nullptr) const override {
81  return src_->get_property(tag, property_value); }
82 
83  protected:
84  //: Reference to underlying image source
86  //: which plane.
87  unsigned plane_;
88 };
89 
90 #endif // vil_plane_h_
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_plane.h:63
unsigned plane_
which plane.
Definition: vil_plane.h:87
unsigned nplanes() const override
Dimensions: Planes x ni x nj.
Definition: vil_plane.h:62
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_plane.h:66
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
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
Definition: vil_plane.h:80
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
Abstract representation of an image source or image destination.
friend vil_image_resource_sptr vil_plane(const vil_image_resource_sptr &src, unsigned p)
Return a specific plane of an image.
Definition: vil_plane.cxx:19
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.
A base class reference-counting view of some image data.
vil_plane_image_resource(vil_image_resource_sptr const &, unsigned p)
Definition: vil_plane.cxx:24
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
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.
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
Representation of a generic image source or destination.
vil_image_view< T > vil_planes(const vil_image_view< T > &im, unsigned first, int skip, unsigned n)
Return a view of a selection of im's planes.
Definition: vil_plane.h:35
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
vil_image_view_base_sptr get_view() const
Create a read/write view of all the data.