vil_crop.h
Go to the documentation of this file.
1 // This is core/vil/vil_crop.h
2 #ifndef vil_crop_h_
3 #define vil_crop_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 //: Create a view which is a cropped version of src.
17 // Doesn't modify underlying data. O(1).
18 // \relatesalso vil_image_view
19 // \return an n_i x n_j window of im with offset (i0,j0)
20 template<class T>
21 inline vil_image_view<T> vil_crop(const vil_image_view<T> &im, unsigned i0,
22  unsigned n_i, unsigned j0, unsigned n_j)
23 {
24  assert(i0<im.ni()); assert(i0+n_i<=im.ni());
25  assert(j0<im.nj()); assert(j0+n_j<=im.nj());
26  return vil_image_view<T>(im.memory_chunk(), im.top_left_ptr()+ i0*im.istep() + j0*im.jstep(),
27  n_i, n_j, im.nplanes(), im.istep(), im.jstep(), im.planestep());
28 }
29 
30 //: Crop to a region of src.
31 // \relatesalso vil_image_resource
33  unsigned n_i, unsigned j0, unsigned n_j);
34 
35 //: A generic_image adaptor that behaves like a cropped version of its input
37 {
38  public:
39  vil_crop_image_resource(vil_image_resource_sptr const&, unsigned i0, unsigned n_i,
40  unsigned j0, unsigned n_j);
41 
42  unsigned nplanes() const override { return src_->nplanes(); }
43  unsigned ni() const override { return ni_; }
44  unsigned nj() const override { return nj_; }
45 
46  enum vil_pixel_format pixel_format() const override { return src_->pixel_format(); }
47 
48 
49  vil_image_view_base_sptr get_copy_view(unsigned i0, unsigned n_i,
50  unsigned j0, unsigned n_j) const override;
51 
52  vil_image_view_base_sptr get_view(unsigned i0, unsigned n_i,
53  unsigned j0, unsigned n_j) const override;
54 
55 
56  //: Put the data in this view back into the image source.
57  bool put_view(const vil_image_view_base& im, unsigned i0, unsigned j0) override
58  {
59  return src_->put_view(im, i0+i0_, j0+j0_);
60  }
61 
62  //: Extra property information
63  bool get_property(char const* tag, void* property_value = nullptr) const override
64  {
65  return src_->get_property(tag, property_value);
66  }
67 
68  protected:
70  int i0_;
71  int ni_;
72  int j0_;
73  int nj_;
74 };
75 
76 #endif // vil_crop_h_
An abstract base class of smart pointers to actual image data in memory.
vil_pixel_format
Describes the type of the concrete data.
vil_crop_image_resource(vil_image_resource_sptr const &, unsigned i0, unsigned n_i, unsigned j0, unsigned n_j)
Definition: vil_crop.cxx:22
unsigned nplanes() const override
Dimensions: Planes x ni x nj.
Definition: vil_crop.h:42
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
Definition: vil_crop.h:63
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_crop.h:57
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.
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_crop.h:43
Abstract representation of an image source or image destination.
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.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
enum vil_pixel_format pixel_format() const override
Pixel Format.
Definition: vil_crop.h:46
const vil_memory_chunk_sptr & memory_chunk() const
Smart pointer to the object holding the data for this view.
vil_image_resource_sptr src_
Definition: vil_crop.h:69
Representation of a generic image source or destination.
vil_image_view< T > vil_crop(const vil_image_view< T > &im, unsigned i0, unsigned n_i, unsigned j0, unsigned n_j)
Create a view which is a cropped version of src.
Definition: vil_crop.h:21
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_crop.h:44
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.
A generic_image adaptor that behaves like a cropped version of its input.
Definition: vil_crop.h:36
vil_image_view_base_sptr get_view() const
Create a read/write view of all the data.