vigra - vigra/blockify.hxx Source File

[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

blockify.hxx |

1 /************************************************************************/
2 /* */
3 /* Copyright 2013-2014 by Martin Bidlingmaier and Ullrich Koethe */
4 /* */
5 /* This file is part of the VIGRA computer vision library. */
6 /* The VIGRA Website is */
7 /* http://hci.iwr.uni-heidelberg.de/vigra/ */
8 /* Please direct questions, bug reports, and contributions to */
9 /* ullrich.koethe@iwr.uni-heidelberg.de or */
10 /* vigra@informatik.uni-hamburg.de */
11 /* */
12 /* Permission is hereby granted, free of charge, to any person */
13 /* obtaining a copy of this software and associated documentation */
14 /* files (the "Software"), to deal in the Software without */
15 /* restriction, including without limitation the rights to use, */
16 /* copy, modify, merge, publish, distribute, sublicense, and/or */
17 /* sell copies of the Software, and to permit persons to whom the */
18 /* Software is furnished to do so, subject to the following */
19 /* conditions: */
20 /* */
21 /* The above copyright notice and this permission notice shall be */
22 /* included in all copies or substantial portions of the */
23 /* Software. */
24 /* */
25 /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
26 /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
27 /* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
28 /* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
29 /* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
30 /* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
31 /* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
32 /* OTHER DEALINGS IN THE SOFTWARE. */
33 /* */
34 /************************************************************************/
35
36 #ifndef VIGRA_BLOCKIFY_HXX
37 #define VIGRA_BLOCKIFY_HXX
38
39 #include "multi_array.hxx"
40
41 namespace vigra
42 {
43
44 namespace blockify_detail
45 {
46
47 template <unsigned int CurrentDimensions>
48 struct blockify_impl
49 {
50 // for CurrentDimension >= 1
51 template <unsigned int N, class T, class S, class Shape>
52 static void make(MultiArrayView<N, T, S>& source,
53 MultiArrayView<N, MultiArrayView<N, T, S> >& blocks,
54 Shape current_block_begin,
55 Shape current_block_end,
56 Shape current_block_pos,
57 Shape block_shape)
58 {
59 typedef typename Shape::value_type size_type;
60 enum{ n = CurrentDimensions - 1};
61
62 size_type blocks_extend = blocks.shape(n);
63
64 vigra_assert(blocks_extend != 0, "");
65 for(current_block_pos[n] = 0, current_block_begin[n] = 0, current_block_end[n] = block_shape[n];
66 current_block_pos[n] != blocks_extend - 1;
67 ++current_block_pos[n],
68 current_block_begin[n] += block_shape[n],
69 current_block_end[n] += block_shape[n])
70 {
71 blockify_impl<n>::make(source, blocks, current_block_begin, current_block_end, current_block_pos, block_shape);
72 }
73 current_block_end[n] = source.shape(n);
74 blockify_impl<n>::make(source, blocks, current_block_begin, current_block_end, current_block_pos, block_shape);
75 }
76 };
77
78 template <>
79 struct blockify_impl<0>
80 {
81 template <unsigned int N, class T, class S, class Shape>
82 static void make(MultiArrayView<N, T, S>& source,
83 MultiArrayView<N, MultiArrayView<N, T, S> >& blocks,
84 Shape current_block_begin,
85 Shape current_block_end,
86 Shape current_block_pos,
87 Shape /*block_shape*/)
88 {
89 blocks[current_block_pos] = source.subarray(current_block_begin, current_block_end);
90 }
91 };
92
93 } // namespace blockify_detail
94
95 template <unsigned int N, class T, class S>
96 MultiArray<N, MultiArrayView<N, T, S> >
97 blockify(MultiArrayView<N, T, S> source, typename MultiArrayView<N, T, S>::difference_type block_shape)
98 {
99 using namespace blockify_detail;
100 typedef typename MultiArrayView<N, T, S>::difference_type Shape;
101
102 Shape blocks_shape;
103 for(unsigned int n = 0; n != N; ++n)
104 {
105 blocks_shape[n] = source.shape(n) / block_shape[n];
106 if(blocks_shape[n] * block_shape[n] != source.shape(n))
107 ++blocks_shape[n];
108 }
109 MultiArray<N, MultiArrayView<N, T, S> > blocks(blocks_shape);
110 if(source.size() == 0)
111 return blocks;
112 Shape a;
113 Shape b;
114 Shape c;
115 blockify_impl<N>::make(source, blocks, a, b, c, block_shape);
116 return blocks;
117 }
118
119 } // namespace vigra
120
121 #endif // VIGRA_BLOCKIFY_HXX
vigra::MultiArrayView< N, T, S >::difference_type
MultiArrayShape< actual_dimension >::type difference_type
Definition: multi_array.hxx:739
vigra::boost_graph::source
vigra::GridGraph< N, DirectedTag >::vertex_descriptor source(typename vigra::GridGraph< N, DirectedTag >::edge_descriptor const &e, vigra::GridGraph< N, DirectedTag > const &g)
Get a vertex descriptor for the start vertex of edge e in graph g (API: boost).
Definition: multi_gridgraph.hxx:2943

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)