6 # include <vcl_msvc_warnings.h> 23 return (
ni()+sbi -1)/sbi;
31 return (
nj()+sbj -1)/sbj;
35 get_blocks(
unsigned int start_block_i,
unsigned int end_block_i,
36 unsigned int start_block_j,
unsigned int end_block_j,
37 std::vector< std::vector< vil_image_view_base_sptr > >& blocks )
const 39 for (
unsigned int bi = start_block_i; bi<=end_block_i; ++bi)
41 std::vector< vil_image_view_base_sptr > jblocks;
43 for (
unsigned int bj = start_block_j; bj<=end_block_j; ++bj)
47 if (view) jblocks.push_back(view);
51 blocks.push_back(jblocks);
57 unsigned int end_block_i,
58 unsigned int start_block_j,
59 unsigned int end_block_j,
60 std::vector< std::vector< vil_image_view_base_sptr > >
const& blocks )
62 for (
unsigned int bi = start_block_i; bi<=end_block_i; ++bi)
63 for (
unsigned int bj = start_block_j; bj<=end_block_j; ++bj)
64 if (!this->
put_block(bi, bj, *blocks[bi][bj]))
78 unsigned int output_width = 0;
79 unsigned int output_height = 0;
81 for (i = 0 ; i < blocks.size() ; i++) {
82 output_width += blocks[i][0]->ni();
84 for (i = 0 ; i < blocks[0].size() ; i++) {
85 output_height += blocks[0][i]->nj();
89 unsigned int curr_i = 0;
90 unsigned int curr_j = 0;
94 #define GLUE_BLOCK_CASE(FORMAT, T) \ 96 vil_image_view<T>* output_image = \ 97 new vil_image_view<T>(output_width, output_height, 1, nplanes()); \ 98 for (unsigned int bi = 0 ; bi < blocks.size() ; bi++) \ 100 for (unsigned int bj = 0 ; bj < blocks[bi].size() ; bj++)\ 102 vil_copy_to_window(static_cast<vil_image_view<T>&>(*blocks[bi][bj]), *output_image, curr_i, curr_j); \ 103 curr_j += blocks[bi][bj]->nj(); \ 106 curr_i += blocks[bi][0]->ni();\ 108 result = output_image; \ 124 #undef GLUE_BLOCK_CASE 127 assert(!
"Unknown vil data type in tiff file format");
135 unsigned int& i_offset)
const 141 unsigned int bstrt = tw*block_i;
150 unsigned int& j_offset)
const 156 unsigned int bstrt = tl*block_j;
167 unsigned int j0,
unsigned int nj,
168 unsigned int start_block_i,
169 unsigned int start_block_j,
170 std::vector< std::vector< vil_image_view_base_sptr > >& blocks)
const 173 for (
unsigned int bi = 0 ; bi < blocks.size() ; bi++) {
174 for (
unsigned int bj = 0 ; bj < blocks[bi].size() ; bj++) {
175 if (!blocks[bi][bj])
continue;
176 auto last_col_index = (
unsigned int)(blocks.size()-1);
177 auto last_row_index = (
unsigned int)(blocks[bi].size()-1);
179 bool first_block_in_row = bi == 0;
180 bool first_block_in_col = bj == 0;
181 bool last_block_in_row = bi == last_col_index;
182 bool last_block_in_col = bj == last_row_index;
185 if (!first_block_in_row && !first_block_in_col &&
186 !last_block_in_row && !last_block_in_col)
continue;
190 if (first_block_in_row)
193 if (last_block_in_row)
196 if (first_block_in_col)
199 if (last_block_in_col)
205 #define TRIM_BORDER_BLOCK_CASE(FORMAT, T) \ 207 vil_image_view< T > currBlock = static_cast<vil_image_view< T >&>(*blocks[bi][bj]);\ 208 vil_image_view< T >* croppedBlock = new vil_image_view< T >();\ 209 *croppedBlock = vil_crop(currBlock, bi0, bin-bi0+1, bj0, bjn-bj0+1);\ 210 blocks[bi][bj] = croppedBlock;\ 225 #undef TRIM_BORDER_BLOCK_CASE 228 assert(!
"Unknown vil data type.");
238 get_copy_view(
unsigned int i0,
unsigned int n_i,
unsigned int j0,
unsigned int n_j)
const 247 unsigned int bi_start = i0/tw, bi_end = (i0+n_i-1)/tw;
248 unsigned int bj_start = j0/tl, bj_end = (j0+n_j-1)/tl;
252 if (bi_start>lbi||bi_end>lbi||bj_start>lbj||bj_end>lbj)
256 std::vector<std::vector< vil_image_view_base_sptr > > blocks;
258 this->
get_blocks(bi_start, bi_end, bj_start, bj_end, blocks);
267 unsigned int nblocks = (bi_end-bi_start+1)*(bj_end-bj_start+1);
269 std::cout <<
"Get copy view of " << nblocks <<
" blocks in " 270 << t.real() <<
"msecs\n";
279 unsigned int sbi=0, sbj=0;
unsigned ni() const override=0
Dimensions: Planes x ni x nj.
virtual vil_image_view_base_sptr get_block(unsigned block_index_i, unsigned block_index_j) const =0
Block access.
virtual unsigned size_block_i() const =0
Block size in columns.
bool block_i_offset(unsigned block_i, unsigned i, unsigned &i_offset) const
Get the offset from the start of the block row for pixel position i.
vil_blocked_image_resource()
enum vil_pixel_format pixel_format() const override=0
Pixel Format.
virtual unsigned n_block_i() const
Number of blocks in image width.
#define GLUE_BLOCK_CASE(FORMAT, T)
bool block_j_offset(unsigned block_j, unsigned j, unsigned &j_offset) const
Get the offset from the start of the block column for pixel position j.
virtual bool get_blocks(unsigned start_block_i, unsigned end_block_i, unsigned start_block_j, unsigned end_block_j, std::vector< std::vector< vil_image_view_base_sptr > > &blocks) const
the multiple blocks are in col row order, i.e. blocks[i][j].
A blocked representation of the image_resource.
~vil_blocked_image_resource() override
vil_blocked_image_resource_sptr blocked_image_resource(const vil_image_resource_sptr &ir)
cast to blocked resource if possible.
#define TRIM_BORDER_BLOCK_CASE(FORMAT, T)
#define vil_property_size_block_i
For unblocked images, the following properties are not implemented.
Various image copying functions.
unsigned nj() const override=0
Dimensions: Planes x ni x nj.
bool trim_border_blocks(unsigned i0, unsigned ni, unsigned j0, unsigned nj, unsigned start_block_i, unsigned start_block_j, std::vector< std::vector< vil_image_view_base_sptr > > &blocks) const
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.
virtual unsigned size_block_j() const =0
Block size in rows.
There is no class or function called vil_property.
#define vil_property_size_block_j
Block size in rows.
virtual bool put_blocks(unsigned start_block_i, unsigned end_block_i, unsigned start_block_j, unsigned end_block_j, std::vector< std::vector< vil_image_view_base_sptr > > const &blocks)
put multiple blocks in raster order, i.e., blocks[i][j].
T * ptr() const
These methods all return the raw/dumb pointer.
virtual bool put_block(unsigned block_index_i, unsigned block_index_j, const vil_image_view_base &view)=0
put the block into the resource at the indicated location.
virtual unsigned n_block_j() const
Number of blocks in image height.
vil_image_view_base_sptr glue_blocks_together(const std::vector< std::vector< vil_image_view_base_sptr > > &blocks) const