36#ifndef VIGRA_CELLIMAGE_HXX
37#define VIGRA_CELLIMAGE_HXX
39#include <vigra/basicimage.hxx>
40#include <vigra/pixelneighborhood.hxx>
47enum CellType { CellTypeRegion = 0,
51 CellTypeVertexOrLine = 4,
52 CellTypeErrorOrLine = 5 };
57typedef unsigned int CellLabel;
64 friend struct CellPixelSerializer;
68 CellPixel(CellType type, CellLabel label = 0)
69 : typeLabel_((label << 2) | type)
72 inline CellType type()
const
73 {
return (CellType)(typeLabel_ & 3); }
74 inline void setType(CellType type)
75 { typeLabel_ = (label() << 2) | type; }
76 inline void setType(CellType type, CellLabel label)
77 { typeLabel_ = label << 2 | type; }
79 inline CellLabel label()
const
80 {
return typeLabel_ >> 2; }
81 inline void setLabel(CellLabel label)
82 { typeLabel_ = label << 2 | type(); }
83 inline void setLabel(CellLabel label, CellType type)
84 { typeLabel_ = label << 2 | type; }
86 bool operator==(CellPixel
const & rhs)
const
87 {
return typeLabel_ == rhs.typeLabel_; }
89 bool operator!=(CellPixel
const & rhs)
const
90 {
return typeLabel_ != rhs.typeLabel_; }
93typedef BasicImage<CellPixel> CellImage;
96 CellImageEightCirculator;
101struct CellPixelSerializer
103 int operator()(CellPixel
const &p)
const
108 CellPixel operator()(
int i)
const
111 result.typeLabel_ = i;
119template<
class VALUE_TYPE = CellType>
122 typedef VALUE_TYPE value_type;
123 typedef VALUE_TYPE result_type;
125 template<
class Iterator>
126 value_type operator()(
const Iterator &it)
const
131 template<
class Iterator>
132 void set(value_type type,
const Iterator &it)
const
138typedef TypeAccessor<unsigned char> TypeAsByteAccessor;
140typedef TypeAccessor<> CellTypeAccessor;
144 typedef CellLabel value_type;
146 template<
class Iterator>
147 CellLabel operator()(
const Iterator &it)
const
152 template<
class Iterator>
153 void set(CellLabel label,
const Iterator &it)
const
159template<CellType type>
162 typedef CellLabel value_type;
164 template<
class Iterator>
165 void set(CellLabel label,
const Iterator &it)
const
167 it->setLabel(label, type);
171template<CellType type>
172struct CellTypeEquals :
public std::unary_function<CellType, bool>
174 bool operator()(CellType t)
const
179 template<
class Iterator>
180 bool operator()(
const Iterator &it)
const
182 return it->type() == type;
186struct CellMask :
public std::unary_function<vigra::cellimage::CellPixel, bool>
188 vigra::cellimage::CellPixel maskPixel_;
190 CellMask(vigra::cellimage::CellPixel maskPixel)
191 : maskPixel_(maskPixel)
194 template<
class Iterator>
195 bool operator()(
const Iterator &it)
const
197 return *it == maskPixel_;
204template<
class VALUETYPE>
207 typedef VALUETYPE value_type;
208 typedef VALUETYPE argument_type;
209 typedef VALUETYPE result_type;
211 RelabelFunctor(VALUETYPE oldValue, VALUETYPE newValue)
212 : oldValue_(oldValue),
216 VALUETYPE operator()(VALUETYPE value)
const
218 return (value == oldValue_) ? newValue_ : value;
221 VALUETYPE oldValue_, newValue_;
232template <
class EndIterator,
class Accessor,
class Functor>
233void inspectCell(EndIterator endIterator, Accessor a, Functor & f)
235 for(; endIterator.inRange(); ++endIterator)
239template <
class EndIterator,
class Functor>
240void inspectCell(EndIterator endIterator, Functor & f)
242 for(; endIterator.inRange(); ++endIterator)
249template <
class SrcEndIterator,
class SrcAccessor,
250 class DestEndIterator,
class DestAccessor,
class Functor>
251void transformCell(SrcEndIterator srcEndIterator, SrcAccessor sa,
252 DestEndIterator destEndIterator, DestAccessor da,
255 for(; srcEndIterator.inRange(); ++srcEndIterator, ++destEndIterator)
256 da.set(f(sa(srcEndIterator)), destEndIterator);
259template <
class SrcEndIterator,
class DestEndIterator,
class Functor>
260void transformCell(SrcEndIterator srcEndIterator,
261 DestEndIterator destEndIterator,
264 for(; srcEndIterator.inRange(); ++srcEndIterator, ++destEndIterator)
265 *destEndIterator = f(*srcEndIterator);
Class for a single RGB value.
Definition rgbvalue.hxx:128