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.LGPL **
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/CompatMacros.h>
00035 #include <ICLUtils/BasicTypes.h>
00036 
00037 namespace icl{
00038   namespace cv{
00039     namespace region_detector_tools{
00040   
00041       template<class IteratorA, class IteratorB, class Predicate>
00042       inline void copy_if(IteratorA srcBegin, IteratorA srcEnd, IteratorB dstBegin, Predicate p){
00043         while(srcBegin != srcEnd){
00044           if(p(*srcBegin)){
00045             *dstBegin = *srcBegin;
00046             ++dstBegin;
00047           }
00048           ++srcBegin;
00049         }
00050       }
00051   
00052       template<class T>
00053       inline const T *find_first_not(const T *first,const T* last, T val){
00054         int n = (int)((last - first) >> 3);
00055         
00056         for (; n ; --n){
00057   #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
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           REGION_DETECTOR_2_ONE
00066           }
00067         switch (last - first){
00068   #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
00069           REGION_DETECTOR_2_ONE_R(7)
00070           REGION_DETECTOR_2_ONE_R(6)
00071           REGION_DETECTOR_2_ONE_R(5)
00072           REGION_DETECTOR_2_ONE_R(4)
00073           REGION_DETECTOR_2_ONE_R(3)
00074           REGION_DETECTOR_2_ONE_R(2)
00075           REGION_DETECTOR_2_ONE_R(1)
00076           case 0: default: return last;
00077         }
00078   #undef REGION_DETECTOR_2_ONE
00079   #undef REGION_DETECTOR_2_ONE_R
00080       }
00081       
00082       template<class T>
00083       inline const T *find_first_not_no_opt(const T *first,const T* last, T val){
00084         int n = (int)((last - first) >> 3);
00085         
00086         for (; n ; --n){
00087   #define REGION_DETECTOR_2_ONE if(*first != val) return first; ++first;
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           REGION_DETECTOR_2_ONE REGION_DETECTOR_2_ONE
00092           }
00093         switch (last - first){
00094   #define REGION_DETECTOR_2_ONE_R(REST) case REST: REGION_DETECTOR_2_ONE
00095           REGION_DETECTOR_2_ONE_R(7)
00096           REGION_DETECTOR_2_ONE_R(6)
00097           REGION_DETECTOR_2_ONE_R(5)
00098           REGION_DETECTOR_2_ONE_R(4)
00099           REGION_DETECTOR_2_ONE_R(3)
00100           REGION_DETECTOR_2_ONE_R(2)
00101           REGION_DETECTOR_2_ONE_R(1)
00102           case 0: default: return last;
00103         }
00104   #undef REGION_DETECTOR_2_ONE
00105   #undef REGION_DETECTOR_2_ONE_R
00106       }
00107       
00108   #define REGION_DETECTOR_2_USE_OPT_4_BYTES
00109       
00110       
00111   #ifdef REGION_DETECTOR_2_USE_OPT_4_BYTES
00112       
00113       template<>
00114       inline const icl8u *find_first_not(const icl8u *first, const icl8u *last, icl8u val){
00115   #ifdef ICL_32BIT
00116         while( first < last && (int)first & 0x3 ){
00117   #else
00118         while( first < last && (int64_t)first & 0x3 ){
00119   #endif
00120           if(*first != val){
00121             return first;
00122           }
00123           ++first;
00124         }
00125         if(first >= last) return first;
00126         
00127         unsigned int n = (last-first)/4;
00128         const icl32u *p32 = find_first_not(reinterpret_cast<const icl32u*>(first),
00129                                            reinterpret_cast<const icl32u*>(first)+n,
00130                                            (icl32u)(val | (val<<8) | (val<<16) | (val<<24)) );
00131         const icl8u *p8u = reinterpret_cast<const icl8u*>(p32);
00132         while(p8u < last && *p8u == val) ++p8u;
00133         return p8u;
00134         //  return find_first_not_no_opt(reinterpret_cast<const icl8u*>(p32),last,val);
00135       }
00136   #endif
00137   
00138     }
00139   } // namespace cv
00140 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines