Image Component Library (ICL)
|
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.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 #pragma once 00032 00033 #include <ICLUtils/CompatMacros.h> 00034 #include <ICLCore/Types.h> 00035 #include <ICLUtils/Size.h> 00036 #include <ICLUtils/Point.h> 00037 #include <ICLUtils/Rect.h> 00038 #include <ICLCore/ImgIterator.h> 00039 00040 namespace icl{ 00041 namespace core{ 00042 00043 00045 00143 template<class T> 00144 class Channel{ 00145 mutable T *m_data; 00146 mutable utils::Size m_size; 00147 mutable utils::Rect m_roi; 00148 00149 public: 00151 00153 Channel():m_data(0){} 00154 00156 inline Channel(const Channel &other){ 00157 *this = other; 00158 } 00159 00161 Channel<T> &operator=(Channel<T> &other){ 00162 m_data = other.m_data; 00163 m_size = other.m_size; 00164 m_roi = other.m_roi; 00165 return *this; 00166 } 00167 00169 00172 const Channel<T> &operator=(const Channel<T> &other) const{ 00173 return *const_cast<Channel*>(this) = const_cast<Channel<T>&>(other); 00174 } 00175 00177 00182 inline T &operator()(int x, int y){ 00183 return m_data[x+m_size.width*y]; 00184 } 00185 00187 00188 inline T &operator()(const utils::Point &p){ 00189 return operator()(p.x,p.y); 00190 } 00191 00193 00194 inline const T &operator()(const utils::Point &p) const{ 00195 return operator()(p.x,p.y); 00196 } 00197 00199 00204 inline const T &operator()(int x, int y) const{ 00205 return m_data[x+m_size.width*y]; 00206 } 00207 00209 00212 inline T &operator[](int idx) { 00213 return m_data[idx]; 00214 } 00215 00217 00220 inline const T &operator[](int idx) const { 00221 return m_data[idx]; 00222 } 00223 00225 00230 template<class Vec2D> 00231 inline T operator()(const Vec2D &p) const{ 00232 float fX0 = p[0] - floor(p[0]), fX1 = 1.0 - fX0; 00233 float fY0 = p[1] - floor(p[1]), fY1 = 1.0 - fY0; 00234 const T* pLL = &operator()((int)p[0],(int)p[1]); 00235 float a = *pLL; // a b 00236 float b = *(++pLL); // c d 00237 pLL += getWidth(); 00238 float d = *pLL; 00239 float c = *(--pLL); 00240 return fX1 * (fY1*a + fY0*c) + fX0 * (fY1*b + fY0*d); 00241 } 00242 00244 typedef T* iterator; 00245 00247 typedef const T* const_iterator; 00248 00250 typedef ImgIterator<T> roi_iterator; 00251 00253 typedef const ImgIterator<T> const_roi_iterator; 00254 00256 iterator begin(){ 00257 return m_data; 00258 } 00259 00261 const_iterator begin() const{ 00262 return m_data; 00263 } 00264 00266 iterator end(){ 00267 return m_data+getDim(); 00268 } 00269 00271 const_iterator end() const{ 00272 return m_data+getDim(); 00273 } 00274 00276 inline roi_iterator beginROI(){ 00277 return roi_iterator(m_data,getWidth(),getROI()); 00278 } 00279 00281 inline const_roi_iterator beginROI() const{ 00282 return const_cast<Channel<T>*>(this)->beginROI(); 00283 } 00284 00286 00287 inline roi_iterator endROI() { 00288 return roi_iterator::create_end_roi_iterator(m_data,getWidth(),getROI()); 00289 } 00290 00292 inline const_roi_iterator endROI() const{ 00293 return const_roi_iterator::create_end_roi_iterator(m_data,getWidth(),getROI()); 00294 } 00295 00296 bool isNull() const { return !m_data; } 00297 00299 00300 inline int getWidth() const { return m_size.width; } 00301 00303 00304 inline int getHeight() const { return m_size.height; } 00305 00307 inline const utils::Size& getSize() const { return m_size; } 00308 00310 00311 inline int getDim() const { return m_size.getDim(); } 00312 00314 inline const utils::Rect &getROI() const { return m_roi; } 00315 00317 inline utils::Point getROIOffset() const { return m_roi.ul(); } 00318 00320 inline utils::Size getROISize() const { return m_roi.getSize(); } 00321 00323 inline int getROIWidth() const { return m_roi.width; } 00324 00326 inline int getROIHeight() const { return m_roi.height; } 00327 00329 inline int getROIXOffset() const { return m_roi.x; } 00330 00332 inline int getROIYOffset() const { return m_roi.y; } 00333 00335 00336 void redefineROI(const utils::Rect &newROI) const{ 00337 m_roi = newROI; 00338 } 00339 00341 friend class Img<T>; 00342 00343 private: 00345 00348 inline Channel(const T *data, const utils::Size &size, const utils::Rect &roi): 00349 m_data(data),m_size(size),m_roi(roi){} 00350 00351 inline Channel(T *data, const utils::Size &size, const utils::Rect &roi): 00352 m_data(data),m_size(size),m_roi(roi){} 00353 00354 }; 00355 00357 #define ICL_INSTANTIATE_DEPTH(D) typedef Channel<icl##D> Channel##D; 00358 ICL_INSTANTIATE_ALL_DEPTHS 00359 #undef ICL_INSTANTIATE_DEPTH 00360 00361 } // namespace core 00362 }