74 #ifndef SLIP_BORDER_TREATMENT_HPP
75 #define SLIP_BORDER_TREATMENT_HPP
135 template <
typename _II>
138 const typename std::iterator_traits<_II>::value_type& value,
139 const std::size_t size)
144 struct __fill_border<std::random_access_iterator_tag>
146 template <
typename _II>
149 const typename std::iterator_traits<_II>::value_type& value,
150 const std::size_t size)
152 typedef typename std::iterator_traits<_II>::value_type value_type;
153 std::fill_n(first,size,value);
154 std::fill_n(std::reverse_iterator<_II>(last),
163 struct __fill_border<std::random_access_iterator2d_tag>
165 template <
typename _II>
168 const typename std::iterator_traits<_II>::value_type& value,
169 const std::size_t size)
171 typedef typename std::iterator_traits<_II>::value_type value_type;
172 typedef typename std::iterator_traits<_II>::difference_type _Difference;
174 _Difference size_nd = last - first;
175 std::size_t rows = std::size_t(size_nd[0]);
176 std::size_t cols = std::size_t(size_nd[1]);
178 for(std::size_t i = 0; i < rows;++i)
183 for(std::size_t j = 0; j < cols;++j)
188 for(std::size_t i = 0; i < size;++i)
196 struct __fill_border<std::random_access_iterator3d_tag>
198 template <
typename _II>
201 const typename std::iterator_traits<_II>::value_type& value,
202 const std::size_t size)
204 typedef typename std::iterator_traits<_II>::value_type value_type;
205 typedef typename std::iterator_traits<_II>::difference_type _Difference;
207 _Difference size_nd = last - first;
208 std::size_t slices = std::size_t(size_nd[0]);
209 std::size_t rows = std::size_t(size_nd[1]);
210 std::size_t cols = std::size_t(size_nd[2]);
212 for(std::size_t k = 0; k < slices;++k)
214 for(std::size_t i = 0; i < rows;++i)
220 for(std::size_t k = 0; k < slices; ++k)
222 for(std::size_t j = 0; j < cols;++j)
228 for(std::size_t i = 0; i < rows;++i)
230 for(std::size_t j = 0; j < cols;++j)
236 for(std::size_t k = 0; k < size; ++k)
238 for(std::size_t i = 0; i < rows;++i)
243 for(std::size_t j = 0; j < cols;++j)
253 for(std::size_t k = 0; k < slices; ++k)
255 for(std::size_t i = 0; i < size;++i)
276 struct __fill_border<std::random_access_iterator4d_tag>
278 template <
typename _II>
281 const typename std::iterator_traits<_II>::value_type& value,
282 const std::size_t size)
284 typedef typename std::iterator_traits<_II>::value_type value_type;
285 typedef typename std::iterator_traits<_II>::difference_type _Difference;
287 _Difference size_nd = last - first;
288 std::size_t slabs = std::size_t(size_nd[0]);
289 std::size_t slices = std::size_t(size_nd[1]);
290 std::size_t rows = std::size_t(size_nd[2]);
291 std::size_t cols = std::size_t(size_nd[3]);
293 for(std::size_t t = 0; t < slabs;++t)
295 for(std::size_t k = 0; k < slices;++k)
297 for(std::size_t i = 0; i < rows;++i)
300 first.row_end(t,k,i),value,size);
305 for(std::size_t t = 0; t < slabs;++t)
307 for(std::size_t k = 0; k < slices; ++k)
309 for(std::size_t j = 0; j < cols;++j)
312 first.col_end(t,k,j),value,size);
317 for(std::size_t t = 0; t < slabs;++t)
319 for(std::size_t i = 0; i < rows;++i)
321 for(std::size_t j = 0; j < cols;++j)
324 first.slice_end(t,i,j),value,size);
329 for(std::size_t k = 0; k < slices;++k)
331 for(std::size_t i = 0; i < rows;++i)
333 for(std::size_t j = 0; j < cols;++j)
336 first.slab_end(k,i,j),value,size);
396 template<
typename _II>
398 const typename std::iterator_traits<_II>::value_type& value =
399 typename std::iterator_traits<_II>::value_type())
401 typedef typename std::iterator_traits<_II>::iterator_category _Category;
439 template <
typename _II>
441 std::size_t b_size = 1,
442 const typename std::iterator_traits<_II>::value_type& value =
443 typename std::iterator_traits<_II>::value_type())
445 assert((last-first) >= 2*b_size);
446 typedef typename std::iterator_traits<_II>::iterator_category _Category;
455 struct __update_border
457 template <
typename _II>
461 const std::size_t size = 1)
466 struct __update_border<std::random_access_iterator_tag>
468 template <
typename _II>
472 const std::size_t size = 1)
474 typedef typename std::iterator_traits<_II>::value_type value_type;
481 std::fill_n(first,size,value_type());
482 std::fill_n(std::reverse_iterator<_II>(last),
488 std::copy(first+size,first+(size+size),std::reverse_iterator<_II>(first+size));
491 std::reverse_iterator<_II>(last));
496 std::copy(first+size,first+(size+size),last - size);
497 std::copy(std::reverse_iterator<_II>(last-size),
498 std::reverse_iterator<_II>(last-(size + size)),
499 std::reverse_iterator<_II>(first+size));
505 std::copy(first+size,first+(size+size),std::reverse_iterator<_II>(first+size));
508 std::reverse_iterator<_II>(last));
513 value_type left = value_type(*(first + size));
514 value_type right = value_type(*(last - size - 1));
515 std::fill_n(first,size,left);
516 std::fill_n(std::reverse_iterator<_II>(last),
522 std::fill_n(first,size,value_type());
523 std::fill_n(std::reverse_iterator<_II>(last-size),
534 struct __update_border<std::random_access_iterator2d_tag>
536 template <
typename _II>
540 const std::size_t size = 1)
542 typedef typename std::iterator_traits<_II>::value_type value_type;
543 typedef typename std::iterator_traits<_II>::difference_type _Difference;
545 _Difference size_nd = last - first;
546 std::size_t rows = std::size_t(size_nd[0]);
547 std::size_t cols = std::size_t(size_nd[1]);
549 for(std::size_t i = 0; i < rows;++i)
554 for(std::size_t j = 0; j < cols;++j)
559 for(std::size_t i = 0; i < size;++i)
567 struct __update_border<std::random_access_iterator3d_tag>
569 template <
typename _II>
573 const std::size_t size = 1)
575 typedef typename std::iterator_traits<_II>::value_type value_type;
576 typedef typename std::iterator_traits<_II>::difference_type _Difference;
578 _Difference size_nd = last - first;
579 std::size_t slices = std::size_t(size_nd[0]);
580 std::size_t rows = std::size_t(size_nd[1]);
581 std::size_t cols = std::size_t(size_nd[2]);
583 for(std::size_t k = 0; k < slices;++k)
585 for(std::size_t i = 0; i < rows;++i)
591 for(std::size_t k = 0; k < slices; ++k)
593 for(std::size_t j = 0; j < cols;++j)
599 for(std::size_t i = 0; i < rows;++i)
601 for(std::size_t j = 0; j < cols;++j)
607 for(std::size_t k = 0; k < size; ++k)
609 for(std::size_t i = 0; i < rows;++i)
614 for(std::size_t j = 0; j < cols;++j)
624 for(std::size_t k = 0; k < slices; ++k)
626 for(std::size_t i = 0; i < size;++i)
645 struct __update_border<std::random_access_iterator4d_tag>
647 template <
typename _II>
651 const std::size_t size = 1)
653 typedef typename std::iterator_traits<_II>::value_type value_type;
654 typedef typename std::iterator_traits<_II>::difference_type _Difference;
656 _Difference size_nd = last - first;
657 std::size_t slabs = std::size_t(size_nd[0]);
658 std::size_t slices = std::size_t(size_nd[1]);
659 std::size_t rows = std::size_t(size_nd[2]);
660 std::size_t cols = std::size_t(size_nd[3]);
662 for(std::size_t t = 0; t < slabs;++t)
664 for(std::size_t k = 0; k < slices;++k)
666 for(std::size_t i = 0; i < rows;++i)
669 first.row_end(t,k,i),border,size);
674 for(std::size_t t = 0; t < slabs;++t)
676 for(std::size_t k = 0; k < slices; ++k)
678 for(std::size_t j = 0; j < cols;++j)
681 first.col_end(t,k,j),border,size);
686 for(std::size_t t = 0; t < slabs;++t)
688 for(std::size_t i = 0; i < rows;++i)
690 for(std::size_t j = 0; j < cols;++j)
693 first.slice_end(t,i,j),border,size);
698 for(std::size_t k = 0; k < slices;++k)
700 for(std::size_t i = 0; i < rows;++i)
702 for(std::size_t j = 0; j < cols;++j)
705 first.slab_end(k,i,j),border,size);
757 template<
typename _II>
760 typedef typename std::iterator_traits<_II>::iterator_category _Category;
801 template <
typename _II>
804 const std::size_t b_size = 1)
806 typedef typename std::iterator_traits<_II>::iterator_category _Category;
815 template <
typename _II,
typename _OI>
819 _OI out_first,
const std::size_t size = 1)
824 struct __add_border<std::random_access_iterator_tag>
826 template <
typename _II,
typename _OI>
830 _OI out_first,
const std::size_t size = 1)
832 typedef typename std::iterator_traits<_OI>::value_type value_type;
833 typedef typename std::iterator_traits<_II>::iterator_category _Category;
838 out_first+(last-first)+(2*size),
845 struct __add_border<std::random_access_iterator2d_tag>
847 template <
typename _II,
typename _OI>
851 _OI out_first,
const std::size_t size = 1)
853 typedef typename std::iterator_traits<_OI>::value_type value_type;
854 typedef typename std::iterator_traits<_II>::difference_type _Difference;
856 _Difference size_nd = last - first;
857 std::size_t rows = std::size_t(size_nd[0]);
858 std::size_t cols = std::size_t(size_nd[1]);
860 for(std::size_t i = 0; i < rows;++i)
862 std::copy(first.row_begin(i),first.row_end(i),out_first.row_begin(i+size) + size);
866 for(std::size_t j = 0; j < cols;++j)
871 for(std::size_t i = 0; i < size;++i)
880 struct __add_border<std::random_access_iterator3d_tag>
882 template <
typename _II,
typename _OI>
886 _OI out_first,
const std::size_t size = 1)
888 typedef typename std::iterator_traits<_OI>::value_type value_type;
889 typedef typename std::iterator_traits<_II>::difference_type _Difference;
891 _Difference size_nd = last - first;
892 std::size_t slices = std::size_t(size_nd[0]);
893 std::size_t rows = std::size_t(size_nd[1]);
894 std::size_t cols = std::size_t(size_nd[2]);
896 for(std::size_t k = 0; k < slices;++k)
898 for(std::size_t i = 0; i < rows;++i)
901 std::copy(first.row_begin(k,i),first.row_end(k,i),out_first.row_begin(k+size,i+size) + size);
906 for(std::size_t k = 0; k < slices; ++k)
908 for(std::size_t j = 0; j < cols;++j)
914 for(std::size_t i = 0; i < rows;++i)
916 for(std::size_t j = 0; j < cols;++j)
922 for(std::size_t k = 0; k < size; ++k)
924 for(std::size_t i = 0; i < rows;++i)
929 for(std::size_t j = 0; j < cols;++j)
939 for(std::size_t k = 0; k < (slices + 2*size); ++k)
941 for(std::size_t i = 0; i < size;++i)
960 struct __add_border<std::random_access_iterator4d_tag>
962 template <
typename _II,
typename _OI>
966 _OI out_first,
const std::size_t size = 1)
968 typedef typename std::iterator_traits<_OI>::value_type value_type;
969 typedef typename std::iterator_traits<_II>::difference_type _Difference;
971 _Difference size_nd = last - first;
972 std::size_t slabs = std::size_t(size_nd[0]);
973 std::size_t slices = std::size_t(size_nd[1]);
974 std::size_t rows = std::size_t(size_nd[2]);
975 std::size_t cols = std::size_t(size_nd[3]);
977 for(std::size_t t = 0; t < slabs; ++t)
979 for(std::size_t k = 0; k < slices;++k)
981 for(std::size_t i = 0; i < rows;++i)
984 std::copy(first.row_begin(t,k,i),first.row_end(t,k,i),out_first.row_begin(t+size,k+size,i+size) + size);
986 border,out_first.row_begin(t+size,k+size,i+size),size);
991 for(std::size_t t = 0; t < slabs; ++t)
993 for(std::size_t k = 0; k < slices; ++k)
995 for(std::size_t j = 0; j < cols;++j)
998 first.col_end(t,k,j),border,out_first.col_begin(t+size,k+size,j+size),size);
1003 for(std::size_t t = 0; t < slabs; ++t)
1005 for(std::size_t i = 0; i < rows;++i)
1007 for(std::size_t j = 0; j < cols;++j)
1010 first.slice_end(t,i,j),border,out_first.slice_begin(t+size,i+size,j+size),size);
1015 for(std::size_t k = 0; k < slices; ++k)
1017 for(std::size_t i = 0; i < rows;++i)
1019 for(std::size_t j = 0; j < cols;++j)
1022 first.slab_end(k,i,j),border,out_first.slab_begin(k+size,i+size,j+size),size);
1027 for(std::size_t t = 0; t < size; ++t)
1029 for(std::size_t k = 0; k < slices; ++k)
1031 for(std::size_t i = 0; i < rows;++i)
1034 out_first.row_end(t,k+size,i+size)-size,border,out_first.row_begin(t,k+size,i+size),size);
1036 out_first.row_begin(t+(slabs+size),k+size,i+size)+size,
1037 out_first.row_end(t+(slabs+size),k+size,i+size)-size,border,
1038 out_first.row_begin(t+(slabs+size),k+size,i+size),size);
1041 for(std::size_t k = 0; k < slices; ++k)
1043 for(std::size_t j = 0; j < cols;++j)
1046 out_first.col_end(t,k+size,j+size)-size,border,out_first.col_begin(t,k+size,j+size),size);
1048 out_first.col_begin(t+(slabs+size),k+size,j+size)+size,
1049 out_first.col_end(t+(slabs+size),k+size,j+size)-size,border,
1050 out_first.col_begin(t+(slabs+size),k+size,j+size),size);
1054 for(std::size_t i = 0; i < rows;++i)
1056 for(std::size_t j = 0; j < cols;++j)
1059 out_first.slice_end(t,i+size,j+size)-size,border,out_first.slice_begin(t,i+size,j+size),size);
1061 out_first.slice_begin(t+(slabs+size),i+size,j+size)+size,
1062 out_first.slice_end(t+(slabs+size),i+size,j+size)-size,border,
1063 out_first.slice_begin(t+(slabs+size),i+size,j+size),size);
1068 for(std::size_t t = 0; t < (slabs + 2*size); ++t)
1070 for(std::size_t k = 0; k < size; ++k)
1072 for(std::size_t i = 0; i < rows;++i)
1075 out_first.row_end(t,k,i+size)-size,border,out_first.row_begin(t,k,i+size),size);
1077 out_first.row_end(t,k+(slices+size),i+size)-size,border,out_first.row_begin(t,k+(slices+size),
1080 for(std::size_t j = 0; j < cols;++j)
1083 out_first.col_end(t,k,j+size)-size,border,out_first.col_begin(t,k,j+size),size);
1085 out_first.col_end(t,k+(slices+size),j+size)-size,border,out_first.col_begin(t,k+(slices+size),
1090 for(std::size_t k = 0; k < (slices + 2*size); ++k)
1092 for(std::size_t i = 0; i < size;++i)
1095 out_first.row_end(t,k,i)-size,border,out_first.row_begin(t,k,i),size);
1097 out_first.row_begin(t,k, i + (rows + size))+size,
1098 out_first.row_end(t,k,i + (rows + size))-size,border,
1099 out_first.row_begin(t,k,i + (rows + size)),size);
1150 template<
typename _II,
typename _OI>
1153 typedef typename std::iterator_traits<_II>::iterator_category _Category;
1190 template <
typename _II,
typename _OI>
1193 const std::size_t b_size = 1)
1196 typedef typename std::iterator_traits<_II>::iterator_category _Category;
1228 template<
typename Container1,
1229 typename Container2>
1233 const std::size_t border_size = 1)
1235 const std::size_t size = in.size();
1237 out.resize(size+(2u*border_size));
1238 b(in.begin(),in.end(),out.begin());
1268 template<
typename Container2d1,
1269 typename Container2d2>
1273 const std::size_t border_size = 1)
1275 const std::size_t rows = in.rows();
1276 const std::size_t cols = in.cols();
1278 out.resize(rows+(2u*border_size),cols+(2u*border_size));
1279 b(in.upper_left(),in.bottom_right(),out.upper_left());
1311 template<
typename Container3d1,
1312 typename Container3d2>
1316 const std::size_t border_size = 1)
1318 const std::size_t slices = in.slices();
1319 const std::size_t rows = in.rows();
1320 const std::size_t cols = in.cols();
1322 out.resize(slices+ (2u*border_size),
1323 rows + (2u*border_size),
1324 cols + (2u*border_size));
1325 b(in.front_upper_left(),in.back_bottom_right(),out.front_upper_left());
1358 template<
typename Container4d1,
1359 typename Container4d2>
1363 const std::size_t border_size = 1)
1365 const std::size_t slabs = in.slabs();
1366 const std::size_t slices = in.slices();
1367 const std::size_t rows = in.rows();
1368 const std::size_t cols = in.cols();
1370 out.resize(slabs + (2u*border_size),
1371 slices+ (2u*border_size),
1372 rows + (2u*border_size),
1373 cols + (2u*border_size));
1374 b(in.first_front_upper_left(),in.last_back_bottom_right(),out.first_front_upper_left());
1380 #endif //SLIP_BORDER_TREATMENT_HPP
UpdateBorder(const slip::BORDER_TREATMENT border, const std::size_t size=1)
Initializes the paramaters of the UpdateBorder functor.
void update_border(_II first, _II last, const slip::BORDER_TREATMENT border, const std::size_t b_size=1)
Updates the border of the range [first,last) according to b_size and border condition: border...
Generic fill border functor: fill border of 1d, 2d or 3d iterator ranges.
Generic add border functor: adds border of 1d, 2d or 3d iterator ranges.
FillBorder()
Initializes the paramaters of the FillBorder functor. The size of border size_ is egal to 1...
void operator()(_II first, _II last)
Updates the border of the range [first,last) according to the parameters of the functor.
Provides a class to tag SLIP iterators.
void add_border1d(const Container1 &in, const slip::BORDER_TREATMENT border_type, Container2 &out, const std::size_t border_size=1)
Adds the border at a 1d container according to the border condition border and the border size b_size...
void add_border3d(const Container3d1 &in, const slip::BORDER_TREATMENT border_type, Container3d2 &out, const std::size_t border_size=1)
Adds the border at a 3d container according to the border condition border and the border size b_size...
void add_border4d(const Container4d1 &in, const slip::BORDER_TREATMENT border_type, Container4d2 &out, const std::size_t border_size=1)
Adds the border at a 4d container according to the border condition border and the border size b_size...
void operator()(_II first, _II last, const typename std::iterator_traits< _II >::value_type &value=typename std::iterator_traits< _II >::value_type())
Fills the border of the range [first,last) according to the parameters of the functor.
slip::BORDER_TREATMENT border_
void add_border2d(const Container2d1 &in, const slip::BORDER_TREATMENT border_type, Container2d2 &out, const std::size_t border_size=1)
Adds the border at a 2d container according to the border condition border and the border size b_size...
void copy(_II first, _II last, _OI output_first)
Copy algorithm optimized for slip iterators.
void add_border(_II first, _II last, _OI out_first, _OI out_last, const slip::BORDER_TREATMENT border, const std::size_t b_size=1)
Adds the border of the range [first,last) according to the border condtion border and the border size...
AddBorder(const slip::BORDER_TREATMENT border, const std::size_t size=1)
Initializes the paramaters of the AddBorder functor.
FillBorder(const std::size_t size)
Initializes the paramaters of the FillBorder functor.
void operator()(_II first, _II last, _OI out_first)
Adds the border of the range [first,last) according to the parameters of the functor.
slip::BORDER_TREATMENT border_
Generic update border functor: update border of 1d, 2d or 3d iterator ranges.
BORDER_TREATMENT
Choose between different border treatment modes for convolution algorithms.
void fill_border(_II first, _II last, std::size_t b_size=1, const typename std::iterator_traits< _II >::value_type &value=typename std::iterator_traits< _II >::value_type())
Fills the border of the range [first,last) with value.