Image Component Library (ICL)
RegionDetectorTools.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLCV/src/ICLCV/RegionDetectorTools.h **
10 ** Module : ICLCV **
11 ** Authors: Christof Elbrechter, Erik Weitnauer **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 
32 #pragma once
33 
34 #include <ICLUtils/CompatMacros.h>
35 #include <ICLUtils/BasicTypes.h>
36 
37 namespace icl{
38  namespace cv{
39  namespace region_detector_tools{
40 
41  template<class IteratorA, class IteratorB, class Predicate>
42  inline void copy_if(IteratorA srcBegin, IteratorA srcEnd, IteratorB dstBegin, Predicate p){
43  while(srcBegin != srcEnd){
44  if(p(*srcBegin)){
45  *dstBegin = *srcBegin;
46  ++dstBegin;
47  }
48  ++srcBegin;
49  }
50  }
51 
52  template<class T>
53  inline const T *find_first_not(const T *first,const T* last, T val){
54  int n = (int)((last - first) >> 3);
55 
56  for (; n ; --n){
57  #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
66  }
67  switch (last - first){
68  #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
76  case 0: default: return last;
77  }
78  #undef REGION_DETECTOR_2_ONE
79  #undef REGION_DETECTOR_2_ONE_R
80  }
81 
82  template<class T>
83  inline const T *find_first_not_no_opt(const T *first,const T* last, T val){
84  int n = (int)((last - first) >> 3);
85 
86  for (; n ; --n){
87  #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
92  }
93  switch (last - first){
94  #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
102  case 0: default: return last;
103  }
104  #undef REGION_DETECTOR_2_ONE
105  #undef REGION_DETECTOR_2_ONE_R
106  }
107 
108  #define REGION_DETECTOR_2_USE_OPT_4_BYTES
109 
110 
111  #ifdef REGION_DETECTOR_2_USE_OPT_4_BYTES
112 
113  template<>
114  inline const icl8u *find_first_not(const icl8u *first, const icl8u *last, icl8u val){
115  #ifdef ICL_32BIT
116  while( first < last && (int)first & 0x3 ){
117  #else
118  while( first < last && (int64_t)first & 0x3 ){
119  #endif
120  if(*first != val){
121  return first;
122  }
123  ++first;
124  }
125  if(first >= last) return first;
126 
127  unsigned int n = (last-first)/4;
128  const icl32u *p32 = find_first_not(reinterpret_cast<const icl32u*>(first),
129  reinterpret_cast<const icl32u*>(first)+n,
130  (icl32u)(val | (val<<8) | (val<<16) | (val<<24)) );
131  const icl8u *p8u = reinterpret_cast<const icl8u*>(p32);
132  while(p8u < last && *p8u == val) ++p8u;
133  return p8u;
134  // return find_first_not_no_opt(reinterpret_cast<const icl8u*>(p32),last,val);
135  }
136  #endif
137 
138  }
139  } // namespace cv
140 }
void copy_if(IteratorA srcBegin, IteratorA srcEnd, IteratorB dstBegin, Predicate p)
Definition: RegionDetectorTools.h:42
#define REGION_DETECTOR_2_ONE
undocument this line if you encounter any issues!
Definition: Any.h:37
Ipp8u icl8u
8Bit unsigned integer type for the ICL
Definition: BasicTypes.h:64
#define REGION_DETECTOR_2_ONE_R(REST)
const T * find_first_not_no_opt(const T *first, const T *last, T val)
Definition: RegionDetectorTools.h:83
const T * find_first_not(const T *first, const T *last, T val)
Definition: RegionDetectorTools.h:53
uint32_t icl32u
32bit unsigned integer type for the ICL
Definition: BasicTypes.h:88