Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RegionDetectorTools.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLCV/src/ICLCV/RegionDetectorTools.h                  **
00010 ** Module : ICLCV                                                  **
00011 ** Authors: Christof Elbrechter, Erik Weitnauer                    **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.GPL  **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 
00032 #pragma once
00033 
00034 #include <ICLUtils/BasicTypes.h>
00035 
00036 namespace icl{
00037   namespace cv{
00038     namespace region_detector_tools{
00039   
00040       template<class IteratorA, class IteratorB, class Predicate>
00041       inline void copy_if(IteratorA srcBegin, IteratorA srcEnd, IteratorB dstBegin, Predicate p){
00042         while(srcBegin != srcEnd){
00043           if(p(*srcBegin)){
00044             *dstBegin = *srcBegin;
00045             ++dstBegin;
00046           }
00047           ++srcBegin;
00048         }
00049       }
00050   
00051       template<class T>
00052       inline const T *find_first_not(const T *first,const T* last, T val){
00053         int n = (int)((last - first) >> 3);
00054         
00055         for (; n ; --n){
00056   #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
00057           REGION_DETECTOR_2_ONE 
00058           REGION_DETECTOR_2_ONE 
00059           REGION_DETECTOR_2_ONE 
00060           REGION_DETECTOR_2_ONE 
00061           REGION_DETECTOR_2_ONE 
00062           REGION_DETECTOR_2_ONE 
00063           REGION_DETECTOR_2_ONE 
00064           REGION_DETECTOR_2_ONE
00065           }
00066         switch (last - first){
00067   #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
00068           REGION_DETECTOR_2_ONE_R(7)
00069           REGION_DETECTOR_2_ONE_R(6)
00070           REGION_DETECTOR_2_ONE_R(5)
00071           REGION_DETECTOR_2_ONE_R(4)
00072           REGION_DETECTOR_2_ONE_R(3)
00073           REGION_DETECTOR_2_ONE_R(2)
00074           REGION_DETECTOR_2_ONE_R(1)
00075           case 0: default: return last;
00076         }
00077   #undef REGION_DETECTOR_2_ONE
00078   #undef REGION_DETECTOR_2_ONE_R
00079       }
00080       
00081       template<class T>
00082       inline const T *find_first_not_no_opt(const T *first,const T* last, T val){
00083         int n = (int)((last - first) >> 3);
00084         
00085         for (; n ; --n){
00086   #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
00087           REGION_DETECTOR_2_ONE REGION_DETECTOR_2_ONE 
00088           REGION_DETECTOR_2_ONE REGION_DETECTOR_2_ONE
00089           REGION_DETECTOR_2_ONE REGION_DETECTOR_2_ONE
00090           REGION_DETECTOR_2_ONE REGION_DETECTOR_2_ONE
00091           }
00092         switch (last - first){
00093   #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
00094           REGION_DETECTOR_2_ONE_R(7)
00095           REGION_DETECTOR_2_ONE_R(6)
00096           REGION_DETECTOR_2_ONE_R(5)
00097           REGION_DETECTOR_2_ONE_R(4)
00098           REGION_DETECTOR_2_ONE_R(3)
00099           REGION_DETECTOR_2_ONE_R(2)
00100           REGION_DETECTOR_2_ONE_R(1)
00101           case 0: default: return last;
00102         }
00103   #undef REGION_DETECTOR_2_ONE
00104   #undef REGION_DETECTOR_2_ONE_R
00105       }
00106       
00107   #define REGION_DETECTOR_2_USE_OPT_4_BYTES
00108       
00109       
00110   #ifdef REGION_DETECTOR_2_USE_OPT_4_BYTES
00111       
00112       template<>
00113       inline const icl8u *find_first_not(const icl8u *first, const icl8u *last, icl8u val){
00114   #ifdef ICL_32BIT
00115         while( first < last && (int)first & 0x3 ){
00116   #else
00117         while( first < last && (int64_t)first & 0x3 ){
00118   #endif
00119           if(*first != val){
00120             return first;
00121           }
00122           ++first;
00123         }
00124         if(first >= last) return first;
00125         
00126         unsigned int n = (last-first)/4;
00127         const icl32u *p32 = find_first_not(reinterpret_cast<const icl32u*>(first),
00128                                            reinterpret_cast<const icl32u*>(first)+n,
00129                                            (icl32u)(val | (val<<8) | (val<<16) | (val<<24)) );
00130         const icl8u *p8u = reinterpret_cast<const icl8u*>(p32);
00131         while(p8u < last && *p8u == val) ++p8u;
00132         return p8u;
00133         //  return find_first_not_no_opt(reinterpret_cast<const icl8u*>(p32),last,val);
00134       }
00135   #endif
00136   
00137     }
00138   } // namespace cv
00139 }
00140 
00141 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines