Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Channel.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   : ICLCore/src/ICLCore/Channel.h                          **
00010 ** Module : ICLCore                                                **
00011 ** Authors: Christof Elbrechter                                    **
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 #pragma once
00032 
00033 #include <ICLCore/Types.h>
00034 #include <ICLUtils/Size.h>
00035 #include <ICLUtils/Rect.h>
00036 #include <ICLCore/ImgIterator.h>
00037 
00038 namespace icl{
00039   namespace core{
00040   
00041   
00043 
00141     template<class T>
00142     class Channel{
00143       mutable T *m_data;   
00144       mutable utils::Size m_size;
00145       mutable utils::Rect m_roi;
00146       
00147       public:
00149 
00151       Channel():m_data(0){}
00152   
00154       inline Channel(const Channel &other){
00155         *this = other;      
00156       }    
00157   
00159       Channel<T> &operator=(Channel<T> &other){
00160         m_data = other.m_data;
00161         m_size = other.m_size;
00162         m_roi = other.m_roi;
00163         return *this;
00164       }
00165   
00167 
00170       const Channel<T> &operator=(const Channel<T> &other) const{
00171         return *const_cast<Channel*>(this) = const_cast<Channel<T>&>(other);
00172       }
00173   
00175 
00180       inline T &operator()(int x, int y){ 
00181         return m_data[x+m_size.width*y]; 
00182       }
00183       
00185 
00190       inline const T &operator()(int x, int y) const{  
00191         return m_data[x+m_size.width*y]; 
00192       }
00193       
00195 
00198       inline T &operator[](int idx) { 
00199         return m_data[idx]; 
00200       }
00201       
00203 
00206       inline const T &operator[](int idx) const { 
00207         return m_data[idx]; 
00208       }
00209   
00211 
00216       template<class Vec2D>
00217       inline T operator()(const Vec2D &p) const{
00218         float fX0 = p[0] - floor(p[0]), fX1 = 1.0 - fX0;
00219         float fY0 = p[1] - floor(p[1]), fY1 = 1.0 - fY0;
00220         const T* pLL = &operator()((int)p[0],(int)p[1]);
00221         float a = *pLL;        //  a b
00222         float b = *(++pLL);    //  c d
00223         pLL += getWidth();
00224         float d = *pLL;
00225         float c = *(--pLL);
00226         return fX1 * (fY1*a + fY0*c) + fX0 * (fY1*b + fY0*d);
00227       }
00228   
00230       typedef T* iterator;
00231   
00233       typedef const T* const_iterator;
00234   
00236       typedef ImgIterator<T> roi_iterator;
00237   
00239       typedef const ImgIterator<T> const_roi_iterator;
00240       
00242       iterator begin(){
00243         return m_data;
00244       }
00245       
00247       const_iterator begin() const{
00248         return m_data;
00249       }
00250   
00252       iterator end(){
00253         return m_data+getDim();
00254       }
00255   
00257       const_iterator end() const{
00258         return m_data+getDim();
00259       }
00260   
00262       inline roi_iterator beginROI(){
00263         return roi_iterator(m_data,getWidth(),getROI());
00264       } 
00265   
00267       inline const_roi_iterator beginROI() const{
00268         return const_cast<Channel<T>*>(this)->beginROI();
00269       } 
00270       
00272 
00273       inline roi_iterator endROI() {
00274         return roi_iterator::create_end_roi_iterator(m_data,getWidth(),getROI());
00275       }
00276   
00278       inline const_roi_iterator endROI() const{
00279         return const_roi_iterator::create_end_roi_iterator(m_data,getWidth(),getROI());
00280       }
00281   
00282       bool isNull() const { return !m_data; }
00283       
00285 
00286       inline int getWidth() const { return m_size.width; }
00287   
00289 
00290       inline int getHeight() const { return m_size.height; }
00291   
00293       inline const utils::Size& getSize() const { return m_size; }
00294       
00296 
00297       inline int getDim() const { return m_size.getDim(); }
00298       
00300       inline const utils::Rect &getROI() const { return m_roi; }
00301   
00303       inline utils::Point getROIOffset() const { return m_roi.ul(); }
00304   
00306       inline utils::Size getROISize() const { return m_roi.getSize(); }
00307   
00309       inline int getROIWidth() const { return m_roi.width; }
00310   
00312       inline int getROIHeight() const { return m_roi.height; }
00313   
00315       inline int getROIXOffset() const { return m_roi.x; }
00316   
00318       inline int getROIYOffset() const { return m_roi.y; }
00319   
00321 
00322       void redefineROI(const utils::Rect &newROI) const{
00323         m_roi = newROI;
00324       }
00325       
00327       friend class Img<T>;
00328   
00329       private:    
00331 
00334       inline Channel(const T *data, const utils::Size &size, const utils::Rect &roi):
00335       m_data(data),m_size(size),m_roi(roi){}
00336   
00337       inline Channel(T *data, const utils::Size &size, const utils::Rect &roi):
00338       m_data(data),m_size(size),m_roi(roi){}
00339   
00340     };
00341     
00343   #define ICL_INSTANTIATE_DEPTH(D) typedef Channel<icl##D> Channel##D;
00344     ICL_INSTANTIATE_ALL_DEPTHS
00345   #undef ICL_INSTANTIATE_DEPTH
00346 
00347   } // namespace core
00348 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines