MultiLayerImage.h

Go to the documentation of this file.
00001 // -*- c-basic-offset: 4 -*-
00024 #ifndef _MULTILAYERIMAGE_H
00025 #define _MULTILAYERIMAGE_H
00026 
00027 #include <vector>
00028 
00029 namespace vigra_ext {
00030 
00036 template<class Image, class Mask>
00037 struct MultiLayerImage
00038 {
00039 
00040         
00041     
00042 public:
00043 
00044     typedef typename Image::value_type      image_value_type;
00045     typedef typename Image::traverser       image_traverser;
00046     typedef typename Image::const_traverser const_image_traverser;
00047     typedef typename Image::Accessor        ImageAccessor;
00048     typedef typename Image::ConstAccessor   ConstImageAccessor;
00049     
00050     typedef typename Mask::value_type       mask_value_type;
00051     typedef typename Mask::traverser        mask_traverser;
00052     typedef typename Mask::const_traverser  const_mask_traverser;
00053     typedef typename Mask::Accessor         MaskAccessor;
00054     typedef typename Mask::ConstAccessor    ConstMaskAccessor;
00055 
00056 private:
00057     typedef typename std::vector<ROIImage<Image, Mask>*> LayerVector;
00058     typedef typename LayerVector::iterator LayerIterator;
00059     typedef typename LayerVector::const_iterator ConstLayerIterator;
00060 
00061     typedef typename std::vector<image_value_type> value_type;
00062 
00063 public:    
00064     MultiLayerImage()
00065     {
00066 
00067     }
00068 
00069     ~MultiLayerImage()
00070     {
00071         for (LayerIterator it = m_layers.begin(); it != m_layers.end();
00072              ++it)
00073         {
00074             delete (*it);
00075         }
00076     }
00077 
00078     unsigned int layers()
00079     {
00080         return m_layers.size();
00081     }
00082 
00083     ROIImage<Image, Mask> & appendLayer()
00084     {
00085         ROIImage<Image, Mask> * l =new ROIImage<Image, Mask>;
00086         m_layers.push_back(l);
00087         return *l;
00088     }
00089 
00090     void removeLayer(unsigned int i)
00091     {
00092         ROIImage<Image, Mask> * old = m_layers[i];
00093         m_layers.erase(m_layers.begin() + i);
00094         delete old;
00095     }
00096 
00098     vigra::Rect2D boundingBox()
00099     {
00100         vigra::Rect2D res;
00101         LayerIterator it = m_layers.begin();
00102         if (it == m_layers.end()) {
00103             return res;
00104         }
00105         res = (*it)->boundingBox();
00106         it++;
00107         while(it != m_layers.end()) {
00108            res |= (*it)->boundingBox();
00109            ++it;
00110         }
00111         return res;
00112     }
00113     
00114 
00115     ROIImage<Image, Mask> & GetLayer(unsigned int i);
00116 
00125     template <class ImgIter, class MaskIter>
00126     void getCut(int x, int y, 
00127                 ImgIter image_iter, MaskIter mask_iter) const
00128     {
00129         mask_value_type m;
00130         for (ConstLayerIterator it = m_layers.begin(); it != m_layers.end();
00131              ++it)
00132         {
00133             m = (*it)->getMask(x,y);
00134             (*mask_iter) = m;
00135             (*image_iter) = (*it)->operator()(x,y);
00136             ++mask_iter;
00137             ++image_iter;
00138         }
00139     }
00140 
00141 protected:
00143     LayerVector m_layers;
00144 };
00145 
00146 
00150 } //namespace
00151 
00152 #endif // _MULTILAYERIMAGE_H

Generated on Wed Sep 17 01:25:39 2014 for Hugintrunk by  doxygen 1.3.9.1