Go to the documentation of this file.00001
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005
00006
00007
00008
00009
00010
00011 #include "vil_crop.h"
00012 #include <vcl_cassert.h>
00013 #include <vil/vil_exception.h>
00014
00015
00016 vil_image_resource_sptr vil_crop(const vil_image_resource_sptr &src, unsigned i0,
00017 unsigned n_i, unsigned j0, unsigned n_j)
00018 {
00019 return new vil_crop_image_resource(src, i0, n_i, j0, n_j);
00020 }
00021
00022
00023 vil_crop_image_resource::vil_crop_image_resource(vil_image_resource_sptr const& gi,
00024 unsigned i0, unsigned n_i,
00025 unsigned j0, unsigned n_j):
00026 src_(gi),
00027 i0_(i0),
00028 ni_(n_i),
00029 j0_(j0),
00030 nj_(n_j)
00031 {
00032 assert (i0+n_i <= src_->ni() && j0 + n_j <= src_->nj());
00033 }
00034
00035 vil_image_view_base_sptr vil_crop_image_resource::get_copy_view(unsigned i0, unsigned n_i,
00036 unsigned j0, unsigned n_j) const
00037 {
00038 if (i0 + n_i > ni() || j0 + n_j > nj())
00039 {
00040 vil_exception_warning(vil_exception_out_of_bounds(
00041 "vil_crop_image_resource::get_copy_view") );
00042 return 0;
00043 }
00044 return src_->get_copy_view(i0+i0_, n_i, j0+j0_, n_j);
00045 }
00046
00047 vil_image_view_base_sptr vil_crop_image_resource::get_view(unsigned i0, unsigned n_i,
00048 unsigned j0, unsigned n_j) const
00049 {
00050 if (i0 + n_i > ni() || j0 + n_j > nj())
00051 {
00052 vil_exception_warning(vil_exception_out_of_bounds(
00053 "vil_crop_image_resource::get_view") );
00054 return 0;
00055 }
00056 return src_->get_view(i0+i0_, n_i, j0+j0_, n_j);
00057 }