/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLCore/src/ICLCore/PixelRef.h ** ** Module : ICLCore ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #pragma once #include #include #include #include #include #include #include namespace icl{ namespace core{ /// Pixel-Type class for copying image pixles to image pixels /** PixelRef instances are returned by an images operator()(int x, int y) It allows to write: Img8u a = ...; Img8u b = ...; a(5,6) = b(3,2); Furthermore it provides a list of setter functions, which allow to set up image pixels form other data types like vectors, ranges (iterator based) and even icl::FixedMatrix. Most of the functions are channel count save, i.e. they throw an ICLException if source channel count is not compatible. */ template class PixelRef{ /// Internal data std::vector m_data; public: /// Empty constructor, create a null pixel ref with 0 length inline PixelRef(){} /// returs whether this instance is null (created with the empty constructor) inline bool isNull() const { return !m_data->size(); } /// single constructor to create a pixelref instance /** This should not be used manually. Rather you should use Img's operator()(int x, int y) */ inline PixelRef(int x, int y, int width, std::vector > &data): m_data(data.size()){ int offs = x+width*y; for(unsigned int i=0;im_data[i] = data[i].get()+offs; } } /// PixelRef copy constructor (copies the reference, not the values) inline PixelRef(const PixelRef &other):m_data(other.m_data){} /// assignment operator which copies the values (most common) /** This operator allows to write imageA(x,y) = imageB(a,b); */ inline PixelRef &operator=(const PixelRef &other)throw (utils::ICLException){ ICLASSERT_THROW(other.m_data.size() == m_data.size(),utils::ICLException("incompatible channel count")); for(unsigned int i=0;i &vec)throw (utils::ICLException){ ICLASSERT_THROW(vec.size() == m_data.size(),utils::ICLException("incompatible channel count")); for(unsigned int i=0;i imageA(x,y) = Color(2,3,4); */ template inline PixelRef &operator=(const math::FixedMatrix &mat)throw (utils::ICLException){ ICLASSERT_THROW((m_data.size() == math::FixedMatrix::DIM), utils::ICLException("channel count and matrix dim are incompatible")); for(unsigned int i=0;i(mat[i]); } return *this; } /// copies image data into a std::vector inline std::vector asVec() const{ std::vector v(m_data.size()); for(unsigned int i=0;i inline void setFromRange(ForwardIterator begin, ForwardIterator end) throw (utils::ICLException){ for(unsigned int i=0;i